Mercurial > projects > dwt-addons
comparison dwtx/jface/action/StatusLineManager.d @ 26:87d8cf0a3074
StatusLine
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 03 Apr 2008 05:03:09 +0200 |
parents | |
children | 644f1334b451 |
comparison
equal
deleted
inserted
replaced
25:ca63e2bea4bf | 26:87d8cf0a3074 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2006 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 module dwtx.jface.action.StatusLineManager; | |
14 | |
15 import dwtx.jface.action.ContributionManager; | |
16 import dwtx.jface.action.IStatusLineManager; | |
17 import dwtx.jface.action.GroupMarker; | |
18 import dwtx.jface.action.StatusLine; | |
19 import dwtx.jface.action.IContributionManager; | |
20 import dwtx.jface.action.IContributionItem; | |
21 | |
22 import dwt.DWT; | |
23 import dwt.graphics.Image; | |
24 import dwt.widgets.Composite; | |
25 import dwt.widgets.Control; | |
26 import dwtx.core.runtime.IProgressMonitor; | |
27 import dwtx.core.runtime.IProgressMonitorWithBlocking; | |
28 import dwtx.core.runtime.IStatus; | |
29 | |
30 import dwt.dwthelper.utils; | |
31 | |
32 /** | |
33 * A status line manager is a contribution manager which realizes itself and its items | |
34 * in a status line control. | |
35 * <p> | |
36 * This class may be instantiated; it may also be subclassed if a more | |
37 * sophisticated layout is required. | |
38 * </p> | |
39 */ | |
40 public class StatusLineManager : ContributionManager, | |
41 IStatusLineManager { | |
42 | |
43 /** | |
44 * Identifier of group marker used to position contributions at the beginning | |
45 * of the status line. | |
46 * | |
47 * @since 3.0 | |
48 */ | |
49 public static const String BEGIN_GROUP = "BEGIN_GROUP"; //$NON-NLS-1$ | |
50 | |
51 /** | |
52 * Identifier of group marker used to position contributions in the middle | |
53 * of the status line. | |
54 * | |
55 * @since 3.0 | |
56 */ | |
57 public static const String MIDDLE_GROUP = "MIDDLE_GROUP"; //$NON-NLS-1$ | |
58 | |
59 /** | |
60 * Identifier of group marker used to position contributions at the end | |
61 * of the status line. | |
62 * | |
63 * @since 3.0 | |
64 */ | |
65 public static const String END_GROUP = "END_GROUP"; //$NON-NLS-1$ | |
66 | |
67 /** | |
68 * The status line control; <code>null</code> before | |
69 * creation and after disposal. | |
70 */ | |
71 private Composite statusLine = null; | |
72 | |
73 /** | |
74 * Creates a new status line manager. | |
75 * Use the <code>createControl</code> method to create the | |
76 * status line control. | |
77 */ | |
78 public this() { | |
79 add(new GroupMarker(BEGIN_GROUP)); | |
80 add(new GroupMarker(MIDDLE_GROUP)); | |
81 add(new GroupMarker(END_GROUP)); | |
82 } | |
83 | |
84 /** | |
85 * Creates and returns this manager's status line control. | |
86 * Does not create a new control if one already exists. | |
87 * <p> | |
88 * Note: Since 3.0 the return type is <code>Control</code>. Before 3.0, the return type was | |
89 * the package-private class <code>StatusLine</code>. | |
90 * </p> | |
91 * | |
92 * @param parent the parent control | |
93 * @return the status line control | |
94 */ | |
95 public Control createControl(Composite parent) { | |
96 return createControl(parent, DWT.NONE); | |
97 } | |
98 | |
99 /** | |
100 * Creates and returns this manager's status line control. | |
101 * Does not create a new control if one already exists. | |
102 * | |
103 * @param parent the parent control | |
104 * @param style the style for the control | |
105 * @return the status line control | |
106 * @since 3.0 | |
107 */ | |
108 public Control createControl(Composite parent, int style) { | |
109 if (!statusLineExist() && parent !is null) { | |
110 statusLine = new StatusLine(parent, style); | |
111 update(false); | |
112 } | |
113 return statusLine; | |
114 } | |
115 | |
116 /** | |
117 * Disposes of this status line manager and frees all allocated DWT resources. | |
118 * Notifies all contribution items of the dispose. Note that this method does | |
119 * not clean up references between this status line manager and its associated | |
120 * contribution items. Use <code>removeAll</code> for that purpose. | |
121 */ | |
122 public void dispose() { | |
123 if (statusLineExist()) { | |
124 statusLine.dispose(); | |
125 } | |
126 statusLine = null; | |
127 | |
128 IContributionItem items[] = getItems(); | |
129 for (int i = 0; i < items.length; i++) { | |
130 items[i].dispose(); | |
131 } | |
132 } | |
133 | |
134 /** | |
135 * Returns the control used by this StatusLineManager. | |
136 * | |
137 * @return the control used by this manager | |
138 */ | |
139 public Control getControl() { | |
140 return statusLine; | |
141 } | |
142 | |
143 /** | |
144 * Returns the progress monitor delegate. Override this method | |
145 * to provide your own object used to handle progress. | |
146 * | |
147 * @return the IProgressMonitor delegate | |
148 * @since 3.0 | |
149 */ | |
150 protected IProgressMonitor getProgressMonitorDelegate() { | |
151 return cast(IProgressMonitor) getControl(); | |
152 } | |
153 | |
154 /* | |
155 * (non-Javadoc) | |
156 * Method declared on IStatusLineManager | |
157 */ | |
158 public IProgressMonitor getProgressMonitor() { | |
159 | |
160 return new class IProgressMonitorWithBlocking { | |
161 | |
162 IProgressMonitor progressDelegate; | |
163 this(){ | |
164 progressDelegate = getProgressMonitorDelegate(); | |
165 } | |
166 | |
167 /* (non-Javadoc) | |
168 * @see dwtx.core.runtime.IProgressMonitor#beginTask(java.lang.String, int) | |
169 */ | |
170 public void beginTask(String name, int totalWork) { | |
171 progressDelegate.beginTask(name, totalWork); | |
172 | |
173 } | |
174 | |
175 /* (non-Javadoc) | |
176 * @see dwtx.core.runtime.IProgressMonitor#done() | |
177 */ | |
178 public void done() { | |
179 progressDelegate.done(); | |
180 } | |
181 | |
182 /* (non-Javadoc) | |
183 * @see dwtx.core.runtime.IProgressMonitor#internalWorked(double) | |
184 */ | |
185 public void internalWorked(double work) { | |
186 progressDelegate.internalWorked(work); | |
187 | |
188 } | |
189 | |
190 /* (non-Javadoc) | |
191 * @see dwtx.core.runtime.IProgressMonitor#isCanceled() | |
192 */ | |
193 public bool isCanceled() { | |
194 return progressDelegate.isCanceled(); | |
195 } | |
196 | |
197 /* (non-Javadoc) | |
198 * @see dwtx.core.runtime.IProgressMonitor#setCanceled(bool) | |
199 */ | |
200 public void setCanceled(bool value) { | |
201 //Don't bother updating for disposed status | |
202 if (statusLine.isDisposed()) { | |
203 return; | |
204 } | |
205 progressDelegate.setCanceled(value); | |
206 | |
207 } | |
208 | |
209 /* (non-Javadoc) | |
210 * @see dwtx.core.runtime.IProgressMonitor#setTaskName(java.lang.String) | |
211 */ | |
212 public void setTaskName(String name) { | |
213 progressDelegate.setTaskName(name); | |
214 | |
215 } | |
216 | |
217 /* (non-Javadoc) | |
218 * @see dwtx.core.runtime.IProgressMonitor#subTask(java.lang.String) | |
219 */ | |
220 public void subTask(String name) { | |
221 progressDelegate.subTask(name); | |
222 | |
223 } | |
224 | |
225 /* (non-Javadoc) | |
226 * @see dwtx.core.runtime.IProgressMonitor#worked(int) | |
227 */ | |
228 public void worked(int work) { | |
229 progressDelegate.worked(work); | |
230 } | |
231 | |
232 /* (non-Javadoc) | |
233 * @see dwtx.core.runtime.IProgressMonitorWithBlocking#clearBlocked() | |
234 */ | |
235 public void clearBlocked() { | |
236 //Do nothing here as we let the modal context handle it | |
237 } | |
238 | |
239 /* (non-Javadoc) | |
240 * @see dwtx.core.runtime.IProgressMonitorWithBlocking#setBlocked(dwtx.core.runtime.IStatus) | |
241 */ | |
242 public void setBlocked(IStatus reason) { | |
243 // Do nothing here as we let the modal context handle it | |
244 } | |
245 }; | |
246 } | |
247 | |
248 /* (non-Javadoc) | |
249 * Method declared on IStatueLineManager | |
250 */ | |
251 public bool isCancelEnabled() { | |
252 return statusLineExist() && (cast(StatusLine) statusLine).isCancelEnabled(); | |
253 } | |
254 | |
255 /* (non-Javadoc) | |
256 * Method declared on IStatueLineManager | |
257 */ | |
258 public void setCancelEnabled(bool enabled) { | |
259 if (statusLineExist()) { | |
260 (cast(StatusLine) statusLine).setCancelEnabled(enabled); | |
261 } | |
262 } | |
263 | |
264 /* (non-Javadoc) | |
265 * Method declared on IStatusLineManager. | |
266 */ | |
267 public void setErrorMessage(String message) { | |
268 if (statusLineExist()) { | |
269 (cast(StatusLine) statusLine).setErrorMessage(message); | |
270 } | |
271 } | |
272 | |
273 /* (non-Javadoc) | |
274 * Method declared on IStatusLineManager. | |
275 */ | |
276 public void setErrorMessage(Image image, String message) { | |
277 if (statusLineExist()) { | |
278 (cast(StatusLine) statusLine).setErrorMessage(image, message); | |
279 } | |
280 } | |
281 | |
282 /* (non-Javadoc) | |
283 * Method declared on IStatusLineManager. | |
284 */ | |
285 public void setMessage(String message) { | |
286 if (statusLineExist()) { | |
287 (cast(StatusLine) statusLine).setMessage(message); | |
288 } | |
289 } | |
290 | |
291 /* (non-Javadoc) | |
292 * Method declared on IStatusLineManager. | |
293 */ | |
294 public void setMessage(Image image, String message) { | |
295 if (statusLineExist()) { | |
296 (cast(StatusLine) statusLine).setMessage(image, message); | |
297 } | |
298 } | |
299 | |
300 /** | |
301 * Returns whether the status line control is created | |
302 * and not disposed. | |
303 * | |
304 * @return <code>true</code> if the control is created | |
305 * and not disposed, <code>false</code> otherwise | |
306 */ | |
307 private bool statusLineExist() { | |
308 return statusLine !is null && !statusLine.isDisposed(); | |
309 } | |
310 | |
311 /* (non-Javadoc) | |
312 * Method declared on IContributionManager. | |
313 */ | |
314 public void update(bool force) { | |
315 | |
316 //bool DEBUG= false; | |
317 | |
318 if (isDirty() || force) { | |
319 | |
320 if (statusLineExist()) { | |
321 statusLine.setRedraw(false); | |
322 | |
323 // NOTE: the update algorithm is non-incremental. | |
324 // An incremental algorithm requires that DWT items can be created in the middle of the list | |
325 // but the ContributionItem.fill(Composite) method used here does not take an index, so this | |
326 // is not possible. | |
327 | |
328 Control ws[] = statusLine.getChildren(); | |
329 for (int i = 0; i < ws.length; i++) { | |
330 Control w = ws[i]; | |
331 Object data = w.getData(); | |
332 if (cast(IContributionItem) data ) { | |
333 w.dispose(); | |
334 } | |
335 } | |
336 | |
337 int oldChildCount = statusLine.getChildren().length; | |
338 IContributionItem[] items = getItems(); | |
339 for (int i = 0; i < items.length; ++i) { | |
340 IContributionItem ci = items[i]; | |
341 if (ci.isVisible()) { | |
342 ci.fill(statusLine); | |
343 // associate controls with contribution item | |
344 Control[] newChildren = statusLine.getChildren(); | |
345 for (int j = oldChildCount; j < newChildren.length; j++) { | |
346 newChildren[j].setData(cast(Object)ci); | |
347 } | |
348 oldChildCount = newChildren.length; | |
349 } | |
350 } | |
351 | |
352 setDirty(false); | |
353 | |
354 statusLine.layout(); | |
355 statusLine.setRedraw(true); | |
356 } | |
357 } | |
358 } | |
359 | |
360 } |