1 11 package org.eclipse.jface.action; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.IProgressMonitorWithBlocking; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 21 29 public class StatusLineManager extends ContributionManager implements 30 IStatusLineManager { 31 32 38 public static final String BEGIN_GROUP = "BEGIN_GROUP"; 40 46 public static final String MIDDLE_GROUP = "MIDDLE_GROUP"; 48 54 public static final String END_GROUP = "END_GROUP"; 56 60 private Composite statusLine = null; 61 62 67 public StatusLineManager() { 68 add(new GroupMarker(BEGIN_GROUP)); 69 add(new GroupMarker(MIDDLE_GROUP)); 70 add(new GroupMarker(END_GROUP)); 71 } 72 73 84 public Control createControl(Composite parent) { 85 return createControl(parent, SWT.NONE); 86 } 87 88 97 public Control createControl(Composite parent, int style) { 98 if (!statusLineExist() && parent != null) { 99 statusLine = new StatusLine(parent, style); 100 update(false); 101 } 102 return statusLine; 103 } 104 105 111 public void dispose() { 112 if (statusLineExist()) { 113 statusLine.dispose(); 114 } 115 statusLine = null; 116 117 IContributionItem items[] = getItems(); 118 for (int i = 0; i < items.length; i++) { 119 items[i].dispose(); 120 } 121 } 122 123 128 public Control getControl() { 129 return statusLine; 130 } 131 132 139 protected IProgressMonitor getProgressMonitorDelegate() { 140 return (IProgressMonitor) getControl(); 141 } 142 143 147 public IProgressMonitor getProgressMonitor() { 148 149 return new IProgressMonitorWithBlocking() { 150 151 IProgressMonitor progressDelegate = getProgressMonitorDelegate(); 152 153 156 public void beginTask(String name, int totalWork) { 157 progressDelegate.beginTask(name, totalWork); 158 159 } 160 161 164 public void done() { 165 progressDelegate.done(); 166 } 167 168 171 public void internalWorked(double work) { 172 progressDelegate.internalWorked(work); 173 174 } 175 176 179 public boolean isCanceled() { 180 return progressDelegate.isCanceled(); 181 } 182 183 186 public void setCanceled(boolean value) { 187 if (statusLine.isDisposed()) { 189 return; 190 } 191 progressDelegate.setCanceled(value); 192 193 } 194 195 198 public void setTaskName(String name) { 199 progressDelegate.setTaskName(name); 200 201 } 202 203 206 public void subTask(String name) { 207 progressDelegate.subTask(name); 208 209 } 210 211 214 public void worked(int work) { 215 progressDelegate.worked(work); 216 } 217 218 221 public void clearBlocked() { 222 } 224 225 228 public void setBlocked(IStatus reason) { 229 } 231 }; 232 } 233 234 237 public boolean isCancelEnabled() { 238 return statusLineExist() && ((StatusLine) statusLine).isCancelEnabled(); 239 } 240 241 244 public void setCancelEnabled(boolean enabled) { 245 if (statusLineExist()) { 246 ((StatusLine) statusLine).setCancelEnabled(enabled); 247 } 248 } 249 250 253 public void setErrorMessage(String message) { 254 if (statusLineExist()) { 255 ((StatusLine) statusLine).setErrorMessage(message); 256 } 257 } 258 259 262 public void setErrorMessage(Image image, String message) { 263 if (statusLineExist()) { 264 ((StatusLine) statusLine).setErrorMessage(image, message); 265 } 266 } 267 268 271 public void setMessage(String message) { 272 if (statusLineExist()) { 273 ((StatusLine) statusLine).setMessage(message); 274 } 275 } 276 277 280 public void setMessage(Image image, String message) { 281 if (statusLineExist()) { 282 ((StatusLine) statusLine).setMessage(image, message); 283 } 284 } 285 286 293 private boolean statusLineExist() { 294 return statusLine != null && !statusLine.isDisposed(); 295 } 296 297 300 public void update(boolean force) { 301 302 304 if (isDirty() || force) { 305 306 if (statusLineExist()) { 307 statusLine.setRedraw(false); 308 309 314 Control ws[] = statusLine.getChildren(); 315 for (int i = 0; i < ws.length; i++) { 316 Control w = ws[i]; 317 Object data = w.getData(); 318 if (data instanceof IContributionItem) { 319 w.dispose(); 320 } 321 } 322 323 int oldChildCount = statusLine.getChildren().length; 324 IContributionItem[] items = getItems(); 325 for (int i = 0; i < items.length; ++i) { 326 IContributionItem ci = items[i]; 327 if (ci.isVisible()) { 328 ci.fill(statusLine); 329 Control[] newChildren = statusLine.getChildren(); 331 for (int j = oldChildCount; j < newChildren.length; j++) { 332 newChildren[j].setData(ci); 333 } 334 oldChildCount = newChildren.length; 335 } 336 } 337 338 setDirty(false); 339 340 statusLine.layout(); 341 statusLine.setRedraw(true); 342 } 343 } 344 } 345 346 } 347 | Popular Tags |