/**
   * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu
   * (populated using the same id as this item...
   *
   * @param event The <code>SWT.Selection</code> event to be tested
   * @return <code>true</code> iff a drop down menu was opened
   */
  private boolean openDropDownMenu(Event event) {
    Widget item = event.widget;
    if (item != null) {
      int style = item.getStyle();
      if ((style & SWT.DROP_DOWN) != 0) {
        if (event.detail == 4) { // on drop-down button
          ToolItem ti = (ToolItem) item;

          final MenuManager menuManager = new MenuManager();
          Menu menu = menuManager.createContextMenu(ti.getParent());
          menuManager.addMenuListener(
              new IMenuListener() {
                public void menuAboutToShow(IMenuManager manager) {
                  String id = getId();
                  if (dropDownMenuOverride != null) {
                    id = dropDownMenuOverride;
                  }
                  menuService.populateContributionManager(menuManager, "menu:" + id); // $NON-NLS-1$
                }
              });
          // position the menu below the drop down item
          Rectangle b = ti.getBounds();
          Point p = ti.getParent().toDisplay(new Point(b.x, b.y + b.height));
          menu.setLocation(p.x, p.y); // waiting for SWT
          // 0.42
          menu.setVisible(true);
          return true; // we don't fire the action
        }
      }
    }

    return false;
  }
Ejemplo n.º 2
0
  private static String formatWidgetPath(Widget widget) {
    StringBuilder b = new StringBuilder();
    while (widget != null) {
      if (b.length() > 0) b.append(" <- ");
      b.append(widget.getClass().getSimpleName());

      try {
        Method getText = widget.getClass().getMethod("getText");
        if (getText.getReturnType() == String.class) {
          String text = (String) getText.invoke(widget);
          if (text != null && text.length() > 0) {
            if (text.length() > 32) text = text.substring(0, 32) + " ...";
            b.append('(').append(text).append(')');
          }
        }
      } catch (SecurityException e) {
      } catch (NoSuchMethodException e) {
      } catch (IllegalArgumentException e) {
      } catch (IllegalAccessException e) {
      } catch (InvocationTargetException e) {
      }

      widget = widget instanceof Control ? ((Control) widget).getParent() : null;
    }
    return b.toString();
  }
  /**
   * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu
   * (populated using the same id as this item...
   *
   * @param event The <code>SWT.Selection</code> event to be tested
   * @return <code>true</code> iff a drop down menu was opened
   */
  private boolean openDropDownMenu(final Event event) {
    final Widget item = event.widget;
    if (item != null) {
      final int style = item.getStyle();
      if ((style & SWT.DROP_DOWN) != 0) {
        if (event.detail == 4) { // on drop-down button
          final ToolItem ti = (ToolItem) item;

          final MenuManager menuManager = new MenuManager();
          final Menu menu = menuManager.createContextMenu(ti.getParent());
          if (this.workbenchHelpSystem != null) {
            this.workbenchHelpSystem.setHelp(menu, this.helpContextId);
          }
          initDropDownMenu(menuManager);

          // position the menu below the drop down item
          final Point point = ti.getParent().toDisplay(new Point(event.x, event.y));
          menu.setLocation(point.x, point.y); // waiting for SWT
          // 0.42
          menu.setVisible(true);
          return true; // we don't fire the action
        }
      }
    }

    return false;
  }
 private void replaceListener(
     Widget provider, TypedListener oldListener, SelectionListener newListener) {
   provider.removeListener(SWT.Selection, oldListener);
   provider.removeListener(SWT.DefaultSelection, oldListener);
   provider.addListener(SWT.Selection, new TypedListener(newListener));
   provider.addListener(SWT.DefaultSelection, new TypedListener(newListener));
 }
 private void handleWidgetDispose(Event event) {
   if (event.widget == widget) {
     widget.removeListener(SWT.Selection, getItemListener());
     widget.removeListener(SWT.Dispose, getItemListener());
     widget = null;
     disposeOldImages();
   }
 }
Ejemplo n.º 6
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#hideChild
   * (org.eclipse.e4.ui.model.application.MElementContainer,
   * org.eclipse.e4.ui.model.application.MUIElement)
   */
  @Override
  public void hideChild(MElementContainer<MUIElement> parentElement, MUIElement child) {
    super.hideChild(parentElement, child);

    // Since there's no place to 'store' a child that's not in a menu
    // we'll blow it away and re-create on an add
    Widget widget = (Widget) child.getWidget();
    if (widget != null && !widget.isDisposed()) widget.dispose();
  }
