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