Differences

This shows you the differences between two versions of the page.

Link to this comparison view

polymorphic [2012/04/02 12:12]
srdjan.lukovic [GUI Code]
polymorphic [2012/07/09 10:52] (current)
srdjan.lukovic [GUI Code]
Line 1: Line 1:
-====== Polymorphic Sample ====== +====== Polymorphic Form ====== 
-This sample demonstrates how GUI can change depending on the class of selected object. Selecting bank adviser from combo-box will add additional form field (//Bank Name//).+ 
 +**Polymorhpic Form** is a [[SOLoist Sample Applications|SOLoist sample application]] that demonstrates how a form can change depending on the type of the selected object that is provided on the form's input pin. 
 + 
 +Selecting a //Bank Adviser// object (as a subkind of //Person//) from the combo box on the left will display a details form with an additional field //Bank Name//
 + 
 +The implementation uses a //GUIConformsToFilter// component that selects one of the panels in a deck to show, according to the type of the object provided on its input pin.
  
 ==== Live example ==== ==== Live example ====
Line 6: Line 11:
 [[http://soloistdemo.org/SampleApplications/polymorphic.html]]\\ [[http://soloistdemo.org/SampleApplications/polymorphic.html]]\\
 [[http://soloistdemo.org/SampleApplications/oql?q=SELECT+p%2C+p.name%2C+p.gender%2C+p.age%2C+p.dateOfBirth%2C+p.height%2C+p.isMarried%2C+p.photo%2C+p.rootFolder%0D%0AFROM+Person+p&f=html | OQL Query: Persons]] [[http://soloistdemo.org/SampleApplications/oql?q=SELECT+p%2C+p.name%2C+p.gender%2C+p.age%2C+p.dateOfBirth%2C+p.height%2C+p.isMarried%2C+p.photo%2C+p.rootFolder%0D%0AFROM+Person+p&f=html | OQL Query: Persons]]
 +|{{screen:polymorphic.png?250}}|
  
 ===== UML Model ===== ===== UML Model =====
-{{bankadvisers.png}}+{{polymorphic.png}}
 ===== Business Logic Code ===== ===== Business Logic Code =====
 None. None.
Line 16: Line 22:
 package rs.sol.sampleapps; package rs.sol.sampleapps;
  
-import rs.sol.sampleapps.gui.GUIPersonDetails; 
 import rs.sol.soloist.helpers.init.DefaultContextInit; import rs.sol.soloist.helpers.init.DefaultContextInit;
 import rs.sol.soloist.helpers.init.Initializer; import rs.sol.soloist.helpers.init.Initializer;
 import rs.sol.soloist.helpers.init.InitializerFailedException; import rs.sol.soloist.helpers.init.InitializerFailedException;
-import rs.sol.soloist.server.builtindomains.builtindatatypes.Text; 
 import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent; import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent;
 +import rs.sol.soloist.server.guiconfiguration.components.GUIDeckComponent;
 import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent; import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent;
 import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent; import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent;
 import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding; import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding;
-import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUICollectionInput; +import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIEdit;
-import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIComboWidget;+
 import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIElementComponent; import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIElementComponent;
-import rs.sol.soloist.server.guiconfiguration.layout.VerticalAlignment;+import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIInput; 
 +import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIConformsToFilter;
 import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIFindAllInstancesSAPComponent; import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIFindAllInstancesSAPComponent;
 import rs.sol.soloist.server.server.SoloistServiceServlet; import rs.sol.soloist.server.server.SoloistServiceServlet;
  
-public enum PersonCombo implements Initializer{ +public enum Polymorphic implements Initializer 
- +{
  INSTANCE;  INSTANCE;
   
Line 40: Line 45:
  {  {
  GUIApplicationComponent page = new GUIApplicationComponent();  GUIApplicationComponent page = new GUIApplicationComponent();
- page.name.set(Text.fromString("PersonCombo")); + page.setName("Polymorphic"); 
  SoloistServiceServlet.registerApplication(page);  SoloistServiceServlet.registerApplication(page);
- page.context.set(DefaultContextInit.getRoot());+ page.setContext(DefaultContextInit.getRoot());
   
  GUIPanelComponent root = GUIPanelComponent.createFlow(page);  GUIPanelComponent root = GUIPanelComponent.createFlow(page);
   
- GUILabelComponent title = GUILabelComponent.create(root, "Dynamic Panel"); + GUILabelComponent title = GUILabelComponent.create(root, "Polymorphic"); 
- title.styleName.set(Text.fromString("titleStyle"));+ title.setStyle("titleStyle");
   
  GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root);  GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root);
- topPanel.styleName.set(Text.fromString("topPanel")); + topPanel.setStyle("topPanel"); 
-  +  
- GUIPanelComponent horizontal = GUIPanelComponent.createHorizontal(topPanelVerticalAlignment.TOP);+ GUIPanelComponent wrap = GUIPanelComponent.createFlow(topPanel); 
 +  
 + GUILabelComponent.create(wrap, "Choose person:")
 +  
 + GUIFindAllInstancesSAPComponent allPersons = GUIFindAllInstancesSAPComponent.create(wrap, Person.CLASSIFIER); 
 + GUIInput comboBox = GUIInput.createCombo(wrap); 
 + GUIComponentBinding.create(allPersons.opValue(), comboBox.ipCollection()); 
 +  
 + GUIDeckComponent deck = GUIDeckComponent.create(wrap); 
 +  
 + GUIPanelComponent personDetailsTable = GUIPanelComponent.createTable(deck); 
 + createPersonsDetails(comboBoxpersonDetailsTable); 
 +  
 + GUIPanelComponent bankAdviserDetailsTable = GUIPanelComponent.createTable(deck); 
 + int row = createPersonsDetails(comboBox, bankAdviserDetailsTable); 
 + GUILabelComponent.create(bankAdviserDetailsTable, "Bank Name: ", row, 0); 
 + GUIEdit nameEditor = GUIEdit.createField(bankAdviserDetailsTable, BankAdviser.PROPERTIES.bank, row++, 1); 
 + GUIComponentBinding.create(comboBox.opValue(), nameEditor.ipElement()); 
 +  
 + // Is the selected object an instance of the BankAdviser class? 
 + GUIConformsToFilter isItBankAdviser = GUIConformsToFilter.create(deck, BankAdviser.CLASSIFIER); 
 + GUIComponentBinding.create(comboBox.opValue(), isItBankAdviser.ipInput()); 
 + GUIComponentBinding.create(isItBankAdviser.opYes(), bankAdviserDetailsTable.ipShow()); 
 + GUIComponentBinding.create(isItBankAdviser.opNo(), personDetailsTable.ipShow()); 
 +
 + 
 + private int createPersonsDetails(GUIElementComponent comboBox, GUIPanelComponent detailsTable) { 
 + int row = 0; 
 + GUILabelComponent.create(detailsTable, "Name: ", row, 0); 
 + GUIEdit nameEditor = GUIEdit.createField(detailsTable, Person.PROPERTIES.name, row++, 1); 
 +  
 + GUILabelComponent.create(detailsTable, "Gender: ", row, 0); 
 + GUIEdit genderEditor = GUIEdit.createField(detailsTable, Person.PROPERTIES.gender, row++, 1); 
 +  
 + GUILabelComponent.create(detailsTable, "Age: ", row, 0); 
 + GUIEdit ageEditor = GUIEdit.createField(detailsTable, Person.PROPERTIES.age, row++, 1);
   
- GUILabelComponent.create(horizontal, "Choose person:").styleName.set(Text.fromString("margin3"));+ GUILabelComponent.create(detailsTable, "Date of birth: ", row, 0)
 + GUIEdit dateOfBirthEditor = GUIEdit.createField(detailsTable, Person.PROPERTIES.dateOfBirth, row++, 1);
   
- GUIFindAllInstancesSAPComponent allPersons = GUIFindAllInstancesSAPComponent.create(horizontalPerson.FQ_TYPE_NAME); + GUILabelComponent.create(detailsTable"Height [m]: ";, row0); 
- GUIElementComponent comboBox = GUIElementComponent.createInput(horizontalnew GUIComboWidget()new GUICollectionInput()); + GUIEdit heightEditor = GUIEdit.createField(detailsTablePerson.PROPERTIES.height, row++, 1);
- GUIComponentBinding.create(allPersons.valueGUICollectionInput.get(comboBox).collection);+
   
- GUIPersonDetails pd = new GUIPersonDetails(); + GUILabelComponent.create(detailsTable, "Is married: ", row, 0); 
- pd.parent.set(horizontal);+ GUIEdit isMarriedEditor = GUIEdit.createField(detailsTable, Person.PROPERTIES.isMarried, row++, 1);
   
- GUIComponentBinding.create(comboBox.valuepd.element);+ GUIComponentBinding.create(comboBox.opValue()nameEditor.ipElement()); 
 + GUIComponentBinding.create(comboBox.opValue(), genderEditor.ipElement()); 
 + GUIComponentBinding.create(comboBox.opValue(), ageEditor.ipElement()); 
 + GUIComponentBinding.create(comboBox.opValue(), dateOfBirthEditor.ipElement()); 
 + GUIComponentBinding.create(comboBox.opValue(), heightEditor.ipElement()); 
 + GUIComponentBinding.create(comboBox.opValue(), isMarriedEditor.ipElement())
 + return row;
  }  }
 } }
 </code> </code>
Print/export