comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.d @ 99:5d5bd660917f

build some databind snippets
author Frank Benoit <benoit@tionex.de>
date Wed, 22 Apr 2009 18:59:26 +0200
parents 6086085e153d
children e884642ad36e
comparison
equal deleted inserted replaced
98:48d4ee626868 99:5d5bd660917f
8 * Contributors: 8 * Contributors:
9 * Boris Bokowski, IBM Corporation - initial API and implementation 9 * Boris Bokowski, IBM Corporation - initial API and implementation
10 * Matthew Hall - bug 260329 10 * Matthew Hall - bug 260329
11 *******************************************************************************/ 11 *******************************************************************************/
12 12
13 package org.eclipse.jface.examples.databinding.snippets; 13 module org.eclipse.jface.examples.databinding.snippets.Snippet014WizardDialog;
14
15 import java.lang.all;
14 16
15 import java.util.Date; 17 import java.util.Date;
16 18
17 import org.eclipse.core.databinding.DataBindingContext; 19 import org.eclipse.core.databinding.DataBindingContext;
18 import org.eclipse.core.databinding.UpdateValueStrategy; 20 import org.eclipse.core.databinding.UpdateValueStrategy;
40 /** 42 /**
41 * Creates and opens a wizard dialog with two simple wizard pages. 43 * Creates and opens a wizard dialog with two simple wizard pages.
42 */ 44 */
43 public class Snippet014WizardDialog { 45 public class Snippet014WizardDialog {
44 46
45 static class FirstWizardPage extends WizardPage { 47 static class FirstWizardPage extends WizardPage {
46 private final class SingleDigitValidator implements IValidator { 48 private final class SingleDigitValidator implements IValidator {
47 public IStatus validate(Object value) { 49 public IStatus validate(Object value) {
48 Integer i = (Integer) value; 50 Integer i = (Integer) value;
49 if (i == null) { 51 if (i == null) {
50 return ValidationStatus 52 return ValidationStatus
51 .info("Please enter a value."); 53 .info("Please enter a value.");
52 } 54 }
53 if (i.intValue() < 0 || i.intValue() > 9) { 55 if (i.intValue() < 0 || i.intValue() > 9) {
54 return ValidationStatus 56 return ValidationStatus
55 .error("Value must be between 0 and 9."); 57 .error("Value must be between 0 and 9.");
56 } 58 }
57 return ValidationStatus.ok(); 59 return ValidationStatus.ok();
58 } 60 }
59 } 61 }
60 62
61 protected FirstWizardPage() { 63 protected FirstWizardPage() {
62 super("First", "First Page", ImageDescriptor 64 super("First", "First Page", ImageDescriptor
63 .createFromImage(new Image(Display.getDefault(), 16, 16))); 65 .createFromImage(new Image(Display.getDefault(), 16, 16)));
64 } 66 }
65 67
66 public void createControl(Composite parent) { 68 public void createControl(Composite parent) {
67 DataBindingContext dbc = new DataBindingContext(); 69 DataBindingContext dbc = new DataBindingContext();
68 WizardPageSupport.create(this, dbc); 70 WizardPageSupport.create(this, dbc);
69 Composite composite = new Composite(parent, SWT.NONE); 71 Composite composite = new Composite(parent, SWT.NONE);
70 Label label = new Label(composite, SWT.NONE); 72 Label label = new Label(composite, SWT.NONE);
71 label.setText("Enter a number between 0 and 9:"); 73 label.setText("Enter a number between 0 and 9:");
72 Text text = new Text(composite, SWT.BORDER); 74 Text text = new Text(composite, SWT.BORDER);
73 75
74 dbc.bindValue( 76 dbc.bindValue(
75 SWTObservables.observeText(text, SWT.Modify), 77 SWTObservables.observeText(text, SWT.Modify),
76 ((SampleWizard) getWizard()).getModel().intValue, 78 ((SampleWizard) getWizard()).getModel().intValue,
77 new UpdateValueStrategy().setAfterConvertValidator(new SingleDigitValidator()), 79 new UpdateValueStrategy().setAfterConvertValidator(new SingleDigitValidator()),
78 null); 80 null);
79 81
80 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( 82 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(
81 composite); 83 composite);
82 setControl(composite); 84 setControl(composite);
83 } 85 }
84 } 86 }
85 87
86 static class SecondWizardPage extends WizardPage { 88 static class SecondWizardPage extends WizardPage {
87 protected SecondWizardPage() { 89 protected SecondWizardPage() {
88 super("Second", "Second Page", ImageDescriptor 90 super("Second", "Second Page", ImageDescriptor
89 .createFromImage(new Image(Display.getDefault(), 16, 16))); 91 .createFromImage(new Image(Display.getDefault(), 16, 16)));
90 } 92 }
91 93
92 public void createControl(Composite parent) { 94 public void createControl(Composite parent) {
93 DataBindingContext dbc = new DataBindingContext(); 95 DataBindingContext dbc = new DataBindingContext();
94 WizardPageSupport.create(this, dbc); 96 WizardPageSupport.create(this, dbc);
95 Composite composite = new Composite(parent, SWT.NONE); 97 Composite composite = new Composite(parent, SWT.NONE);
96 Label label = new Label(composite, SWT.NONE); 98 Label label = new Label(composite, SWT.NONE);
97 label.setText("Enter a date:"); 99 label.setText("Enter a date:");
98 Text text = new Text(composite, SWT.BORDER); 100 Text text = new Text(composite, SWT.BORDER);
99 101
100 dbc.bindValue( 102 dbc.bindValue(
101 SWTObservables.observeText(text, SWT.Modify), 103 SWTObservables.observeText(text, SWT.Modify),
102 ((SampleWizard) getWizard()).getModel().dateValue); 104 ((SampleWizard) getWizard()).getModel().dateValue);
103 105
104 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( 106 GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(
105 composite); 107 composite);
106 setControl(composite); 108 setControl(composite);
107 } 109 }
108 } 110 }
109 111
110 static class SampleWizardModel { 112 static class SampleWizardModel {
111 IObservableValue intValue = new WritableValue(null, Integer.class); 113 IObservableValue intValue = new WritableValue(null, Integer.class);
112 IObservableValue dateValue = new WritableValue(null, Date.class); 114 IObservableValue dateValue = new WritableValue(null, Date.class);
113 } 115 }
114 116
115 static class SampleWizard extends Wizard { 117 static class SampleWizard extends Wizard {
116 118
117 private SampleWizardModel model = new SampleWizardModel(); 119 private SampleWizardModel model = new SampleWizardModel();
118 120
119 public void addPages() { 121 public void addPages() {
120 addPage(new FirstWizardPage()); 122 addPage(new FirstWizardPage());
121 addPage(new SecondWizardPage()); 123 addPage(new SecondWizardPage());
122 } 124 }
123 125
124 public SampleWizardModel getModel() { 126 public SampleWizardModel getModel() {
125 return model; 127 return model;
126 } 128 }
127 129
128 public String getWindowTitle() { 130 public String getWindowTitle() {
129 return "Data Binding Snippet014"; 131 return "Data Binding Snippet014";
130 } 132 }
131 133
132 public boolean performFinish() { 134 public bool performFinish() {
133 return true; 135 return true;
134 } 136 }
135 137
136 } 138 }
137 139
138 public static void main(String[] args) { 140 public static void main(String[] args) {
139 Display display = new Display(); 141 Display display = new Display();
140 142
141 // note that the "runWithDefault" will be done for you if you are using 143 // note that the "runWithDefault" will be done for you if you are using
142 // the 144 // the
143 // Workbench as opposed to just JFace/SWT. 145 // Workbench as opposed to just JFace/SWT.
144 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { 146 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
145 public void run() { 147 public void run() {
146 IWizard wizard = new SampleWizard(); 148 IWizard wizard = new SampleWizard();
147 WizardDialog dialog = new WizardDialog(null, wizard); 149 WizardDialog dialog = new WizardDialog(null, wizard);
148 dialog.open(); 150 dialog.open();
149 // The SWT event loop 151 // The SWT event loop
150 Display display = Display.getCurrent(); 152 Display display = Display.getCurrent();
151 while (dialog.getShell() != null 153 while (dialog.getShell() != null
152 && !dialog.getShell().isDisposed()) { 154 && !dialog.getShell().isDisposed()) {
153 if (!display.readAndDispatch()) { 155 if (!display.readAndDispatch()) {
154 display.sleep(); 156 display.sleep();
155 } 157 }
156 } 158 }
157 } 159 }
158 }); 160 });
159 } 161 }
160 162
161 } 163 }
164 void main( String[] args ){
165 Snippet014WizardDialog.main(args);
166 }