Пример #1
0
 public static CellEditor createPropertyEditor(
     final IServiceLocator serviceLocator,
     Composite parent,
     DBPPropertySource source,
     DBPPropertyDescriptor property) {
   if (source == null) {
     return null;
   }
   final Object object = source.getEditableValue();
   if (!property.isEditable(object)) {
     return null;
   }
   CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property);
   if (cellEditor != null) {
     final Control editorControl = cellEditor.getControl();
     UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl);
     editorControl.addDisposeListener(
         new DisposeListener() {
           @Override
           public void widgetDisposed(DisposeEvent e) {
             UIUtils.removeFocusTracker(serviceLocator, editorControl);
           }
         });
   }
   return cellEditor;
 }
Пример #2
0
  /**
   * Install a copy popup menu on the specified control and activate the copy handler for the
   * control when the control has focus. The handler will be deactivated when the control is
   * disposed.
   *
   * @param copyable the copyable that will perform the copy
   * @param control the control on which to install the menu and handler
   */
  public static void activateCopy(ICopyable copyable, final Control control) {
    IFocusService fs = PlatformUI.getWorkbench().getService(IFocusService.class);
    final IHandlerService hs = PlatformUI.getWorkbench().getService(IHandlerService.class);
    new CopyPopup(copyable, control);
    if (fs != null && hs != null) {
      fs.addFocusTracker(control, CONTROL_ID);
      final IHandlerActivation handlerActivation =
          hs.activateHandler(
              CopyHandler.ID,
              new CopyHandler(copyable),
              new Expression() {
                public EvaluationResult evaluate(IEvaluationContext context) {
                  return context.getVariable(ISources.ACTIVE_FOCUS_CONTROL_NAME) == control
                      ? EvaluationResult.TRUE
                      : EvaluationResult.FALSE;
                }

                public void collectExpressionInfo(final ExpressionInfo info) {
                  info.addVariableNameAccess(ISources.ACTIVE_FOCUS_CONTROL_NAME);
                }
              });
      control.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              hs.deactivateHandler(handlerActivation);
            }
          });
    }
  }
Пример #3
0
  /** Adds validation overlay component to the control. */
  private void addValidationOverlay(
      final AttributeDescriptor descriptor,
      final IAttributeEditor editor,
      final Object defaultValue,
      final Control label) {
    final ControlDecoration decoration = new ControlDecoration(label, SWT.LEFT | SWT.BOTTOM);
    decoration.hide();

    final FieldDecoration requiredDecoration =
        FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);

    decoration.setImage(requiredDecoration.getImage());
    decoration.setDescriptionText("Invalid value");

    final IAttributeListener validationListener =
        new InvalidStateDecorationListener(decoration, descriptor, defaultValue);

    globalEventsProvider.addAttributeListener(validationListener);
    editor.addAttributeListener(validationListener);

    label.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            globalEventsProvider.removeAttributeListener(validationListener);
            editor.removeAttributeListener(validationListener);
            decoration.dispose();
          }
        });
  }
 /**
  * NE: Copied from ContentViewer. We don't want the OpenStrategy hooked in
  * StructuredViewer.hookControl otherwise the canvas will take focus since it has a key listener.
  * We don't want this included in the window's tab traversal order. Defeating it here is more
  * self-contained then setting the tab list on the shell or other parent composite.
  */
 protected void hookControl(Control control) {
   control.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent event) {
           handleDispose(event);
         }
       });
 }
 public static void setFontStyle(Control ctrl, int style) {
   Font font = UIUtil.setFontStyle(ctrl.getFont(), style);
   ctrl.setFont(font);
   ctrl.addDisposeListener(
       new DisposeListenerWithData<Font>(font) {
         public void widgetDisposed(DisposeEvent e) {
           data().dispose();
         }
       });
 }
 public static void increaseFontSize(Control ctrl, int inc) {
   Font font = UIUtil.increaseFontSize(ctrl.getFont(), inc);
   ctrl.setFont(font);
   ctrl.addDisposeListener(
       new DisposeListenerWithData<Font>(font) {
         public void widgetDisposed(DisposeEvent e) {
           data().dispose();
         }
       });
 }
 SelectableMouseTrackListener(Control root) {
   this.root = root;
   initialBg = root.getBackground();
   root.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           SelectableMouseTrackListener.this.root = null;
           border = null;
           painter = null;
           initialBg = null;
         }
       });
 }
Пример #8
0
 public Resizer(Control c, int dir) {
   fDirection = dir;
   fControl = c;
   fLiveResize = !(fControl instanceof Sash);
   updateCursor(c, dir);
   fControl.addMouseListener(this);
   fControl.addMouseMoveListener(this);
   fControl.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           fControl = null;
         }
       });
 }
    private FocusHandler(Navigable navigable) {
      fIterator = new JavaWordIterator();
      fNavigable = navigable;

      Control control = navigable.getControl();
      control.addFocusListener(this);
      if (control.isFocusControl()) activate();
      control.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              deactivate();
            }
          });
    }
