예제 #1
0
 /** Recreate the receiver given the new side */
 private void recreate() {
   if (region != null && !region.isDisposed()) {
     Composite parent = region.getParent();
     boolean animating = animationItem.animationRunning();
     AnimationManager.getInstance().removeItem(animationItem);
     region.dispose();
     createContents(parent, workbenchWindow);
     if (animating) animationItem.animationStart();
   }
 }
예제 #2
0
  /**
   * Create the contents of the receiver in the parent. Use the window for the animation item.
   *
   * @param parent The parent widget of the composite.
   * @param window The WorkbenchWindow this is in.
   * @return Control
   */
  public Control createContents(Composite parent, WorkbenchWindow window) {
    workbenchWindow = window;

    // Test whether or not 'advanced' graphics are available
    // If not then we'll 'force' the ProgressBar to always be
    // HORIZONTAL...
    // TODO: This should likely be at some 'global' level state
    forceHorizontal = true;
    //        GC gc = new GC(parent);
    //        gc.setAdvanced(true);
    //        forceHorizontal = !gc.getAdvanced();
    //        gc.dispose();

    region =
        new Composite(parent, SWT.NONE) {
          /*
           * (non-Javadoc)
           *
           * @see org.eclipse.swt.widgets.Composite#computeSize(int, int,
           *      boolean)
           */
          public Point computeSize(int wHint, int hHint, boolean changed) {
            Point size = super.computeSize(wHint, hHint, changed);
            if (isHorizontal(side)) size.y = TrimUtil.TRIM_DEFAULT_HEIGHT;
            else {
              size.x = TrimUtil.TRIM_DEFAULT_HEIGHT;
            }
            return size;
          }
        };

    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    if (isHorizontal(side)) gl.numColumns = 3;
    region.setLayout(gl);

    viewer =
        new ProgressCanvasViewer(
            region, SWT.NO_FOCUS, 1, 36, isHorizontal(side) ? SWT.HORIZONTAL : SWT.VERTICAL);
    viewer.setUseHashlookup(true);
    Control viewerControl = viewer.getControl();
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    Point viewerSizeHints = viewer.getSizeHints();
    if (isHorizontal(side)) {
      gd.widthHint = viewerSizeHints.x;
      gd.heightHint = viewerSizeHints.y;
    } else {
      gd.widthHint = viewerSizeHints.y;
      gd.heightHint = viewerSizeHints.x;
    }
    viewerControl.setLayoutData(gd);

    int widthPreference = AnimationManager.getInstance().getPreferredWidth() + 25;
    animationItem =
        new ProgressAnimationItem(this, isHorizontal(side) ? SWT.HORIZONTAL : SWT.VERTICAL);
    animationItem.createControl(region);

    animationItem.setAnimationContainer(
        new AnimationItem.IAnimationContainer() {
          /* (non-Javadoc)
           * @see org.eclipse.ui.internal.progress.AnimationItem.IAnimationContainer#animationDone()
           */
          public void animationDone() {
            // Add an extra refresh to the viewer in case
            // of stale input if the controls are not disposed
            if (viewer.getControl().isDisposed()) {
              return;
            }
            viewer.refresh();
          }

          /* (non-Javadoc)
           * @see org.eclipse.ui.internal.progress.AnimationItem.IAnimationContainer#animationStart()
           */
          public void animationStart() {
            // Nothing by default here.

          }
        });
    if (isHorizontal(side)) {
      gd = new GridData(GridData.FILL_VERTICAL);
      gd.widthHint = widthPreference;
    } else {
      gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.heightHint = widthPreference;
    }

    animationItem.getControl().setLayoutData(gd);

    //        viewerControl.addMouseListener(new MouseAdapter() {
    //            /*
    //             * (non-Javadoc)
    //             *
    //             * @see
    // org.eclipse.swt.events.MouseAdapter#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
    //             */
    //            public void mouseDoubleClick(MouseEvent e) {
    //                processDoubleClick();
    //            }
    //        });

    // Never show debug info
    IContentProvider provider = new ProgressViewerContentProvider(viewer, false, false);
    viewer.setContentProvider(provider);
    viewer.setInput(provider);
    viewer.setLabelProvider(new ProgressViewerLabelProvider(viewerControl));
    viewer.setComparator(ProgressManagerUtil.getProgressViewerComparator());
    return region;
  }