This is an old revision of the document!


Person's Tables

This sample presents Person's details in tabular view.

Live example

UML Model

Business Logic Code

None.

GUI Code

package rs.sol.sampleapps;
 
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.builtindatatypes.Boolean;
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.GUILabelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent;
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.GUISlotEditorKind;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUITableWidget;
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 PersonsTable implements Initializer{
 
	INSTANCE;
 
	@Override
	public void init() throws InitializerFailedException
	{
		GUIApplicationComponent page = new GUIApplicationComponent();
		page.name.set(Text.fromString("PersonsTable")); 
		SoloistServiceServlet.registerApplication(page);
		GUIContext context = createContextAndStyles();
		page.context.set(context);
 
		GUIPanelComponent root = GUIPanelComponent.createVertical(page);
 
		GUILabelComponent title = GUILabelComponent.create(root, "Persons Table");
		title.styleName.set(Text.fromString("titleStyle"));
 
		GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root);
		topPanel.styleName.set(Text.fromString("topPanel"));
 
		GUIFindAllInstancesSAPComponent allPersons = GUIFindAllInstancesSAPComponent.create(root, Person.FQ_TYPE_NAME); // this component fetches all persons
 
		GUILabelComponent.create(topPanel, "Editable fields").styleName.set(Text.fromString("subtitle"));
		createPersonsTable(topPanel, allPersons, false, false);
		GUILabelComponent.create(topPanel, "Readonly fields").styleName.set(Text.fromString("subtitle"));
		createPersonsTable(topPanel, allPersons, true, false);
		GUILabelComponent.create(topPanel, "Readonly fields as labels").styleName.set(Text.fromString("subtitle"));
		createPersonsTable(topPanel, allPersons, true, true);
	}
 
	private void createPersonsTable(GUIPanelComponent root, GUIFindAllInstancesSAPComponent allPersons, boolean readonly, boolean displayAsLabel)
	{
		// column components
		GUIElementComponent nameEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.name);
		GUISlotEditorKind.get(nameEditor).readOnly.set(Boolean.valueOf(readonly));
		GUISlotEditorKind.get(nameEditor).displayAsLabel.set(Boolean.valueOf(displayAsLabel));
 
		GUIElementComponent genderEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.gender);
		GUISlotEditorKind.get(genderEditor).readOnly.set(Boolean.valueOf(readonly));
		GUISlotEditorKind.get(genderEditor).displayAsLabel.set(Boolean.valueOf(displayAsLabel));
 
		GUIElementComponent ageEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.age);
		GUISlotEditorKind.get(ageEditor).readOnly.set(Boolean.valueOf(readonly));
		GUISlotEditorKind.get(ageEditor).displayAsLabel.set(Boolean.valueOf(displayAsLabel));
 
		GUIElementComponent dateOfBirthEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.dateOfBirth);
		GUISlotEditorKind.get(dateOfBirthEditor).readOnly.set(Boolean.valueOf(readonly));
		GUISlotEditorKind.get(dateOfBirthEditor).displayAsLabel.set(Boolean.valueOf(displayAsLabel));
 
		GUIElementComponent heightEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.height);
		GUISlotEditorKind.get(heightEditor).readOnly.set(Boolean.valueOf(readonly));
		GUISlotEditorKind.get(heightEditor).displayAsLabel.set(Boolean.valueOf(displayAsLabel));
 
		GUIElementComponent isMarriedEditor = GUIElementComponent.createSlotEditor(null, Person.PROPERTIES.isMarried);
		GUISlotEditorKind.get(isMarriedEditor).readOnly.set(Boolean.valueOf(readonly));
		GUISlotEditorKind.get(isMarriedEditor).displayAsLabel.set(Boolean.valueOf(displayAsLabel));
 
		// column header texts and oredering of column components
		GUITableWidget gtw = GUITableWidget.create(new String[]{"Person", "Name", "Gender", "Age", "Date of Birth", "Height", "Is Married"}, 
				new GUIComponent[]{nameEditor, genderEditor, ageEditor, dateOfBirthEditor, heightEditor, isMarriedEditor});
 
		gtw.minRows.set(Integer.valueOf(3)); // min rows to show if there is no data in the table
		GUIElementComponent editableTable = GUIElementComponent.create(root, new GUIInputKind(), gtw, new GUICollectionInput()); // the very table
 
		GUIComponentBinding.create(allPersons.value, GUICollectionInput.get(editableTable).collection);
	}
 
	private GUIContext createContextAndStyles()
	{
		GUIContext context = new GUIContext();
		context.supercontext.set(DefaultContextInit.getRoot());
 
		GUIObjectSetting person = GUIObjectSetting.create(context, Person.CLASSIFIER);
		GUITextFeature.createName(person, Person.PROPERTIES.name);
		GUIPictureFeature.createSmallIcon(person, "images/icons/person.png");
		return context;
	}
}
Print/export