Пример #10
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;
 }
Пример #11
0
  /**
   * Sets the control whose position will be managed by this proxy
   *
   * @param target the control, or null if none
   */
  public void setTargetControl(Control target) {
    if (this.target != target) {

      if (this.target != null) {
        for (Control next = control;
            next != commonAncestor && next != null;
            next = next.getParent()) {
          next.removeControlListener(controlListener);
        }
        commonAncestor = null;

        // If we already had a target, detach the dispose listener
        // (prevents memory leaks due to listeners)
        if (!this.target.isDisposed()) {
          this.target.removeDisposeListener(disposeListener);
        }
      }

      if (this.target == null && target != null) {
        // If we had previously forced the dummy control invisible, restore its visibility
        control.setVisible(visible);
      }

      this.target = target;

      if (target != null) {
        commonAncestor = SwtUtil.findCommonAncestor(this.target, control);
        for (Control next = control;
            next != null && next != commonAncestor;
            next = next.getParent()) {
          next.addControlListener(controlListener);
        }

        // Make the new target's visiblity match the visibility of the dummy control
        target.setVisible(control.getVisible());
        // Add a dispose listener. Ensures that the target is cleared
        // if it is ever disposed.
        target.addDisposeListener(disposeListener);
      } else {
        control.setVisible(false);
      }
    }
  }
Пример #12
0
  public static void enableHostEditorKeyBindingsSupport(
      final IWorkbenchPartSite partSite, Control control) {
    if (!(partSite.getPart() instanceof AbstractTextEditor)) {
      return;
    }

    final boolean[] activated = new boolean[] {false};
    control.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent e) {
            if (!activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, false);
              activated[0] = true;
            }
          }

          @Override
          public void focusLost(FocusEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
    control.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
  }
Пример #13
0
  public void open() {
    if (screenPos == null) screenPos = Display.getDefault().getCursorLocation();
    leftScreenPos = screenPos;
    popupRight = true;
    if (control == null || control.isDisposed()) return;
    control.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            dispose();
          }
        });
    final ShellListener shellListener =
        new ShellAdapter() {

          public void shellClosed(ShellEvent e) {
            hideMenu();
          }

          public void shellDeactivated(ShellEvent e) {
            hideMenu();
          }

          public void shellIconified(ShellEvent e) {
            hideMenu();
          }
        };
    control.getShell().addShellListener(shellListener);
    ignoreTaskbar = true;

    Event event = new Event();
    event.data = this;
    event.type = SWT.OPEN;
    menu.fireMenuEvent(event);

    createAndShowWindow();
    installMouseHook();
    shell.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            if (!control.isDisposed()) control.getShell().removeShellListener(shellListener);
          }
        });

    final Listener mouseDownListener =
        new Listener() {

          public void handleEvent(Event e) {
            if (shell == null || shell.isDisposed()) {
              Display.getDefault().removeFilter(SWT.MouseDown, this);
              return;
            }
            if (e.widget == null
                || e.widget.isDisposed()
                || checkMouseDownEvent(((Control) e.widget).toDisplay(e.x, e.y))) {
              hideMenu();
            }
          }
        };

    Display.getDefault().addFilter(SWT.MouseDown, mouseDownListener);

    final Listener keyDownListener =
        new Listener() {

          public void handleEvent(Event e) {
            if (shell == null || shell.isDisposed()) {
              Display.getDefault().removeFilter(SWT.KeyDown, this);
              e.doit = false;
              return;
            }
            KeyEvent ke = new KeyEvent(e);
            if ((ke.keyCode == SWT.ALT) || ke.keyCode == SWT.F10) {
              hideMenu();
              return;
            }
            getCurrentMenu().dealAltKeyEvent(ke);

            if (ke.keyCode == KEY_RIGHT && trackItemIndex > -1) {
              getCurrentMenu().subMenuSelected();
            }
            if (ke.keyCode == KEY_LEFT && trackItemIndex > -1) {
              getCurrentMenu().parentMenuSelected();
            }
            if (ke.keyCode == KEY_DOWN || ke.keyCode == KEY_UP) {
              if (ke.keyCode == KEY_DOWN) getCurrentMenu().downSelected();
              else getCurrentMenu().upSelected();
            }
            if (ke.keyCode == SWT.ESC) {
              if (getCurrentMenu().parentMenu == null) getCurrentMenu().hideMenu();
              else getCurrentMenu().parentMenuSelected();
            }
            if (ke.keyCode == SWT.CR) {
              getCurrentMenu().handleSelectedEvent();
            }
          }
        };
    Display.getDefault().addFilter(SWT.KeyDown, keyDownListener);

    shell.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            Display.getDefault().removeFilter(SWT.MouseDown, mouseDownListener);
            Display.getDefault().removeFilter(SWT.KeyDown, keyDownListener);
            getShell().removeShellListener(shellListener);
          }
        });
  }