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.forms.IMessageManager;
|
|
15
|
|
16 import dwtx.ui.forms.IMessagePrefixProvider;
|
|
17 import dwtx.ui.forms.IMessage;
|
|
18
|
|
19 import dwt.widgets.Control;
|
|
20 import dwtx.jface.dialogs.IMessageProvider;
|
|
21 import dwtx.jface.fieldassist.ControlDecoration;
|
|
22 import dwtx.ui.forms.widgets.Form;
|
|
23
|
|
24 import dwt.dwthelper.utils;
|
|
25
|
|
26 /**
|
|
27 * This interface provides for managing typed messages in a form. Typed messages
|
|
28 * are messages associated with a type that indicates their severity (error,
|
|
29 * warning, information). The interface is responsible for:
|
|
30 * <ul>
|
|
31 * <li>Bridging the concept of typed messages and control decorations</li>
|
|
32 * <li>Adding one or more messages per control in a form</li>
|
|
33 * <li>Rolling the local messages up to the form header</li>
|
|
34 * <li>Adding one or more general messages to the form header</li>
|
|
35 * </ul>
|
|
36 * <p>
|
|
37 * To use it in a form, do the following:
|
|
38 * <ol>
|
|
39 * <li>For each interactive control, add a listener to it to monitor user input</li>
|
|
40 * <li>Every time the input changes, validate it. If there is a problem, add a
|
|
41 * message with a unique key to the manager. If there is already a message with
|
|
42 * the same key in the manager, its type and message text will be replaced (no
|
|
43 * duplicates). Note that you add can messages with different keys to the same
|
|
44 * control to track multiple problems with the user input.</li>
|
|
45 * <li>If the problem has been cleared, remove the message using the key
|
|
46 * (attempting to remove a message that is not in the manager is safe).</li>
|
|
47 * <li>If something happens in the form that is not related to any control, use
|
|
48 * the other <code>addMessage</code> method.</li>
|
|
49 * </ol>
|
|
50 * <p>
|
|
51 * This interface should only be referenced. It must not be implemented or
|
|
52 * extended.
|
|
53 * </p>
|
|
54 *
|
|
55 * @since 3.3
|
|
56 * @see IMessageProvider
|
|
57 * @see IManagedForm
|
90
|
58 * @noimplement This interface is not intended to be implemented by clients.
|
75
|
59 */
|
|
60
|
|
61 public interface IMessageManager {
|
|
62 /**
|
|
63 * Adds a general message that is not associated with any decorated field.
|
|
64 * Note that subsequent calls using the same key will not result in
|
|
65 * duplicate messages. Instead, the previous message with the same key will
|
|
66 * be replaced with the new message.
|
|
67 *
|
|
68 * @param key
|
|
69 * a unique message key that will be used to look the message up
|
|
70 * later
|
|
71 *
|
|
72 * @param messageText
|
|
73 * the message to add
|
|
74 * @param data
|
|
75 * an object for application use (can be <code>null</code>)
|
|
76 * @param type
|
|
77 * the message type as defined in <code>IMessageProvider</code>.
|
|
78 */
|
|
79 void addMessage(Object key, String messageText, Object data, int type);
|
|
80
|
|
81 /**
|
|
82 * Adds a message that should be associated with the provided control. Note
|
|
83 * that subsequent calls using the same key will not result in duplicate
|
|
84 * messages. Instead, the previous message with the same key will be
|
|
85 * replaced with the new message.
|
|
86 *
|
|
87 * @param key
|
|
88 * the unique message key
|
|
89 * @param messageText
|
|
90 * the message to add
|
|
91 * @param data
|
|
92 * an object for application use (can be <code>null</code>)
|
|
93 * @param type
|
|
94 * the message type
|
|
95 * @param control
|
|
96 * the control to associate the message with
|
|
97 */
|
|
98 void addMessage(Object key, String messageText, Object data, int type,
|
|
99 Control control);
|
|
100
|
|
101 /**
|
|
102 * Removes the general message with the provided key. Does nothing if
|
|
103 * message for the key does not exist.
|
|
104 *
|
|
105 * @param key
|
|
106 * the key of the message to remove
|
|
107 */
|
|
108 void removeMessage(Object key);
|
|
109
|
|
110 /**
|
|
111 * Removes all the general messages. If there are local messages associated
|
|
112 * with controls, the replacement message may show up drawing user's
|
|
113 * attention to these local messages. Otherwise, the container will clear
|
|
114 * the message area.
|
|
115 */
|
|
116 void removeMessages();
|
|
117
|
|
118 /**
|
|
119 * Removes a keyed message associated with the provided control. Does
|
|
120 * nothing if the message for that key does not exist.
|
|
121 *
|
|
122 * @param key
|
|
123 * the id of the message to remove
|
|
124 * @param control
|
|
125 * the control the message is associated with
|
|
126 */
|
|
127 void removeMessage(Object key, Control control);
|
|
128
|
|
129 /**
|
|
130 * Removes all the messages associated with the provided control. Does
|
|
131 * nothing if there are no messages for this control.
|
|
132 *
|
|
133 * @param control
|
|
134 * the control the messages are associated with
|
|
135 */
|
|
136 void removeMessages(Control control);
|
|
137
|
|
138 /**
|
|
139 * Removes all the local field messages and all the general container
|
|
140 * messages.
|
|
141 */
|
|
142 void removeAllMessages();
|
|
143
|
|
144 /**
|
|
145 * Updates the message container with the messages currently in the manager.
|
|
146 * There are two scenarios in which a client may want to use this method:
|
|
147 * <ol>
|
|
148 * <li>When controls previously managed by this manager have been disposed.</li>
|
|
149 * <li>When automatic update has been turned off.</li>
|
|
150 * </ol>
|
|
151 * In all other situations, the manager will keep the form in sync
|
|
152 * automatically.
|
|
153 *
|
|
154 * @see #setAutoUpdate(bool)
|
|
155 */
|
|
156 void update();
|
|
157
|
|
158 /**
|
|
159 * Controls whether the form is automatically updated when messages are
|
|
160 * added or removed. By default, auto update is on. Clients can turn it off
|
|
161 * prior to adding or removing a number of messages as a batch. Turning it
|
|
162 * back on will trigger an update.
|
|
163 *
|
|
164 * @param enabled
|
|
165 * sets the state of the automatic update
|
|
166 */
|
|
167 void setAutoUpdate(bool enabled);
|
|
168
|
|
169 /**
|
|
170 * Tests whether the form will be automatically updated when messages are
|
|
171 * added or removed.
|
|
172 *
|
|
173 * @return <code>true</code> if auto update is active, <code>false</code>
|
|
174 * otherwise.
|
|
175 */
|
|
176 bool isAutoUpdate();
|
|
177
|
|
178 /**
|
|
179 * Sets the alternative message prefix provider. The default prefix provider
|
|
180 * is set by the manager.
|
|
181 *
|
|
182 * @param provider
|
|
183 * the new prefix provider or <code>null</code> to turn the
|
|
184 * prefix generation off.
|
|
185 */
|
|
186 void setMessagePrefixProvider(IMessagePrefixProvider provider);
|
|
187
|
|
188 /**
|
|
189 * @return the current prefix provider or <code>null</code> if prefixes
|
|
190 * are not generated.
|
|
191 */
|
|
192 IMessagePrefixProvider getMessagePrefixProvider();
|
|
193
|
|
194 /**
|
|
195 * Message manager uses DWT.LEFT|DWT.BOTTOM for the default decoration
|
|
196 * position. Use this method to change it.
|
|
197 *
|
|
198 * @param position
|
|
199 * the decoration position
|
|
200 * @see ControlDecoration
|
|
201 */
|
|
202 void setDecorationPosition(int position);
|
|
203
|
|
204 /**
|
|
205 * Returns the currently used decoration position for all control messages.
|
|
206 *
|
|
207 * @return the current decoration position
|
|
208 */
|
|
209
|
|
210 int getDecorationPosition();
|
|
211
|
|
212 /**
|
|
213 * When message manager is used in context of a form, and there are
|
|
214 * hyperlink listeners for messages in the header, the hyperlink event will
|
|
215 * carry an object of type <code>IMessage[]</code> as an href. You can use
|
|
216 * this method to create a summary text from this array consistent with the
|
|
217 * tool tip used by the form header.
|
|
218 *
|
|
219 * @param messages
|
|
220 * an array of messages
|
|
221 * @return a textual representation of the messages with one message per
|
|
222 * line.
|
|
223 * @see Form#addMessageHyperlinkListener(dwtx.ui.forms.events.IHyperlinkListener)
|
|
224 */
|
|
225 String createSummary(IMessage[] messages);
|
|
226 }
|