Ejemplo n.º 7
0
 public static void dispose(Widget widget) {
   if (widget != null && !widget.isDisposed()) {
     try {
       widget.dispose();
     } catch (Exception e) {
       log.debug("widget dispose error", e);
     }
   }
 }
Ejemplo n.º 8
0
 public static boolean hasStyle(final Widget w, final int style) {
   if ((w == null) || w.isDisposed()) return false;
   return UIThreadRunnable.syncExec(
       w.getDisplay(),
       new BoolResult() {
         public boolean run() {
           return (w.getStyle() & style) != 0;
         }
       });
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.e4.ui.workbench.renderers.swt.PartFactory#hookControllerLogic
  * (org.eclipse.e4.ui.model.application.MPart)
  */
 @Override
 public void hookControllerLogic(final MUIElement me) {
   super.hookControllerLogic(me);
   if (!(me instanceof MPart)) {
     return;
   }
   Widget widget = (Widget) me.getWidget();
   if (widget instanceof Composite) {
     widget.addListener(SWT.Activate, activationListener);
   }
 }
Ejemplo n.º 10
0
  private void doRemoveGroup(String group) {
    try {
      policy.setRedraw(false);

      for (Widget col : policy.getColumns()) {
        Column column = (Column) col.getData(Column.class.getName());
        if (group.equals(column.getGroupLabel())) col.dispose();
      }
    } finally {
      policy.getViewer().refresh();
      policy.setRedraw(true);
    }
  }
 /**
  * The <code>WizardNewFileCreationPage</code> implementation of this <code>Listener</code> method
  * handles all events and enablements for controls on this page. Subclasses may extend.
  */
 public void handleEvent(Event event) {
   Widget widget = event.widget;
   if (widget.equals(nameText)) {
     name = nameText.getText();
   } else if (widget.equals(idText)) {
     paletteID = idText.getText();
   } else if (widget.equals(editorText)) {
     editorID = editorText.getText();
   } else if (widget.equals(priorityCombo)) {
     priority = ProviderPriority.parse(priorityCombo.getText());
   }
   setPageComplete(validatePage());
 }
Ejemplo n.º 12
0
 public Event sendEvent(final Widget w, final Widget item, final Event event) {
   if (w.isDisposed() || (item != null && item.isDisposed())) {
     return null;
   }
   try {
     event.widget = w;
     event.item = item;
     sendEventRaw(event.type, event);
     return event;
   } catch (Exception e) {
     TeslaCore.log(e);
     return null;
   }
 }
Ejemplo n.º 13
0
 public void destroyColumnWithOption(Column column, Object option) {
   for (Widget widget : policy.getColumns()) {
     if (column.equals(widget.getData(Column.class.getName())) //
         && (option == null || option.equals(widget.getData(OPTIONS_KEY)))) {
       try {
         policy.setRedraw(false);
         widget.dispose();
       } finally {
         policy.getViewer().refresh();
         policy.setRedraw(true);
       }
       break;
     }
   }
 }
Ejemplo n.º 14
0
  public static String getText(final Object w) {
    if ((w instanceof Widget) && !((Widget) w).isDisposed()) {
      final Widget widget = (Widget) w;
      return UIThreadRunnable.syncExec(
          widget.getDisplay(),
          new StringResult() {

            public String run() {
              Object returnV = ReflectionUtil.invokeMethod("getText", widget);
              return (String) returnV;
            }
          });
    }
    return null;
  }
Ejemplo n.º 15
0
  public synchronized void sendUnfocus(Widget widget) {
    if (widget.isDisposed()) {
      return;
    }
    if (!(widget instanceof Control)) {
      return;
    }
    Control ctrl = (Control) widget;
    boolean sendUnfocus = TeslaCellEditorManager.getInstance().getEditors().length > 0;

    if (!sendUnfocus) {
      if (ctrl.isFocusControl() || widget == lastFocusControl) {
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.FocusOut);
        }
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.Deactivate);
        }
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.MouseMove);
        }
        if (!ctrl.isDisposed()) {
          sendEvent(ctrl, SWT.MouseExit);
        }
      }
      lastFocusControl = null;
      TeslaEventManager.getManager().setForceFocusControl(null);
    }
  }
 @Override
 protected List getSelectionFromWidget() {
   if (virtualManager != null) {
     return getVirtualSelection();
   }
   Widget[] items = doGetSelection();
   ArrayList list = new ArrayList(items.length);
   for (int i = 0; i < items.length; i++) {
     Widget item = items[i];
     Object e = item.getData();
     if (e != null) {
       list.add(e);
     }
   }
   return list;
 }
