Example #1
0
  private Rectangle getDisplayBounds(final Point location) {

    Rectangle displayBounds;
    final Monitor[] allMonitors = _ownerControl.getDisplay().getMonitors();

    if (allMonitors.length > 1) {
      // By default present in the monitor of the control
      displayBounds = _ownerControl.getMonitor().getBounds();
      final Point p = new Point(location.x, location.y);

      // Search on which monitor the event occurred
      Rectangle tmp;
      for (final Monitor element : allMonitors) {
        tmp = element.getBounds();
        if (tmp.contains(p)) {
          displayBounds = tmp;
          break;
        }
      }

    } else {
      displayBounds = _ownerControl.getDisplay().getBounds();
    }

    return displayBounds;
  }
 void updateCursor(Control c, int dir) {
   if (!(c instanceof Sash)) {
     Cursor cursor = null;
     switch (dir) {
       case VERTICAL:
         if (fAncestorVisible) {
           if (fVSashCursor == null) fVSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZENS);
           cursor = fVSashCursor;
         } else {
           if (fNormalCursor == null) fNormalCursor = new Cursor(c.getDisplay(), SWT.CURSOR_ARROW);
           cursor = fNormalCursor;
         }
         break;
       case HORIZONTAL:
         if (fHSashCursor == null) fHSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZEWE);
         cursor = fHSashCursor;
         break;
       case VERTICAL + HORIZONTAL:
         if (fAncestorVisible) {
           if (fHVSashCursor == null)
             fHVSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZEALL);
           cursor = fHVSashCursor;
         } else {
           if (fHSashCursor == null) fHSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZEWE);
           cursor = fHSashCursor;
         }
         break;
     }
     if (cursor != null) c.setCursor(cursor);
   }
 }
  protected final void executeRunnables(final Collection<Runnable> runnables) {

    // now post all collected runnables
    Control ctrl = fViewer.getControl();
    if (ctrl != null && !ctrl.isDisposed()) {
      final boolean hasPendingUpdates;
      synchronized (this) {
        hasPendingUpdates = fPendingUpdates != null && !fPendingUpdates.isEmpty();
      }
      // Are we in the UIThread? If so spin it until we are done
      if (!hasPendingUpdates
          && ctrl.getDisplay().getThread() == Thread.currentThread()
          && !fViewer.isBusy()) {
        runUpdates(runnables);
      } else {
        synchronized (this) {
          if (fPendingUpdates == null) {
            fPendingUpdates = runnables;
          } else {
            fPendingUpdates.addAll(runnables);
          }
        }
        postAsyncUpdate(ctrl.getDisplay());
      }
    }
  }
Example #4
0
  /* (non-Javadoc)
   * @see org.eclipse.cdt.make.core.IMakeTargetListener#targetChanged(org.eclipse.cdt.make.core.MakeTargetEvent)
   */
  public void targetChanged(final MakeTargetEvent event) {
    final Control ctrl = viewer.getControl();
    if (ctrl != null && !ctrl.isDisposed()) {
      switch (event.getType()) {
        case MakeTargetEvent.PROJECT_ADDED:
        case MakeTargetEvent.PROJECT_REMOVED:
          ctrl.getDisplay()
              .asyncExec(
                  new Runnable() {

                    public void run() {
                      if (!ctrl.isDisposed()) {
                        viewer.refresh();
                      }
                    }
                  });
          break;
        case MakeTargetEvent.TARGET_ADD:
        case MakeTargetEvent.TARGET_CHANGED:
        case MakeTargetEvent.TARGET_REMOVED:
          ctrl.getDisplay()
              .asyncExec(
                  new Runnable() {

                    public void run() {
                      if (!ctrl.isDisposed()) {
                        if (bFlatten) {
                          viewer.refresh();
                        } else {
                          // We can't just call refresh on the container target that
                          // has been created since it may be that the container has
                          // been filtered out and the filters in the viewer don't know
                          // any better how to call out to the filter selection again.
                          // Instead we walk to the root project container and refresh it.
                          Set<IContainer> containers = new HashSet<IContainer>();
                          IMakeTarget[] targets = event.getTargets();
                          for (IMakeTarget target : targets) {
                            IContainer container = target.getContainer();
                            while (!(container instanceof IProject)
                                && container.getParent() != null) {
                              container = container.getParent();
                            }
                            containers.add(container);
                          }
                          for (IContainer container : containers) {
                            viewer.refresh(container);
                          }
                        }
                      }
                    }
                  });
          break;
      }
    }
  }
 private void postRunnable(final Runnable r) {
   Control ctrl = fViewer.getControl();
   if (ctrl != null && !ctrl.isDisposed()) {
     fBrowsingPart.setProcessSelectionEvents(false);
     try {
       if (isDisplayThread() && fReadsInDisplayThread == 0) ctrl.getDisplay().syncExec(r);
       else ctrl.getDisplay().asyncExec(r);
     } finally {
       fBrowsingPart.setProcessSelectionEvents(true);
     }
   }
 }
