예제 #1
0
  private void addSearchButton(ToolBar toolBar) {
    final Text search = new Text(toolBar, SWT.SEARCH | SWT.ICON_CANCEL);
    search.setSize(100, SWT.DEFAULT);
    search.setMessage(Messages.LabelSearch);

    ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
    toolItem.setWidth(search.getSize().x);
    toolItem.setControl(search);

    search.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            String filter = search.getText().trim();
            if (filter.length() == 0) {
              filterPattern = null;
              securities.refresh();
            } else {
              filterPattern =
                  Pattern.compile(
                      ".*" + filter + ".*", Pattern.CASE_INSENSITIVE); // $NON-NLS-1$ //$NON-NLS-2$
              securities.refresh();
            }
          }
        });
  }
 /** Add a separator to the toolbar, unless there already is one there at the end already */
 private static void addSeparator(ToolBar toolBar) {
   int n = toolBar.getItemCount();
   if (n > 0 && (toolBar.getItem(n - 1).getStyle() & SWT.SEPARATOR) == 0) {
     ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR);
     separator.setWidth(15);
   }
 }
  /**
   * Creates and returns the control for this contribution item under the given parent composite.
   *
   * @param parent the parent composite
   * @return the new control
   */
  protected Control createControl(final Composite parent) {
    combo = new Combo(parent, SWT.DROP_DOWN);
    combo.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(final SelectionEvent e) {
            handleWidgetSelected(e);
          }

          public void widgetDefaultSelected(final SelectionEvent e) {
            handleWidgetDefaultSelected(e);
          }
        });
    combo.addFocusListener(
        new FocusListener() {
          public void focusGained(final FocusEvent e) {
            // do nothing
          }

          public void focusLost(final FocusEvent e) {
            refresh(false);
          }
        });

    // Initialize width of combo
    combo.setItems(initStrings);
    toolitem.setWidth(computeWidth(combo));
    combo.setToolTipText("Current concern");
    refresh(true);
    return combo;
  }
 @Override
 public void doSetValue(Object value) {
   final Object oldValue = doGetValue();
   if (attribute.equals(Constants.ATTR_IMAGE)) {
     item.setImage((Image) value);
   } else if (attribute.equals(Constants.ATTR_TEXT)) {
     item.setText((String) value);
   } else if (attribute.equals(Constants.ATTR_TOOLTIP)) {
     if (item instanceof TableColumn) {
       ((TableColumn) item).setToolTipText((String) value);
     }
     if (item instanceof TreeColumn) {
       ((TreeColumn) item).setToolTipText((String) value);
     }
     if (item instanceof ToolItem) {
       ((ToolItem) item).setToolTipText((String) value);
     }
     if (item instanceof TabItem) {
       ((TabItem) item).setToolTipText((String) value);
     }
   } else if (attribute.equals(Constants.ATTR_ALIGNMENT)) {
     if (item instanceof TableColumn) {
       ((TableColumn) item).setAlignment((Integer) value);
     }
     if (item instanceof TreeColumn) {
       ((TreeColumn) item).setAlignment((Integer) value);
     }
   } else if (attribute.equals(Constants.ATTR_WIDTH)) {
     if (item instanceof TableColumn) {
       ((TableColumn) item).setWidth((Integer) value);
     }
     if (item instanceof TreeColumn) {
       ((TreeColumn) item).setWidth((Integer) value);
     }
     if (item instanceof ToolItem) {
       ((ToolItem) item).setWidth((Integer) value);
     }
   } else if (attribute.equals(Constants.ATTR_ENABLED)) {
     if (item instanceof ToolItem) {
       ((ToolItem) item).setEnabled(value == Boolean.TRUE);
     }
   }
   fireValueChange(Diffs.createValueDiff(oldValue, value));
 }
