This is an old revision of the document!


Bank Advisers Sample

Live example

UML Model

Business Logic Code

//FetchPersonsOnly.java
public void execute() 
    // -------------<SOL id="1a6091eb-09c4-4579-8d13-14cd0d54d44c:___throw__" />
    // -------------<LOS id="1a6091eb-09c4-4579-8d13-14cd0d54d44c:___throw__" />
    {
        // ---------<SOL id="1a6091eb-09c4-4579-8d13-14cd0d54d44c:___body___" />
        List<Person> allPersons = QueryUtils.getAllInstances(Person.CLASSIFIER);
        List<Person> justPersons = new ArrayList<Person>();
        for (Person person : allPersons)
        {
			if (person instanceof BankAdviser)
			{
				continue;
			}
			justPersons.add(person);
		}
        fetchedPersons.set(justPersons);
        // ---------<LOS id="1a6091eb-09c4-4579-8d13-14cd0d54d44c:___body___" />
    }

GUI Code

package rs.sol.sampleapps;
 
import rs.sol.sampleapps.commands.FetchPersonsOnly;
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.builtindomains.builtincommands.CmdCreateObjectOfClass;
import rs.sol.soloist.server.builtindomains.builtincommands.CmdDestroyObject;
import rs.sol.soloist.server.builtindomains.builtindatatypes.Integer;
import rs.sol.soloist.server.builtindomains.builtindatatypes.Text;
import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIButtonComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUICommandComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent;
import rs.sol.soloist.server.guiconfiguration.components.PerformImmediately;
import rs.sol.soloist.server.guiconfiguration.construction.GUIComponent;
import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUICollectionInput;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIElementComponent;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIInputKind;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIListWidget;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUISlotEditorKind;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUITableWidget;
import rs.sol.soloist.server.guiconfiguration.layout.CellLayoutData;
import rs.sol.soloist.server.guiconfiguration.layout.VerticalAlignment;
import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIFindAllInstancesSAPComponent;
import rs.sol.soloist.server.guiconfiguration.style.GUIContext;
import rs.sol.soloist.server.guiconfiguration.style.GUIObjectSetting;
import rs.sol.soloist.server.guiconfiguration.style.GUIPictureFeature;
import rs.sol.soloist.server.guiconfiguration.style.GUITextFeature;
import rs.sol.soloist.server.server.SoloistServiceServlet;
 
public enum BankAdvisers implements Initializer{
 
	INSTANCE;
 
	@Override
	public void init() throws InitializerFailedException
	{
		GUIApplicationComponent page = new GUIApplicationComponent();
		page.name.set(Text.fromString("BankAdvisers")); 
		SoloistServiceServlet.registerApplication(page);
		GUIContext context = createContextAndStyles();
		page.context.set(context);
 
		GUIPanelComponent root = GUIPanelComponent.createFlow(page);
 
		GUILabelComponent title = GUILabelComponent.create(root, "Bank Advisers");
		title.styleName.set(Text.fromString("titleStyle"));
 
		GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root);
		topPanel.styleName.set(Text.fromString("topPanel"));
 
		GUIFindAllInstancesSAPComponent allBankAdvisers = GUIFindAllInstancesSAPComponent.create(root, BankAdviser.FQ_TYPE_NAME);
 
		// column components
		GUIElementComponent nameEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.name);
		GUIElementComponent bankNameEditor = GUIElementComponent.createSlotEditor(null, BankAdviser.PROPERTIES.bank);
		GUIElementComponent genderEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.gender);
		GUIElementComponent ageEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.age);
		GUIElementComponent isMarriedEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.isMarried);
 
		// column header texts and oredering of column components
		GUITableWidget gtw = GUITableWidget.create(new String[]{"Bank Adviser", "Name", "Bank Name", "Age", "Gender", "Is married"}, 
				new GUIComponent[]{nameEditor, bankNameEditor, ageEditor, genderEditor, isMarriedEditor});
 
		gtw.minRows.set(Integer.valueOf(3)); // min rows to show if there is no data in the table
		GUIElementComponent editableTable = GUIElementComponent.create(topPanel, new GUIInputKind(), gtw, new GUICollectionInput()); // the very table
 
		GUIComponentBinding.create(allBankAdvisers.value, GUICollectionInput.get(editableTable).collection);
 
		GUIPanelComponent buttonsPanel = GUIPanelComponent.createHorizontal(topPanel, VerticalAlignment.MIDDLE);
		buttonsPanel.styleName.set(Text.fromString("margin3"));
 
		CmdCreateObjectOfClass createCmd = new CmdCreateObjectOfClass();
		createCmd.className.set(Text.fromString(BankAdviser.FQ_TYPE_NAME));
		GUIButtonComponent createAdviserButton = GUIButtonComponent.create(buttonsPanel, "Create Bank Adviser", createCmd);
		CmdDestroyObject destroyCmd = new CmdDestroyObject();
		destroyCmd.type.set(Text.fromString(BankAdviser.FQ_TYPE_NAME));
		GUIButtonComponent destroyAdviserButton = GUIButtonComponent.create(buttonsPanel, "Delete Bank Adviser", destroyCmd);
 
		GUIComponentBinding.create(editableTable.value, destroyAdviserButton, CmdDestroyObject.PROPERTIES.input);
		GUIComponentBinding.create(createAdviserButton.commandExecuted, allBankAdvisers.refresh); // this is to tell SAP to read advisers again
		GUIComponentBinding.create(destroyAdviserButton.commandExecuted, allBankAdvisers.refresh); // this is to tell SAP to read advisers again
 
		GUILabelComponent.create(topPanel, "Clients").styleName.set(Text.fromString("padding3"));
 
		GUICommandComponent allPersons = GUICommandComponent.create(topPanel, new FetchPersonsOnly(), PerformImmediately.NOTHING); // invisible command: fetches all persons, but not bank advisers
		GUIElementComponent clients = GUIElementComponent.create(topPanel, GUISlotEditorKind.create(BankAdviser.PROPERTIES.myClients), new GUIListWidget(), new GUICollectionInput());
		CellLayoutData.setSize(clients, "250px", "300px");
		clients.styleName.set(Text.fromString("listEditor"));
		GUIComponentBinding.create(allPersons, FetchPersonsOnly.PROPERTIES.fetchedPersons, GUICollectionInput.get(clients).collection);
		GUIComponentBinding.create(editableTable.value, GUISlotEditorKind.get(clients).element);
		GUIComponentBinding.create(page.start, allPersons.click);
	}
 
	private GUIContext createContextAndStyles()
	{
		GUIContext context = new GUIContext();
		context.supercontext.set(DefaultContextInit.getRoot());
 
		// this how Person objects will look like in the GUI?
		GUIObjectSetting person = GUIObjectSetting.create(context, Person.CLASSIFIER);
		GUITextFeature.createName(person, Person.PROPERTIES.name);
		GUIPictureFeature.createSmallIcon(person, "images/icons/person.png");
 
		return context;
	}
}
Print/export