Example #6
0
 public MoveTracker(Control control) {
   this.control = control;
   cursor = new Cursor(control.getDisplay(), SWT.CURSOR_SIZEALL);
   control.setCursor(cursor);
   control.addListener(SWT.MouseDown, this);
   control.addListener(SWT.Dispose, this);
 }
 /*
  * In an async block, request the proposals. This is used when clients are
  * in the middle of processing an event that affects the widget content. By
  * using an async, we ensure that the widget content is up to date with the
  * event.
  */
 private void asyncRecomputeProposals() {
   footer.setText("Searching...");
   if (isValid()) {
     control
         .getDisplay()
         .asyncExec(
             new Runnable() {
               public void run() {
                 adapter.recordCursorPosition();
                 adapter.getProposals(
                     new IContentProposalSearchHandler() {
                       @Override
                       public void handleResult(ContentProposalList proposalList) {
                         recomputeProposals(proposalList);
                       }
                     });
               }
             });
   } else {
     adapter.getProposals(
         new IContentProposalSearchHandler() {
           @Override
           public void handleResult(ContentProposalList proposalList) {
             recomputeProposals(proposalList);
           }
         });
   }
 }
 protected Color getColor(Control control, Object colorValue) {
   Color color = null;
   if (colorValue != null) {
     RGB rgb = null;
     if (colorValue instanceof Color) {
       color = (Color) colorValue;
     } else if (colorValue instanceof List) {
       rgb = ColorConverter.getInstance().parse((List<?>) colorValue);
       color = new Color(control.getDisplay(), rgb);
     } else {
       rgb = ColorConverter.getInstance().parse(colorValue.toString());
       color = new Color(control.getDisplay(), rgb);
     }
   }
   return color;
 }
 public void runViewUpdate(final Runnable runnable, final boolean preserveExpansion) {
   if (Utils.canUpdateViewer(getViewer()) || isPerformingBackgroundUpdate()) {
     internalRunViewUpdate(runnable, preserveExpansion);
   } else {
     if (Thread.currentThread() != getEventHandlerJob().getThread()) {
       // Run view update should only be called from the UI thread or
       // the update handler thread.
       // We will log the problem for now and make it an assert later
       TeamUIPlugin.log(
           IStatus.WARNING,
           "View update invoked from invalid thread",
           new TeamException(
               "View update invoked from invalid thread")); //$NON-NLS-1$ //$NON-NLS-2$
     }
     final Control ctrl = getViewer().getControl();
     if (ctrl != null && !ctrl.isDisposed()) {
       ctrl.getDisplay()
           .syncExec(
               new Runnable() {
                 public void run() {
                   if (!ctrl.isDisposed()) {
                     BusyIndicator.showWhile(
                         ctrl.getDisplay(),
                         new Runnable() {
                           public void run() {
                             internalRunViewUpdate(runnable, preserveExpansion);
                           }
                         });
                   }
                 }
               });
     }
   }
 }
 /* package */ void postRunnable(final Runnable r) {
   Control ctrl = fViewer.getControl();
   final Runnable trackedRunnable =
       new Runnable() {
         public void run() {
           try {
             r.run();
           } finally {
             removePendingChange();
           }
         }
       };
   if (ctrl != null && !ctrl.isDisposed()) {
     addPendingChange();
     try {
       ctrl.getDisplay().asyncExec(trackedRunnable);
     } catch (RuntimeException e) {
       removePendingChange();
       throw e;
     } catch (Error e) {
       removePendingChange();
       throw e;
     }
   }
 }
 private void handleNewFeature() {
   final Control control = fCategoryViewer.getControl();
   BusyIndicator.showWhile(
       control.getDisplay(),
       new Runnable() {
         public void run() {
           IFeatureModel[] allModels = PDECore.getDefault().getFeatureModelManager().getModels();
           ArrayList<IFeatureModel> newModels = new ArrayList<IFeatureModel>();
           for (int i = 0; i < allModels.length; i++) {
             if (canAdd(allModels[i])) newModels.add(allModels[i]);
           }
           IFeatureModel[] candidateModels =
               newModels.toArray(new IFeatureModel[newModels.size()]);
           FeatureSelectionDialog dialog =
               new FeatureSelectionDialog(
                   fCategoryViewer.getTree().getShell(), candidateModels, true);
           if (dialog.open() == Window.OK) {
             Object[] models = dialog.getResult();
             try {
               doAdd(models);
             } catch (CoreException e) {
               PDEPlugin.log(e);
             }
           }
         }
       });
 }
  private boolean isDisplayThread() {
    Control ctrl = fViewer.getControl();
    if (ctrl == null) return false;

    Display currentDisplay = Display.getCurrent();
    return currentDisplay != null && currentDisplay.equals(ctrl.getDisplay());
  }
