コード例 #1
0
  protected void setupPortEditors() {
    viewer.setCellEditors(new CellEditor[] {null, new TextCellEditor(ports)});

    ICellModifier cellModifier =
        new ICellModifier() {
          public Object getValue(Object element, String property) {
            ServerPort sp = (ServerPort) element;
            if (sp.getPort() < 0) return "-";
            return sp.getPort() + "";
          }

          public boolean canModify(Object element, String property) {
            if ("port".equals(property)) return true;

            return false;
          }

          public void modify(Object element, String property, Object value) {
            try {
              Item item = (Item) element;
              ServerPort sp = (ServerPort) item.getData();
              int port = Integer.parseInt((String) value);
              execute(new ModifyPortCommand(tomcatConfiguration, sp.getId(), port));
            } catch (Exception ex) {
              // ignore
            }
          }
        };
    viewer.setCellModifier(cellModifier);

    // preselect second column (Windows-only)
    String os = System.getProperty("os.name");
    if (os != null && os.toLowerCase().indexOf("win") >= 0) {
      ports.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              try {
                int n = ports.getSelectionIndex();
                viewer.editElement(ports.getItem(n).getData(), 1);
              } catch (Exception e) {
                // ignore
              }
            }
          });
    }
  }
コード例 #2
0
  /** Initialize the fields in this editor. */
  protected void initialize() {
    if (ports == null) return;

    ports.removeAll();

    Iterator iterator = tomcatConfiguration.getServerPorts().iterator();
    while (iterator.hasNext()) {
      ServerPort port = (ServerPort) iterator.next();
      TableItem item = new TableItem(ports, SWT.NONE);
      String portStr = "-";
      if (port.getPort() >= 0) portStr = port.getPort() + "";
      String[] s = new String[] {port.getName(), portStr};
      item.setText(s);
      item.setImage(TomcatUIPlugin.getImage(TomcatUIPlugin.IMG_PORT));
      item.setData(port);
    }

    if (readOnly) {
      viewer.setCellEditors(new CellEditor[] {null, null});
      viewer.setCellModifier(null);
    } else {
      setupPortEditors();
    }
  }