예제 #5
0
  /** Performs layouting. */
  private void layout() {

    // Disable redrawing
    toolbar.setRedraw(false);

    // Adjust size of items and composite
    Rectangle bounds = toolbar.getBounds();
    int remaining = toolbar.getBounds().width;
    for (final ToolItem item : toolitems) {
      remaining -= item.getBounds().width;
    }
    remaining -= OFFSET;
    infoComposite.setSize(remaining, bounds.height);
    infoItem.setWidth(remaining);
    int locationY = (infoComposite.getBounds().height - labelSelected.getBounds().height) / 2;

    // Layout label
    int locationX = remaining - labelApplied.getSize().x;
    labelApplied.setLocation(locationX, locationY);
    if (locationX < 0) labelApplied.setVisible(false);
    else labelApplied.setVisible(true);

    // Layout label
    locationX -= labelSelected.getSize().x + OFFSET;
    labelSelected.setLocation(locationX, locationY);
    if (locationX < 0) labelSelected.setVisible(false);
    else labelSelected.setVisible(true);

    // Layout label
    locationX -= labelTransformations.getSize().x + OFFSET;
    labelTransformations.setLocation(locationX, locationY);
    if (locationX < 0) labelTransformations.setVisible(false);
    else labelTransformations.setVisible(true);

    // Layout label
    locationX -= labelAttribute.getSize().x + OFFSET;
    labelAttribute.setLocation(locationX, locationY);
    if (locationX < 0) labelAttribute.setVisible(false);
    else labelAttribute.setVisible(true);

    // Redraw
    toolbar.setRedraw(true);
  }
  public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();

    shell =
        new Shell(
            parent,
            SWT.DIALOG_TRIM
                | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE)
                | SWT.RESIZE
                | SWT.MIN
                | SWT.MAX);
    props.setLook(shell);

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(shellText);
    shell.setImage(GUIResource.getInstance().getImageSpoon());

    int margin = Const.MARGIN;

    if (quickSearch) {
      ToolBar treeTb = new ToolBar(shell, SWT.HORIZONTAL | SWT.FLAT);
      props.setLook(treeTb);

      ToolItem wtfilter = new ToolItem(treeTb, SWT.SEPARATOR);
      Label wlfilter = new Label(treeTb, SWT.SEARCH);
      props.setLook(wlfilter);
      wlfilter.setText(BaseMessages.getString(PKG, "EnterSelectionDialog.FilterString.Label"));
      wtfilter.setControl(wlfilter);
      if (Const.isOSX()) {
        wtfilter.setWidth(100);
      } else {
        wtfilter.setWidth(70);
      }

      wfilter = new ToolItem(treeTb, SWT.SEPARATOR);
      searchText = new Text(treeTb, SWT.SEARCH | SWT.CANCEL);
      props.setLook(searchText);
      searchText.setToolTipText(
          BaseMessages.getString(PKG, "EnterSelectionDialog.FilterString.ToolTip"));
      wfilter.setControl(searchText);
      wfilter.setWidth(120);

      wbRegex = new ToolItem(treeTb, SWT.CHECK);
      wbRegex.setImage(GUIResource.getInstance().getImageRegexSmall());
      wbRegex.setToolTipText(BaseMessages.getString(PKG, "EnterSelectionDialog.useRegEx.Tooltip"));

      goSearch = new ToolItem(treeTb, SWT.PUSH);
      goSearch.setImage(GUIResource.getInstance().getImageSearchSmall());
      goSearch.setToolTipText(BaseMessages.getString(PKG, "EnterSelectionDialog.refresh.Label"));

      goSearch.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              updateFilter();
            }
          });

      if (this.databasesInterface != null) {
        addConnection = new ToolItem(treeTb, SWT.PUSH);
        addConnection.setImage(GUIResource.getInstance().getImageAdd());
        addConnection.setToolTipText(BaseMessages.getString(PKG, "Add.Datasource.Label"));

        addConnection.addSelectionListener(
            new SelectionAdapter() {
              public void widgetSelected(SelectionEvent event) {
                addDataSource();
              }
            });
      }

      FormData fd = new FormData();
      fd.right = new FormAttachment(100, -margin);
      fd.top = new FormAttachment(0, margin);
      treeTb.setLayoutData(fd);

      searchText.addSelectionListener(
          new SelectionAdapter() {
            public void widgetDefaultSelected(SelectionEvent e) {
              updateFilter();
            }
          });

      // From step line
      wlSelection = new Label(shell, SWT.NONE);
      wlSelection.setText(lineText);
      props.setLook(wlSelection);
      fdlSelection = new FormData();
      fdlSelection.left = new FormAttachment(0, 0);
      fdlSelection.top = new FormAttachment(treeTb, margin);
      wlSelection.setLayoutData(fdlSelection);
    } else {
      // From step line
      wlSelection = new Label(shell, SWT.NONE);
      wlSelection.setText(lineText);
      props.setLook(wlSelection);
      fdlSelection = new FormData();
      fdlSelection.left = new FormAttachment(0, 0);
      wlSelection.setLayoutData(fdlSelection);
    }

    int options = SWT.LEFT | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL;
    if (multi) {
      options |= SWT.MULTI;
    } else {
      options |= SWT.SINGLE;
    }

    wSelection = new List(shell, options);
    for (int i = 0; i < choices.length; i++) {
      wSelection.add(choices[i]);
    }
    if (selectedNrs != null) {
      wSelection.select(selectedNrs);
      wSelection.showSelection();
    }
    if (fixed) {
      props.setLook(wSelection, Props.WIDGET_STYLE_FIXED);
    } else {
      props.setLook(wSelection);
    }

    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    if (viewOnly) {
      wOK.setText(BaseMessages.getString(PKG, "System.Button.Close"));
    } else {
      wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    }
    lsOK =
        new Listener() {
          public void handleEvent(Event e) {
            ok();
          }
        };
    wOK.addListener(SWT.Selection, lsOK);

    Button[] buttons = new Button[] {wOK};

    if (!viewOnly) {
      wCancel = new Button(shell, SWT.PUSH);
      wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
      lsCancel =
          new Listener() {
            public void handleEvent(Event e) {
              cancel();
            }
          };
      wCancel.addListener(SWT.Selection, lsCancel);

      buttons = new Button[] {wOK, wCancel};
    }

    BaseStepDialog.positionBottomButtons(shell, buttons, margin, null);

    fdSelection = new FormData();
    fdSelection.left = new FormAttachment(0, 0);
    fdSelection.right = new FormAttachment(100, 0);
    fdSelection.top = new FormAttachment(wlSelection, margin);
    fdSelection.bottom = new FormAttachment(wOK, -margin * 3);
    wSelection.setLayoutData(fdSelection);

    // Add listeners

    lsDef =
        new SelectionAdapter() {
          public void widgetDefaultSelected(SelectionEvent e) {
            ok();
          }
        };
    wSelection.addSelectionListener(lsDef);
    wSelection.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.character == SWT.CR) {
              ok();
            }
          }
        });
    // Detect [X] or ALT-F4 or something that kills this window...
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            cancel();
          }
        });

    getData();

    BaseStepDialog.setSize(shell);

    wOK.setFocus();

    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    return selection;
  }