Mercurial > projects > dwt-addons
annotate dwtx/ui/internal/forms/MessageManager.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 | 1088ca33d3e0 |
children |
rev | line source |
---|---|
75 | 1 /******************************************************************************* |
2 * Copyright (c) 2007 IBM Corporation and others. | |
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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 ******************************************************************************/ | |
13 | |
14 module dwtx.ui.internal.forms.MessageManager; | |
15 | |
16 import dwtx.ui.internal.forms.Messages; | |
17 | |
18 import dwt.DWT; | |
19 import dwt.custom.CLabel; | |
20 import dwt.widgets.Composite; | |
21 import dwt.widgets.Control; | |
22 import dwt.widgets.Label; | |
23 import dwtx.jface.dialogs.IMessageProvider; | |
24 import dwtx.jface.fieldassist.ControlDecoration; | |
25 import dwtx.jface.fieldassist.FieldDecoration; | |
26 import dwtx.jface.fieldassist.FieldDecorationRegistry; | |
27 import dwtx.ui.forms.IMessage; | |
28 import dwtx.ui.forms.IMessageManager; | |
29 import dwtx.ui.forms.IMessagePrefixProvider; | |
30 import dwtx.ui.forms.widgets.Hyperlink; | |
31 import dwtx.ui.forms.widgets.ScrolledForm; | |
32 | |
33 import dwt.dwthelper.utils; | |
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:
95
diff
changeset
|
34 import dwtx.dwtxhelper.Collection; |
75 | 35 |
36 import tango.util.Convert; | |
76 | 37 import tango.text.Text; |
95
1088ca33d3e0
Removed version=TANGOSVN for release 0.99.7
Frank Benoit <benoit@tionex.de>
parents:
94
diff
changeset
|
38 import tango.io.model.IFile; |
94 | 39 |
75 | 40 /** |
41 * @see IMessageManager | |
42 */ | |
43 | |
44 public class MessageManager : IMessageManager { | |
45 | |
76 | 46 private static DefaultPrefixProvider DEFAULT_PREFIX_PROVIDER_; |
47 private static DefaultPrefixProvider DEFAULT_PREFIX_PROVIDER(){ | |
75 | 48 if( DEFAULT_PREFIX_PROVIDER_ is null ){ |
49 synchronized(MessageManager.classinfo){ | |
50 if( DEFAULT_PREFIX_PROVIDER_ is null ){ | |
51 DEFAULT_PREFIX_PROVIDER_ = new DefaultPrefixProvider(); | |
52 } | |
53 } | |
54 } | |
55 return DEFAULT_PREFIX_PROVIDER_; | |
56 } | |
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:
95
diff
changeset
|
57 private ArrayList messages; |
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:
95
diff
changeset
|
58 private Hashtable decorators; |
75 | 59 private bool autoUpdate = true; |
60 private ScrolledForm scrolledForm; | |
61 private IMessagePrefixProvider prefixProvider; | |
62 private int decorationPosition = DWT.LEFT | DWT.BOTTOM; | |
63 | |
64 private static FieldDecoration standardError_; | |
65 private static FieldDecoration standardError(){ | |
66 if( standardError_ is null ){ | |
67 synchronized(MessageManager.classinfo){ | |
68 if( standardError_ is null ){ | |
69 standardError_ = FieldDecorationRegistry | |
70 .getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); | |
71 } | |
72 } | |
73 } | |
74 return standardError_; | |
75 } | |
76 | |
77 private static FieldDecoration standardWarning_; | |
78 private static FieldDecoration standardWarning(){ | |
79 if( standardWarning_ is null ){ | |
80 synchronized(MessageManager.classinfo){ | |
81 if( standardWarning_ is null ){ | |
82 standardWarning_ = FieldDecorationRegistry | |
83 .getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING); | |
84 } | |
85 } | |
86 } | |
87 return standardWarning_; | |
88 } | |
89 | |
90 private static FieldDecoration standardInformation_; | |
91 private static FieldDecoration standardInformation(){ | |
92 if( standardInformation_ is null ){ | |
93 synchronized(MessageManager.classinfo){ | |
94 if( standardInformation_ is null ){ | |
95 standardInformation_ = FieldDecorationRegistry | |
96 .getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION); | |
97 } | |
98 } | |
99 } | |
100 return standardInformation_; | |
101 } | |
102 | |
78 | 103 private static String[] SINGLE_MESSAGE_SUMMARY_KEYS_; |
104 private static String[] SINGLE_MESSAGE_SUMMARY_KEYS(){ | |
105 if( SINGLE_MESSAGE_SUMMARY_KEYS_ is null ){ | |
106 synchronized(MessageManager.classinfo){ | |
107 if( SINGLE_MESSAGE_SUMMARY_KEYS_ is null ){ | |
108 SINGLE_MESSAGE_SUMMARY_KEYS_ = [ | |
109 Messages.MessageManager_sMessageSummary, | |
110 Messages.MessageManager_sMessageSummary, | |
111 Messages.MessageManager_sWarningSummary, | |
112 Messages.MessageManager_sErrorSummary ]; | |
113 } | |
114 } | |
115 } | |
116 return SINGLE_MESSAGE_SUMMARY_KEYS_; | |
117 } | |
76 | 118 |
78 | 119 private static String[] MULTIPLE_MESSAGE_SUMMARY_KEYS_; |
120 private static String[] MULTIPLE_MESSAGE_SUMMARY_KEYS(){ | |
121 if( MULTIPLE_MESSAGE_SUMMARY_KEYS_ is null ){ | |
122 synchronized(MessageManager.classinfo){ | |
123 if( MULTIPLE_MESSAGE_SUMMARY_KEYS_ is null ){ | |
124 MULTIPLE_MESSAGE_SUMMARY_KEYS_ = [ | |
125 Messages.MessageManager_pMessageSummary, | |
126 Messages.MessageManager_pMessageSummary, | |
127 Messages.MessageManager_pWarningSummary, | |
128 Messages.MessageManager_pErrorSummary ]; | |
129 } | |
130 } | |
131 } | |
132 return MULTIPLE_MESSAGE_SUMMARY_KEYS_; | |
76 | 133 } |
75 | 134 |
135 static class Message : IMessage { | |
136 Control control; | |
137 Object data; | |
138 Object key; | |
139 String message; | |
140 int type; | |
141 String prefix; | |
142 | |
143 this(Object key, String message, int type, Object data) { | |
144 this.key = key; | |
145 this.message = message; | |
146 this.type = type; | |
147 this.data = data; | |
148 } | |
149 | |
150 /* | |
151 * (non-Javadoc) | |
152 * | |
153 * @see dwtx.jface.dialogs.IMessage#getKey() | |
154 */ | |
155 public Object getKey() { | |
156 return key; | |
157 } | |
158 | |
159 /* | |
160 * (non-Javadoc) | |
161 * | |
162 * @see dwtx.jface.dialogs.IMessageProvider#getMessage() | |
163 */ | |
164 public String getMessage() { | |
165 return message; | |
166 } | |
167 | |
168 /* | |
169 * (non-Javadoc) | |
170 * | |
171 * @see dwtx.jface.dialogs.IMessageProvider#getMessageType() | |
172 */ | |
173 public int getMessageType() { | |
174 return type; | |
175 } | |
176 | |
177 /* | |
178 * (non-Javadoc) | |
179 * | |
180 * @see dwtx.ui.forms.messages.IMessage#getControl() | |
181 */ | |
182 public Control getControl() { | |
183 return control; | |
184 } | |
185 | |
186 /* | |
187 * (non-Javadoc) | |
188 * | |
189 * @see dwtx.ui.forms.messages.IMessage#getData() | |
190 */ | |
191 public Object getData() { | |
192 return data; | |
193 } | |
194 | |
195 /* | |
196 * (non-Javadoc) | |
197 * | |
198 * @see dwtx.ui.forms.messages.IMessage#getPrefix() | |
199 */ | |
200 public String getPrefix() { | |
201 return prefix; | |
202 } | |
203 } | |
204 | |
205 static class DefaultPrefixProvider : IMessagePrefixProvider { | |
206 | |
207 public String getPrefix(Control c) { | |
208 Composite parent = c.getParent(); | |
209 Control[] siblings = parent.getChildren(); | |
210 for (int i = 0; i < siblings.length; i++) { | |
211 if (siblings[i] is c) { | |
212 // this is us - go backward until you hit | |
213 // a label-like widget | |
214 for (int j = i - 1; j >= 0; j--) { | |
215 Control label = siblings[j]; | |
216 String ltext = null; | |
217 if ( auto l = cast(Label)label ) { | |
218 ltext = l.getText(); | |
219 } else if ( auto hl = cast(Hyperlink)label ) { | |
220 ltext = hl.getText(); | |
221 } else if ( auto cl = cast(CLabel)label ) { | |
222 ltext = cl.getText(); | |
223 } | |
224 if (ltext !is null) { | |
225 if (!ltext.endsWith(":")) //$NON-NLS-1$ | |
226 return ltext ~ ": "; //$NON-NLS-1$ | |
227 return ltext ~ " "; //$NON-NLS-1$ | |
228 } | |
229 } | |
230 break; | |
231 } | |
232 } | |
233 return null; | |
234 } | |
235 } | |
236 | |
237 class ControlDecorator { | |
238 private ControlDecoration decoration; | |
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:
95
diff
changeset
|
239 private ArrayList controlMessages; |
75 | 240 private String prefix; |
241 | |
242 this(Control control) { | |
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:
95
diff
changeset
|
243 controlMessages = new ArrayList(); |
75 | 244 this.decoration = new ControlDecoration(control, decorationPosition, scrolledForm.getBody()); |
245 } | |
246 | |
247 public bool isDisposed() { | |
248 return decoration.getControl() is null; | |
249 } | |
250 | |
251 void updatePrefix() { | |
252 prefix = null; | |
253 } | |
254 | |
255 void updatePosition() { | |
256 Control control = decoration.getControl(); | |
257 decoration.dispose(); | |
258 this.decoration = new ControlDecoration(control, decorationPosition, scrolledForm.getBody()); | |
259 update(); | |
260 } | |
261 | |
262 String getPrefix() { | |
263 if (prefix is null) | |
264 createPrefix(); | |
265 return prefix; | |
266 } | |
267 | |
268 private void createPrefix() { | |
269 if (prefixProvider is null) { | |
270 prefix = ""; //$NON-NLS-1$ | |
271 return; | |
272 } | |
273 prefix = prefixProvider.getPrefix(decoration.getControl()); | |
274 if (prefix is null) | |
275 // make a prefix anyway | |
276 prefix = ""; //$NON-NLS-1$ | |
277 } | |
278 | |
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:
95
diff
changeset
|
279 void addAll(ArrayList target) { |
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:
95
diff
changeset
|
280 target.addAll(controlMessages); |
75 | 281 } |
282 | |
283 void addMessage(Object key, String text, Object data, int type) { | |
284 Message message = this.outer.addMessage(getPrefix(), key, | |
285 text, data, type, controlMessages); | |
286 message.control = decoration.getControl(); | |
287 if (isAutoUpdate()) | |
288 update(); | |
289 } | |
290 | |
291 bool removeMessage(Object key) { | |
292 Message message = findMessage(key, controlMessages); | |
293 if (message !is null) { | |
294 controlMessages.remove(message); | |
295 if (isAutoUpdate()) | |
296 update(); | |
297 } | |
298 return message !is null; | |
299 } | |
300 | |
301 bool removeMessages() { | |
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:
95
diff
changeset
|
302 if (controlMessages.isEmpty()) |
75 | 303 return false; |
304 controlMessages.clear(); | |
305 if (isAutoUpdate()) | |
306 update(); | |
307 return true; | |
308 } | |
309 | |
310 public void update() { | |
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:
95
diff
changeset
|
311 if (controlMessages.isEmpty()) { |
75 | 312 decoration.setDescriptionText(null); |
313 decoration.hide(); | |
314 } else { | |
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:
95
diff
changeset
|
315 ArrayList peers = createPeers(controlMessages); |
75 | 316 int type = (cast(IMessage) peers.get(0)).getMessageType(); |
317 String description = createDetails(createPeers(peers), true); | |
318 if (type is IMessageProvider.ERROR) | |
319 decoration.setImage(standardError.getImage()); | |
320 else if (type is IMessageProvider.WARNING) | |
321 decoration.setImage(standardWarning.getImage()); | |
322 else if (type is IMessageProvider.INFORMATION) | |
323 decoration.setImage(standardInformation.getImage()); | |
324 decoration.setDescriptionText(description); | |
325 decoration.show(); | |
326 } | |
327 } | |
328 } | |
329 | |
330 /** | |
331 * Creates a new instance of the message manager that will work with the | |
332 * provided form. | |
333 * | |
334 * @param scrolledForm | |
335 * the form to control | |
336 */ | |
337 public this(ScrolledForm scrolledForm) { | |
338 prefixProvider = DEFAULT_PREFIX_PROVIDER; | |
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:
95
diff
changeset
|
339 messages = new ArrayList(); |
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:
95
diff
changeset
|
340 decorators = new Hashtable(); |
75 | 341 this.scrolledForm = scrolledForm; |
342 } | |
343 | |
344 /* | |
345 * (non-Javadoc) | |
346 * | |
347 * @see dwtx.ui.forms.IMessageManager#addMessage(java.lang.Object, | |
348 * java.lang.String, int) | |
349 */ | |
350 public void addMessage(Object key, String messageText, Object data, int type) { | |
351 addMessage(null, key, messageText, data, type, messages); | |
352 if (isAutoUpdate()) | |
353 updateForm(); | |
354 } | |
355 | |
356 /* | |
357 * (non-Javadoc) | |
358 * | |
359 * @see dwtx.ui.forms.IMessageManager#addMessage(java.lang.Object, | |
360 * java.lang.String, int, dwt.widgets.Control) | |
361 */ | |
362 public void addMessage(Object key, String messageText, Object data, | |
363 int type, Control control) { | |
364 ControlDecorator dec = cast(ControlDecorator) decorators.get(control); | |
365 | |
366 if (dec is null) { | |
367 dec = new ControlDecorator(control); | |
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:
95
diff
changeset
|
368 decorators.put(control, dec); |
75 | 369 } |
370 dec.addMessage(key, messageText, data, type); | |
371 if (isAutoUpdate()) | |
372 updateForm(); | |
373 } | |
374 | |
375 /* | |
376 * (non-Javadoc) | |
377 * | |
378 * @see dwtx.ui.forms.IMessageManager#removeMessage(java.lang.Object) | |
379 */ | |
380 public void removeMessage(Object key) { | |
381 Message message = findMessage(key, messages); | |
382 if (message !is null) { | |
383 messages.remove(message); | |
384 if (isAutoUpdate()) | |
385 updateForm(); | |
386 } | |
387 } | |
388 | |
389 /* | |
390 * (non-Javadoc) | |
391 * | |
392 * @see dwtx.ui.forms.IMessageManager#removeMessages() | |
393 */ | |
394 public void removeMessages() { | |
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:
95
diff
changeset
|
395 if (!messages.isEmpty()) { |
75 | 396 messages.clear(); |
397 if (isAutoUpdate()) | |
398 updateForm(); | |
399 } | |
400 } | |
401 | |
402 /* | |
403 * (non-Javadoc) | |
404 * | |
405 * @see dwtx.ui.forms.IMessageManager#removeMessage(java.lang.Object, | |
406 * dwt.widgets.Control) | |
407 */ | |
408 public void removeMessage(Object key, Control control) { | |
409 ControlDecorator dec = cast(ControlDecorator) decorators.get(control); | |
410 if (dec is null) | |
411 return; | |
412 if (dec.removeMessage(key)) | |
413 if (isAutoUpdate()) | |
414 updateForm(); | |
415 } | |
416 | |
417 /* | |
418 * (non-Javadoc) | |
419 * | |
420 * @see dwtx.ui.forms.IMessageManager#removeMessages(dwt.widgets.Control) | |
421 */ | |
422 public void removeMessages(Control control) { | |
423 ControlDecorator dec = cast(ControlDecorator) decorators.get(control); | |
424 if (dec !is null) { | |
425 if (dec.removeMessages()) { | |
426 if (isAutoUpdate()) | |
427 updateForm(); | |
428 } | |
429 } | |
430 } | |
431 | |
432 /* | |
433 * (non-Javadoc) | |
434 * | |
435 * @see dwtx.ui.forms.IMessageManager#removeAllMessages() | |
436 */ | |
437 public void removeAllMessages() { | |
438 bool needsUpdate = false; | |
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:
95
diff
changeset
|
439 for (Enumeration enm = decorators.elements(); enm.hasMoreElements();) { |
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:
95
diff
changeset
|
440 ControlDecorator control = cast(ControlDecorator) enm.nextElement(); |
75 | 441 if (control.removeMessages()) |
442 needsUpdate = true; | |
443 } | |
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:
95
diff
changeset
|
444 if (!messages.isEmpty()) { |
75 | 445 messages.clear(); |
446 needsUpdate = true; | |
447 } | |
448 if (needsUpdate && isAutoUpdate()) | |
449 updateForm(); | |
450 } | |
451 | |
452 /* | |
453 * Adds the message if it does not already exist in the provided list. | |
454 */ | |
455 | |
456 private Message addMessage(String prefix, Object key, String messageText, | |
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:
95
diff
changeset
|
457 Object data, int type, ArrayList list) { |
75 | 458 Message message = findMessage(key, list); |
459 if (message is null) { | |
460 message = new Message(key, messageText, type, data); | |
461 message.prefix = prefix; | |
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:
95
diff
changeset
|
462 list.add(message); |
75 | 463 } else { |
464 message.message = messageText; | |
465 message.type = type; | |
466 message.data = data; | |
467 } | |
468 return message; | |
469 } | |
470 | |
471 /* | |
472 * Finds the message with the provided key in the provided list. | |
473 */ | |
474 | |
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:
95
diff
changeset
|
475 private Message findMessage(Object key, ArrayList list) { |
75 | 476 for (int i = 0; i < list.size(); i++) { |
477 Message message = cast(Message) list.get(i); | |
76 | 478 if (message.getKey().opEquals(key)) |
75 | 479 return message; |
480 } | |
481 return null; | |
482 } | |
483 | |
484 /* | |
485 * (non-Javadoc) | |
486 * | |
487 * @see dwtx.ui.forms.IMessageManager#update() | |
488 */ | |
489 public void update() { | |
490 // Update decorations | |
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:
95
diff
changeset
|
491 for (Iterator iter = decorators.values().iterator(); iter.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:
95
diff
changeset
|
492 ControlDecorator dec = cast(ControlDecorator) iter.next(); |
75 | 493 dec.update(); |
494 } | |
495 // Update the form | |
496 updateForm(); | |
497 } | |
498 | |
499 /* | |
500 * Updates the container by rolling the messages up from the controls. | |
501 */ | |
502 | |
503 private void updateForm() { | |
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:
95
diff
changeset
|
504 ArrayList mergedList = new ArrayList(); |
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:
95
diff
changeset
|
505 mergedList.addAll(messages); |
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:
95
diff
changeset
|
506 for (Enumeration enm = decorators.elements(); enm.hasMoreElements();) { |
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:
95
diff
changeset
|
507 ControlDecorator dec = cast(ControlDecorator) enm.nextElement(); |
75 | 508 dec.addAll(mergedList); |
509 } | |
510 update(mergedList); | |
511 } | |
512 | |
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:
95
diff
changeset
|
513 private void update(ArrayList mergedList) { |
75 | 514 pruneControlDecorators(); |
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:
95
diff
changeset
|
515 if (scrolledForm.getForm().getHead().getBounds().height is 0 || mergedList.isEmpty() || mergedList is null) { |
75 | 516 scrolledForm.setMessage(null, IMessageProvider.NONE); |
517 return; | |
518 } | |
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:
95
diff
changeset
|
519 ArrayList peers = createPeers(mergedList); |
75 | 520 int maxType = (cast(IMessage) peers.get(0)).getMessageType(); |
521 String messageText; | |
522 IMessage[] array = arraycast!(IMessage)( peers | |
523 .toArray()); | |
524 if (peers.size() is 1 && (cast(Message) peers.get(0)).prefix is null) { | |
525 // a single message | |
526 IMessage message = cast(IMessage) peers.get(0); | |
527 messageText = message.getMessage(); | |
528 scrolledForm.setMessage(messageText, maxType, array); | |
529 } else { | |
530 // show a summary message for the message | |
531 // and list of errors for the details | |
532 if (peers.size() > 1) | |
533 messageText = Messages.bind( | |
534 MULTIPLE_MESSAGE_SUMMARY_KEYS[maxType], | |
535 [ to!(String)(peers.size()) ]); //$NON-NLS-1$ | |
536 else | |
537 messageText = SINGLE_MESSAGE_SUMMARY_KEYS[maxType]; | |
538 scrolledForm.setMessage(messageText, maxType, array); | |
539 } | |
540 } | |
541 | |
542 private static String getFullMessage(IMessage message) { | |
543 if (message.getPrefix() is null) | |
544 return message.getMessage(); | |
76 | 545 return message.getPrefix() ~ message.getMessage(); |
75 | 546 } |
547 | |
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:
95
diff
changeset
|
548 private ArrayList createPeers(ArrayList messages) { |
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:
95
diff
changeset
|
549 ArrayList peers = new ArrayList(); |
75 | 550 int maxType = 0; |
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:
95
diff
changeset
|
551 for (int i = 0; i < messages.size(); i++) { |
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:
95
diff
changeset
|
552 Message message = cast(Message) messages.get(i); |
75 | 553 if (message.type > maxType) { |
554 peers.clear(); | |
555 maxType = message.type; | |
556 } | |
557 if (message.type is maxType) | |
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:
95
diff
changeset
|
558 peers.add(message); |
75 | 559 } |
560 return peers; | |
561 } | |
562 | |
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:
95
diff
changeset
|
563 private String createDetails(ArrayList messages, bool excludePrefix) { |
76 | 564 auto txt = new tango.text.Text.Text!(char); |
75 | 565 |
566 for (int i = 0; i < messages.size(); i++) { | |
567 if (i > 0) | |
76 | 568 txt.append( FileConst.NewlineString ); |
75 | 569 IMessage m = cast(IMessage) messages.get(i); |
76 | 570 txt.append(excludePrefix ? m.getMessage() : getFullMessage(m)); |
75 | 571 } |
76 | 572 return txt.toString(); |
75 | 573 } |
574 | |
575 public static String createDetails(IMessage[] messages) { | |
576 if (messages is null || messages.length is 0) | |
577 return null; | |
76 | 578 auto txt = new tango.text.Text.Text!(char); |
75 | 579 |
580 for (int i = 0; i < messages.length; i++) { | |
581 if (i > 0) | |
76 | 582 txt.append( FileConst.NewlineString ); |
583 txt.append(getFullMessage(messages[i])); | |
75 | 584 } |
76 | 585 return txt.toString(); |
75 | 586 } |
587 | |
588 /* | |
589 * (non-Javadoc) | |
590 * | |
591 * @see dwtx.ui.forms.IMessageManager#createSummary(dwtx.ui.forms.IMessage[]) | |
592 */ | |
593 public String createSummary(IMessage[] messages) { | |
594 return createDetails(messages); | |
595 } | |
596 | |
597 private void pruneControlDecorators() { | |
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:
95
diff
changeset
|
598 for (Iterator iter = decorators.values().iterator(); iter.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:
95
diff
changeset
|
599 ControlDecorator dec = cast(ControlDecorator) iter.next(); |
75 | 600 if (dec.isDisposed()) |
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:
95
diff
changeset
|
601 iter.remove(); |
75 | 602 } |
603 } | |
604 | |
605 /* | |
606 * (non-Javadoc) | |
607 * | |
608 * @see dwtx.ui.forms.IMessageManager#getMessagePrefixProvider() | |
609 */ | |
610 public IMessagePrefixProvider getMessagePrefixProvider() { | |
611 return prefixProvider; | |
612 } | |
613 | |
614 /* | |
615 * (non-Javadoc) | |
616 * | |
617 * @see dwtx.ui.forms.IMessageManager#setMessagePrefixProvider(dwtx.ui.forms.IMessagePrefixProvider) | |
618 */ | |
619 public void setMessagePrefixProvider(IMessagePrefixProvider provider) { | |
620 this.prefixProvider = provider; | |
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:
95
diff
changeset
|
621 for (Iterator iter = decorators.values().iterator(); iter.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:
95
diff
changeset
|
622 ControlDecorator dec = cast(ControlDecorator) iter.next(); |
75 | 623 dec.updatePrefix(); |
624 } | |
625 } | |
626 | |
627 /* | |
628 * (non-Javadoc) | |
629 * | |
630 * @see dwtx.ui.forms.IMessageManager#getDecorationPosition() | |
631 */ | |
632 public int getDecorationPosition() { | |
633 return decorationPosition; | |
634 } | |
635 | |
636 /* | |
637 * (non-Javadoc) | |
638 * | |
639 * @see dwtx.ui.forms.IMessageManager#setDecorationPosition(int) | |
640 */ | |
641 public void setDecorationPosition(int position) { | |
642 this.decorationPosition = position; | |
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:
95
diff
changeset
|
643 for (Iterator iter = decorators.values().iterator(); iter.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:
95
diff
changeset
|
644 ControlDecorator dec = cast(ControlDecorator) iter.next(); |
75 | 645 dec.updatePosition(); |
646 } | |
647 } | |
648 | |
649 /* | |
650 * (non-Javadoc) | |
651 * | |
652 * @see dwtx.ui.forms.IMessageManager#isAutoUpdate() | |
653 */ | |
654 public bool isAutoUpdate() { | |
655 return autoUpdate; | |
656 } | |
657 | |
658 /* | |
659 * (non-Javadoc) | |
660 * | |
661 * @see dwtx.ui.forms.IMessageManager#setAutoUpdate(bool) | |
662 */ | |
663 public void setAutoUpdate(bool autoUpdate) { | |
664 bool needsUpdate = !this.autoUpdate && autoUpdate; | |
665 this.autoUpdate = autoUpdate; | |
666 if (needsUpdate) | |
667 update(); | |
668 } | |
669 } |