Example #13
0
 private Point computeMenuLocation(Control focus, Menu menu) {
   Point cursorLocation = focus.getDisplay().getCursorLocation();
   Rectangle clientArea = null;
   Point result = null;
   if (focus instanceof StyledText) {
     StyledText styledText = (StyledText) focus;
     clientArea = styledText.getClientArea();
     result = computeMenuLocation(styledText);
   } else if (focus instanceof Tree) {
     Tree tree = (Tree) focus;
     clientArea = tree.getClientArea();
     result = computeMenuLocation(tree);
   } else if (focus instanceof Table) {
     Table table = (Table) focus;
     clientArea = table.getClientArea();
     result = computeMenuLocation(table);
   }
   if (result == null) {
     result = focus.toControl(cursorLocation);
   }
   if (clientArea != null && !clientArea.contains(result)) {
     result = new Point(clientArea.x + clientArea.width / 2, clientArea.y + clientArea.height / 2);
   }
   Rectangle shellArea = focus.getShell().getClientArea();
   if (!shellArea.contains(focus.getShell().toControl(focus.toDisplay(result)))) {
     result = new Point(shellArea.x + shellArea.width / 2, shellArea.y + shellArea.height / 2);
   }
   return focus.toDisplay(result);
 }
Example #14
0
 public static void postEvent(Control ownerControl, final Event event) {
   final Display display = ownerControl.getDisplay();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           display.post(event);
         }
       });
 }
 public static boolean isVisible(Control c) {
   if (c.getParent() == null) return true;
   Rectangle displayRect = c.getDisplay().getBounds();
   Point loc = c.getLocation();
   loc = c.getParent().toDisplay(loc);
   Point size = c.getSize();
   if (!displayRect.intersects(loc.x, loc.y, size.x, size.y)) return false;
   if (c.getParent() == null) return true;
   Rectangle r = getVisibleRectangleInParent(c);
   return r != null;
 }
Example #16
0
 /**
  * Determine whether this control or any of it's child has focus
  *
  * @param control control to check
  * @return true if it has focus
  */
 public static boolean hasFocus(Control control) {
   Control focusControl = control.getDisplay().getFocusControl();
   if (focusControl == null) {
     return false;
   }
   for (Control fc = focusControl; fc != null; fc = fc.getParent()) {
     if (fc == control) {
       return true;
     }
   }
   return false;
 }
Example #17
0
  public static void setVisiable(ActionContext actionContext) throws OgnlException {
    Thing self = (Thing) actionContext.get("self");

    String method = self.getString("method");
    if (method == null || "".equals(method)) {
      method = "enable";
    }

    String controlList = self.getString("controlList");
    if (controlList == null || "".equals(controlList)) {
      return;
    }

    for (String controlName : controlList.split("[,]")) {
      Object c = Ognl.getValue(controlName, actionContext);
      if (c instanceof Control) {
        final Control control = (Control) c;
        if (control != null) {
          final String m = method;
          control
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    public void run() {
                      if ("true".equals(m)) {
                        control.setVisible(true);
                      } else if ("false".equals(m)) {
                        control.setVisible(false);
                      } else if ("reverse".equals(m)) {
                        control.setVisible(!control.getEnabled());
                      }
                    }
                  });
        }
      } else if (c instanceof Menu) {
        final Menu item = (Menu) c;
        final String m = method;
        item.getDisplay()
            .asyncExec(
                new Runnable() {
                  public void run() {
                    if ("true".equals(m)) {
                      item.setVisible(true);
                    } else if ("false".equals(m)) {
                      item.setVisible(false);
                    } else if ("reverse".equals(m)) {
                      item.setVisible(!item.getEnabled());
                    }
                  }
                });
      }
    }
  }
