1 11 package org.eclipse.ui.internal.progress; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.IProgressMonitorWithBlocking; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.jface.dialogs.IDialogConstants; 19 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 20 import org.eclipse.jface.operation.IRunnableWithProgress; 21 import org.eclipse.jface.viewers.Viewer; 22 import org.eclipse.jface.viewers.ViewerComparator; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.SelectionAdapter; 25 import org.eclipse.swt.events.SelectionEvent; 26 import org.eclipse.swt.graphics.Cursor; 27 import org.eclipse.swt.graphics.Point; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.layout.GridLayout; 30 import org.eclipse.swt.widgets.Button; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Control; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.swt.widgets.Shell; 35 import org.eclipse.ui.PlatformUI; 36 import org.eclipse.ui.internal.misc.Policy; 37 38 42 public class ProgressMonitorJobsDialog extends ProgressMonitorDialog { 43 private DetailedProgressViewer viewer; 44 45 48 private int viewerHeight = -1; 49 50 Composite viewerComposite; 51 52 private Button detailsButton; 53 54 private long watchTime = -1; 55 56 protected boolean alreadyClosed = false; 57 58 private IProgressMonitor wrapperedMonitor; 59 60 protected boolean enableDetailsButton = false; 63 64 69 public ProgressMonitorJobsDialog(Shell parent) { 70 super(parent); 71 setShellStyle(getShellStyle() | SWT.RESIZE); 72 } 73 74 79 protected Control createDialogArea(Composite parent) { 80 Composite top = (Composite) super.createDialogArea(parent); 81 viewerComposite = new Composite(parent, SWT.NONE); 82 GridLayout layout = new GridLayout(); 83 layout.marginHeight = 0; 84 layout.marginWidth = 0; 85 viewerComposite.setLayout(layout); 86 GridData viewerData = new GridData(GridData.FILL_BOTH); 87 viewerData.horizontalSpan = 2; 88 viewerData.heightHint = 0; 89 viewerComposite.setLayoutData(viewerData); 90 return top; 91 } 92 93 98 void handleDetailsButtonSelect() { 99 Shell shell = getShell(); 100 Point shellSize = shell.getSize(); 101 Composite composite = (Composite) getDialogArea(); 102 if (viewer != null) { 103 viewer.getControl().dispose(); 104 viewer = null; 105 composite.layout(); 106 shell.setSize(shellSize.x, shellSize.y - viewerHeight); 107 detailsButton.setText(ProgressMessages.ProgressMonitorJobsDialog_DetailsTitle); 108 } else { 109 if (ProgressManager.getInstance().getRootElements(Policy.DEBUG_SHOW_ALL_JOBS).length == 0) { 111 detailsButton.setEnabled(false); 112 return; 113 } 114 115 viewer = new DetailedProgressViewer(viewerComposite, SWT.MULTI 116 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); 117 viewer.setComparator(new ViewerComparator() { 118 124 public int compare(Viewer testViewer, Object e1, Object e2) { 125 return ((Comparable ) e1).compareTo(e2); 126 } 127 }); 128 129 viewer.setContentProvider(new ProgressViewerContentProvider(viewer,true,false){ 130 public Object [] getElements(Object inputElement) { 131 return super.getElements(inputElement); 132 }} 133 ); 134 135 viewer.setLabelProvider(new ProgressLabelProvider()); 136 viewer.setInput(this); 137 GridData viewerData = new GridData(GridData.FILL_BOTH); 138 viewer.getControl().setLayoutData(viewerData); 139 GridData viewerCompositeData = (GridData) viewerComposite.getLayoutData(); 140 viewerCompositeData.heightHint = convertHeightInCharsToPixels(10); 141 viewerComposite.layout(true); 142 viewer.getControl().setVisible(true); 143 viewerHeight = viewerComposite.computeTrim(0, 0, 0, viewerCompositeData.heightHint).height; 144 detailsButton.setText(ProgressMessages.ProgressMonitorJobsDialog_HideTitle); 145 shell.setSize(shellSize.x, shellSize.y + viewerHeight); 146 } 147 } 148 149 154 protected void createButtonsForButtonBar(Composite parent) { 155 super.createButtonsForButtonBar(parent); 156 createDetailsButton(parent); 157 } 158 159 165 protected void createSpacer(Composite parent) { 166 Label spacer = new Label(parent, SWT.NONE); 168 spacer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL 169 | GridData.GRAB_HORIZONTAL)); 170 } 171 172 178 protected void createDetailsButton(Composite parent) { 179 detailsButton = createButton(parent, IDialogConstants.DETAILS_ID, 180 ProgressMessages.ProgressMonitorJobsDialog_DetailsTitle, 181 false); 182 detailsButton.addSelectionListener(new SelectionAdapter() { 183 188 public void widgetSelected(SelectionEvent e) { 189 handleDetailsButtonSelect(); 190 } 191 }); 192 detailsButton.setCursor(arrowCursor); 193 detailsButton.setEnabled(enableDetailsButton); 194 } 195 196 201 protected Control createButtonBar(Composite parent) { 202 Composite composite = new Composite(parent, SWT.NONE); 203 GridLayout layout = new GridLayout(); 206 layout.numColumns = 1; layout.makeColumnsEqualWidth = false; 208 layout.marginWidth = 0; 209 layout.marginHeight = 0; 210 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 211 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 212 composite.setLayout(layout); 213 GridData data = new GridData(GridData.FILL_HORIZONTAL); 214 data.horizontalSpan = 2; 215 data.horizontalAlignment = GridData.END; 216 data.grabExcessHorizontalSpace = true; 217 composite.setLayoutData(data); 218 composite.setFont(parent.getFont()); 219 if (arrowCursor == null) { 221 arrowCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW); 222 } 223 createButtonsForButtonBar(composite); 224 return composite; 225 } 226 227 232 protected void clearCursors() { 233 if (detailsButton != null && !detailsButton.isDisposed()) { 234 detailsButton.setCursor(null); 235 } 236 super.clearCursors(); 237 } 238 239 244 protected void updateForSetBlocked(IStatus reason) { 245 if(alreadyClosed) 246 return; 247 248 super.updateForSetBlocked(reason); 249 enableDetails(true); 250 if (viewer == null) { 251 handleDetailsButtonSelect(); 252 } 253 } 254 255 261 public void run(boolean fork, boolean cancelable, 262 IRunnableWithProgress runnable) throws InvocationTargetException , 263 InterruptedException { 264 if (!fork) { 266 enableDetails(false); 267 } 268 super.run(fork, cancelable, runnable); 269 } 270 271 278 protected void enableDetails(boolean enableState) { 279 if (detailsButton == null) { 280 enableDetailsButton = enableState; 281 } else { 282 detailsButton.setEnabled(enableState); 283 } 284 } 285 286 290 public void watchTicks() { 291 watchTime = System.currentTimeMillis(); 292 } 293 294 298 public void createWrapperedMonitor() { 299 wrapperedMonitor = new IProgressMonitorWithBlocking() { 300 301 IProgressMonitor superMonitor = ProgressMonitorJobsDialog.super 302 .getProgressMonitor(); 303 304 310 public void beginTask(String name, int totalWork) { 311 superMonitor.beginTask(name, totalWork); 312 checkTicking(); 313 } 314 315 318 private void checkTicking() { 319 if (watchTime < 0) { 320 return; 321 } 322 if ((System.currentTimeMillis() - watchTime) > ProgressManager 323 .getInstance().getLongOperationTime()) { 324 watchTime = -1; 325 openDialog(); 326 } 327 } 328 329 332 private void openDialog() { 333 if (!PlatformUI.isWorkbenchRunning()) { 334 return; 335 } 336 337 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable () { 338 341 public void run() { 342 if (!ProgressManagerUtil.safeToOpen(ProgressMonitorJobsDialog.this,null)){ 344 watchTicks(); 345 return; 346 } 347 348 if (!alreadyClosed) { 349 open(); 350 } 351 } 352 }); 353 } 354 355 360 public void done() { 361 superMonitor.done(); 362 checkTicking(); 363 } 364 365 370 public void internalWorked(double work) { 371 superMonitor.internalWorked(work); 372 checkTicking(); 373 } 374 375 380 public boolean isCanceled() { 381 return superMonitor.isCanceled(); 382 } 383 384 389 public void setCanceled(boolean value) { 390 superMonitor.setCanceled(value); 391 392 } 393 394 399 public void setTaskName(String name) { 400 superMonitor.setTaskName(name); 401 checkTicking(); 402 403 } 404 405 410 public void subTask(String name) { 411 superMonitor.subTask(name); 412 checkTicking(); 413 } 414 415 420 public void worked(int work) { 421 superMonitor.worked(work); 422 checkTicking(); 423 424 } 425 426 431 public void clearBlocked() { 432 if (superMonitor instanceof IProgressMonitorWithBlocking) { 434 ((IProgressMonitorWithBlocking) superMonitor) 435 .clearBlocked(); 436 } 437 438 } 439 440 445 public void setBlocked(IStatus reason) { 446 openDialog(); 447 if (superMonitor instanceof IProgressMonitorWithBlocking) { 448 ((IProgressMonitorWithBlocking) superMonitor) 449 .setBlocked(reason); 450 } 451 452 } 453 454 }; 455 } 456 457 462 public IProgressMonitor getProgressMonitor() { 463 if (wrapperedMonitor == null) { 464 createWrapperedMonitor(); 465 } 466 return wrapperedMonitor; 467 } 468 469 474 public boolean close() { 475 alreadyClosed = true; boolean result = super.close(); 477 if (!result) { alreadyClosed = false; 479 } 480 return result; 481 } 482 483 } 484 | Popular Tags |