Mercurial > projects > dwt-addons
annotate dwtx/jface/preference/PreferenceDialog.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | 9d7d88f13040 |
children | 4878bef4a38e |
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 ) { | |
9 | 740 if (!isCurrentPageValid()) { |
741 handleError(); | |
34 | 742 } else if (!showPage(cast(IPreferenceNode) selection)) { |
9 | 743 // Page flipping wasn't successful |
744 handleError(); | |
745 } else { | |
746 // Everything went well | |
34 | 747 lastSuccessfulNode = cast(IPreferenceNode) selection; |
9 | 748 } |
749 } | |
750 } | |
751 }); | |
39 | 752 (cast(Tree) viewer.getControl()).addSelectionListener(new class(viewer) SelectionAdapter { |
34 | 753 TreeViewer viewer_; |
39 | 754 this(TreeViewer a){ |
755 viewer_=a; | |
34 | 756 } |
757 public void widgetDefaultSelected(SelectionEvent event) { | |
758 ISelection selection = viewer_.getSelection(); | |
9 | 759 if (selection.isEmpty()) { |
760 return; | |
761 } | |
762 IPreferenceNode singleSelection = getSingleSelection(selection); | |
34 | 763 bool expanded = viewer_.getExpandedState(cast(Object)singleSelection); |
764 viewer_.setExpandedState(cast(Object)singleSelection, !expanded); | |
9 | 765 } |
766 }); | |
767 //Register help listener on the tree to use context sensitive help | |
34 | 768 viewer.getControl().addHelpListener(new class HelpListener { |
9 | 769 public void helpRequested(HelpEvent event) { |
770 // call perform help on the current page | |
771 if (currentPage !is null) { | |
772 currentPage.performHelp(); | |
773 } | |
774 } | |
775 }); | |
776 } | |
777 | |
778 /** | |
779 * Find the <code>IPreferenceNode</code> that has data the same id as the | |
780 * supplied value. | |
781 * | |
782 * @param nodeId | |
783 * the id to search for. | |
784 * @return <code>IPreferenceNode</code> or <code>null</code> if not | |
785 * found. | |
786 */ | |
787 protected IPreferenceNode findNodeMatching(String nodeId) { | |
34 | 788 foreach( e; preferenceManager.getElements(PreferenceManager.POST_ORDER)){ |
789 IPreferenceNode node = cast(IPreferenceNode) e; | |
9 | 790 if (node.getId().equals(nodeId)) { |
791 return node; | |
792 } | |
793 } | |
794 return null; | |
795 } | |
796 | |
797 /** | |
798 * Get the last known right side width. | |
799 * | |
800 * @return the width. | |
801 */ | |
802 protected int getLastRightWidth() { | |
803 return lastTreeWidth; | |
804 } | |
805 | |
806 /** | |
807 * Returns the preference mananger used by this preference dialog. | |
808 * | |
809 * @return the preference mananger | |
810 */ | |
811 public PreferenceManager getPreferenceManager() { | |
812 return preferenceManager; | |
813 } | |
814 | |
815 /* | |
816 * (non-Javadoc) | |
817 * | |
818 * @see dwtx.jface.preference.IPreferencePageContainer#getPreferenceStore() | |
819 */ | |
820 public IPreferenceStore getPreferenceStore() { | |
821 return preferenceStore; | |
822 } | |
823 | |
824 /** | |
825 * Get the name of the selected item preference | |
826 * | |
827 * @return String | |
828 */ | |
829 protected String getSelectedNodePreference() { | |
830 return lastPreferenceId; | |
831 } | |
832 | |
833 /** | |
834 * @param selection | |
835 * the <code>ISelection</code> to examine. | |
836 * @return the first element, or null if empty. | |
837 */ | |
838 protected IPreferenceNode getSingleSelection(ISelection selection) { | |
839 if (!selection.isEmpty()) { | |
34 | 840 IStructuredSelection structured = cast(IStructuredSelection) selection; |
841 if (cast(IPreferenceNode)structured.getFirstElement() ) { | |
842 return cast(IPreferenceNode) structured.getFirstElement(); | |
9 | 843 } |
844 } | |
845 return null; | |
846 } | |
847 | |
848 /** | |
849 * @return the <code>TreeViewer</code> for this dialog. | |
850 * @since 3.3 | |
851 */ | |
852 public TreeViewer getTreeViewer() { | |
853 return treeViewer; | |
854 } | |
855 | |
856 /** | |
857 * Save the values specified in the pages. | |
858 * <p> | |
859 * The default implementation of this framework method saves all pages of | |
860 * type <code>PreferencePage</code> (if their store needs saving and is a | |
861 * <code>PreferenceStore</code>). | |
862 * </p> | |
863 * <p> | |
864 * Subclasses may override. | |
865 * </p> | |
866 */ | |
867 protected void handleSave() { | |
34 | 868 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){ |
869 IPreferenceNode node = cast(IPreferenceNode) e; | |
9 | 870 IPreferencePage page = node.getPage(); |
34 | 871 if (cast(PreferencePage)page ) { |
9 | 872 // Save now in case tbe workbench does not shutdown cleanly |
34 | 873 IPreferenceStore store = (cast(PreferencePage) page).getPreferenceStore(); |
9 | 874 if (store !is null && store.needsSaving() |
34 | 875 && cast(IPersistentPreferenceStore)store ) { |
9 | 876 try { |
34 | 877 (cast(IPersistentPreferenceStore) store).save(); |
9 | 878 } catch (IOException e) { |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
879 String message =JFaceResources.format( |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
880 "PreferenceDialog.saveErrorMessage", new Object[] { page.getTitle(), e.getMessage() }); //$NON-NLS-1$ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
881 Policy.getStatusHandler().show( |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
882 new Status(IStatus.ERROR, Policy.JFACE, message, e), |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
883 JFaceResources.getString("PreferenceDialog.saveErrorTitle")); //$NON-NLS-1$ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
884 |
9 | 885 } |
886 } | |
887 } | |
888 } | |
889 } | |
890 | |
891 /** | |
892 * Notifies that the window's close button was pressed, the close menu was | |
893 * selected, or the ESCAPE key pressed. | |
894 * <p> | |
895 * The default implementation of this framework method sets the window's | |
896 * return code to <code>CANCEL</code> and closes the window using | |
897 * <code>close</code>. Subclasses may extend or reimplement. | |
898 * </p> | |
899 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
900 protected override void handleShellCloseEvent() { |
9 | 901 // handle the same as pressing cancel |
902 cancelPressed(); | |
903 } | |
904 | |
905 /** | |
906 * Notifies of the pressing of the Help button. | |
907 * <p> | |
908 * The default implementation of this framework method calls | |
909 * <code>performHelp</code> on the currently active page. | |
910 * </p> | |
911 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
912 protected /+override+/ void helpPressed() { |
9 | 913 if (currentPage !is null) { |
914 currentPage.performHelp(); | |
915 } | |
916 } | |
917 | |
918 /** | |
919 * Returns whether the current page is valid. | |
920 * | |
921 * @return <code>false</code> if the current page is not valid, or or | |
922 * <code>true</code> if the current page is valid or there is no | |
923 * current page | |
924 */ | |
925 protected bool isCurrentPageValid() { | |
926 if (currentPage is null) { | |
927 return true; | |
928 } | |
929 return currentPage.isValid(); | |
930 } | |
931 | |
932 /** | |
933 * @param control | |
934 * the <code>Control</code> to lay out. | |
935 * @since 3.0 | |
936 */ | |
937 protected void layoutTreeAreaControl(Control control) { | |
938 GridData gd = new GridData(GridData.FILL_VERTICAL); | |
939 gd.widthHint = getLastRightWidth(); | |
940 gd.verticalSpan = 1; | |
941 control.setLayoutData(gd); | |
942 } | |
943 | |
944 /** | |
945 * The preference dialog implementation of this <code>Dialog</code> | |
946 * framework method sends <code>performOk</code> to all pages of the | |
947 * preference dialog, then calls <code>handleSave</code> on this dialog to | |
948 * save any state, and then calls <code>close</code> to close this dialog. | |
949 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
950 protected override void okPressed() { |
34 | 951 SafeRunnable.run(new class SafeRunnable { |
9 | 952 private bool errorOccurred; |
953 | |
954 /* | |
955 * (non-Javadoc) | |
956 * | |
957 * @see dwtx.core.runtime.ISafeRunnable#run() | |
958 */ | |
959 public void run() { | |
960 getButton(IDialogConstants.OK_ID).setEnabled(false); | |
961 errorOccurred = false; | |
962 bool hasFailedOK = false; | |
963 try { | |
964 // Notify all the pages and give them a chance to abort | |
34 | 965 foreach( e; preferenceManager.getElements(PreferenceManager.PRE_ORDER)){ |
966 IPreferenceNode node = cast(IPreferenceNode) e; | |
9 | 967 IPreferencePage page = node.getPage(); |
968 if (page !is null) { | |
969 if (!page.performOk()){ | |
970 hasFailedOK = true; | |
971 return; | |
972 } | |
973 } | |
974 } | |
975 } catch (Exception e) { | |
976 handleException(e); | |
977 } finally { | |
978 //Don't bother closing if the OK failed | |
979 if(hasFailedOK){ | |
980 setReturnCode(FAILED); | |
981 getButton(IDialogConstants.OK_ID).setEnabled(true); | |
34 | 982 //return; |
9 | 983 } |
34 | 984 else{ |
9 | 985 |
34 | 986 if (!errorOccurred) { |
987 //Give subclasses the choice to save the state of the | |
988 //preference pages. | |
989 handleSave(); | |
990 } | |
991 setReturnCode(OK); | |
992 close(); | |
9 | 993 } |
994 } | |
995 } | |
996 | |
997 /* | |
998 * (non-Javadoc) | |
999 * | |
1000 * @see dwtx.core.runtime.ISafeRunnable#handleException(java.lang.Throwable) | |
1001 */ | |
34 | 1002 public void handleException(Exception e) { |
9 | 1003 errorOccurred = true; |
1004 | |
1005 Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e)); | |
1006 | |
1007 clearSelectedNode(); | |
1008 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
|
1009 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1010 Policy.getStatusHandler().show( |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1011 new Status(IStatus.ERROR, Policy.JFACE, message, e), |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1012 JFaceResources.getString("Error")); //$NON-NLS-1$ |
9 | 1013 |
1014 } | |
1015 }); | |
1016 } | |
1017 | |
1018 /** | |
1019 * Selects the page determined by <code>lastSuccessfulNode</code> in the | |
1020 * page hierarchy. | |
1021 */ | |
1022 void selectCurrentPageAgain() { | |
1023 if (lastSuccessfulNode is null) { | |
1024 return; | |
1025 } | |
34 | 1026 getTreeViewer().setSelection(new StructuredSelection(cast(Object)lastSuccessfulNode)); |
9 | 1027 currentPage.setVisible(true); |
1028 } | |
1029 | |
1030 /** | |
1031 * Selects the saved item in the tree of preference pages. If it cannot do | |
1032 * this it saves the first one. | |
1033 */ | |
1034 protected void selectSavedItem() { | |
1035 IPreferenceNode node = findNodeMatching(getSelectedNodePreference()); | |
1036 if (node is null) { | |
1037 IPreferenceNode[] nodes = preferenceManager.getRootSubNodes(); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1038 ViewerComparator comparator = getTreeViewer().getComparator(); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1039 if (comparator !is null) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1040 comparator.sort(null, nodes); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1041 } |
9 | 1042 ViewerFilter[] filters = getTreeViewer().getFilters(); |
1043 for (int i = 0; i < nodes.length; i++) { | |
1044 IPreferenceNode selectedNode = nodes[i]; | |
1045 // See if it passes all filters | |
1046 for (int j = 0; j < filters.length; j++) { | |
34 | 1047 if (!filters[j].select(this.treeViewer, cast(Object)preferenceManager |
1048 .getRoot_package(), cast(Object)selectedNode)) { | |
9 | 1049 selectedNode = null; |
1050 break; | |
1051 } | |
1052 } | |
1053 // if it passes all filters select it | |
1054 if (selectedNode !is null) { | |
1055 node = selectedNode; | |
1056 break; | |
1057 } | |
1058 } | |
1059 } | |
1060 if (node !is null) { | |
34 | 1061 getTreeViewer().setSelection(new StructuredSelection(cast(Object)node), true); |
9 | 1062 // Keep focus in tree. See bugs 2692, 2621, and 6775. |
1063 getTreeViewer().getControl().setFocus(); | |
1064 } | |
1065 } | |
1066 | |
1067 /** | |
1068 * Display the given error message. The currently displayed message is saved | |
1069 * and will be redisplayed when the error message is set to | |
1070 * <code>null</code>. | |
1071 * | |
1072 * @param newErrorMessage | |
1073 * the errorMessage to display or <code>null</code> | |
1074 */ | |
1075 public void setErrorMessage(String newErrorMessage) { | |
1076 if (newErrorMessage is null) { | |
1077 messageArea.clearErrorMessage(); | |
1078 } else { | |
1079 messageArea.updateText(newErrorMessage, IMessageProvider.ERROR); | |
1080 } | |
1081 } | |
1082 | |
1083 /** | |
1084 * Save the last known tree width. | |
1085 * | |
1086 * @param width | |
1087 * the width. | |
1088 */ | |
1089 private void setLastTreeWidth(int width) { | |
1090 lastTreeWidth = width; | |
1091 } | |
1092 | |
1093 /** | |
1094 * Set the message text. If the message line currently displays an error, | |
1095 * the message is stored and will be shown after a call to clearErrorMessage | |
1096 * <p> | |
1097 * Shortcut for <code>setMessage(newMessage, NONE)</code> | |
1098 * </p> | |
1099 * | |
1100 * @param newMessage | |
1101 * the message, or <code>null</code> to clear the message | |
1102 */ | |
1103 public void setMessage(String newMessage) { | |
1104 setMessage(newMessage, IMessageProvider.NONE); | |
1105 } | |
1106 | |
1107 /** | |
1108 * Sets the message for this dialog with an indication of what type of | |
1109 * message it is. | |
1110 * <p> | |
1111 * The valid message types are one of <code>NONE</code>, | |
1112 * <code>INFORMATION</code>,<code>WARNING</code>, or | |
1113 * <code>ERROR</code>. | |
1114 * </p> | |
1115 * <p> | |
1116 * Note that for backward compatibility, a message of type | |
1117 * <code>ERROR</code> is different than an error message (set using | |
1118 * <code>setErrorMessage</code>). An error message overrides the current | |
1119 * message until the error message is cleared. This method replaces the | |
1120 * current message and does not affect the error message. | |
1121 * </p> | |
1122 * | |
1123 * @param newMessage | |
1124 * the message, or <code>null</code> to clear the message | |
1125 * @param newType | |
1126 * the message type | |
1127 * @since 2.0 | |
1128 */ | |
1129 public void setMessage(String newMessage, int newType) { | |
1130 messageArea.updateText(newMessage, newType); | |
1131 } | |
1132 | |
1133 /** | |
1134 * Sets the minimum page size. | |
1135 * | |
1136 * @param minWidth | |
1137 * the minimum page width | |
1138 * @param minHeight | |
1139 * the minimum page height | |
1140 * @see #setMinimumPageSize(Point) | |
1141 */ | |
1142 public void setMinimumPageSize(int minWidth, int minHeight) { | |
1143 minimumPageSize.x = minWidth; | |
1144 minimumPageSize.y = minHeight; | |
1145 } | |
1146 | |
1147 /** | |
1148 * Sets the minimum page size. | |
1149 * | |
1150 * @param size | |
1151 * the page size encoded as <code>new Point(width,height)</code> | |
1152 * @see #setMinimumPageSize(int,int) | |
1153 */ | |
1154 public void setMinimumPageSize(Point size) { | |
1155 minimumPageSize.x = size.x; | |
1156 minimumPageSize.y = size.y; | |
1157 } | |
1158 | |
1159 /** | |
1160 * Sets the preference store for this preference dialog. | |
1161 * | |
1162 * @param store | |
1163 * the preference store | |
1164 * @see #getPreferenceStore | |
1165 */ | |
1166 public void setPreferenceStore(IPreferenceStore store) { | |
34 | 1167 Assert.isNotNull(cast(Object)store); |
9 | 1168 preferenceStore = store; |
1169 } | |
1170 | |
1171 /** | |
1172 * Save the currently selected node. | |
1173 */ | |
1174 private void setSelectedNode() { | |
1175 String storeValue = null; | |
34 | 1176 IStructuredSelection selection = cast(IStructuredSelection) getTreeViewer().getSelection(); |
9 | 1177 if (selection.size() is 1) { |
34 | 1178 IPreferenceNode node = cast(IPreferenceNode) selection.getFirstElement(); |
9 | 1179 storeValue = node.getId(); |
1180 } | |
1181 setSelectedNodePreference(storeValue); | |
1182 } | |
1183 | |
1184 /** | |
1185 * Sets the name of the selected item preference. Public equivalent to | |
1186 * <code>setSelectedNodePreference</code>. | |
1187 * | |
1188 * @param pageId | |
1189 * The identifier for the page | |
1190 * @since 3.0 | |
1191 */ | |
1192 public void setSelectedNode(String pageId) { | |
1193 setSelectedNodePreference(pageId); | |
1194 } | |
1195 | |
1196 /** | |
1197 * Sets the name of the selected item preference. | |
1198 * | |
1199 * @param pageId | |
1200 * The identifier for the page | |
1201 */ | |
1202 protected void setSelectedNodePreference(String pageId) { | |
1203 lastPreferenceId = pageId; | |
1204 } | |
1205 | |
1206 /** | |
1207 * Changes the shell size to the given size, ensuring that it is no larger | |
1208 * than the display bounds. | |
1209 * | |
1210 * @param width | |
1211 * the shell width | |
1212 * @param height | |
1213 * the shell height | |
1214 */ | |
1215 private void setShellSize(int width, int height) { | |
1216 Rectangle preferred = getShell().getBounds(); | |
1217 preferred.width = width; | |
1218 preferred.height = height; | |
1219 getShell().setBounds(getConstrainedShellBounds(preferred)); | |
1220 } | |
1221 | |
1222 /** | |
1223 * Shows the preference page corresponding to the given preference node. | |
1224 * Does nothing if that page is already current. | |
1225 * | |
1226 * @param node | |
1227 * the preference node, or <code>null</code> if none | |
1228 * @return <code>true</code> if the page flip was successful, and | |
1229 * <code>false</code> is unsuccessful | |
1230 */ | |
1231 protected bool showPage(IPreferenceNode node) { | |
1232 if (node is null) { | |
1233 return false; | |
1234 } | |
1235 // Create the page if nessessary | |
1236 if (node.getPage() is null) { | |
1237 createPage(node); | |
1238 } | |
1239 if (node.getPage() is null) { | |
1240 return false; | |
1241 } | |
1242 IPreferencePage newPage = getPage(node); | |
1243 if (newPage is currentPage) { | |
1244 return true; | |
1245 } | |
1246 if (currentPage !is null) { | |
1247 if (!currentPage.okToLeave()) { | |
1248 return false; | |
1249 } | |
1250 } | |
1251 IPreferencePage oldPage = currentPage; | |
1252 currentPage = newPage; | |
1253 // Set the new page's container | |
1254 currentPage.setContainer(this); | |
1255 // Ensure that the page control has been created | |
1256 // (this allows lazy page control creation) | |
1257 if (currentPage.getControl() is null) { | |
34 | 1258 bool[1] failed; failed[0] = false; |
46 | 1259 SafeRunnable.run(new class(failed) ISafeRunnable { |
1260 bool[] failed_; | |
1261 this(bool[] a){ | |
1262 this.failed_=a; | |
1263 } | |
34 | 1264 public void handleException(Exception e) { |
46 | 1265 this.failed_[0] = true; |
9 | 1266 } |
1267 | |
1268 public void run() { | |
1269 createPageControl(currentPage, pageContainer); | |
1270 } | |
1271 }); | |
1272 if (failed[0]) { | |
1273 return false; | |
1274 } | |
1275 // the page is responsible for ensuring the created control is | |
1276 // accessable | |
1277 // via getControl. | |
1278 Assert.isNotNull(currentPage.getControl()); | |
1279 } | |
1280 // Force calculation of the page's description label because | |
1281 // label can be wrapped. | |
46 | 1282 Point[1] size; |
1283 Point failed = new Point(-1, -1); | |
1284 SafeRunnable.run(new class(size,failed) ISafeRunnable { | |
1285 Point[] size_; | |
1286 Point failed_; | |
1287 this(Point[] a,Point b){ | |
1288 size_=a; | |
1289 failed_=b; | |
1290 } | |
34 | 1291 public void handleException(Exception e) { |
46 | 1292 size_[0] = failed_; |
9 | 1293 } |
1294 | |
1295 public void run() { | |
46 | 1296 size_[0] = currentPage.computeSize(); |
9 | 1297 } |
1298 }); | |
34 | 1299 if (size[0].opEquals(failed)) { |
9 | 1300 return false; |
1301 } | |
1302 Point contentSize = size[0]; | |
1303 // Do we need resizing. Computation not needed if the | |
1304 // first page is inserted since computing the dialog's | |
1305 // size is done by calling dialog.open(). | |
1306 // Also prevent auto resize if the user has manually resized | |
1307 Shell shell = getShell(); | |
1308 Point shellSize = shell.getSize(); | |
1309 if (oldPage !is null) { | |
1310 Rectangle rect = pageContainer.getClientArea(); | |
1311 Point containerSize = new Point(rect.width, rect.height); | |
1312 int hdiff = contentSize.x - containerSize.x; | |
1313 int vdiff = contentSize.y - containerSize.y; | |
34 | 1314 if ((hdiff > 0 || vdiff > 0) && shellSize.opEquals(lastShellSize)) { |
9 | 1315 hdiff = Math.max(0, hdiff); |
1316 vdiff = Math.max(0, vdiff); | |
1317 setShellSize(shellSize.x + hdiff, shellSize.y + vdiff); | |
1318 lastShellSize = shell.getSize(); | |
1319 if (currentPage.getControl().getSize().x is 0) { | |
1320 currentPage.getControl().setSize(containerSize); | |
1321 } | |
1322 | |
1323 } else { | |
1324 currentPage.setSize(containerSize); | |
1325 } | |
1326 } | |
1327 | |
1328 scrolled.setMinSize(contentSize); | |
1329 // Ensure that all other pages are invisible | |
1330 // (including ones that triggered an exception during | |
1331 // their creation). | |
1332 Control[] children = pageContainer.getChildren(); | |
1333 Control currentControl = currentPage.getControl(); | |
1334 for (int i = 0; i < children.length; i++) { | |
1335 if (children[i] !is currentControl) { | |
1336 children[i].setVisible(false); | |
1337 } | |
1338 } | |
1339 // Make the new page visible | |
1340 currentPage.setVisible(true); | |
1341 if (oldPage !is null) { | |
1342 oldPage.setVisible(false); | |
1343 } | |
1344 // update the dialog controls | |
1345 update(); | |
1346 return true; | |
1347 } | |
1348 | |
1349 /** | |
1350 * Create the page for the node. | |
1351 * @param node | |
1352 * | |
1353 * @since 3.1 | |
1354 */ | |
1355 protected void createPage(IPreferenceNode node) { | |
1356 node.createPage(); | |
1357 } | |
1358 | |
1359 /** | |
1360 * Get the page for the node. | |
1361 * @param node | |
1362 * @return IPreferencePage | |
1363 * | |
1364 * @since 3.1 | |
1365 */ | |
1366 protected IPreferencePage getPage(IPreferenceNode node) { | |
1367 return node.getPage(); | |
1368 } | |
1369 | |
1370 /** | |
1371 * Shows the "Page Flipping abort" dialog. | |
1372 */ | |
1373 void showPageFlippingAbortDialog() { | |
1374 MessageDialog.openError(getShell(), JFaceResources | |
1375 .getString("AbortPageFlippingDialog.title"), //$NON-NLS-1$ | |
1376 JFaceResources.getString("AbortPageFlippingDialog.message")); //$NON-NLS-1$ | |
1377 } | |
1378 | |
1379 /** | |
1380 * Updates this dialog's controls to reflect the current page. | |
1381 */ | |
1382 protected void update() { | |
1383 // Update the title bar | |
1384 updateTitle(); | |
1385 // Update the message line | |
1386 updateMessage(); | |
1387 // Update the buttons | |
1388 updateButtons(); | |
1389 //Saved the selected node in the preferences | |
1390 setSelectedNode(); | |
34 | 1391 firePageChanged(new PageChangedEvent(this, cast(Object)getCurrentPage())); |
9 | 1392 } |
1393 | |
1394 /* | |
1395 * (non-Javadoc) | |
1396 * | |
1397 * @see dwtx.jface.preference.IPreferencePageContainer#updateButtons() | |
1398 */ | |
1399 public void updateButtons() { | |
1400 okButton.setEnabled(isCurrentPageValid()); | |
1401 } | |
1402 | |
1403 /* | |
1404 * (non-Javadoc) | |
1405 * | |
1406 * @see dwtx.jface.preference.IPreferencePageContainer#updateMessage() | |
1407 */ | |
1408 public void updateMessage() { | |
1409 String message = null; | |
1410 String errorMessage = null; | |
1411 if(currentPage !is null){ | |
1412 message = currentPage.getMessage(); | |
1413 errorMessage = currentPage.getErrorMessage(); | |
1414 } | |
1415 int messageType = IMessageProvider.NONE; | |
34 | 1416 if (message !is null && cast(IMessageProvider)currentPage ) { |
1417 messageType = (cast(IMessageProvider) currentPage).getMessageType(); | |
9 | 1418 } |
1419 | |
1420 if (errorMessage is null){ | |
1421 if (showingError) { | |
1422 // we were previously showing an error | |
1423 showingError = false; | |
1424 } | |
1425 } | |
1426 else { | |
1427 message = errorMessage; | |
1428 messageType = IMessageProvider.ERROR; | |
1429 if (!showingError) { | |
1430 // we were not previously showing an error | |
1431 showingError = true; | |
1432 } | |
1433 } | |
1434 messageArea.updateText(message,messageType); | |
1435 } | |
1436 | |
1437 /* | |
1438 * (non-Javadoc) | |
1439 * | |
1440 * @see dwtx.jface.preference.IPreferencePageContainer#updateTitle() | |
1441 */ | |
1442 public void updateTitle() { | |
1443 if(currentPage is null) { | |
1444 return; | |
1445 } | |
1446 messageArea.showTitle(currentPage.getTitle(), currentPage.getImage()); | |
1447 } | |
1448 | |
1449 /** | |
1450 * Update the tree to use the specified <code>Font</code>. | |
1451 * | |
1452 * @param dialogFont | |
1453 * the <code>Font</code> to use. | |
1454 * @since 3.0 | |
1455 */ | |
1456 protected void updateTreeFont(Font dialogFont) { | |
1457 getTreeViewer().getControl().setFont(dialogFont); | |
1458 } | |
1459 | |
1460 /** | |
1461 * Returns the currentPage. | |
1462 * @return IPreferencePage | |
1463 * @since 3.1 | |
1464 */ | |
1465 protected IPreferencePage getCurrentPage() { | |
1466 return currentPage; | |
1467 } | |
1468 | |
1469 /** | |
1470 * Sets the current page. | |
1471 * @param currentPage | |
1472 * | |
1473 * @since 3.1 | |
1474 */ | |
1475 protected void setCurrentPage(IPreferencePage currentPage) { | |
1476 this.currentPage = currentPage; | |
1477 } | |
1478 | |
1479 /** | |
1480 * Set the treeViewer. | |
1481 * @param treeViewer | |
1482 * | |
1483 * @since 3.1 | |
1484 */ | |
1485 protected void setTreeViewer(TreeViewer treeViewer) { | |
1486 this.treeViewer = treeViewer; | |
1487 } | |
1488 | |
1489 /** | |
1490 * Get the composite that is showing the page. | |
1491 * | |
1492 * @return Composite. | |
1493 * | |
1494 * @since 3.1 | |
1495 */ | |
1496 protected Composite getPageContainer() { | |
1497 return this.pageContainer; | |
1498 } | |
1499 | |
1500 /** | |
1501 * Set the composite that is showing the page. | |
1502 * @param pageContainer Composite | |
1503 * | |
1504 * @since 3.1 | |
1505 */ | |
1506 protected void setPageContainer(Composite pageContainer) { | |
1507 this.pageContainer = pageContainer; | |
1508 } | |
1509 /** | |
1510 * Create the page control for the supplied page. | |
1511 * | |
1512 * @param page - the preference page to be shown | |
1513 * @param parent - the composite to parent the page | |
1514 * | |
1515 * @since 3.1 | |
1516 */ | |
1517 protected void createPageControl(IPreferencePage page, Composite parent) { | |
1518 page.createControl(parent); | |
1519 } | |
1520 | |
1521 /** | |
1522 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage() | |
1523 * | |
1524 * @since 3.1 | |
1525 */ | |
1526 public Object getSelectedPage() { | |
34 | 1527 return cast(Object)getCurrentPage(); |
9 | 1528 } |
1529 | |
1530 /** | |
1531 * @see dwtx.jface.dialogs.IPageChangeProvider#addPageChangedListener(dwtx.jface.dialogs.IPageChangedListener) | |
1532 * @since 3.1 | |
1533 */ | |
1534 public void addPageChangedListener(IPageChangedListener listener) { | |
34 | 1535 pageChangedListeners.add(cast(Object)listener); |
9 | 1536 } |
1537 | |
1538 /** | |
1539 * @see dwtx.jface.dialogs.IPageChangeProvider#removePageChangedListener(dwtx.jface.dialogs.IPageChangedListener) | |
1540 * @since 3.1 | |
1541 */ | |
1542 public void removePageChangedListener(IPageChangedListener listener) { | |
34 | 1543 pageChangedListeners.remove(cast(Object)listener); |
9 | 1544 |
1545 } | |
1546 | |
1547 /** | |
1548 * Notifies any selection changed listeners that the selected page | |
1549 * has changed. | |
1550 * Only listeners registered at the time this method is called are notified. | |
1551 * | |
1552 * @param event a selection changed event | |
1553 * | |
1554 * @see IPageChangedListener#pageChanged | |
1555 * | |
1556 * @since 3.1 | |
1557 */ | |
34 | 1558 protected void firePageChanged(PageChangedEvent event) { |
9 | 1559 Object[] listeners = pageChangedListeners.getListeners(); |
1560 for (int i = 0; i < listeners.length; i++) { | |
39 | 1561 SafeRunnable.run(new class(event,cast(IPageChangedListener) listeners[i]) SafeRunnable { |
34 | 1562 PageChangedEvent event_; |
1563 IPageChangedListener l; | |
39 | 1564 this(PageChangedEvent a,IPageChangedListener b){ |
1565 event_=a; | |
1566 l =b ; | |
34 | 1567 } |
9 | 1568 public void run() { |
34 | 1569 l.pageChanged(event_); |
9 | 1570 } |
1571 }); | |
1572 } | |
1573 } | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1574 |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1575 /* |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1576 * (non-Javadoc) |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1577 * @see dwtx.jface.dialogs.Dialog#isResizable() |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1578 */ |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1579 protected bool isResizable() { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
46
diff
changeset
|
1580 return true; |
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 |
9 | 1583 } |