Example #18
0
 public void hook(Control control) {
   control.getDisplay().addFilter(SWT.KeyDown, this);
   control
       .getShell()
       .addDisposeListener(
           new DisposeListener() {
             public void widgetDisposed(DisposeEvent e) {
               if (!e.display.isDisposed()) {
                 e.display.removeFilter(SWT.KeyDown, PopupKeyboardListener.this);
               }
             }
           });
 }
  /** All selection must be named model objects. */
  @Override
  public void dragStart(DragSourceEvent event) {

    // Workaround for 1GEUS9V
    DragSource dragSource = (DragSource) event.widget;
    Control control = dragSource.getControl();
    if (control != control.getDisplay().getFocusControl()) {
      event.doit = false;
      return;
    }

    event.doit = canDrag();
  }
  public void show() {
    super.show();

    IFigure fig = getEditPart().getFigure();

    Control control = getCellEditor().getControl();
    this.zoomLevelFont = getZoomLevelFont(fig.getFont(), control.getDisplay());

    control.setFont(this.zoomLevelFont);

    // since the font's have been resized, we need to resize the Text
    // control...
    getLocator().relocate(getCellEditor());
  }
 void ourPlaceMouseInViewer(Point p) {
   if (getCurrentViewer() == null) return;
   Control c = getCurrentViewer().getControl();
   Rectangle rect;
   if (c instanceof Scrollable) rect = ((Scrollable) c).getClientArea();
   else rect = c.getBounds();
   if (p.x > rect.x + rect.width - 1) p.x = rect.x + rect.width - 1;
   else if (p.x < rect.x) p.x = rect.x;
   if (p.y > rect.y + rect.height - 1) p.y = rect.y + rect.height - 1;
   else if (p.y < rect.y) p.y = rect.y;
   org.eclipse.swt.graphics.Point swt = new org.eclipse.swt.graphics.Point(p.x, p.y);
   swt = c.toDisplay(swt);
   c.getDisplay().setCursorLocation(swt);
 }
  public InlineTextInputDialog(final IGraphicalEditPart graphicalEditPart, final String value) {
    super(graphicalEditPart.getViewer().getControl().getShell());
    final IFigure theFigure = graphicalEditPart.getFigure();

    final org.eclipse.draw2d.geometry.Rectangle r = theFigure.getBounds().getCopy();
    theFigure.translateToAbsolute(r);

    final Control theCanvas = graphicalEditPart.getViewer().getControl();
    labelBounds =
        theCanvas.getDisplay().map(theCanvas, null, new Rectangle(r.x, r.y, r.width, r.height));

    this.value = value;
    setShellStyle(SWT.NO_TRIM | SWT.APPLICATION_MODAL);
  }
