Mercurial > projects > dwt-addons
comparison dwtx/jface/util/SafeRunnableDialog.d @ 14:cf7413989c65
SafeRunnableDialog
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 31 Mar 2008 01:56:41 +0200 |
parents | b6c35faf97c8 |
children | ea8ff534f622 |
comparison
equal
deleted
inserted
replaced
13:6886832e1ed8 | 14:cf7413989c65 |
---|---|
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | 11 * Frank Benoit <benoit@tionex.de> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module dwtx.jface.util.SafeRunnableDialog; | 13 module dwtx.jface.util.SafeRunnableDialog; |
14 | 14 |
15 pragma(msg,"FIXME dwtx.jface.util.SafeRunnableDialog" ); | 15 import tango.util.collection.model.Seq; |
16 import dwt.widgets.Shell; | 16 import tango.util.collection.ArraySeq; |
17 import dwtx.core.runtime.IStatus; | |
18 class SafeRunnableDialog{ | |
19 this(IStatus status) ; | |
20 Shell getShell(); | |
21 void create(); | |
22 void open(); | |
23 void addStatus(IStatus); | |
24 void refresh(); | |
25 } | |
26 | |
27 /++ | |
28 | |
29 | |
30 // import java.util.ArrayList; | |
31 // import java.util.Collection; | |
32 | 17 |
33 import dwt.DWT; | 18 import dwt.DWT; |
34 import dwt.graphics.Point; | 19 import dwt.graphics.Point; |
35 import dwt.layout.GridData; | 20 import dwt.layout.GridData; |
36 import dwt.widgets.Button; | 21 import dwt.widgets.Button; |
48 import dwtx.jface.viewers.SelectionChangedEvent; | 33 import dwtx.jface.viewers.SelectionChangedEvent; |
49 import dwtx.jface.viewers.TableViewer; | 34 import dwtx.jface.viewers.TableViewer; |
50 import dwtx.jface.viewers.Viewer; | 35 import dwtx.jface.viewers.Viewer; |
51 import dwtx.jface.viewers.ViewerCell; | 36 import dwtx.jface.viewers.ViewerCell; |
52 import dwtx.jface.viewers.ViewerComparator; | 37 import dwtx.jface.viewers.ViewerComparator; |
38 import dwtx.jface.util.Util; | |
53 | 39 |
54 import dwt.dwthelper.utils; | 40 import dwt.dwthelper.utils; |
55 | 41 |
56 /** | 42 /** |
57 * SafeRunnableDialog is a dialog that can show the results of multiple safe | 43 * SafeRunnableDialog is a dialog that can show the results of multiple safe |
60 */ | 46 */ |
61 class SafeRunnableDialog : ErrorDialog { | 47 class SafeRunnableDialog : ErrorDialog { |
62 | 48 |
63 private TableViewer statusListViewer; | 49 private TableViewer statusListViewer; |
64 | 50 |
65 private Collection statuses = new ArrayList(); | 51 private Seq!(IStatus) statuses; |
66 | 52 |
67 /** | 53 /** |
68 * Create a new instance of the receiver on a status. | 54 * Create a new instance of the receiver on a status. |
69 * | 55 * |
70 * @param status | 56 * @param status |
72 */ | 58 */ |
73 this(IStatus status) { | 59 this(IStatus status) { |
74 | 60 |
75 super(null, JFaceResources.getString("error"), status.getMessage(), //$NON-NLS-1$ | 61 super(null, JFaceResources.getString("error"), status.getMessage(), //$NON-NLS-1$ |
76 status, IStatus.ERROR); | 62 status, IStatus.ERROR); |
77 | 63 statuses = new ArraySeq!(IStatus); |
78 setShellStyle(DWT.DIALOG_TRIM | DWT.MODELESS | DWT.RESIZE | DWT.MIN | 64 setShellStyle(DWT.DIALOG_TRIM | DWT.MODELESS | DWT.RESIZE | DWT.MIN |
79 | getDefaultOrientation()); | 65 | getDefaultOrientation()); |
80 | 66 |
81 setStatus(status); | 67 setStatus(status); |
82 statuses.add(status); | 68 statuses.append(status); |
83 | 69 |
84 setBlockOnOpen(false); | 70 setBlockOnOpen(false); |
85 | 71 |
86 String reason = JFaceResources | 72 String reason = JFaceResources |
87 .getString("SafeRunnableDialog_checkDetailsMessage"); //$NON-NLS-1$ | 73 .getString("SafeRunnableDialog_checkDetailsMessage"); //$NON-NLS-1$ |
88 if (status.getException() !is null) { | 74 if (status.getException() !is null) { |
89 reason = status.getException().getMessage() is null ? status | 75 reason = status.getException().msg is null ? status |
90 .getException().toString() : status.getException() | 76 .getException().toString() : status.getException() |
91 .getMessage(); | 77 .msg; |
92 } | 78 } |
93 this.message = JFaceResources.format(JFaceResources | 79 this.message = JFaceResources.format(JFaceResources |
94 .getString("SafeRunnableDialog_reason"), new Object[] { //$NON-NLS-1$ | 80 .getString("SafeRunnableDialog_reason"), [ //$NON-NLS-1$ |
95 status.getMessage(), reason }); | 81 status.getMessage(), reason ]); |
96 } | 82 } |
97 | 83 |
98 /** | 84 /** |
99 * Method which should be invoked when new errors become available for | 85 * Method which should be invoked when new errors become available for |
100 * display | 86 * display |
102 void refresh() { | 88 void refresh() { |
103 | 89 |
104 if (AUTOMATED_MODE) | 90 if (AUTOMATED_MODE) |
105 return; | 91 return; |
106 | 92 |
107 createStatusList((Composite) dialogArea); | 93 createStatusList(cast(Composite) dialogArea); |
108 updateEnablements(); | 94 updateEnablements(); |
109 } | 95 } |
110 | 96 |
111 /* | 97 /* |
112 * (non-Javadoc) | 98 * (non-Javadoc) |
113 * | 99 * |
114 * @see dwtx.jface.dialogs.ErrorDialog#createDialogArea(dwt.widgets.Composite) | 100 * @see dwtx.jface.dialogs.ErrorDialog#createDialogArea(dwt.widgets.Composite) |
115 */ | 101 */ |
116 protected Control createDialogArea(Composite parent) { | 102 protected Control createDialogArea(Composite parent) { |
117 Control area = super.createDialogArea(parent); | 103 Control area = super.createDialogArea(parent); |
118 createStatusList((Composite) area); | 104 createStatusList(cast(Composite) area); |
119 return area; | 105 return area; |
120 } | 106 } |
121 | 107 |
122 /** | 108 /** |
123 * Create the status list if required. | 109 * Create the status list if required. |
185 data.heightHint = convertHeightInCharsToPixels(10); | 171 data.heightHint = convertHeightInCharsToPixels(10); |
186 control.setLayoutData(data); | 172 control.setLayoutData(data); |
187 statusListViewer.setContentProvider(getStatusContentProvider()); | 173 statusListViewer.setContentProvider(getStatusContentProvider()); |
188 statusListViewer.setLabelProvider(getStatusListLabelProvider()); | 174 statusListViewer.setLabelProvider(getStatusListLabelProvider()); |
189 statusListViewer | 175 statusListViewer |
190 .addSelectionChangedListener(new ISelectionChangedListener() { | 176 .addSelectionChangedListener(new class ISelectionChangedListener { |
191 public void selectionChanged(SelectionChangedEvent event) { | 177 public void selectionChanged(SelectionChangedEvent event) { |
192 handleSelectionChange(); | 178 handleSelectionChange(); |
193 } | 179 } |
194 }); | 180 }); |
195 applyDialogFont(parent); | 181 applyDialogFont(parent); |
200 * Return the label provider for the status list. | 186 * Return the label provider for the status list. |
201 * | 187 * |
202 * @return CellLabelProvider | 188 * @return CellLabelProvider |
203 */ | 189 */ |
204 private CellLabelProvider getStatusListLabelProvider() { | 190 private CellLabelProvider getStatusListLabelProvider() { |
205 return new CellLabelProvider() { | 191 return new class CellLabelProvider { |
206 /* | 192 /* |
207 * (non-Javadoc) | 193 * (non-Javadoc) |
208 * | 194 * |
209 * @see dwtx.jface.viewers.CellLabelProvider#update(dwtx.jface.viewers.ViewerCell) | 195 * @see dwtx.jface.viewers.CellLabelProvider#update(dwtx.jface.viewers.ViewerCell) |
210 */ | 196 */ |
211 public void update(ViewerCell cell) { | 197 public void update(ViewerCell cell) { |
212 cell.setText(((IStatus) cell.getElement()).getMessage()); | 198 cell.setText((cast(IStatus) cell.getElement()).getMessage()); |
213 | 199 |
214 } | 200 } |
215 }; | 201 }; |
216 } | 202 } |
217 | 203 |
219 * Return the content provider for the statuses. | 205 * Return the content provider for the statuses. |
220 * | 206 * |
221 * @return IStructuredContentProvider | 207 * @return IStructuredContentProvider |
222 */ | 208 */ |
223 private IStructuredContentProvider getStatusContentProvider() { | 209 private IStructuredContentProvider getStatusContentProvider() { |
224 return new IStructuredContentProvider() { | 210 return new class IStructuredContentProvider { |
225 /* | 211 /* |
226 * (non-Javadoc) | 212 * (non-Javadoc) |
227 * | 213 * |
228 * @see dwtx.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) | 214 * @see dwtx.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
229 */ | 215 */ |
230 public Object[] getElements(Object inputElement) { | 216 public Object[] getElements(Object inputElement) { |
231 return statuses.toArray(); | 217 Object[] res = new Object[ statuses.size() ]; |
218 int idx; | |
219 foreach( st; statuses ){ | |
220 res[idx] = cast(Object)st; | |
221 idx++; | |
222 } | |
223 return res; | |
232 } | 224 } |
233 | 225 |
234 /* | 226 /* |
235 * (non-Javadoc) | 227 * (non-Javadoc) |
236 * | 228 * |
264 * Return a viewer sorter for looking at the jobs. | 256 * Return a viewer sorter for looking at the jobs. |
265 * | 257 * |
266 * @return ViewerSorter | 258 * @return ViewerSorter |
267 */ | 259 */ |
268 private ViewerComparator getViewerComparator() { | 260 private ViewerComparator getViewerComparator() { |
269 return new ViewerComparator() { | 261 return new class ViewerComparator { |
270 /* | 262 /* |
271 * (non-Javadoc) | 263 * (non-Javadoc) |
272 * | 264 * |
273 * @see dwtx.jface.viewers.ViewerComparator#compare(dwtx.jface.viewers.Viewer, | 265 * @see dwtx.jface.viewers.ViewerComparator#compare(dwtx.jface.viewers.Viewer, |
274 * java.lang.Object, java.lang.Object) | 266 * java.lang.Object, java.lang.Object) |
275 */ | 267 */ |
276 public int compare(Viewer testViewer, Object e1, Object e2) { | 268 public int compare(Viewer testViewer, Object e1, Object e2) { |
277 String message1 = ((IStatus) e1).getMessage(); | 269 String message1 = (cast(IStatus) e1).getMessage(); |
278 String message2 = ((IStatus) e2).getMessage(); | 270 String message2 = (cast(IStatus) e2).getMessage(); |
279 if (message1 is null) | 271 if (message1 is null) |
280 return 1; | 272 return 1; |
281 if (message2 is null) | 273 if (message2 is null) |
282 return -1; | 274 return -1; |
283 | 275 |
284 return message1.compareTo(message2); | 276 //TODO: was compareTo, is this sufficient? |
277 return message1 < message2; | |
285 } | 278 } |
286 }; | 279 }; |
287 } | 280 } |
288 | 281 |
289 /** | 282 /** |
305 * @return IStatus or <code>null</code>. | 298 * @return IStatus or <code>null</code>. |
306 */ | 299 */ |
307 private IStatus getSingleSelection() { | 300 private IStatus getSingleSelection() { |
308 ISelection rawSelection = statusListViewer.getSelection(); | 301 ISelection rawSelection = statusListViewer.getSelection(); |
309 if (rawSelection !is null | 302 if (rawSelection !is null |
310 && rawSelection instanceof IStructuredSelection) { | 303 && cast(IStructuredSelection)rawSelection ) { |
311 IStructuredSelection selection = (IStructuredSelection) rawSelection; | 304 IStructuredSelection selection = cast(IStructuredSelection) rawSelection; |
312 if (selection.size() is 1) { | 305 if (selection.size() is 1) { |
313 return (IStatus) selection.getFirstElement(); | 306 return cast(IStatus) selection.getFirstElement(); |
314 } | 307 } |
315 } | 308 } |
316 return null; | 309 return null; |
317 } | 310 } |
318 | 311 |
339 /** | 332 /** |
340 * Add the status to the receiver. | 333 * Add the status to the receiver. |
341 * @param status | 334 * @param status |
342 */ | 335 */ |
343 public void addStatus(IStatus status) { | 336 public void addStatus(IStatus status) { |
344 statuses.add(status); | 337 statuses.append(status); |
345 refresh(); | 338 refresh(); |
346 | 339 |
347 } | 340 } |
348 | 341 |
349 | 342 |
350 } | 343 } |
351 ++/ |