Ejemplo n.º 17
0
 public Event sendEvent(final SWTUIElement w, Event event) {
   Widget unwrapWidget = PlayerWrapUtils.unwrapWidget(w);
   if (unwrapWidget.isDisposed()) {
     return null;
   }
   try {
     event.widget = unwrapWidget;
     sendEventRaw(event.type, event);
     return event;
   } catch (SecurityException e) {
     TeslaCore.log(e);
   } catch (IllegalArgumentException e) {
     TeslaCore.log(e);
   }
   return null;
 }
 private TypedListener findSelectionListener(Widget provider, Class<?> declaringClass) {
   for (Listener o : provider.getListeners(SWT.Selection))
     if (o instanceof TypedListener
         && ((TypedListener) o).getEventListener().getClass().getDeclaringClass()
             == declaringClass) return (TypedListener) o;
   return null;
 }
  @Override
  public void hideChild(MElementContainer<MUIElement> parentElement, MUIElement child) {
    super.hideChild(parentElement, child);

    // Since there's no place to 'store' a child that's not in a menu
    // we'll blow it away and re-create on an add
    Widget widget = (Widget) child.getWidget();
    if (widget != null && !widget.isDisposed()) {
      widget.dispose();
    }
    ToolBar toolbar = (ToolBar) getUIContainer(child);
    if (toolbar != null && !toolbar.isDisposed()) {
      toolbar.getShell().layout(new Control[] {toolbar}, SWT.DEFER);
    }
    disposeToolbarIfNecessary(parentElement);
  }
Ejemplo n.º 20
0
 protected void handleEvents() {
   while (display != null && (!display.isDisposed()) && (!parent.isDisposed())) {
     if (!display.readAndDispatch()) {
       break; // display.sleep();
     }
   }
 }
Ejemplo n.º 21
0
 private static String genericFormatObject(Object value) {
   if (value == null) return null;
   if (value instanceof Character && (Character) value == 0) return "NUL";
   if (justToStringClasses.contains(value.getClass())) return value.toString();
   if (value instanceof Object[]) return formatArray((Object[]) value);
   if (value instanceof Widget) {
     Widget widget = (Widget) value;
     return String.format(
         "%s@%x [%s] %s",
         value.getClass().getName(),
         System.identityHashCode(value),
         widget.isDisposed() ? "disposed" : formatWidgetPath(widget),
         widget.isDisposed() ? "[disposed]" : value.toString());
   }
   return String.format(
       "%s@%x %s", value.getClass().getName(), System.identityHashCode(value), value.toString());
 }
 protected void controlChanged(Widget widget) {
   ComboData data = (ComboData) widget.getData();
   if (widget instanceof Combo) {
     data.setIndex(((Combo) widget).getSelectionIndex());
   } else {
     return;
   }
 }
Ejemplo n.º 23
0
 private static AbstractLabelLCADelegate getDelegate(final Widget widget) {
   AbstractLabelLCADelegate result;
   if ((widget.getStyle() & SWT.SEPARATOR) != 0) {
     result = SEPARATOR_LCA;
   } else {
     result = LABEL_LCA;
   }
   return result;
 }
Ejemplo n.º 24
0
  private String serialize() {
    StringBuilder buf = new StringBuilder();

    Widget sortedColumn = policy.getSortColumn();

    for (int index : policy.getColumnOrder()) {
      Widget col = policy.getColumn(index);
      Column column = (Column) col.getData(Column.class.getName());
      buf.append(column.getId()).append('=');

      Object option = col.getData(OPTIONS_KEY);
      if (option != null) buf.append(option).append('|');
      if (col.equals(sortedColumn)) buf.append(policy.getSortDirection()).append('$');

      buf.append(policy.getWidth(col)).append(';');
    }
    return buf.toString();
  }
