示例#1
0
 private boolean isAncestorShell(Shell ancestor, Shell shell) {
   if (ancestor == null || shell == null || shell == ancestor) return false;
   Composite parent = shell.getParent();
   if (parent == ancestor) return true;
   if (parent instanceof Shell) return isAncestorShell(ancestor, (Shell) parent);
   return false;
 }
  /**
   * Get an <code>Image</code> from the provide SWT image constant.
   *
   * @param imageID the SWT image constant
   * @return image the image
   */
  private Image getSWTImage(final int imageID) {
    Shell shell = getShell();
    final Display display;
    if (!Widgets.isDisposed(shell)) {
      shell = shell.getParent().getShell();
    }
    if (Widgets.isDisposed(shell)) {
      display = Display.getCurrent();
      // The dialog should be always instantiated in UI thread.
      // However it was possible to instantiate it in other threads
      // (the code worked in most cases) so the assertion covers
      // only the failing scenario. See bug 107082 for details.
      Assert.isNotNull(display, "The dialog should be created in UI thread"); // $NON-NLS-1$
    } else {
      display = shell.getDisplay();
    }

    final Image[] image = new Image[1];
    display.syncExec(
        new Runnable() {
          @Override
          public void run() {
            image[0] = display.getSystemImage(imageID);
          }
        });

    return image[0];
  }
    /** @see org.eclipse.jface.window.Window#constrainShellSize() */
    @Override
    protected void constrainShellSize() {
      super.constrainShellSize();

      final Shell shell = getShell();
      shell.setText(Messages.selectProcedureTypeDialogTitle);

      { // set size
        final Rectangle r = shell.getBounds();
        shell.setBounds(r.x, r.y, (int) (r.width * 0.67), r.height);
      }

      { // center on parent
        final Shell parentShell = (Shell) shell.getParent();
        final Rectangle parentBounds = parentShell.getBounds();
        final Point parentCenter =
            new Point(
                parentBounds.x + (parentBounds.width / 2),
                parentBounds.y + parentBounds.height / 2);

        final Rectangle r = shell.getBounds();
        final Point shellLocation =
            new Point(parentCenter.x - r.width / 2, parentCenter.y - r.height / 2);

        shell.setBounds(
            Math.max(0, shellLocation.x), Math.max(0, shellLocation.y), r.width, r.height);
      }
    }
 @Override
 protected void configureShell(Shell shell) {
   super.configureShell(shell);
   Shell s2 = shell.getParent().getShell();
   if (s2 != null) shell.setLocation(s2.getLocation());
   shell.setBounds(shell.getLocation().x, shell.getLocation().y, 550, 500);
   if (domain == null) shell.setText(CredentialMessages.AddACredentialDomain);
   else {
     shell.setText(CredentialMessages.EditACredentialDomain);
   }
 }
示例#5
0
 public void open(Shell shell) {
   if (shell.getParent() != null) {
     shell.setMaximized(true);
     shell.open();
     return;
   }
   //    shell.setMaximized(true);
   shell.setSize(800, 550);
   shell.open();
   Display display = shell.getDisplay();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
   System.exit(-1);
 }
  /** @see org.eclipse.gef.tools.DirectEditManager#commit() */
  protected void commit() {
    Shell activeShell = Display.getCurrent().getActiveShell();
    if (activeShell != null
        && getCellEditor().getControl().getShell().equals(activeShell.getParent())) {
      Control[] children = activeShell.getChildren();
      if (children.length == 1 && children[0] instanceof Table) {
        /*
         * CONTENT ASSIST: focus is lost to the content assist pop up -
         * stay in focus
         */
        getCellEditor().getControl().setVisible(true);
        ((XtextStyledTextCellEditorEx) getCellEditor()).setDeactivationLock(true);
        return;
      }
    }

    // content assist hacks
    if (committed) {
      bringDown();
      return;
    }
    committed = true;
    super.commit();
  }
 public void testMessageWithConstruct() throws IOException, JSONException {
   StringWriter stringWriter = new StringWriter();
   PrintWriter printWriter = new PrintWriter(stringWriter);
   ProtocolMessageWriter writer = new JsonMessageWriter(printWriter);
   Display display = new Display();
   Shell shell = new Shell(display);
   Button button = new Button(shell, SWT.PUSH);
   writer.addConstructPayload(
       WidgetUtil.getId(shell),
       DisplayUtil.getId(display),
       "org.Text",
       new String[] {"TRIM"},
       new Object[] {"a", "b"});
   String parentId = "";
   if (shell.getParent() != null) {
     parentId = WidgetUtil.getId(shell.getParent());
   } else {
     parentId = DisplayUtil.getId(display);
   }
   String widgetId = WidgetUtil.getId(shell);
   String actual = stringWriter.getBuffer().toString();
   JSONObject message = new JSONObject(actual + "]}");
   JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   JSONObject widgetObject = widgetArray.getJSONObject(0);
   String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type);
   String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(widgetId, actualId);
   JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   String actualParentId = payload.getString(IProtocolConstants.KEY_PARENT_ID);
   assertEquals(parentId, actualParentId);
   String actualType = payload.getString(IProtocolConstants.KEY_WIDGET_TYPE);
   assertEquals("org.Text", actualType);
   JSONArray actualStyle = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE);
   assertEquals("TRIM", actualStyle.getString(0));
   JSONArray actualParams = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST);
   assertEquals("a", actualParams.getString(0));
   assertEquals("b", actualParams.getString(1));
   writer.addConstructPayload(
       WidgetUtil.getId(button),
       WidgetUtil.getId(shell),
       "org.Shell",
       new String[] {"PUSH", "BORDER"},
       new Object[] {"a", new Boolean(true)});
   writer.finish();
   actual = stringWriter.getBuffer().toString();
   message = new JSONObject(actual);
   widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   widgetObject = widgetArray.getJSONObject(1);
   type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_CONSTRUCT, type);
   actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(WidgetUtil.getId(button), actualId);
   payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   JSONArray styles = payload.getJSONArray(IProtocolConstants.KEY_WIDGET_STYLE);
   assertEquals("PUSH", styles.getString(0));
   assertEquals("BORDER", styles.getString(1));
   String actualParent = payload.getString(IProtocolConstants.KEY_PARENT_ID);
   assertEquals(WidgetUtil.getId(shell), actualParent);
   JSONArray params = payload.getJSONArray(IProtocolConstants.KEY_PARAMETER_LIST);
   assertTrue(params.getBoolean(1));
 }
示例#8
0
 /**
  * Registers the shell as the same type as its parent with the context support. This ensures that
  * it does not modify the current state of the application.
  */
 private final void registerShellType() {
   final Shell shell = getShell();
   final IContextService contextService =
       (IContextService) EditorUtils.getActiveWorkbenchWindow().getService(IContextService.class);
   contextService.registerShell(shell, contextService.getShellType((Shell) shell.getParent()));
 }