summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java149
1 files changed, 149 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java
new file mode 100644
index 0000000..a83a389
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java
@@ -0,0 +1,149 @@
1package org.yocto.bc.ui.wizards;
2import java.util.Map;
3
4import org.eclipse.jface.viewers.ISelectionChangedListener;
5import org.eclipse.jface.viewers.SelectionChangedEvent;
6import org.eclipse.jface.wizard.WizardPage;
7import org.eclipse.swt.events.ModifyEvent;
8import org.eclipse.swt.events.ModifyListener;
9import org.eclipse.swt.events.SelectionEvent;
10import org.eclipse.swt.events.SelectionListener;
11import org.eclipse.swt.widgets.Composite;
12import org.eclipse.swt.widgets.Event;
13import org.eclipse.swt.widgets.Listener;
14
15public abstract class FiniteStateWizardPage extends WizardPage {
16 protected Map model = null;
17 protected FiniteStateWizard wizard = null;
18 private static boolean previousState = false;
19 /**
20 * @param pageName
21 */
22 protected FiniteStateWizardPage(String name, Map model) {
23 super(name);
24 this.model = model;
25 this.setPageComplete(false);
26 }
27
28 /*
29 * (non-Javadoc)
30 *
31 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
32 */
33 public abstract void createControl(Composite parent);
34
35 protected void setModelWizard() {
36 if (wizard == null) {
37 wizard = (FiniteStateWizard)FiniteStateWizardPage.this.getWizard();
38 }
39 }
40
41 /**
42 * Add page validation logic here. Returning <code>true</code> means that
43 * the page is complete and the user can go to the next page.
44 *
45 * @return
46 */
47 protected abstract boolean validatePage();
48
49 /**
50 * This method should be implemented by ModelWizardPage classes. This method
51 * is called after the <code>validatePage()</code> returns successfully.
52 * Update the model with the contents of the controls on the page.
53 */
54 protected abstract void updateModel();
55
56 /**
57 * Helper method to see if a field has some sort of text in it.
58 * @param value
59 * @return
60 */
61 protected boolean hasContents(String value) {
62 if (value == null || value.length() == 0) {
63 return false;
64 }
65
66 return true;
67 }
68
69 /**
70 * This method is called right before a page is displayed.
71 * This occurs on user action (Next/Back buttons).
72 */
73 public abstract void pageDisplay();
74
75 /**
76 * This method is called on the concrete WizardPage after the user has
77 * gone to the page after.
78 */
79 public abstract void pageCleanup();
80
81 /* (non-Javadoc)
82 * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
83 */
84 public void setVisible(boolean arg0) {
85
86 if (!arg0 && previousState) {
87 pageCleanup();
88 } else if (arg0 && !previousState) {
89 pageDisplay();
90 } else if (arg0 && previousState) {
91 pageDisplay();
92 }
93
94 previousState = arg0;
95
96 super.setVisible(arg0);
97 }
98
99 public class ValidationListener implements SelectionListener, ModifyListener, Listener, ISelectionChangedListener {
100
101 /*
102 * (non-Javadoc)
103 *
104 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
105 */
106 public void widgetSelected(SelectionEvent e) {
107 validate();
108 }
109
110 /*
111 * (non-Javadoc)
112 *
113 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
114 */
115 public void widgetDefaultSelected(SelectionEvent e) {
116 }
117
118 /*
119 * (non-Javadoc)
120 *
121 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
122 */
123 public void modifyText(ModifyEvent e) {
124 validate();
125 }
126
127 public void validate() {
128 if (validatePage()) {
129 updateModel();
130 setPageComplete(true);
131 return;
132 }
133
134 setPageComplete(false);
135 }
136
137 /* (non-Javadoc)
138 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
139 */
140 public void handleEvent(Event event) {
141
142 validate();
143 }
144
145 public void selectionChanged(SelectionChangedEvent event) {
146 validate();
147 }
148 }
149}