Ejemplo n.º 25
0
 protected Rectangle getControlBounds() {
   Widget widget = (Widget) getControl();
   if (widget instanceof Control) {
     Control control = (Control) widget;
     return control.getBounds();
   }
   Method drawMethod = findBoundsMethod(widget.getClass());
   if (drawMethod != null) {
     try {
       drawMethod.setAccessible(true);
       return (Rectangle) drawMethod.invoke(widget);
     } catch (Exception e) {
       throw new XWTException(e);
     }
   }
   Control control = findHostControl();
   return control.getBounds();
 }
Ejemplo n.º 26
0
  public synchronized void sendFocus(Widget widget) {
    if (widget.isDisposed()) {
      return;
    }
    if (!(widget instanceof Control)) {
      return;
    }
    Control ctrl = (Control) widget;

    boolean sendUnfocus = TeslaCellEditorManager.getInstance().getEditors().length > 0;

    if (sendUnfocus) {
      if (ctrl != lastFocusControl) {
        // new focus control
        // send focusOut for real last focused control
        if (ctrl == lastFocusControl) {
          return;
        }
        if (lastFocusControl != null && !lastFocusControl.isDisposed()) {
          if (lastFocusControl.isFocusControl()) {
            sendEvent(lastFocusControl, SWT.FocusOut);
            if (!lastFocusControl.isDisposed()) {
              sendEvent(lastFocusControl, SWT.Deactivate);
            }
            if (!lastFocusControl.isDisposed()) {
              sendEvent(lastFocusControl, SWT.MouseExit);
            }
          }
        }
        lastFocusControl = ctrl;
        if (!ctrl.isFocusControl()) {
          ctrl.setFocus();
          sendEvent(lastFocusControl, SWT.MouseEnter);
          sendEvent(lastFocusControl, SWT.MouseMove);
          sendEvent(lastFocusControl, SWT.Activate);
          sendEvent(lastFocusControl, SWT.FocusIn);
        }
      }
    } else {
      // ctrl.getShell().forceActive();
      if (!ctrl.isFocusControl()) {
        try {
          ShellUtilsProvider.getShellUtils().forceActive(ctrl.getShell());
        } catch (CoreException e) {
          throw new RuntimeException(e);
        }
        ctrl.setFocus();
        ctrl.forceFocus();
        sendEvent(ctrl, SWT.MouseEnter);
        sendEvent(ctrl, SWT.MouseMove);
        sendEvent(ctrl, SWT.Activate);
        sendEvent(ctrl, SWT.FocusIn);
      }
      lastFocusControl = ctrl;
    }
  }
Ejemplo n.º 27
0
  /* (non-Javadoc)
   * @see com.windowtester.runtime.IUIContext#close(com.windowtester.runtime.locator.IWidgetLocator)
   */
  public void close(IWidgetLocator locator) throws WidgetSearchException {

    ICloseableLocator closeable = getCloseable(locator);

    if (closeable != null) {
      closeable.doClose(this);
      return;
    }

    // conditions handled in the close
    // handleConditions();
    Widget widget = findWidget(locator);
    if (widget == null) throw new WidgetSearchException("target of a close call must not be null");
    if (!(widget instanceof Shell))
      throw new WidgetSearchException(
          "target of a close call must be a Shell, got a: " + widget.getClass() + " instead");

    close((Shell) widget);
  }
Ejemplo n.º 28
0
 // Widget argument: Image cache will be cleared when the given widget is disposed
 public FileIconCache(@NotNull Widget disposeWidget) {
   this.disposeWidget = disposeWidget;
   disposeWidget.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           for (Image image : fileIconMap.values()) image.dispose();
           fileIconMap.clear();
         }
       });
 }
  @Override
  public void disposeWidget(MUIElement element) {
    if (element instanceof MPart) {
      MPart part = (MPart) element;
      MToolBar toolBar = part.getToolbar();
      if (toolBar != null) {
        Widget widget = (Widget) toolBar.getWidget();
        if (widget != null) {
          unbindWidget(toolBar);
          widget.dispose();
        }
      }

      for (MMenu menu : part.getMenus()) {
        engine.removeGui(menu);
      }
    }
    super.disposeWidget(element);
  }
Ejemplo n.º 30
0
  /**
   * Dispose of the resource manager when the widget is disposed
   *
   * @param widget
   * @param resources
   */
  public static void hookDisposal(Widget widget, final ResourceManager resources) {
    if (widget == null || resources == null) return;

    widget.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            resources.dispose();
          }
        });
  }