Dynamic Panel

Dynamic Panel is a SOLoist sample application that demonstrates a panel with dynamic contents that are programmatically created by the backend UI code triggered from the client, using GUIDynamicContentPanel.

Selecting an object of Person from the combo box will show its details on the right. The details will be bordered by a red or a blue line, depending on the gender of the selected person. In addition, the details will have some additional information if the selected person is a Bank Adviser.

The backend processing that creates the contents of a dynamic panel is triggerred when the dynamic panel gets a new value on its input pin.

Live example

UML Model

Business Logic Code

None.

GUI Code

package rs.sol.sampleapps;
 
import rs.sol.sampleapps.gui.GUIPersonDetails;
import rs.sol.soloist.helpers.init.DefaultContextInit;
import rs.sol.soloist.helpers.init.Initializer;
import rs.sol.soloist.helpers.init.InitializerFailedException;
import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent;
import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIInput;
import rs.sol.soloist.server.guiconfiguration.layout.VerticalAlignment;
import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIFindAllInstancesSAPComponent;
import rs.sol.soloist.server.server.SoloistServiceServlet;
 
public enum PersonCombo implements Initializer{
 
	INSTANCE;
 
	@Override
	public void init() throws InitializerFailedException
	{
		GUIApplicationComponent page = new GUIApplicationComponent();
		page.setName("PersonCombo");
		SoloistServiceServlet.registerApplication(page);
		page.setContext(DefaultContextInit.getRoot());
 
		GUIPanelComponent root = GUIPanelComponent.createFlow(page);
 
		GUILabelComponent title = GUILabelComponent.create(root, "Dynamic Panel");
		title.setStyle("titleStyle");
 
		GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root);
		topPanel.setStyle("topPanel");
 
		GUIPanelComponent horizontal = GUIPanelComponent.createHorizontal(topPanel, VerticalAlignment.TOP);
 
		GUILabelComponent.create(horizontal, "Choose person:").setStyle("margin3");
		GUIFindAllInstancesSAPComponent allPersons = GUIFindAllInstancesSAPComponent.create(horizontal, Person.CLASSIFIER);
		GUIInput comboBox = GUIInput.createCombo(horizontal);
		GUIComponentBinding.create(allPersons.opValue(), comboBox.ipCollection());
 
		GUIPersonDetails pd = new GUIPersonDetails();
		horizontal.add(pd);
 
		GUIComponentBinding.create(comboBox.opValue(), pd.ipElement());
	}
}
GUIPersonDetails.java
    @Override
	protected GUIContainerComponent getDynamicContents(IElement el) {
		GUIPanelComponent rootPanel = GUIPanelComponent.createFlow(null);
		rootPanel.setStyle("person_details");
 
		Person p = (Person) el;
		if (p == null) {
			GUILabelComponent.create(rootPanel, "No Persons selected.");
			return rootPanel;
		}
 
		GUIPanelComponent table = GUIPanelComponent.createTable(rootPanel);
 
		int row = 0;
		if (p instanceof BankAdviser) {
			GUILabelComponent.create(table, "Bank: ", row, 0);
			GUILabelComponent.create(table, Text.stringValue(((BankAdviser) p).bank), row++, 1);
		}
 
		GUILabelComponent.create(table, "Name: ", row, 0);
		GUILabelComponent.create(table, Text.stringValue(p.name), row++, 1);
		GUILabelComponent.create(table, "Is married? ", row, 0);
		GUILabelComponent.create(table, p.isMarried.val().toBoolean() ? "YES" : "NO", row++, 1);
 
		if (Gender.MALE.equals(p.gender.val())) {
			GUILabelComponent.create(table, "Age: ", row, 0);
			GUILabelComponent.create(table, p.age.val().toString(), row++, 1);
			table.setStyle("male");
		} else {
			table.setStyle("female");
		}
 
		return rootPanel;
	}
Print/export