Mercurial > projects > dwt-samples
comparison jface/user/PopUp.d @ 171:0a21c7cabc16
presentation windows
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 26 Oct 2008 14:07:11 +0100 |
parents | cc2a8879c8b7 |
children |
comparison
equal
deleted
inserted
replaced
170:b5ce05a02738 | 171:0a21c7cabc16 |
---|---|
1 module user.PopUp; | 1 module user.PopUp; |
2 import tango.util.log.Trace; | 2 import tango.util.log.Trace; |
3 import tango.io.FileConduit; | |
4 import tango.io.Stdout; | |
5 import tango.core.Thread; | |
3 | 6 |
4 import dwt.dwthelper.utils; | 7 import dwt.dwthelper.utils; |
8 import dwt.dwthelper.FileOutputStream; | |
5 import dwt.DWT; | 9 import dwt.DWT; |
6 | 10 |
7 import dwt.layout.GridLayout; | 11 import dwt.layout.GridLayout; |
8 import dwt.layout.GridData; | 12 import dwt.layout.GridData; |
9 import dwt.layout.FillLayout; | 13 import dwt.layout.FillLayout; |
19 import dwt.widgets.Listener; | 23 import dwt.widgets.Listener; |
20 import dwt.widgets.Event; | 24 import dwt.widgets.Event; |
21 import dwt.widgets.Button; | 25 import dwt.widgets.Button; |
22 import dwt.widgets.Label; | 26 import dwt.widgets.Label; |
23 | 27 |
28 import dwtx.core.runtime.IProgressMonitor; | |
29 import dwtx.jface.operation.IRunnableWithProgress; | |
30 import dwtx.jface.preference.PreferenceStore; | |
24 import dwtx.jface.dialogs.PopupDialog; | 31 import dwtx.jface.dialogs.PopupDialog; |
25 import dwtx.jface.dialogs.ErrorDialog; | 32 import dwtx.jface.dialogs.ErrorDialog; |
26 import dwtx.jface.dialogs.MessageDialogWithToggle; | 33 import dwtx.jface.dialogs.MessageDialogWithToggle; |
27 import dwtx.jface.dialogs.MessageDialog; | 34 import dwtx.jface.dialogs.MessageDialog; |
28 import dwtx.jface.dialogs.IDialogConstants; | 35 import dwtx.jface.dialogs.IDialogConstants; |
29 import dwtx.jface.dialogs.TitleAreaDialog; | 36 import dwtx.jface.dialogs.TitleAreaDialog; |
30 import dwtx.jface.dialogs.InputDialog; | 37 import dwtx.jface.dialogs.InputDialog; |
31 import dwtx.jface.dialogs.IMessageProvider; | 38 import dwtx.jface.dialogs.IMessageProvider; |
32 import dwtx.jface.dialogs.DialogTray; | 39 import dwtx.jface.dialogs.DialogTray; |
33 import dwtx.jface.dialogs.IInputValidator; | 40 import dwtx.jface.dialogs.IInputValidator; |
41 import dwtx.jface.dialogs.DialogSettings; | |
42 import dwtx.jface.dialogs.IDialogSettings; | |
43 import dwtx.jface.dialogs.StatusDialog; | |
44 | |
45 import dwtx.jface.wizard.Wizard; | |
46 import dwtx.jface.wizard.WizardPage; | |
47 import dwtx.jface.wizard.WizardSelectionPage; | |
48 import dwtx.jface.wizard.WizardDialog; | |
34 | 49 |
35 import dwtx.jface.window.ApplicationWindow; | 50 import dwtx.jface.window.ApplicationWindow; |
36 import dwtx.core.runtime.IStatus; | 51 import dwtx.core.runtime.IStatus; |
37 import dwtx.core.runtime.Status; | 52 import dwtx.core.runtime.Status; |
38 import dwtx.core.runtime.MultiStatus; | 53 import dwtx.core.runtime.MultiStatus; |
55 with( new Button( comp, DWT.PUSH )){ | 70 with( new Button( comp, DWT.PUSH )){ |
56 addListener( DWT.Selection, dgListener( & doPopUp )); | 71 addListener( DWT.Selection, dgListener( & doPopUp )); |
57 setText( "PopUp" ); | 72 setText( "PopUp" ); |
58 } | 73 } |
59 with( new Button( comp, DWT.PUSH )){ | 74 with( new Button( comp, DWT.PUSH )){ |
75 addListener( DWT.Selection, dgListener( & doMessageDlg )); | |
76 setText( "Message DLG" ); | |
77 } | |
78 with( new Button( comp, DWT.PUSH )){ | |
60 addListener( DWT.Selection, dgListener( & doErrorDlg )); | 79 addListener( DWT.Selection, dgListener( & doErrorDlg )); |
61 setText( "Error DLG" ); | 80 setText( "Error DLG" ); |
62 } | 81 } |
63 with( new Button( comp, DWT.PUSH )){ | 82 with( new Button( comp, DWT.PUSH )){ |
64 addListener( DWT.Selection, dgListener( & doInputDlg )); | 83 addListener( DWT.Selection, dgListener( & doInputDlg )); |
69 setText( "MessageDialogWithToggle" ); | 88 setText( "MessageDialogWithToggle" ); |
70 } | 89 } |
71 with( new Button( comp, DWT.PUSH )){ | 90 with( new Button( comp, DWT.PUSH )){ |
72 addListener( DWT.Selection, dgListener( & doTitleAreaDialog )); | 91 addListener( DWT.Selection, dgListener( & doTitleAreaDialog )); |
73 setText( "TitleAreaDialog" ); | 92 setText( "TitleAreaDialog" ); |
93 } | |
94 with( new Button( comp, DWT.PUSH )){ | |
95 addListener( DWT.Selection, dgListener( & doWizard )); | |
96 setText( "Wizard" ); | |
97 } | |
98 with( new Button( comp, DWT.PUSH )){ | |
99 addListener( DWT.Selection, dgListener( & doStatusDialog )); | |
100 setText( "StatusDialog" ); | |
74 } | 101 } |
75 return comp; | 102 return comp; |
76 } | 103 } |
77 void doPopUp( Event e ){ | 104 void doPopUp( Event e ){ |
78 auto pu = new PopupDialog( | 105 auto pu = new PopupDialog( |
85 true, | 112 true, |
86 "Title", | 113 "Title", |
87 "Info line..."); | 114 "Info line..."); |
88 pu.open(); | 115 pu.open(); |
89 } | 116 } |
117 void doMessageDlg( Event e ){ | |
118 } | |
90 void doErrorDlg( Event e ){ | 119 void doErrorDlg( Event e ){ |
91 auto status = new MultiStatus( "plugin-ID", 0, "MultiStatus message", null ); | 120 auto status = new MultiStatus( "plugin-ID", 0, "Message text of the MultiStatus", null ); |
92 status.add( new Status( Status.ERROR, "plugin-ID", "Status message 'error'"/+, new RuntimeException("bla")+/ ) ); | 121 status.add( new Status( Status.ERROR, "plugin-ID", "message of an example 'error' status"/+, new RuntimeException("bla")+/ ) ); |
93 status.add( new Status( Status.WARNING, "plugin-ID", "Status message 'warning'" ) ); | 122 status.add( new Status( Status.WARNING, "plugin-ID", "message of an example 'warning' status" ) ); |
94 auto dlg = new ErrorDialog( | 123 auto dlg = new ErrorDialog( |
95 getShell(), | 124 getShell(), |
96 "Title", | 125 "ErrorDialog", |
97 "Dialog message", | 126 "Dialog message", |
98 status, | 127 status, |
99 IStatus.ERROR|IStatus.WARNING); | 128 IStatus.ERROR|IStatus.WARNING); |
100 dlg.open(); | 129 dlg.open(); |
101 } | 130 } |
102 void doMessageDialogWithToggleDlg( Event e ){ | 131 void doMessageDialogWithToggleDlg( Event e ){ |
132 auto ps = new PreferenceStore( "ps.txt" ); | |
133 auto dlg = MessageDialogWithToggle.openYesNoCancelQuestion( | |
134 getShell(), | |
135 "MessageDialogWithToggle", | |
136 "MessageDialogWithToggle with additional toggle message. " | |
137 "A preference can be controlled by this that is set to 'always' if check and 'YES' or is set to 'never' if check and NO is selected. ", | |
138 "Toggle message (e.g. Remember my decision)", | |
139 false, | |
140 ps, | |
141 "key" ); | |
142 ps.save(); | |
143 Stdout.formatln("list:" ); | |
144 ps.list(Stdout); | |
145 /+ | |
103 auto dlg = new MessageDialogWithToggle( | 146 auto dlg = new MessageDialogWithToggle( |
104 getShell(), | 147 getShell(), |
105 "Title", | 148 "Title", |
106 null, | 149 null, |
107 "Dialog message", | 150 "Dialog message", |
109 [ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL ], | 152 [ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL ], |
110 0, | 153 0, |
111 "Toggle message", | 154 "Toggle message", |
112 true); | 155 true); |
113 dlg.open(); | 156 dlg.open(); |
157 +/ | |
158 } | |
159 void doStatusDialog( Event e ){ | |
160 auto dlg = new MyStatusDialog( getShell() ); | |
161 dlg.setTitle( "StatusDialog" ); | |
162 dlg.open(); | |
114 } | 163 } |
115 void doInputDlg( Event e ){ | 164 void doInputDlg( Event e ){ |
116 auto dlg = new InputDialog( | 165 auto dlg = new InputDialog( |
117 getShell(), | 166 getShell(), |
118 "Title", | 167 "InputDialog", |
119 "Enter a positive number", | 168 "Enter a positive number", |
120 "42", | 169 "42", |
121 new class() IInputValidator{ | 170 new class() IInputValidator{ |
122 String isValid( String newText ){ | 171 String isValid( String newText ){ |
123 try{ | 172 try{ |
124 Integer.parseInt( newText ); | 173 Integer.parseInt( newText ); |
125 return null; | 174 return null; |
126 } | 175 } |
127 catch( Exception e ){ | 176 catch( Exception e ){ |
128 return "Not a valid number"; | 177 return "\"" ~ newText ~ "\" is not a valid number"; |
129 } | 178 } |
130 } | 179 } |
131 } ); | 180 } ); |
132 dlg.open(); | 181 dlg.open(); |
133 } | 182 } |
134 | 183 |
184 DialogSettings dlgsettings; | |
135 void doTitleAreaDialog( Event e ){ | 185 void doTitleAreaDialog( Event e ){ |
186 if( dlgsettings is null ){ | |
187 dlgsettings = new DialogSettings("TitleAreaDialog"); | |
188 | |
189 try{ | |
190 dlgsettings.load( "dlgsettings.txt" ); | |
191 } | |
192 catch( IOException e ){ | |
193 | |
194 } | |
195 } | |
136 auto dlg = new MyTitleAreaDialog( | 196 auto dlg = new MyTitleAreaDialog( |
137 getShell()); | 197 getShell(), dlgsettings ); |
138 dlg.open(); | 198 dlg.open(); |
139 } | 199 dlgsettings.save( "dlgsettings.txt" ); |
140 | 200 } |
201 | |
202 void doWizard( Event e ){ | |
203 auto myWizard = new MyWizard(); | |
204 auto w = new WizardDialog( getShell(), myWizard ); | |
205 w.open(); | |
206 } | |
141 } | 207 } |
142 | 208 class MyStatusDialog : StatusDialog { |
209 this( Shell parent ) { | |
210 super(parent ); | |
211 } | |
212 override void create(){ | |
213 super.create(); | |
214 updateStatus( new Status( IStatus.ERROR, "id", "the error message" ) ); | |
215 } | |
216 } | |
143 class MyTitleAreaDialog : TitleAreaDialog { | 217 class MyTitleAreaDialog : TitleAreaDialog { |
144 this( Shell shell ){ | 218 IDialogSettings settings; |
219 this( Shell shell, IDialogSettings settings ){ | |
220 this.settings = settings; | |
145 super(shell); | 221 super(shell); |
146 } | 222 } |
147 protected override void configureShell(Shell newShell){ | 223 protected override void configureShell(Shell newShell){ |
148 super.configureShell(newShell); | 224 super.configureShell(newShell); |
149 newShell.setText( "Application Name" ); | 225 newShell.setText( "Application Name" ); |
150 } | 226 } |
227 protected override IDialogSettings getDialogBoundsSettings(){ | |
228 return settings; | |
229 } | |
151 protected override bool isResizable(){ | 230 protected override bool isResizable(){ |
152 return true; | 231 return true; |
153 } | 232 } |
233 protected override int getDialogBoundsStrategy(){ | |
234 //return DIALOG_PERSISTLOCATION; | |
235 //return DIALOG_PERSISTSIZE; | |
236 return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE; | |
237 //return 0; | |
238 } | |
154 protected override Control createContents(Composite parent) { | 239 protected override Control createContents(Composite parent) { |
155 auto comp = cast(Composite) super.createContents(parent); | 240 auto comp = cast(Composite) super.createContents(parent); |
156 openTray( new MyTray() ); | 241 //openTray( new MyTray() ); |
157 setTitle( "Title" ); | 242 setTitle( "Title" ); |
158 setMessage( "A custom message", IMessageProvider.INFORMATION ); | 243 setMessage( "A custom message", IMessageProvider.INFORMATION ); |
159 return comp; | 244 return comp; |
160 } | 245 } |
161 protected override Control createDialogArea(Composite parent){ | 246 protected override Control createDialogArea(Composite parent){ |
162 auto comp = cast(Composite) super.createDialogArea(parent); | 247 auto comp = cast(Composite) super.createDialogArea(parent); |
163 //comp.setLayout( new FillLayout()); | |
164 auto lbl = new Label( comp, DWT.None ); | 248 auto lbl = new Label( comp, DWT.None ); |
165 lbl.setText( "Dialog Area" ); | 249 lbl.setText( "Dialog Area" ); |
166 auto gd = new GridData( GridData.FILL, GridData.FILL, true, false ); | 250 auto gd = new GridData( GridData.FILL, GridData.FILL, true, false ); |
167 gd.verticalIndent = 5; | 251 gd.verticalIndent = 5; |
168 gd.horizontalIndent = 5; | 252 gd.horizontalIndent = 5; |
169 lbl.setLayoutData( gd ); | 253 lbl.setLayoutData( gd ); |
170 return comp; | 254 |
255 Group grp = new Group( comp, DWT.NONE ); | |
256 grp.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, false )); | |
257 grp.setLayout( new GridLayout( 2, true )); | |
258 grp.setText( "Select" ); | |
259 | |
260 with( new Button( grp, DWT.RADIO )){ | |
261 addListener( DWT.Selection, dgListener( &selNone )); | |
262 setText( "None" ); | |
263 } | |
264 with( new Button( grp, DWT.RADIO )){ | |
265 addListener( DWT.Selection, dgListener( &selDescription )); | |
266 setText( "Description" ); | |
267 } | |
268 with( new Button( grp, DWT.RADIO )){ | |
269 addListener( DWT.Selection, dgListener( &selInfo )); | |
270 setText( "Info" ); | |
271 } | |
272 with( new Button( grp, DWT.RADIO )){ | |
273 addListener( DWT.Selection, dgListener( &selWarning )); | |
274 setText( "Warning" ); | |
275 } | |
276 with( new Button( grp, DWT.RADIO )){ | |
277 addListener( DWT.Selection, dgListener( &selError )); | |
278 setText( "Error" ); | |
279 } | |
280 | |
281 return comp; | |
282 } | |
283 private void selNone( Event e ){ | |
284 setMessage(null); | |
285 } | |
286 private void selDescription( Event e ){ | |
287 setMessage("Description which can also be a bit\nlonger.", IMessageProvider.NONE ); | |
288 } | |
289 private void selInfo( Event e ){ | |
290 setMessage("Information", IMessageProvider.INFORMATION ); | |
291 } | |
292 private void selWarning( Event e ){ | |
293 setMessage("Warning", IMessageProvider.WARNING ); | |
294 } | |
295 private void selError( Event e ){ | |
296 setMessage("Error", IMessageProvider.ERROR ); | |
171 } | 297 } |
172 } | 298 } |
173 class MyTray : DialogTray { | 299 class MyTray : DialogTray { |
174 protected Control createContents(Composite parent){ | 300 protected Control createContents(Composite parent){ |
175 auto comp = new Composite(parent, DWT.NONE ); | 301 auto comp = new Composite(parent, DWT.NONE ); |
183 } | 309 } |
184 return comp; | 310 return comp; |
185 } | 311 } |
186 } | 312 } |
187 | 313 |
314 class Page1 : WizardPage { | |
315 this( char[] title ){ | |
316 super(title); | |
317 setTitle( title ); | |
318 setMessage( "A description of the wizard page", IMessageProvider.NONE ); | |
319 } | |
320 public void createControl( Composite parent ){ | |
321 Composite comp = new Composite( parent, DWT.NONE ); | |
322 comp.setLayout( new FillLayout() ); | |
323 with( new Label( comp, DWT.NONE )){ | |
324 setText( "content" ); | |
325 } | |
326 setControl( comp ); | |
327 return comp; | |
328 } | |
329 } | |
330 class Page2 : WizardSelectionPage { | |
331 this( char[] title ){ | |
332 super(title); | |
333 } | |
334 public void createControl( Composite parent ){ | |
335 Composite comp = new Composite( parent, DWT.NONE ); | |
336 comp.setLayout( new FillLayout() ); | |
337 with( new Label( comp, DWT.NONE )){ | |
338 setText( "content" ); | |
339 } | |
340 setControl( comp ); | |
341 | |
342 return comp; | |
343 } | |
344 } | |
345 class MyWizard : Wizard { | |
346 this(){ | |
347 addPage( new Page1( "First Wizard Page") ); | |
348 addPage( new Page1( "Second Wizard Page") ); | |
349 setNeedsProgressMonitor(true); | |
350 setWindowTitle( "Wizard" ); | |
351 } | |
352 public override bool performFinish(){ | |
353 // puts the data into a database ... | |
354 getContainer().run(true, true, new class IRunnableWithProgress { | |
355 public void run(IProgressMonitor monitor) { | |
356 monitor.beginTask("Store data", 100); | |
357 | |
358 monitor.worked(40); | |
359 | |
360 // store data here ... | |
361 //System.out.println(data); | |
362 | |
363 Thread.sleep(5.200); | |
364 monitor.done(); | |
365 } | |
366 }); | |
367 return true; | |
368 } | |
369 } | |
188 | 370 |
189 void main(){ | 371 void main(){ |
190 auto d = new Display(); | 372 auto d = new Display(); |
191 auto app = new App(); | 373 auto app = new App(); |
192 app.open(); | 374 app.open(); |