====== Bank Advisers ====== **Bank Advisers** is a [[SOLoist Sample Applications|SOLoist sample application]] that combines several features presented in the previous examples, most notably [[Edit Person's Details|Edit Object Details]], [[Person Tables|Grids]], [[Persons and Bank Accounts|CRUD]], and [[Association Editor|Selection List]]. All objects of the class //BankAdviser// are shown in a grid. Attribute slots of these objects can be edited in the grid fields. Objects of the class // BankAdviser// can be created or deleted with the command buttons. Selecting one //Bank Adviser// from the grid will enable the checkbox editor in the Clients list. Ticking a checkbox next to a //Person// object in the list will make that person a client of the selected //Bank Adviser//. ==== Live example ==== [[http://soloistdemo.org/SampleApplications/bankadvisers.html]]\\ [[http://soloistdemo.org/SampleApplications/oql?q=SELECT+b%2C+b.name%2C+b.gender%2C+b.age%2C+b.dateOfBirth%2C+b.height%2C+b.isMarried%2C+b.photo%2C+b.rootFolder%2C+b.bank%2C+b.myDepartment%0D%0AFROM+BankAdviser+b&f=html | OQL Query: Bank Advisers]] |{{screen:bankadvisers.png?250}}| ===== UML Model ===== {{bankadvisers.png}} ===== Business Logic Code ===== public void execute() // ------------- // ------------- { // --------- List allPersons = QueryUtils.getAllInstances(Person.CLASSIFIER); List justPersons = new ArrayList(); for (Person person : allPersons) { if (person instanceof BankAdviser) { continue; } justPersons.add(person); } fetchedPersons.set(justPersons); // --------- } ===== 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.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.GUIComponentBinding; import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIEdit; 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.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.setName("BankAdvisers"); SoloistServiceServlet.registerApplication(page); GUIContext context = createContextAndStyles(); page.setContext(context); GUIPanelComponent root = GUIPanelComponent.createFlow(page); GUILabelComponent title = GUILabelComponent.create(root, "Bank Advisers"); title.setStyle("titleStyle"); GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root); topPanel.setStyle("topPanel"); GUIFindAllInstancesSAPComponent allBankAdvisers = GUIFindAllInstancesSAPComponent.create(root, BankAdviser.CLASSIFIER); // Column components GUIEdit nameEditor = GUIEdit.createField(null, Person.PROPERTIES.name); GUIEdit bankNameEditor = GUIEdit.createField(null, BankAdviser.PROPERTIES.bank); GUIEdit genderEditor = GUIEdit.createField(null, Person.PROPERTIES.gender); GUIEdit ageEditor = GUIEdit.createField(null, Person.PROPERTIES.age); GUIEdit isMarriedEditor = GUIEdit.createField(null, Person.PROPERTIES.isMarried); // Column header texts and oredering of column components GUIInput editableTable = GUIInput.createTable(topPanel, "Bank Adviser", "Name", "Bank Name", "Age", "Gender", "Is married"); editableTable.setColumnComponents(nameEditor, bankNameEditor, ageEditor, genderEditor, isMarriedEditor); editableTable.setMinRows(3); // min rows to show if there is no data in the table GUIComponentBinding.create(allBankAdvisers.opValue(), editableTable.ipCollection()); GUIPanelComponent buttonsPanel = GUIPanelComponent.createHorizontal(topPanel, VerticalAlignment.MIDDLE); buttonsPanel.setStyle("margin3"); CmdCreateObjectOfClass createCmd = new CmdCreateObjectOfClass(); createCmd.setClass(BankAdviser.CLASSIFIER); GUIButtonComponent createAdviserButton = GUIButtonComponent.create(buttonsPanel, "Create Bank Adviser", createCmd); CmdDestroyObject destroyCmd = new CmdDestroyObject(); destroyCmd.setType(BankAdviser.CLASSIFIER); GUIButtonComponent destroyAdviserButton = GUIButtonComponent.create(buttonsPanel, "Delete Bank Adviser", destroyCmd); GUIComponentBinding.create(editableTable.opValue(), destroyAdviserButton, CmdDestroyObject.PROPERTIES.input); GUIComponentBinding.create(createAdviserButton.opCommandExecuted(), allBankAdvisers.ipRefresh()); // this is to tell SAP to read advisers again GUIComponentBinding.create(destroyAdviserButton.opCommandExecuted(), allBankAdvisers.ipRefresh()); // this is to tell SAP to read advisers again GUILabelComponent clientsLabel = GUILabelComponent.create(topPanel, "Clients"); clientsLabel.setStyle("padding3"); GUIEdit clients = GUIEdit.createList(topPanel, BankAdviser.PROPERTIES.myClients); clients.setSize("250px", "300px"); clients.setStyle("listEditor"); // invisible command: fetches all persons, but not bank advisers GUICommandComponent allPersons = GUICommandComponent.create(root, new FetchPersonsOnly(), PerformImmediately.NOTHING); GUIComponentBinding.create(allPersons, FetchPersonsOnly.PROPERTIES.fetchedPersons, clients.ipCollection()); GUIComponentBinding.create(editableTable.opValue(), clients.ipElement()); GUIComponentBinding.create(page.opStart(), allPersons.ipClick()); } private GUIContext createContextAndStyles() { GUIContext context = new GUIContext(); DefaultContextInit.getRoot().addContext(context); // This is 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; } }