Example #23
0
 public Image defaultCapture(Control control) {
   Image image = new Image(control.getDisplay(), control.getBounds());
   GC gc = new GC(image);
   try {
     if (control.print(gc)) {
       return image;
     } else {
       image.dispose();
       Rectangle bounds = control.getBounds();
       return getImage(control, bounds.width, bounds.height, true);
     }
   } finally {
     DisposeUtil.dispose(gc);
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.pde.internal.core.IPluginModelListener#modelsChanged(org.eclipse.pde.internal.core.PluginModelDelta)
  */
 public void modelsChanged(PluginModelDelta delta) {
   final Control control = fPluginTable.getControl();
   if (!control.isDisposed()) {
     control
         .getDisplay()
         .asyncExec(
             new Runnable() {
               public void run() {
                 if (!control.isDisposed()) {
                   fPluginTable.refresh();
                   updateRemoveButtons(true, true);
                 }
               }
             });
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.dialogs.PopupDialog.adjustBounds()
   */
  protected void adjustBounds() {
    // Get our control's location in display coordinates.
    Point location = control.getDisplay().map(control.getParent(), null, control.getLocation());
    int initialX = location.x + POPUP_OFFSET;
    int initialY = location.y + control.getSize().y + POPUP_OFFSET;
    // If we are inserting content, use the cursor position to
    // position the control.
    if (adapter.getProposalAcceptanceStyle() == ContentProposalAdapter.PROPOSAL_INSERT) {
      Rectangle insertionBounds = adapter.getControlContentAdapter().getInsertionBounds(control);
      initialX = initialX + insertionBounds.x;
      initialY = location.y + insertionBounds.y + insertionBounds.height;
    }

    // If there is no specified size, force it by setting
    // up a layout on the table.
    if (popupSize == null) {
      GridData data = new GridData(GridData.FILL_BOTH);
      data.heightHint = proposalTable.getItemHeight() * POPUP_CHAR_HEIGHT;
      data.widthHint = Math.max(control.getSize().x, POPUP_MINIMUM_WIDTH);
      proposalTable.setLayoutData(data);
      getShell().pack();
      popupSize = getShell().getSize();
    }

    // Constrain to the display
    Rectangle constrainedBounds =
        getConstrainedShellBounds(new Rectangle(initialX, initialY, popupSize.x, popupSize.y));

    // If there has been an adjustment causing the popup to overlap
    // with the control, then put the popup above the control.
    if (constrainedBounds.y < initialY)
      getShell().setBounds(initialX, location.y - popupSize.y, popupSize.x, popupSize.y);
    else getShell().setBounds(initialX, initialY, popupSize.x, popupSize.y);

    // Now set up a listener to monitor any changes in size.
    getShell()
        .addListener(
            SWT.Resize,
            new Listener() {
              public void handleEvent(Event e) {
                popupSize = getShell().getSize();
                if (infoPopup != null) {
                  infoPopup.adjustBounds();
                }
              }
            });
  }
  /**
   * Forces the standby state of the intro part.
   *
   * @param standby update the standby state
   */
  public void setStandby(final boolean standby) {
    final Control control = ((PartSite) getSite()).getPane().getControl();
    BusyIndicator.showWhile(
        control.getDisplay(),
        new Runnable() {
          public void run() {
            try {
              control.setRedraw(false);
              introPart.standbyStateChanged(standby);
            } finally {
              control.setRedraw(true);
            }

            setBarVisibility(standby);
          }
        });
  }
Example #27
0
 protected IFigure createBlockFigure() {
   final BlockFigure figure = new BlockFigure();
   ImageDescriptor descriptor = ToolkitImages.get(ToolkitImages.SLIDER_HANDLE);
   final Image image = descriptor == null ? null : descriptor.createImage(control.getDisplay());
   figure.setImage(image);
   figure.setSize(figure.getPreferredSize());
   control.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           if (image != null) {
             image.dispose();
           }
           figure.setImage(null);
         }
       });
   return figure;
 }
Example #28
0
  /**
   * Create new instance which add TooltipSupport to the widget
   *
   * @param state
   * @param ownerControl the control on whose action the tooltip is shown
   */
  public AnimatedToolTipShell(final Control ownerControl) {

    _ownerControl = ownerControl;
    _display = _ownerControl.getDisplay();

    _ttAllControlsListener = new ToolTipAllControlsListener();
    _ttShellListener = new ToolTipShellListener();
    _ttDisplayListener = new ToolTipDisplayListener();

    _ownerControlListener = new OwnerControlListener();
    _ownerShellListener = new OwnerShellListener();

    _animationTimer = new AnimationTimer();
    _ttAutoCloseTimer = new ToolTipAutoCloseTimer();

    addOwnerControlListener();
    addOwnerShellListener();
  }
Example #29
0
 private void deactivate() {
   SpellCheckerAgent.removeListener(visitor);
   if (viewer != null) {
     viewer.removeTextListener(this);
     viewer = null;
   }
   if (control != null && !control.isDisposed()) {
     control.removeListener(SWT.Modify, this);
     control.removeListener(SWT.Paint, this);
     control.removeListener(SWT.Dispose, this);
     redraw(control.getDisplay());
     control = null;
   }
   if (job != null) {
     job.dispose();
     job = null;
   }
   ranges.clear();
 }
Example #30
0
  public Image captureImage(Control control) {
    Rectangle rectangle = control.getBounds();
    Display display = control.getDisplay();
    Image image = null;
    if (control instanceof Shell) {
      Shell shell = (Shell) control;
      shell.layout();
      Point parentLocation = control.toDisplay(0, 0);
      image = getImage(control, rectangle.width, rectangle.height, false);

      rectangle.x = parentLocation.x;
      rectangle.y = parentLocation.y;

      GC myImageGC = new GC(image);
      try {
        for (Control child : shell.getChildren()) {
          Rectangle childBounds = child.getBounds();
          // bug of SWT on Win32, child bounds is not correct in the Window is not in the ToolBar
          int x = (rectangle.width - childBounds.width) / 2;
          int y = (rectangle.height - childBounds.height) - x;
          childBounds.x = rectangle.x + x;
          childBounds.y = rectangle.y + y;
          if (!rectangle.intersects(childBounds)) continue; // Child is completely outside parent.

          Image childImage = new Image(display, child.getBounds());
          GC gc = new GC(childImage);
          child.print(gc);
          DisposeUtil.dispose(gc);
          try {
            myImageGC.drawImage(childImage, x, y);
          } finally {
            childImage.dispose();
          }
        }
      } finally {
        myImageGC.dispose();
      }
    } else {
      image = defaultCapture(control);
    }
    return image;
  }