Differences
This shows you the differences between two versions of the page.
wizard [2012/03/31 21:41] srdjan.lukovic created |
wizard [2012/07/09 10:46] (current) srdjan.lukovic [GUI Code] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Wizard Sample ====== | + | ====== Wizard ====== |
- | This sample demonstrates simple wizard. | + | |
+ | **Wizard** is a [[SOLoist Sample Applications|SOLoist sample application]] that demonstrates a classical wizard pattern. Introduces the dialog component (//GUIDialogComponent//). | ||
==== Live example ==== | ==== Live example ==== | ||
[[http://soloistdemo.org/SampleApplications/wizard.html]] | [[http://soloistdemo.org/SampleApplications/wizard.html]] | ||
+ | |{{screen:wizard.png?250}}| | ||
===== UML Model ===== | ===== UML Model ===== | ||
Line 14: | Line 16: | ||
===== GUI Code ===== | ===== GUI Code ===== | ||
<code java> | <code java> | ||
- | //... | + | package rs.sol.sampleapps.wizard; |
+ | |||
+ | 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.GUIButtonComponent; | ||
+ | import rs.sol.soloist.server.guiconfiguration.components.GUIDialogComponent; | ||
+ | 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.layout.FlowLayout; | ||
+ | import rs.sol.soloist.server.server.SoloistServiceServlet; | ||
+ | |||
+ | public enum WizardSample implements Initializer { | ||
+ | |||
+ | INSTANCE; | ||
+ | |||
+ | @Override | ||
+ | public void init() throws InitializerFailedException { | ||
+ | GUIApplicationComponent application = new GUIApplicationComponent(); | ||
+ | application.setName("WizardSample"); | ||
+ | SoloistServiceServlet.registerApplication(application); | ||
+ | |||
+ | GUIPanelComponent root = GUIPanelComponent.createFlow(application); | ||
+ | |||
+ | GUILabelComponent title = GUILabelComponent.create(root, "Wizard"); | ||
+ | title.setStyle("titleStyle"); | ||
+ | |||
+ | GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root); | ||
+ | topPanel.setStyle("topPanel"); | ||
+ | |||
+ | // background panel which is shown when wizard dialog pops up, aids visual effect | ||
+ | GUIPanelComponent blackScreen = GUIPanelComponent.createFlow(root); | ||
+ | blackScreen.setStyle("blackScreen"); | ||
+ | |||
+ | GUIDialogComponent dialog = new GUIDialogComponent(); | ||
+ | dialog.setModal(true); | ||
+ | application.addDialog(dialog); | ||
+ | dialog.setCaption("SOLoist Wizard"); | ||
+ | |||
+ | GUIPanelComponent dialogPanel = GUIPanelComponent.createFlow(dialog); | ||
+ | dialogPanel.setStyle("dialogPanel"); | ||
+ | |||
+ | Wizard wizard = new Wizard(dialogPanel, dialog, blackScreen); | ||
+ | |||
+ | // Panels which will be shown as steps in wizard | ||
+ | GUIPanelComponent p1 = new GUIPanelComponent(); | ||
+ | p1.setLayout(new FlowLayout()); | ||
+ | GUIPanelComponent p2 = new GUIPanelComponent(); | ||
+ | p2.setLayout(new FlowLayout()); | ||
+ | GUIPanelComponent p3 = new GUIPanelComponent(); | ||
+ | p3.setLayout(new FlowLayout()); | ||
+ | |||
+ | // The content can arbitrarily complex | ||
+ | GUILabelComponent.create(p1, "1/3").setStyle("largeText"); | ||
+ | GUILabelComponent.create(p2, "2/3").setStyle("largeText"); | ||
+ | GUILabelComponent.create(p3, "3/3").setStyle("largeText"); | ||
+ | |||
+ | // Add pages to wizard in order | ||
+ | wizard.addPage(p1); | ||
+ | wizard.addPage(p2); | ||
+ | wizard.addPage(p3); | ||
+ | |||
+ | // Generate the wizard GUI | ||
+ | wizard.generate(); | ||
+ | |||
+ | GUIButtonComponent cmdStart = GUIButtonComponent.create(topPanel, "Start wizard"); | ||
+ | |||
+ | GUIComponentBinding.create(cmdStart.opClick(), wizard.getBufferDarkenBackground().ipSend()); | ||
+ | GUIComponentBinding.create(cmdStart.opClick(), wizard.getFirstChild().ipShowInParent()); | ||
+ | GUIComponentBinding.create(cmdStart.opClick(), wizard.getFirstButtonChild().ipShowInParent()); | ||
+ | |||
+ | GUIComponentBinding.create(cmdStart.opClick(), dialog.ipShow()); | ||
+ | GUIComponentBinding.create(cmdStart.opResult(), dialogPanel.ipRelay1()); | ||
+ | |||
+ | GUIComponentBinding.create(cmdStart.opResult(), p1.ipRelay1()); | ||
+ | GUIComponentBinding.create(cmdStart.opResult(), p2.ipRelay1()); | ||
+ | GUIComponentBinding.create(cmdStart.opResult(), p3.ipRelay1()); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </code> | ||
+ | |||
+ | <code java> | ||
+ | package rs.sol.sampleapps.wizard; | ||
+ | |||
+ | import java.util.ArrayList; | ||
+ | import java.util.List; | ||
+ | |||
+ | import rs.sol.soloist.server.builtindomains.builtindatatypes.Text; | ||
+ | import rs.sol.soloist.server.guiconfiguration.components.GUIButtonComponent; | ||
+ | import rs.sol.soloist.server.guiconfiguration.components.GUIDeckComponent; | ||
+ | import rs.sol.soloist.server.guiconfiguration.components.GUIDialogComponent; | ||
+ | import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent; | ||
+ | import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding; | ||
+ | import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIBufferComponent; | ||
+ | |||
+ | public class Wizard { | ||
+ | |||
+ | private List<GUIPanelComponent> pages = new ArrayList<GUIPanelComponent>(); | ||
+ | private GUIDeckComponent mainDeck; | ||
+ | private GUIDeckComponent buttonDeck; | ||
+ | private GUIDialogComponent dialog; | ||
+ | private GUIBufferComponent bufferSet; | ||
+ | private GUIBufferComponent bufferRemove; | ||
+ | private GUIPanelComponent blackScreen; | ||
+ | private GUIPanelComponent rootPanel; | ||
+ | |||
+ | public Wizard(GUIPanelComponent rootPanel, GUIDialogComponent dialog, GUIPanelComponent blackScreen) { | ||
+ | this.rootPanel = rootPanel; | ||
+ | this.dialog = dialog; | ||
+ | this.blackScreen = blackScreen; | ||
+ | } | ||
+ | |||
+ | public void addPage(GUIPanelComponent page) { | ||
+ | pages.add(page); | ||
+ | } | ||
+ | |||
+ | public void generate() { | ||
+ | |||
+ | bufferSet = GUIBufferComponent.create(rootPanel, false, Text.fromString("darkenBackground")); | ||
+ | bufferRemove = GUIBufferComponent.create(rootPanel, false, Text.fromString("darkenBackground")); | ||
+ | |||
+ | GUIComponentBinding.create(bufferSet.opOutput(), blackScreen.ipAddStyle()); | ||
+ | GUIComponentBinding.create(bufferRemove.opOutput(), blackScreen.ipRemoveStyle()); | ||
+ | |||
+ | GUIPanelComponent mainPanel = GUIPanelComponent.createFlow(rootPanel); | ||
+ | GUIPanelComponent btnPanel = GUIPanelComponent.createFlow(rootPanel); | ||
+ | |||
+ | mainDeck = GUIDeckComponent.create(mainPanel); | ||
+ | mainPanel.setStyle("wizardMain"); | ||
+ | |||
+ | buttonDeck = GUIDeckComponent.create(btnPanel); | ||
+ | btnPanel.setStyle("wizardButtons"); | ||
+ | |||
+ | for (int i = 0; i < pages.size(); i++) { | ||
+ | mainDeck.add(pages.get(i)); | ||
+ | GUIPanelComponent.createFlow(buttonDeck); | ||
+ | } | ||
+ | |||
+ | for (int i = 0; i < pages.size(); i++) { | ||
+ | |||
+ | GUIPanelComponent buttonPanel = (GUIPanelComponent) buttonDeck.get(i); | ||
+ | |||
+ | GUIButtonComponent btnCancel = GUIButtonComponent.create(buttonPanel, "Cancel"); | ||
+ | btnCancel.setStyle("cancelButton"); | ||
+ | btnCancel.setConfirmationRequired(true); | ||
+ | btnCancel.setConfirmationMessage("Cancel?"); | ||
+ | |||
+ | GUIComponentBinding.create(btnCancel.opClick(), dialog.ipHide()); | ||
+ | GUIComponentBinding.create(btnCancel.opClick(), bufferRemove.ipSend()); | ||
+ | |||
+ | if (i != 0) { | ||
+ | GUIButtonComponent btnPrev = GUIButtonComponent.create(buttonPanel, "< Back"); | ||
+ | GUIComponentBinding.create(btnPrev.opClick(), mainDeck.get(i - 1).ipShow()); | ||
+ | GUIComponentBinding.create(btnPrev.opClick(), buttonDeck.get(i - 1).ipShow()); | ||
+ | btnPrev.setStyle("previousButton"); | ||
+ | } | ||
+ | |||
+ | if (i == pages.size() - 1) { | ||
+ | GUIButtonComponent btnFinish = GUIButtonComponent.create(buttonPanel, "Finish"); | ||
+ | btnFinish.setStyle("finishButton"); | ||
+ | btnFinish.setConfirmationMessage("Finish?"); | ||
+ | btnFinish.setConfirmationRequired(true); | ||
+ | GUIComponentBinding.create(btnFinish.opClick(), dialog.ipHide()); | ||
+ | GUIComponentBinding.create(btnFinish.opClick(), bufferRemove.ipSend()); | ||
+ | } else { | ||
+ | GUIButtonComponent btnNext = GUIButtonComponent.create(buttonPanel, "Next >"); | ||
+ | btnNext.setStyle("nextButton"); | ||
+ | GUIComponentBinding.create(btnNext.opClick(), mainDeck.get(i + 1).ipShow()); | ||
+ | GUIComponentBinding.create(btnNext.opClick(), buttonDeck.get(i + 1).ipShow()); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public GUIBufferComponent getBufferDarkenBackground() { | ||
+ | return bufferSet; | ||
+ | } | ||
+ | |||
+ | public GUIPanelComponent getFirstChild() { | ||
+ | return (GUIPanelComponent) mainDeck.get(0); | ||
+ | } | ||
+ | |||
+ | public GUIPanelComponent getFirstButtonChild() { | ||
+ | return (GUIPanelComponent) buttonDeck.get(0); | ||
+ | } | ||
+ | } | ||
</code> | </code> |