Mercurial > projects > dwt-addons
annotate dwtx/jface/preference/PreferenceDialog.d @ 90:7ffeace6c47f
Update 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 23:30:07 +0200 |
parents | 5df4896124c7 |
children | 04b47443bb01 |
rev | line source |
---|---|
9 | 1 /******************************************************************************* |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
9 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Teddy Walker <teddy.walker@googlemail.com> | |
11 * - Bug 188056 [Preferences] PreferencePages have to less indent in PreferenceDialog | |
12 * Port to the D programming language: | |
13 * Frank Benoit <benoit@tionex.de> | |
14 *******************************************************************************/ | |
15 module dwtx.jface.preference.PreferenceDialog; | |
16 | |
34 | 17 import dwtx.jface.preference.IPreferencePageContainer; |
18 import dwtx.jface.preference.IPreferencePage; | |
19 import dwtx.jface.preference.IPreferenceNode; | |
20 import dwtx.jface.preference.IPreferenceStore; | |
21 import dwtx.jface.preference.IPersistentPreferenceStore; | |
22 import dwtx.jface.preference.PreferenceManager; | |
23 import dwtx.jface.preference.PreferencePage; | |
24 import dwtx.jface.preference.PreferenceLabelProvider; | |
25 import dwtx.jface.preference.PreferenceContentProvider; | |
9 | 26 |
27 import dwt.DWT; | |
28 import dwt.custom.BusyIndicator; | |
29 import dwt.custom.ScrolledComposite; | |
30 import dwt.events.ControlAdapter; | |
31 import dwt.events.ControlEvent; | |
32 import dwt.events.DisposeEvent; | |
33 import dwt.events.DisposeListener; | |
34 import dwt.events.HelpEvent; | |
35 import dwt.events.HelpListener; | |
36 import dwt.events.SelectionAdapter; | |
37 import dwt.events.SelectionEvent; | |
38 import dwt.events.ShellAdapter; | |
39 import dwt.events.ShellEvent; | |
40 import dwt.graphics.Font; | |
41 import dwt.graphics.Point; | |
42 import dwt.graphics.Rectangle; | |
43 import dwt.layout.FormAttachment; | |
44 import dwt.layout.FormData; | |
45 import dwt.layout.FormLayout; | |
46 import dwt.layout.GridData; | |
47 import dwt.layout.GridLayout; | |
48 import dwt.widgets.Button; | |
49 import dwt.widgets.Composite; | |
50 import dwt.widgets.Control; | |
51 import dwt.widgets.Event; | |
52 import dwt.widgets.Label; | |
53 import dwt.widgets.Layout; | |
54 import dwt.widgets.Listener; | |
55 import dwt.widgets.Sash; | |
56 import dwt.widgets.Shell; | |
57 import dwt.widgets.Tree; | |
58 import dwtx.core.runtime.Assert; | |
59 import dwtx.core.runtime.ISafeRunnable; | |
60 import dwtx.core.runtime.IStatus; | |
61 import dwtx.core.runtime.ListenerList; | |
62 import dwtx.core.runtime.SafeRunner; | |
63 import dwtx.core.runtime.Status; | |
64 import dwtx.jface.dialogs.DialogMessageArea; | |
65 import dwtx.jface.dialogs.IDialogConstants; | |
66 import dwtx.jface.dialogs.IMessageProvider; | |
67 import dwtx.jface.dialogs.IPageChangeProvider; | |
68 import dwtx.jface.dialogs.IPageChangedListener; | |
69 import dwtx.jface.dialogs.MessageDialog; | |
70 import dwtx.jface.dialogs.PageChangedEvent; | |
71 import dwtx.jface.dialogs.TrayDialog; | |
72 import dwtx.jface.resource.JFaceResources; | |
73 import dwtx.jface.util.IPropertyChangeListener; | |
74 import dwtx.jface.util.Policy; | |
75 import dwtx.jface.util.PropertyChangeEvent; | |
76 import dwtx.jface.util.SafeRunnable; | |
77 import dwtx.jface.viewers.ISelection; | |
78 import dwtx.jface.viewers.ISelectionChangedListener; | |
79 import dwtx.jface.viewers.IStructuredSelection; | |
80 import dwtx.jface.viewers.SelectionChangedEvent; | |
81 import dwtx.jface.viewers.StructuredSelection; | |
82 import dwtx.jface.viewers.TreeViewer; | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
83 import dwtx.jface.viewers.ViewerComparator; |
9 | 84 import dwtx.jface.viewers.ViewerFilter; |
85 | |
34 | 86 import dwt.dwthelper.utils; |
87 import dwt.dwthelper.Runnable; | |
88 | |
9 | 89 /** |
90 * A preference dialog is a hierarchical presentation of preference pages. Each | |
91 * page is represented by a node in the tree shown on the left hand side of the | |
92 * dialog; when a node is selected, the corresponding page is shown on the right | |
93 * hand side. | |
94 */ | |
34 | 95 public class PreferenceDialog : TrayDialog, IPreferencePageContainer, IPageChangeProvider { |
9 | 96 /** |
97 * Layout for the page container. | |
98 * | |
99 */ | |
34 | 100 private class PageLayout : Layout { |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
101 public override Point computeSize(Composite composite, int wHint, int hHint, bool force) { |
9 | 102 if (wHint !is DWT.DEFAULT && hHint !is DWT.DEFAULT) { |
103 return new Point(wHint, hHint); | |
104 } | |
105 int x = minimumPageSize.x; | |
106 int y = minimumPageSize.y; | |
107 Control[] children = composite.getChildren(); | |
108 for (int i = 0; i < children.length; i++) { | |
109 Point size = children[i].computeSize(DWT.DEFAULT, DWT.DEFAULT, force); | |
110 x = Math.max(x, size.x); | |
111 y = Math.max(y, size.y); | |
112 } | |
113 | |
114 //As pages can implement thier own computeSize | |
115 //take it into account | |
116 if(currentPage !is null){ | |
117 Point size = currentPage.computeSize(); | |
118 x = Math.max(x, size.x); | |
119 y = Math.max(y, size.y); | |
120 } | |
121 | |
122 if (wHint !is DWT.DEFAULT) { | |
123 x = wHint; | |
124 } | |
125 if (hHint !is DWT.DEFAULT) { | |
126 y = hHint; | |
127 } | |
128 return new Point(x, y); | |
129 } | |
130 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
131 public override void layout(Composite composite, bool force) { |
9 | 132 Rectangle rect = composite.getClientArea(); |
133 Control[] children = composite.getChildren(); | |
134 for (int i = 0; i < children.length; i++) { | |
135 children[i].setSize(rect.width, rect.height); | |
136 } | |
137 } | |
138 } | |
139 | |
140 //The id of the last page that was selected | |
141 private static String lastPreferenceId = null; | |
142 | |
143 //The last known tree width | |
144 private static int lastTreeWidth = 180; | |
145 | |
146 /** | |
147 * Indentifier for the error image | |
148 */ | |
34 | 149 public static const String PREF_DLG_IMG_TITLE_ERROR = DLG_IMG_MESSAGE_ERROR; |
9 | 150 |
151 /** | |
152 * Title area fields | |
153 */ | |
34 | 154 public static const String PREF_DLG_TITLE_IMG = "preference_dialog_title_image"; //$NON-NLS-1$ |
9 | 155 |
156 /** | |
157 * Return code used when dialog failed | |
158 */ | |
34 | 159 protected static const int FAILED = 2; |
9 | 160 |
161 /** | |
162 * The current preference page, or <code>null</code> if there is none. | |
163 */ | |
164 private IPreferencePage currentPage; | |
165 | |
166 private DialogMessageArea messageArea; | |
167 | |
168 private Point lastShellSize; | |
169 | |
170 private IPreferenceNode lastSuccessfulNode; | |
171 | |
172 /** | |
173 * The minimum page size; 400 by 400 by default. | |
174 * | |
175 * @see #setMinimumPageSize(Point) | |
176 */ | |
34 | 177 private Point minimumPageSize; |
9 | 178 |
179 /** | |
180 * The OK button. | |
181 */ | |
182 private Button okButton; | |
183 | |
184 /** | |
185 * The Composite in which a page is shown. | |
186 */ | |
187 private Composite pageContainer; | |
188 | |
189 /** | |
190 * The preference manager. | |
191 */ | |
192 private PreferenceManager preferenceManager; | |
193 | |
194 /** | |
195 * Flag for the presence of the error message. | |
196 */ | |
197 private bool showingError = false; | |
198 | |
199 /** | |
200 * Preference store, initially <code>null</code> meaning none. | |
201 * | |
202 * @see #setPreferenceStore | |
203 */ | |
204 private IPreferenceStore preferenceStore; | |
205 | |
206 private Composite titleArea; | |
207 | |
208 /** | |
209 * The tree viewer. | |
210 */ | |
211 private TreeViewer treeViewer; | |
212 | |
34 | 213 private ListenerList pageChangedListeners; |
9 | 214 |
215 /** | |
216 * Composite with a FormLayout to contain the title area | |
217 */ | |
218 Composite formTitleComposite; | |
219 | |
220 private ScrolledComposite scrolled; | |
221 | |
222 /** | |
223 * Creates a new preference dialog under the control of the given preference | |
224 * manager. | |
225 * | |
226 * @param parentShell | |
227 * the parent shell | |
228 * @param manager | |
229 * the preference manager | |
230 */ | |
34 | 231 public this(Shell parentShell, PreferenceManager manager) { |
232 minimumPageSize = new Point(400, 400); | |
233 pageChangedListeners = new ListenerList(); | |
9 | 234 super(parentShell); |
235 preferenceManager = manager; | |
236 } | |
237 | |
238 /* | |
239 * (non-Javadoc) | |
240 * | |
241 * @see dwtx.jface.dialogs.Dialog#buttonPressed(int) | |
242 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
243 protected override void buttonPressed(int buttonId) { |
9 | 244 switch (buttonId) { |
245 case IDialogConstants.OK_ID: { | |
246 okPressed(); | |
247 return; | |
248 } | |
249 case IDialogConstants.CANCEL_ID: { | |
250 cancelPressed(); | |
251 return; | |
252 } | |
253 case IDialogConstants.HELP_ID: { | |
254 helpPressed(); | |
255 return; | |
256 } | |
257 } | |
258 } | |
259 | |
260 /* | |
261 * (non-Javadoc) | |
262 * | |
263 * @see dwtx.jface.dialogs.Dialog#cancelPressed() | |
264 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
265 protected override void cancelPressed() { |
9 | 266 // Inform all pages that we are cancelling |
34 | 267 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){ |
268 IPreferenceNode node = cast(IPreferenceNode) e; | |
9 | 269 if (getPage(node) !is null) { |
34 | 270 |
271 // this_: strange workaround for compiler error with dmd 1.028 in run() | |
39 | 272 SafeRunnable.run(new class(this,node) SafeRunnable { |
34 | 273 IPreferenceNode node_; |
39 | 274 PreferenceDialog this_; |
275 this(PreferenceDialog pd, IPreferenceNode b){ | |
276 this_=pd; | |
277 node_=b; | |
34 | 278 } |
9 | 279 public void run() { |
34 | 280 if (!this_.getPage(node_).performCancel()) { |
9 | 281 return; |
282 } | |
283 } | |
284 }); | |
285 } | |
286 } | |
287 setReturnCode(CANCEL); | |
288 close(); | |
289 } | |
290 | |
291 /** | |
292 * Clear the last selected node. This is so that we not chache the last | |
293 * selection in case of an error. | |
294 */ | |
295 void clearSelectedNode() { | |
296 setSelectedNodePreference(null); | |
297 } | |
298 | |
299 /* | |
300 * (non-Javadoc) | |
301 * | |
302 * @see dwtx.jface.window.Window#close() | |
303 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
304 public override bool close() { |
9 | 305 |
306 //Do this is in a SafeRunnable as it may run client code | |
34 | 307 SafeRunnable runnable = new class SafeRunnable{ |
9 | 308 /* (non-Javadoc) |
309 * @see dwtx.core.runtime.ISafeRunnable#run() | |
310 */ | |
34 | 311 public void run() { |
312 auto nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER); | |
9 | 313 for (int i = 0; i < nodes.size(); i++) { |
34 | 314 IPreferenceNode node = cast(IPreferenceNode) nodes.get(i); |
9 | 315 node.disposeResources(); |
316 } | |
317 | |
318 } | |
319 | |
320 /* (non-Javadoc) | |
321 * @see dwtx.jface.util.SafeRunnable#handleException(java.lang.Throwable) | |
322 */ | |
34 | 323 public void handleException(Exception e) { |
9 | 324 super.handleException(e); |
325 clearSelectedNode();//Do not cache a node with problems | |
326 } | |
327 }; | |
328 | |
329 SafeRunner.run(runnable); | |
330 | |
331 return super.close(); | |
332 } | |
333 | |
334 /* | |
335 * (non-Javadoc) | |
336 * | |
337 * @see dwtx.jface.window.Window#configureShell(dwt.widgets.Shell) | |
338 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
339 protected override void configureShell(Shell newShell) { |
9 | 340 super.configureShell(newShell); |
341 newShell.setText(JFaceResources.getString("PreferenceDialog.title")); //$NON-NLS-1$ | |
34 | 342 newShell.addShellListener(new class ShellAdapter { |
9 | 343 public void shellActivated(ShellEvent e) { |
344 if (lastShellSize is null) { | |
345 lastShellSize = getShell().getSize(); | |
346 } | |
347 } | |
348 | |
349 }); | |
350 | |
351 } | |
352 | |
353 /* | |
354 * (non-Javadoc) | |
355 * | |
356 * @see dwtx.jface.window.Window#constrainShellSize() | |
357 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
358 protected override void constrainShellSize() { |
9 | 359 super.constrainShellSize(); |
360 // record opening shell size | |
361 if (lastShellSize is null) { | |
362 lastShellSize = getShell().getSize(); | |
363 } | |
364 } | |
365 | |
366 /* | |
367 * (non-Javadoc) | |
368 * | |
369 * @see dwtx.jface.dialogs.Dialog#createButtonsForButtonBar(dwt.widgets.Composite) | |
370 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
371 protected override void createButtonsForButtonBar(Composite parent) { |
9 | 372 // create OK and Cancel buttons by default |
373 okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); | |
374 getShell().setDefaultButton(okButton); | |
375 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); | |
376 } | |
377 | |
378 /* | |
379 * (non-Javadoc) | |
380 * | |
381 * @see dwtx.jface.window.Window#createContents(dwt.widgets.Composite) | |
382 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
383 protected override Control createContents(Composite parent) { |
34 | 384 Control[1] control; |
46 | 385 BusyIndicator.showWhile(getShell().getDisplay(), new class(parent,control) Runnable { |
34 | 386 Composite parent_; |
46 | 387 Control[] control_; |
388 this(Composite a,Control[] b){ | |
39 | 389 parent_=a; |
46 | 390 control_=b; |
34 | 391 } |
9 | 392 public void run() { |
46 | 393 control_[0] = callSuperCreateContents(parent_); |
9 | 394 // Add the first page |
395 selectSavedItem(); | |
396 } | |
397 }); | |
398 | |
399 return control[0]; | |
400 } | |
34 | 401 private Control callSuperCreateContents( Composite c ){ |
402 return super.createContents( c ); | |
403 } | |
9 | 404 /* |
405 * (non-Javadoc) | |
406 * | |
407 * @see dwtx.jface.dialogs.Dialog#createDialogArea(dwt.widgets.Composite) | |
408 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
409 protected override Control createDialogArea(Composite parent) { |
34 | 410 final Composite composite = cast(Composite) super.createDialogArea(parent); |
411 GridLayout parentLayout = (cast(GridLayout) composite.getLayout()); | |
9 | 412 parentLayout.numColumns = 4; |
413 parentLayout.marginHeight = 0; | |
414 parentLayout.marginWidth = 0; | |
415 parentLayout.verticalSpacing = 0; | |
416 parentLayout.horizontalSpacing = 0; | |
417 | |
418 composite.setBackground(parent.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND)); | |
419 | |
420 Control treeControl = createTreeAreaContents(composite); | |
421 createSash(composite,treeControl); | |
422 | |
423 Label versep = new Label(composite, DWT.SEPARATOR | DWT.VERTICAL); | |
424 GridData verGd = new GridData(GridData.FILL_VERTICAL | GridData.GRAB_VERTICAL); | |
425 | |
426 versep.setLayoutData(verGd); | |
427 versep.setLayoutData(new GridData(DWT.LEFT, DWT.FILL, false, true)); | |
428 | |
429 Composite pageAreaComposite = new Composite(composite, DWT.NONE); | |
430 pageAreaComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
431 GridLayout layout = new GridLayout(1, true); | |
432 layout.marginHeight = 0; | |
433 layout.marginWidth = 0; | |
434 layout.verticalSpacing = 0; | |
435 pageAreaComposite.setLayout(layout); | |
436 | |
437 formTitleComposite = new Composite(pageAreaComposite, DWT.NONE); | |
438 FormLayout titleLayout = new FormLayout(); | |
439 titleLayout.marginWidth = 0; | |
440 titleLayout.marginHeight = 0; | |
441 formTitleComposite.setLayout(titleLayout); | |
442 | |
443 GridData titleGridData = new GridData(GridData.FILL_HORIZONTAL); | |
444 titleGridData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN; | |
445 formTitleComposite.setLayoutData(titleGridData); | |
446 | |
447 // Build the title area and separator line | |
448 Composite titleComposite = new Composite(formTitleComposite, DWT.NONE); | |
449 layout = new GridLayout(); | |
450 layout.marginBottom = 5; | |
451 layout.marginHeight = 0; | |
452 layout.marginWidth = 0; | |
453 layout.horizontalSpacing = 0; | |
454 titleComposite.setLayout(layout); | |
455 | |
456 FormData titleFormData = new FormData(); | |
457 titleFormData.top = new FormAttachment(0,0); | |
458 titleFormData.left = new FormAttachment(0,0); | |
459 titleFormData.right = new FormAttachment(100,0); | |
460 titleFormData.bottom = new FormAttachment(100,0); | |
461 | |
462 titleComposite.setLayoutData(titleFormData); | |
463 createTitleArea(titleComposite); | |
464 | |
465 Label separator = new Label(pageAreaComposite, DWT.HORIZONTAL | DWT.SEPARATOR); | |
466 | |
467 separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); | |
468 | |
469 | |
470 // Build the Page container | |
471 pageContainer = createPageContainer(pageAreaComposite); | |
472 GridData pageContainerData = new GridData(GridData.FILL_BOTH); | |
473 pageContainerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN; | |
474 pageContainer.setLayoutData(pageContainerData); | |
475 // Build the separator line | |
476 Label bottomSeparator = new Label(parent, DWT.HORIZONTAL | DWT.SEPARATOR); | |
477 bottomSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); | |
478 return composite; | |
479 } | |
480 | |
481 /** | |
482 * Create the sash with right control on the right. Note | |
483 * that this method assumes GridData for the layout data | |
484 * of the rightControl. | |
485 * @param composite | |
486 * @param rightControl | |
487 * @return Sash | |
488 * | |
489 * @since 3.1 | |
490 */ | |
34 | 491 protected Sash createSash(Composite composite, Control rightControl) { |
492 Sash sash = new Sash(composite, DWT.VERTICAL); | |
9 | 493 sash.setLayoutData(new GridData(GridData.FILL_VERTICAL)); |
494 sash.setBackground(composite.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND)); | |
495 // the following listener resizes the tree control based on sash deltas. | |
496 // If necessary, it will also grow/shrink the dialog. | |
39 | 497 sash.addListener(DWT.Selection, new class(composite,rightControl,sash) Listener { |
34 | 498 Composite composite_; |
499 Control rightControl_; | |
500 Sash sash_; | |
39 | 501 this(Composite a,Control b,Sash c){ |
502 composite_=a; | |
503 rightControl_=b; | |
504 sash_=c; | |
34 | 505 } |
9 | 506 /* |
507 * (non-Javadoc) | |
508 * | |
509 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) | |
510 */ | |
511 public void handleEvent(Event event) { | |
512 if (event.detail is DWT.DRAG) { | |
513 return; | |
514 } | |
34 | 515 int shift = event.x - sash_.getBounds().x; |
516 GridData data = cast(GridData) rightControl_.getLayoutData(); | |
9 | 517 int newWidthHint = data.widthHint + shift; |
518 if (newWidthHint < 20) { | |
519 return; | |
520 } | |
521 Point computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT); | |
522 Point currentSize = getShell().getSize(); | |
523 // if the dialog wasn't of a custom size we know we can shrink | |
524 // it if necessary based on sash movement. | |
34 | 525 bool customSize = !computedSize.opEquals(currentSize); |
9 | 526 data.widthHint = newWidthHint; |
527 setLastTreeWidth(newWidthHint); | |
34 | 528 composite_.layout(true); |
9 | 529 // recompute based on new widget size |
530 computedSize = getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT); | |
531 // if the dialog was of a custom size then increase it only if | |
532 // necessary. | |
533 if (customSize) { | |
534 computedSize.x = Math.max(computedSize.x, currentSize.x); | |
535 } | |
536 computedSize.y = Math.max(computedSize.y, currentSize.y); | |
34 | 537 if (computedSize.opEquals(currentSize)) { |
9 | 538 return; |
539 } | |
540 setShellSize(computedSize.x, computedSize.y); | |
541 lastShellSize = getShell().getSize(); | |
542 } | |
543 }); | |
544 return sash; | |
545 } | |
546 | |
547 /** | |
548 * Creates the inner page container. | |
549 * | |
550 * @param parent | |
551 * @return Composite | |
552 */ | |
553 protected Composite createPageContainer(Composite parent) { | |
554 | |
555 Composite outer = new Composite(parent, DWT.NONE); | |
556 | |
557 GridData outerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | |
558 | GridData.GRAB_VERTICAL); | |
559 outerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN; | |
560 | |
561 outer.setLayout(new GridLayout()); | |
562 outer.setLayoutData(outerData); | |
563 | |
564 //Create an outer composite for spacing | |
565 scrolled = new ScrolledComposite(outer, DWT.V_SCROLL | DWT.H_SCROLL); | |
566 | |
567 scrolled.setExpandHorizontal(true); | |
568 scrolled.setExpandVertical(true); | |
569 | |
570 GridData scrolledData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | |
571 | GridData.GRAB_VERTICAL); | |
572 | |
573 scrolled.setLayoutData(scrolledData); | |
574 | |
575 Composite result = new Composite(scrolled, DWT.NONE); | |
576 | |
577 GridData resultData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | |
578 | GridData.GRAB_VERTICAL); | |
579 | |
580 result.setLayout(getPageLayout()); | |
581 result.setLayoutData(resultData); | |
582 | |
583 scrolled.setContent(result); | |
584 | |
585 return result; | |
586 } | |
587 | |
588 /** | |
589 * Return the layout for the composite that contains | |
590 * the pages. | |
591 * @return PageLayout | |
592 * | |
593 * @since 3.1 | |
594 */ | |
595 protected Layout getPageLayout() { | |
596 return new PageLayout(); | |
597 } | |
598 | |
599 /** | |
600 * Creates the wizard's title area. | |
601 * | |
602 * @param parent | |
603 * the DWT parent for the title area composite. | |
604 * @return the created title area composite. | |
605 */ | |
606 protected Composite createTitleArea(Composite parent) { | |
607 // Create the title area which will contain | |
608 // a title, message, and image. | |
609 int margins = 2; | |
610 titleArea = new Composite(parent, DWT.NONE); | |
611 FormLayout layout = new FormLayout(); | |
612 layout.marginHeight = 0; | |
613 layout.marginWidth = margins; | |
614 titleArea.setLayout(layout); | |
615 | |
616 | |
617 GridData layoutData = new GridData(GridData.FILL_HORIZONTAL); | |
618 layoutData.verticalAlignment = DWT.TOP; | |
619 titleArea.setLayoutData(layoutData); | |
620 | |
621 // Message label | |
622 messageArea = new DialogMessageArea(); | |
623 messageArea.createContents(titleArea); | |
624 | |
34 | 625 titleArea.addControlListener(new class ControlAdapter { |
9 | 626 /* (non-Javadoc) |
627 * @see dwt.events.ControlAdapter#controlResized(dwt.events.ControlEvent) | |
628 */ | |
629 public void controlResized(ControlEvent e) { | |
630 updateMessage(); | |
631 } | |
632 }); | |
633 | |
46 | 634 IPropertyChangeListener fontListener = new class IPropertyChangeListener { |
9 | 635 public void propertyChange(PropertyChangeEvent event) { |
636 if (JFaceResources.BANNER_FONT.equals(event.getProperty())) { | |
637 updateMessage(); | |
638 } | |
639 if (JFaceResources.DIALOG_FONT.equals(event.getProperty())) { | |
640 updateMessage(); | |
641 Font dialogFont = JFaceResources.getDialogFont(); | |
642 updateTreeFont(dialogFont); | |
34 | 643 Control[] children = (cast(Composite) buttonBar).getChildren(); |
9 | 644 for (int i = 0; i < children.length; i++) { |
645 children[i].setFont(dialogFont); | |
646 } | |
647 } | |
648 } | |
649 }; | |
650 | |
46 | 651 titleArea.addDisposeListener(new class(fontListener) DisposeListener { |
652 IPropertyChangeListener fontListener_; | |
653 this(IPropertyChangeListener a){ | |
654 fontListener_=a; | |
655 } | |
9 | 656 public void widgetDisposed(DisposeEvent event) { |
46 | 657 JFaceResources.getFontRegistry().removeListener(fontListener_); |
9 | 658 } |
659 }); | |
660 JFaceResources.getFontRegistry().addListener(fontListener); | |
661 messageArea.setTitleLayoutData(createMessageAreaData()); | |
662 messageArea.setMessageLayoutData(createMessageAreaData()); | |
663 return titleArea; | |
664 } | |
665 | |
666 /** | |
667 * Create the layout data for the message area. | |
668 * | |
669 * @return FormData for the message area. | |
670 */ | |
671 private FormData createMessageAreaData() { | |
672 FormData messageData = new FormData(); | |
673 messageData.top = new FormAttachment(0); | |
674 messageData.bottom = new FormAttachment(100); | |
675 messageData.right = new FormAttachment(100); | |
676 messageData.left = new FormAttachment(0); | |
677 return messageData; | |
678 } | |
679 | |
680 /** | |
681 * @param parent | |
682 * the DWT parent for the tree area controls. | |
683 * @return the new <code>Control</code>. | |
684 * @since 3.0 | |
685 */ | |
686 protected Control createTreeAreaContents(Composite parent) { | |
687 // Build the tree an put it into the composite. | |
688 treeViewer = createTreeViewer(parent); | |
689 treeViewer.setInput(getPreferenceManager()); | |
690 updateTreeFont(JFaceResources.getDialogFont()); | |
691 layoutTreeAreaControl(treeViewer.getControl()); | |
692 return treeViewer.getControl(); | |
693 } | |
694 | |
695 /** | |
696 * Create a new <code>TreeViewer</code>. | |
697 * | |
698 * @param parent | |
699 * the parent <code>Composite</code>. | |
700 * @return the <code>TreeViewer</code>. | |
701 * @since 3.0 | |
702 */ | |
703 protected TreeViewer createTreeViewer(Composite parent) { | |
704 final TreeViewer viewer = new TreeViewer(parent, DWT.NONE); | |
705 addListeners(viewer); | |
706 viewer.setLabelProvider(new PreferenceLabelProvider()); | |
707 viewer.setContentProvider(new PreferenceContentProvider()); | |
708 return viewer; | |
709 } | |
710 | |
711 /** | |
712 * Add the listeners to the tree viewer. | |
713 * @param viewer | |
714 * | |
715 * @since 3.1 | |
716 */ | |
34 | 717 protected void addListeners(TreeViewer viewer) { |
39 | 718 viewer.addPostSelectionChangedListener(new class(viewer) ISelectionChangedListener { |
34 | 719 TreeViewer viewer_; |
39 | 720 this(TreeViewer a){ |
721 viewer_=a; | |
34 | 722 } |
9 | 723 private void handleError() { |
724 try { | |
725 // remove the listener temporarily so that the events caused | |
726 // by the error handling dont further cause error handling | |
727 // to occur. | |
34 | 728 viewer_.removePostSelectionChangedListener(this); |
9 | 729 showPageFlippingAbortDialog(); |
730 selectCurrentPageAgain(); | |
731 clearSelectedNode(); | |
732 } finally { | |
34 | 733 viewer_.addPostSelectionChangedListener(this); |
9 | 734 } |
735 } | |
736 | |
737 public void selectionChanged(SelectionChangedEvent event) { | |
34 | 738 Object selection = cast(Object) getSingleSelection(event.getSelection()); |
739 if (cast(IPreferenceNode)selection ) { | |
90 | 740 BusyIndicator.showWhile(getShell().getDisplay(), new class(selection) Runnable { |
741 Object selection_; | |
742 this(Object o){ selection_=o; } | |
743 public void run() { | |
744 if (!isCurrentPageValid()) { | |
745 handleError(); | |
746 } else if (!showPage(cast(IPreferenceNode) selection_)) { | |
747 // Page flipping wasn't successful | |
748 handleError(); | |
749 } else { | |
750 // Everything went well | |
751 lastSuccessfulNode = cast(IPreferenceNode) selection_; | |
752 } | |
753 } | |
754 }); | |
9 | 755 } |
756 } | |
757 }); | |
39 | 758 (cast(Tree) viewer.getControl()).addSelectionListener(new class(viewer) SelectionAdapter { |
34 | 759 TreeViewer viewer_; |
39 | 760 this(TreeViewer a){ |
761 viewer_=a; | |
34 | 762 } |
763 public void widgetDefaultSelected(SelectionEvent event) { | |
764 ISelection selection = viewer_.getSelection(); | |
9 | 765 if (selection.isEmpty()) { |
766 return; | |
767 } | |
768 IPreferenceNode singleSelection = getSingleSelection(selection); | |
34 | 769 bool expanded = viewer_.getExpandedState(cast(Object)singleSelection); |
770 viewer_.setExpandedState(cast(Object)singleSelection, !expanded); | |
9 | 771 } |
772 }); | |
773 //Register help listener on the tree to use context sensitive help | |
34 | 774 viewer.getControl().addHelpListener(new class HelpListener { |
9 | 775 public void helpRequested(HelpEvent event) { |
776 // call perform help on the current page | |
777 if (currentPage !is null) { | |
778 currentPage.performHelp(); | |
779 } | |
780 } | |
781 }); | |
782 } | |
783 | |
784 /** | |
785 * Find the <code>IPreferenceNode</code> that has data the same id as the | |
786 * supplied value. | |
787 * | |
788 * @param nodeId | |
789 * the id to search for. | |
790 * @return <code>IPreferenceNode</code> or <code>null</code> if not | |
791 * found. | |
792 */ | |
793 protected IPreferenceNode findNodeMatching(String nodeId) { | |
34 | 794 foreach( e; preferenceManager.getElements(PreferenceManager.POST_ORDER)){ |
795 IPreferenceNode node = cast(IPreferenceNode) e; | |
9 | 796 if (node.getId().equals(nodeId)) { |
797 return node; | |
798 } | |
799 } | |
800 return null; | |
801 } | |
802 | |
803 /** | |
804 * Get the last known right side width. | |
805 * | |
806 * @return the width. | |
807 */ | |
808 protected int getLastRightWidth() { | |
809 return lastTreeWidth; | |
810 } | |
811 | |
812 /** | |
813 * Returns the preference mananger used by this preference dialog. | |
814 * | |
815 * @return the preference mananger | |
816 */ | |
817 public PreferenceManager getPreferenceManager() { | |
818 return preferenceManager; | |
819 } | |
820 | |
821 /* | |
822 * (non-Javadoc) | |
823 * | |
824 * @see dwtx.jface.preference.IPreferencePageContainer#getPreferenceStore() | |
825 */ | |
826 public IPreferenceStore getPreferenceStore() { | |
827 return preferenceStore; | |
828 } | |
829 | |
830 /** | |
831 * Get the name of the selected item preference | |
832 * | |
833 * @return String | |
834 */ | |
835 protected String getSelectedNodePreference() { | |
836 return lastPreferenceId; | |
837 } | |
838 | |
839 /** | |
840 * @param selection | |
841 * the <code>ISelection</code> to examine. | |
842 * @return the first element, or null if empty. | |
843 */ | |
844 protected IPreferenceNode getSingleSelection(ISelection selection) { | |
845 if (!selection.isEmpty()) { | |
34 | 846 IStructuredSelection structured = cast(IStructuredSelection) selection; |
847 if (cast(IPreferenceNode)structured.getFirstElement() ) { | |
848 return cast(IPreferenceNode) structured.getFirstElement(); | |
9 | 849 } |
850 } | |
851 return null; | |
852 } | |
853 | |
854 /** | |
855 * @return the <code>TreeViewer</code> for this dialog. | |
856 * @since 3.3 | |
857 */ | |
858 public TreeViewer getTreeViewer() { | |
859 return treeViewer; | |
860 } | |
861 | |
862 /** | |
863 * Save the values specified in the pages. | |
864 * <p> | |
865 * The default implementation of this framework method saves all pages of | |
866 * type <code>PreferencePage</code> (if their store needs saving and is a | |
867 * <code>PreferenceStore</code>). | |
868 * </p> | |
869 * <p> | |
870 * Subclasses may override. | |
871 * </p> | |
872 */ | |
873 protected void handleSave() { | |
34 | 874 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){ |
875 IPreferenceNode node = cast(IPreferenceNode) e; | |
9 | 876 IPreferencePage page = node.getPage(); |
34 | 877 if (cast(PreferencePage)page ) { |
9 | 878 // Save now in case tbe workbench does not shutdown cleanly |
34 | 879 IPreferenceStore store = (cast(PreferencePage) page).getPreferenceStore(); |
9 | 880 if (store !is null && store.needsSaving() |
34 | 881 && cast(IPersistentPreferenceStore)store ) { |
9 | 882 try { |
34 | 883 (cast(IPersistentPreferenceStore) store).save(); |
9 | 884 } catch (IOException e) { |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
885 String message =JFaceResources.format( |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
71
diff
changeset
|
886 "PreferenceDialog.saveErrorMessage", [ page.getTitle(), e.msg ]); //$NON-NLS-1$ |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
887 Policy.getStatusHandler().show( |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
888 new Status(IStatus.ERROR, Policy.JFACE, message, e), |
71 | 889 JFaceResources.getString("PreferenceDialog.saveErrorTitle")); //$NON-NLS-1$ |
890 | |
9 | 891 } |
892 } | |
893 } | |
894 } | |
895 } | |
896 | |
897 /** | |
898 * Notifies that the window's close button was pressed, the close menu was | |
899 * selected, or the ESCAPE key pressed. | |
900 * <p> | |
901 * The default implementation of this framework method sets the window's | |
902 * return code to <code>CANCEL</code> and closes the window using | |
903 * <code>close</code>. Subclasses may extend or reimplement. | |
904 * </p> | |
905 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
906 protected override void handleShellCloseEvent() { |
9 | 907 // handle the same as pressing cancel |
908 cancelPressed(); | |
909 } | |
910 | |
911 /** | |
912 * Notifies of the pressing of the Help button. | |
913 * <p> | |
914 * The default implementation of this framework method calls | |
915 * <code>performHelp</code> on the currently active page. | |
916 * </p> | |
917 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
918 protected /+override+/ void helpPressed() { |
9 | 919 if (currentPage !is null) { |
920 currentPage.performHelp(); | |
921 } | |
922 } | |
923 | |
924 /** | |
925 * Returns whether the current page is valid. | |
926 * | |
927 * @return <code>false</code> if the current page is not valid, or or | |
928 * <code>true</code> if the current page is valid or there is no | |
929 * current page | |
930 */ | |
931 protected bool isCurrentPageValid() { | |
932 if (currentPage is null) { | |
933 return true; | |
934 } | |
935 return currentPage.isValid(); | |
936 } | |
937 | |
938 /** | |
939 * @param control | |
940 * the <code>Control</code> to lay out. | |
941 * @since 3.0 | |
942 */ | |
943 protected void layoutTreeAreaControl(Control control) { | |
944 GridData gd = new GridData(GridData.FILL_VERTICAL); | |
945 gd.widthHint = getLastRightWidth(); | |
946 gd.verticalSpan = 1; | |
947 control.setLayoutData(gd); | |
948 } | |
949 | |
950 /** | |
951 * The preference dialog implementation of this <code>Dialog</code> | |
952 * framework method sends <code>performOk</code> to all pages of the | |
953 * preference dialog, then calls <code>handleSave</code> on this dialog to | |
954 * save any state, and then calls <code>close</code> to close this dialog. | |
955 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
956 protected override void okPressed() { |
34 | 957 SafeRunnable.run(new class SafeRunnable { |
9 | 958 private bool errorOccurred; |
959 | |
960 /* | |
961 * (non-Javadoc) | |
962 * | |
963 * @see dwtx.core.runtime.ISafeRunnable#run() | |
964 */ | |
965 public void run() { | |
966 getButton(IDialogConstants.OK_ID).setEnabled(false); | |
967 errorOccurred = false; | |
968 bool hasFailedOK = false; | |
969 try { | |
970 // Notify all the pages and give them a chance to abort | |
34 | 971 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){ |
972 IPreferenceNode node = cast(IPreferenceNode) e; | |
9 | 973 IPreferencePage page = node.getPage(); |
974 if (page !is null) { | |
975 if (!page.performOk()){ | |
976 hasFailedOK = true; | |
977 return; | |
978 } | |
979 } | |
980 } | |
981 } catch (Exception e) { | |
982 handleException(e); | |
983 } finally { | |
984 //Don't bother closing if the OK failed | |
985 if(hasFailedOK){ | |
986 setReturnCode(FAILED); | |
987 getButton(IDialogConstants.OK_ID).setEnabled(true); | |
34 | 988 //return; |
9 | 989 } |
34 | 990 else{ |
9 | 991 |
34 | 992 if (!errorOccurred) { |
993 //Give subclasses the choice to save the state of the | |
994 //preference pages. | |
995 handleSave(); | |
996 } | |
997 setReturnCode(OK); | |
998 close(); | |
9 | 999 } |
1000 } | |
1001 } | |
1002 | |
1003 /* | |
1004 * (non-Javadoc) | |
1005 * | |
1006 * @see dwtx.core.runtime.ISafeRunnable#handleException(java.lang.Throwable) | |
1007 */ | |
34 | 1008 public void handleException(Exception e) { |
9 | 1009 errorOccurred = true; |
1010 | |
1011 Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e)); | |
1012 | |
1013 clearSelectedNode(); | |
1014 String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$ | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1015 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1016 Policy.getStatusHandler().show( |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1017 new Status(IStatus.ERROR, Policy.JFACE, message, e), |
71 | 1018 JFaceResources.getString("Error")); //$NON-NLS-1$ |
9 | 1019 |
1020 } | |
1021 }); | |
1022 } | |
1023 | |
1024 /** | |
1025 * Selects the page determined by <code>lastSuccessfulNode</code> in the | |
1026 * page hierarchy. | |
1027 */ | |
1028 void selectCurrentPageAgain() { | |
1029 if (lastSuccessfulNode is null) { | |
1030 return; | |
1031 } | |
34 | 1032 getTreeViewer().setSelection(new StructuredSelection(cast(Object)lastSuccessfulNode)); |
9 | 1033 currentPage.setVisible(true); |
1034 } | |
1035 | |
1036 /** | |
1037 * Selects the saved item in the tree of preference pages. If it cannot do | |
1038 * this it saves the first one. | |
1039 */ | |
1040 protected void selectSavedItem() { | |
1041 IPreferenceNode node = findNodeMatching(getSelectedNodePreference()); | |
1042 if (node is null) { | |
1043 IPreferenceNode[] nodes = preferenceManager.getRootSubNodes(); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1044 ViewerComparator comparator = getTreeViewer().getComparator(); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1045 if (comparator !is null) { |
72
5df4896124c7
JFace and its examples do compile
Frank Benoit <benoit@tionex.de>
parents:
71
diff
changeset
|
1046 comparator.sort(null, arraycast!(Object)(nodes)); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1047 } |
9 | 1048 ViewerFilter[] filters = getTreeViewer().getFilters(); |
1049 for (int i = 0; i < nodes.length; i++) { | |
1050 IPreferenceNode selectedNode = nodes[i]; | |
1051 // See if it passes all filters | |
1052 for (int j = 0; j < filters.length; j++) { | |
34 | 1053 if (!filters[j].select(this.treeViewer, cast(Object)preferenceManager |
1054 .getRoot_package(), cast(Object)selectedNode)) { | |
9 | 1055 selectedNode = null; |
1056 break; | |
1057 } | |
1058 } | |
1059 // if it passes all filters select it | |
1060 if (selectedNode !is null) { | |
1061 node = selectedNode; | |
1062 break; | |
1063 } | |
1064 } | |
1065 } | |
1066 if (node !is null) { | |
34 | 1067 getTreeViewer().setSelection(new StructuredSelection(cast(Object)node), true); |
9 | 1068 // Keep focus in tree. See bugs 2692, 2621, and 6775. |
1069 getTreeViewer().getControl().setFocus(); | |
1070 } | |
1071 } | |
1072 | |
1073 /** | |
1074 * Display the given error message. The currently displayed message is saved | |
1075 * and will be redisplayed when the error message is set to | |
1076 * <code>null</code>. | |
1077 * | |
1078 * @param newErrorMessage | |
1079 * the errorMessage to display or <code>null</code> | |
1080 */ | |
1081 public void setErrorMessage(String newErrorMessage) { | |
1082 if (newErrorMessage is null) { | |
1083 messageArea.clearErrorMessage(); | |
1084 } else { | |
1085 messageArea.updateText(newErrorMessage, IMessageProvider.ERROR); | |
1086 } | |
1087 } | |
1088 | |
1089 /** | |
1090 * Save the last known tree width. | |
1091 * | |
1092 * @param width | |
1093 * the width. | |
1094 */ | |
1095 private void setLastTreeWidth(int width) { | |
1096 lastTreeWidth = width; | |
1097 } | |
1098 | |
1099 /** | |
1100 * Set the message text. If the message line currently displays an error, | |
1101 * the message is stored and will be shown after a call to clearErrorMessage | |
1102 * <p> | |
1103 * Shortcut for <code>setMessage(newMessage, NONE)</code> | |
1104 * </p> | |
1105 * | |
1106 * @param newMessage | |
1107 * the message, or <code>null</code> to clear the message | |
1108 */ | |
1109 public void setMessage(String newMessage) { | |
1110 setMessage(newMessage, IMessageProvider.NONE); | |
1111 } | |
1112 | |
1113 /** | |
1114 * Sets the message for this dialog with an indication of what type of | |
1115 * message it is. | |
1116 * <p> | |
1117 * The valid message types are one of <code>NONE</code>, | |
1118 * <code>INFORMATION</code>,<code>WARNING</code>, or | |
1119 * <code>ERROR</code>. | |
1120 * </p> | |
1121 * <p> | |
1122 * Note that for backward compatibility, a message of type | |
1123 * <code>ERROR</code> is different than an error message (set using | |
1124 * <code>setErrorMessage</code>). An error message overrides the current | |
1125 * message until the error message is cleared. This method replaces the | |
1126 * current message and does not affect the error message. | |
1127 * </p> | |
1128 * | |
1129 * @param newMessage | |
1130 * the message, or <code>null</code> to clear the message | |
1131 * @param newType | |
1132 * the message type | |
1133 * @since 2.0 | |
1134 */ | |
1135 public void setMessage(String newMessage, int newType) { | |
1136 messageArea.updateText(newMessage, newType); | |
1137 } | |
1138 | |
1139 /** | |
1140 * Sets the minimum page size. | |
1141 * | |
1142 * @param minWidth | |
1143 * the minimum page width | |
1144 * @param minHeight | |
1145 * the minimum page height | |
1146 * @see #setMinimumPageSize(Point) | |
1147 */ | |
1148 public void setMinimumPageSize(int minWidth, int minHeight) { | |
1149 minimumPageSize.x = minWidth; | |
1150 minimumPageSize.y = minHeight; | |
1151 } | |
1152 | |
1153 /** | |
1154 * Sets the minimum page size. | |
1155 * | |
1156 * @param size | |
1157 * the page size encoded as <code>new Point(width,height)</code> | |
1158 * @see #setMinimumPageSize(int,int) | |
1159 */ | |
1160 public void setMinimumPageSize(Point size) { | |
1161 minimumPageSize.x = size.x; | |
1162 minimumPageSize.y = size.y; | |
1163 } | |
1164 | |
1165 /** | |
1166 * Sets the preference store for this preference dialog. | |
1167 * | |
1168 * @param store | |
1169 * the preference store | |
1170 * @see #getPreferenceStore | |
1171 */ | |
1172 public void setPreferenceStore(IPreferenceStore store) { | |
34 | 1173 Assert.isNotNull(cast(Object)store); |
9 | 1174 preferenceStore = store; |
1175 } | |
1176 | |
1177 /** | |
1178 * Save the currently selected node. | |
1179 */ | |
1180 private void setSelectedNode() { | |
1181 String storeValue = null; | |
34 | 1182 IStructuredSelection selection = cast(IStructuredSelection) getTreeViewer().getSelection(); |
9 | 1183 if (selection.size() is 1) { |
34 | 1184 IPreferenceNode node = cast(IPreferenceNode) selection.getFirstElement(); |
9 | 1185 storeValue = node.getId(); |
1186 } | |
1187 setSelectedNodePreference(storeValue); | |
1188 } | |
1189 | |
1190 /** | |
1191 * Sets the name of the selected item preference. Public equivalent to | |
1192 * <code>setSelectedNodePreference</code>. | |
1193 * | |
1194 * @param pageId | |
1195 * The identifier for the page | |
1196 * @since 3.0 | |
1197 */ | |
1198 public void setSelectedNode(String pageId) { | |
1199 setSelectedNodePreference(pageId); | |
1200 } | |
1201 | |
1202 /** | |
1203 * Sets the name of the selected item preference. | |
1204 * | |
1205 * @param pageId | |
1206 * The identifier for the page | |
1207 */ | |
1208 protected void setSelectedNodePreference(String pageId) { | |
1209 lastPreferenceId = pageId; | |
1210 } | |
1211 | |
1212 /** | |
1213 * Changes the shell size to the given size, ensuring that it is no larger | |
1214 * than the display bounds. | |
1215 * | |
1216 * @param width | |
1217 * the shell width | |
1218 * @param height | |
1219 * the shell height | |
1220 */ | |
1221 private void setShellSize(int width, int height) { | |
1222 Rectangle preferred = getShell().getBounds(); | |
1223 preferred.width = width; | |
1224 preferred.height = height; | |
1225 getShell().setBounds(getConstrainedShellBounds(preferred)); | |
1226 } | |
1227 | |
1228 /** | |
1229 * Shows the preference page corresponding to the given preference node. | |
1230 * Does nothing if that page is already current. | |
1231 * | |
1232 * @param node | |
1233 * the preference node, or <code>null</code> if none | |
1234 * @return <code>true</code> if the page flip was successful, and | |
1235 * <code>false</code> is unsuccessful | |
1236 */ | |
1237 protected bool showPage(IPreferenceNode node) { | |
1238 if (node is null) { | |
1239 return false; | |
1240 } | |
1241 // Create the page if nessessary | |
1242 if (node.getPage() is null) { | |
1243 createPage(node); | |
1244 } | |
1245 if (node.getPage() is null) { | |
1246 return false; | |
1247 } | |
1248 IPreferencePage newPage = getPage(node); | |
1249 if (newPage is currentPage) { | |
1250 return true; | |
1251 } | |
1252 if (currentPage !is null) { | |
1253 if (!currentPage.okToLeave()) { | |
1254 return false; | |
1255 } | |
1256 } | |
1257 IPreferencePage oldPage = currentPage; | |
1258 currentPage = newPage; | |
1259 // Set the new page's container | |
1260 currentPage.setContainer(this); | |
1261 // Ensure that the page control has been created | |
1262 // (this allows lazy page control creation) | |
1263 if (currentPage.getControl() is null) { | |
34 | 1264 bool[1] failed; failed[0] = false; |
46 | 1265 SafeRunnable.run(new class(failed) ISafeRunnable { |
1266 bool[] failed_; | |
1267 this(bool[] a){ | |
1268 this.failed_=a; | |
1269 } | |
34 | 1270 public void handleException(Exception e) { |
46 | 1271 this.failed_[0] = true; |
9 | 1272 } |
1273 | |
1274 public void run() { | |
1275 createPageControl(currentPage, pageContainer); | |
1276 } | |
1277 }); | |
1278 if (failed[0]) { | |
1279 return false; | |
1280 } | |
1281 // the page is responsible for ensuring the created control is | |
1282 // accessable | |
1283 // via getControl. | |
1284 Assert.isNotNull(currentPage.getControl()); | |
1285 } | |
1286 // Force calculation of the page's description label because | |
1287 // label can be wrapped. | |
46 | 1288 Point[1] size; |
1289 Point failed = new Point(-1, -1); | |
1290 SafeRunnable.run(new class(size,failed) ISafeRunnable { | |
1291 Point[] size_; | |
1292 Point failed_; | |
1293 this(Point[] a,Point b){ | |
1294 size_=a; | |
1295 failed_=b; | |
1296 } | |
34 | 1297 public void handleException(Exception e) { |
46 | 1298 size_[0] = failed_; |
9 | 1299 } |
1300 | |
1301 public void run() { | |
46 | 1302 size_[0] = currentPage.computeSize(); |
9 | 1303 } |
1304 }); | |
34 | 1305 if (size[0].opEquals(failed)) { |
9 | 1306 return false; |
1307 } | |
1308 Point contentSize = size[0]; | |
1309 // Do we need resizing. Computation not needed if the | |
1310 // first page is inserted since computing the dialog's | |
1311 // size is done by calling dialog.open(). | |
1312 // Also prevent auto resize if the user has manually resized | |
1313 Shell shell = getShell(); | |
1314 Point shellSize = shell.getSize(); | |
1315 if (oldPage !is null) { | |
1316 Rectangle rect = pageContainer.getClientArea(); | |
1317 Point containerSize = new Point(rect.width, rect.height); | |
1318 int hdiff = contentSize.x - containerSize.x; | |
1319 int vdiff = contentSize.y - containerSize.y; | |
34 | 1320 if ((hdiff > 0 || vdiff > 0) && shellSize.opEquals(lastShellSize)) { |
9 | 1321 hdiff = Math.max(0, hdiff); |
1322 vdiff = Math.max(0, vdiff); | |
1323 setShellSize(shellSize.x + hdiff, shellSize.y + vdiff); | |
1324 lastShellSize = shell.getSize(); | |
1325 if (currentPage.getControl().getSize().x is 0) { | |
1326 currentPage.getControl().setSize(containerSize); | |
1327 } | |
1328 | |
1329 } else { | |
1330 currentPage.setSize(containerSize); | |
1331 } | |
1332 } | |
1333 | |
1334 scrolled.setMinSize(contentSize); | |
1335 // Ensure that all other pages are invisible | |
1336 // (including ones that triggered an exception during | |
1337 // their creation). | |
1338 Control[] children = pageContainer.getChildren(); | |
1339 Control currentControl = currentPage.getControl(); | |
1340 for (int i = 0; i < children.length; i++) { | |
1341 if (children[i] !is currentControl) { | |
1342 children[i].setVisible(false); | |
1343 } | |
1344 } | |
1345 // Make the new page visible | |
1346 currentPage.setVisible(true); | |
1347 if (oldPage !is null) { | |
1348 oldPage.setVisible(false); | |
1349 } | |
1350 // update the dialog controls | |
1351 update(); | |
1352 return true; | |
1353 } | |
1354 | |
1355 /** | |
1356 * Create the page for the node. | |
1357 * @param node | |
1358 * | |
1359 * @since 3.1 | |
1360 */ | |
1361 protected void createPage(IPreferenceNode node) { | |
1362 node.createPage(); | |
1363 } | |
1364 | |
1365 /** | |
1366 * Get the page for the node. | |
1367 * @param node | |
1368 * @return IPreferencePage | |
1369 * | |
1370 * @since 3.1 | |
1371 */ | |
1372 protected IPreferencePage getPage(IPreferenceNode node) { | |
1373 return node.getPage(); | |
1374 } | |
1375 | |
1376 /** | |
1377 * Shows the "Page Flipping abort" dialog. | |
1378 */ | |
1379 void showPageFlippingAbortDialog() { | |
1380 MessageDialog.openError(getShell(), JFaceResources | |
1381 .getString("AbortPageFlippingDialog.title"), //$NON-NLS-1$ | |
1382 JFaceResources.getString("AbortPageFlippingDialog.message")); //$NON-NLS-1$ | |
1383 } | |
1384 | |
1385 /** | |
1386 * Updates this dialog's controls to reflect the current page. | |
1387 */ | |
1388 protected void update() { | |
1389 // Update the title bar | |
1390 updateTitle(); | |
1391 // Update the message line | |
1392 updateMessage(); | |
1393 // Update the buttons | |
1394 updateButtons(); | |
1395 //Saved the selected node in the preferences | |
1396 setSelectedNode(); | |
34 | 1397 firePageChanged(new PageChangedEvent(this, cast(Object)getCurrentPage())); |
9 | 1398 } |
1399 | |
1400 /* | |
1401 * (non-Javadoc) | |
1402 * | |
1403 * @see dwtx.jface.preference.IPreferencePageContainer#updateButtons() | |
1404 */ | |
1405 public void updateButtons() { | |
1406 okButton.setEnabled(isCurrentPageValid()); | |
1407 } | |
1408 | |
1409 /* | |
1410 * (non-Javadoc) | |
1411 * | |
1412 * @see dwtx.jface.preference.IPreferencePageContainer#updateMessage() | |
1413 */ | |
1414 public void updateMessage() { | |
1415 String message = null; | |
1416 String errorMessage = null; | |
1417 if(currentPage !is null){ | |
1418 message = currentPage.getMessage(); | |
1419 errorMessage = currentPage.getErrorMessage(); | |
1420 } | |
1421 int messageType = IMessageProvider.NONE; | |
34 | 1422 if (message !is null && cast(IMessageProvider)currentPage ) { |
1423 messageType = (cast(IMessageProvider) currentPage).getMessageType(); | |
9 | 1424 } |
1425 | |
1426 if (errorMessage is null){ | |
1427 if (showingError) { | |
1428 // we were previously showing an error | |
1429 showingError = false; | |
1430 } | |
1431 } | |
1432 else { | |
1433 message = errorMessage; | |
1434 messageType = IMessageProvider.ERROR; | |
1435 if (!showingError) { | |
1436 // we were not previously showing an error | |
1437 showingError = true; | |
1438 } | |
1439 } | |
1440 messageArea.updateText(message,messageType); | |
1441 } | |
1442 | |
1443 /* | |
1444 * (non-Javadoc) | |
1445 * | |
1446 * @see dwtx.jface.preference.IPreferencePageContainer#updateTitle() | |
1447 */ | |
1448 public void updateTitle() { | |
1449 if(currentPage is null) { | |
1450 return; | |
1451 } | |
1452 messageArea.showTitle(currentPage.getTitle(), currentPage.getImage()); | |
1453 } | |
1454 | |
1455 /** | |
1456 * Update the tree to use the specified <code>Font</code>. | |
1457 * | |
1458 * @param dialogFont | |
1459 * the <code>Font</code> to use. | |
1460 * @since 3.0 | |
1461 */ | |
1462 protected void updateTreeFont(Font dialogFont) { | |
1463 getTreeViewer().getControl().setFont(dialogFont); | |
1464 } | |
1465 | |
1466 /** | |
1467 * Returns the currentPage. | |
1468 * @return IPreferencePage | |
1469 * @since 3.1 | |
1470 */ | |
1471 protected IPreferencePage getCurrentPage() { | |
1472 return currentPage; | |
1473 } | |
1474 | |
1475 /** | |
1476 * Sets the current page. | |
1477 * @param currentPage | |
1478 * | |
1479 * @since 3.1 | |
1480 */ | |
1481 protected void setCurrentPage(IPreferencePage currentPage) { | |
1482 this.currentPage = currentPage; | |
1483 } | |
1484 | |
1485 /** | |
1486 * Set the treeViewer. | |
1487 * @param treeViewer | |
1488 * | |
1489 * @since 3.1 | |
1490 */ | |
1491 protected void setTreeViewer(TreeViewer treeViewer) { | |
1492 this.treeViewer = treeViewer; | |
1493 } | |
1494 | |
1495 /** | |
1496 * Get the composite that is showing the page. | |
1497 * | |
1498 * @return Composite. | |
1499 * | |
1500 * @since 3.1 | |
1501 */ | |
1502 protected Composite getPageContainer() { | |
1503 return this.pageContainer; | |
1504 } | |
1505 | |
1506 /** | |
1507 * Set the composite that is showing the page. | |
1508 * @param pageContainer Composite | |
1509 * | |
1510 * @since 3.1 | |
1511 */ | |
1512 protected void setPageContainer(Composite pageContainer) { | |
1513 this.pageContainer = pageContainer; | |
1514 } | |
1515 /** | |
1516 * Create the page control for the supplied page. | |
1517 * | |
1518 * @param page - the preference page to be shown | |
1519 * @param parent - the composite to parent the page | |
1520 * | |
1521 * @since 3.1 | |
1522 */ | |
1523 protected void createPageControl(IPreferencePage page, Composite parent) { | |
1524 page.createControl(parent); | |
1525 } | |
1526 | |
1527 /** | |
1528 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage() | |
1529 * | |
1530 * @since 3.1 | |
1531 */ | |
1532 public Object getSelectedPage() { | |
34 | 1533 return cast(Object)getCurrentPage(); |
9 | 1534 } |
1535 | |
1536 /** | |
1537 * @see dwtx.jface.dialogs.IPageChangeProvider#addPageChangedListener(dwtx.jface.dialogs.IPageChangedListener) | |
1538 * @since 3.1 | |
1539 */ | |
1540 public void addPageChangedListener(IPageChangedListener listener) { | |
34 | 1541 pageChangedListeners.add(cast(Object)listener); |
9 | 1542 } |
1543 | |
1544 /** | |
1545 * @see dwtx.jface.dialogs.IPageChangeProvider#removePageChangedListener(dwtx.jface.dialogs.IPageChangedListener) | |
1546 * @since 3.1 | |
1547 */ | |
1548 public void removePageChangedListener(IPageChangedListener listener) { | |
34 | 1549 pageChangedListeners.remove(cast(Object)listener); |
9 | 1550 |
1551 } | |
1552 | |
1553 /** | |
1554 * Notifies any selection changed listeners that the selected page | |
1555 * has changed. | |
1556 * Only listeners registered at the time this method is called are notified. | |
1557 * | |
1558 * @param event a selection changed event | |
1559 * | |
1560 * @see IPageChangedListener#pageChanged | |
1561 * | |
1562 * @since 3.1 | |
1563 */ | |
34 | 1564 protected void firePageChanged(PageChangedEvent event) { |
9 | 1565 Object[] listeners = pageChangedListeners.getListeners(); |
1566 for (int i = 0; i < listeners.length; i++) { | |
39 | 1567 SafeRunnable.run(new class(event,cast(IPageChangedListener) listeners[i]) SafeRunnable { |
34 | 1568 PageChangedEvent event_; |
1569 IPageChangedListener l; | |
39 | 1570 this(PageChangedEvent a,IPageChangedListener b){ |
1571 event_=a; | |
1572 l =b ; | |
34 | 1573 } |
9 | 1574 public void run() { |
34 | 1575 l.pageChanged(event_); |
9 | 1576 } |
1577 }); | |
1578 } | |
1579 } | |
71 | 1580 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1581 /* |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1582 * (non-Javadoc) |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1583 * @see dwtx.jface.dialogs.Dialog#isResizable() |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1584 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1585 protected bool isResizable() { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1586 return true; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1587 } |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1588 |
9 | 1589 } |