You are viewing the documentation for Blueriq 13. Documentation for other versions is available in our documentation directory.

In this tutorial you will learn how you can add a configurationwidget of your custom plugin to the connection manager (see below).

e

----

1. Add dependency 

Start by adding a dependency to the plugin-dev-sdk. Do this by adding the codeblock displayed below to your pom file. 

pom.xml
<dependency>
	<groupId>com.aquima</groupId>
	<artifactId>plugin-dev-sdk</artifactId>
	<version>${project.version}</version>
	<scope>provided</scope>
</dependency>

2. Create class

Open your plugin-project in your IDE and create a class named "{plugin-name}PluginWidget" in a (to-be-created) subpackage of your plugin named "widget".

3. Extend and annotate your class

Add the annotation "@AquimaConnectionSettingsWidget" to your class and let your class extend the AbstractSettingsWidget. Let your IDE add all the imports and implement the methods and constructor. If done correctly your class will look like this (note the parameterless constructor) :

package com.aquima.plugin.fileupload.widget;

import com.aquima.interactions.composer.model.Container;
import com.aquima.plugin.dev.widget.IWidgetContext;
import com.aquima.plugin.dev.widget.IWidgetEvent;
import com.aquima.plugin.dev.widget.IWidgetState;
import com.aquima.plugin.dev.widget.settings.AbstractSettingsWidget;
import com.aquima.plugin.dev.widget.settings.annotation.AquimaConnectionSettingsWidget;

@AquimaConnectionSettingsWidget
public class OtherConnectionPluginWidget extends AbstractSettingsWidget {
	
	public OtherConnectionPluginWidget() {
		super(prefix);
		// TODO Auto-generated constructor stub
	}
	@Override
	public void handleEvent(IWidgetContext context, IWidgetState state,
			IWidgetEvent event) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public Container composeContainer(IWidgetContext context, IWidgetState state) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public IWidgetState initializeState(IWidgetContext context) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public String getDisplayName() {
		// TODO Auto-generated method stub
		return null;
	}
}

4. Implementation of the widget

4.1 Constructor

The constructor is used to define the prefix of the settings used in the configuration file. In this widget the constructor will be implemented with "other.connection" as prefix.

public OtherConnectionPluginWidget(String prefix) {
	super("other.connection");
}

4.2 GetDisplayName

The method GetDisplayName is used by the widget to get its name. For this tutorial it will return "Other connection". 

@Override
public String getDisplayName() {
	return "Other connection";
}

4.3 InitializeState

InitializeState is used to initialize the widget. To keep it simple in this example a default SettingWidgetState will be created and returned.

@Override
public IWidgetState initializeState(IWidgetContext context) {
	return new SettingsWidgetState();
}

4.4 ComposeContainer

The composeContainer method creates a container and fills it with fields. For this widget a text entry box and a dropdown box will be used. The name and property of these boxes will be defined as field variables:

private static final String NAME_FIELD = "Name";
private static final String CONNECTION_FIELD = "ConnectionType";
private static final String NAME_PROPERTY = "other.connection.name";
private static final String CONNECTION_TYPE_PROPERTY = "other.connection.type";

The composeContainer method is self-explanatory 

 

@Override
public Container composeContainer(IWidgetContext context, IWidgetState state) {	
	SettingsWidgetState settingsWidgetState = (SettingsWidgetState) state;
	Container result = new Container("OtherConfig");
	result.addElement(new PlainText("Other config").presentationStyle(PresentationStyleEnum.HEADER1.value())
			.asElement());
	// create fields
	Field usernameField = new Field(NAME_FIELD, DataType.STRING, false, new MultilingualText(NAME_FIELD + " :"), new MultilingualText("explaintext"));
	DomainField connectionType = new DomainField(CONNECTION_FIELD, "Connection type", true);
	
	//get values from propertie file  
	PropertiesEncryptor properties = settingsWidgetState.getProperties();
	
	// set value to fields
	usernameField.setValue(new StringValue(properties.getProperty(NAME_PROPERTY)));
	
	for (String name : ConfigurableConnectionManager.getConnectionNames(properties.getProperties(),
			ConnectionType.CUSTOM)) {
		connectionType.addDomainValue(name);
	}
	connectionType.allowEmptyValue(false);
	connectionType.setAndGetValue(properties.getProperty(CONNECTION_TYPE_PROPERTY));
	
	// add fields to widget
	result.addElement(usernameField);
	result.addElement(connectionType.asElement());
	
	return result;
}

4.5 HandleEvent 

Handle event is used for every page event. In this widget it will be used to save the field data in the SettingsWidgetState. To do this a loop will run through every updated field and update the value.

@Override
public void handleEvent(IWidgetContext context, IWidgetState state,
		IWidgetEvent event) {
	SettingsWidgetState settingsWidgetState = (SettingsWidgetState) state;
	
	for (IField field : event.getUpdatedFields()) {
		if (field.getName().equals(CONNECTION_FIELD)) {
			settingsWidgetState.getProperties().setProperty(CONNECTION_FIELD, (String) event.getValue(field));	
		} else if (field.getName().equals(NAME_FIELD)) {
			settingsWidgetState.getProperties().setProperty(NAME_PROPERTY, (String) event.getValue(field));
		}			
	}		
}	

5. Spring initialization

After creating the custom connection settings widget it needs to be initialized by Spring. A reference to the package in the Spring Bean Configuration file will make sure this happens.

<context:component-scan base-package="com.aquima.plugin.fileupload.widget" />

6. The result

As you can see there's an text entry box to create a name and a dropdownbox to select a custom connection.

 

 

 

 

  • No labels