Package org.eclipse.swt.custom

Examples of org.eclipse.swt.custom.TableEditor


   * @param shell
   */
  public void createContents(final Shell shell)
  {
    // Create an editor object to use for text editing
    final TableEditor editor = new TableEditor(table);
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    editor.grabVertical = true;

    // Use a selection listener to get seleceted row
    table.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent event)
      {
        // Dispose any existing editor
        Control old = editor.getEditor();

        if (old != null)
        {
          old.dispose();
        }

        // Determine which row was selected
        final TableItem item = (TableItem) event.item;

        if (item != null)
        {
          // COMBO
          if (item.getText().equals("Style")
            || item.getText().equals("Arrow")
            || item.getText().equals("Shape"))
          {
            // Create the dropdown and add data to it
            final CCombo combo = new CCombo(table, SWT.READ_ONLY);

            if (item.getText().equals("Style"))
            {
              String[] styleOfEdge = {"Solid", "Dashed"};
              combo.setItems(styleOfEdge);
            }
            else if (item.getText().equals("Arrow"))
            {
              String[] arrowOfEdge = {"None",
                "Source",
                "Target",
                "Both"};
              combo.setItems(arrowOfEdge);
            }
            else if (item.getText().equals("Shape"))
            {
               combo.setItems(NodeModel.shapes);
            }

            // Select the previously selected item from the cell
            combo.select(combo.indexOf(item.getText(1)));
//            combo.setFont(tableFont);
            editor.setEditor(combo, item, 1);

            // Add a listener to set the selected item back into the
            // cell
            combo.addSelectionListener(new SelectionAdapter()
            {
              public void widgetSelected(SelectionEvent event)
              {
                item.setText(1, combo.getText());
                                // They selected an item; end the editing
                // session
                combo.dispose();
              }
            });
          }

          // TEXT
          else if (item.getText().equals("Text"))
          {
            // Create the Text object for our editor
            final Text text = new Text(table, SWT.LEFT);
            // text.setForeground(item.getForeground());

            // Transfer any text from the cell to the Text control,
            // set the color to match this row, select the text,
            // and set focus to the control
            text.setText(item.getText(1));
//            text.setFont(tableFont);

            // text.setForeground(item.getForeground());
            text.selectAll();
            text.setFocus();
            editor.setEditor(text, item, 1);

            // Add a handler to transfer the text back to the cell
            // any time it's modified
            text.addModifyListener(new ModifyListener()
            {
              public void modifyText(ModifyEvent event)
              {
                // Set the text of the editor's control back
                // into the cell
                item.setText(1, text.getText());
              }
            });
          }

          // NUMBER
          else if (item.getText().equals("Margin")
            || item.getText().equals("Cluster ID")
            || item.getText().equals("Width"))
          {
            // Create the Text object for our editor
            final Text text = new Text(table, SWT.LEFT);
            // text.setForeground(item.getForeground());

            // Transfer any text from the cell to the Text control,
            // set the color to match this row, select the text,
            // and set focus to the control
            text.setText(item.getText(1));
//            text.setFont(tableFont);

            // text.setForeground(item.getForeground());
            text.selectAll();
            text.setFocus();
            editor.setEditor(text, item, 1);

            // Add a handler to transfer the text back to the cell
            // any time it's modified
            text.addModifyListener(new ModifyListener()
            {
View Full Code Here


        .getResourceString("page2.package.caption"));
       
        namespace2packageTable.setVisible(true);
       
        // add the table editor
        final TableEditor editor = new TableEditor(namespace2packageTable);
        editor.setColumn(1);
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        //This is the cute way of making the namespaces columns editable
        namespace2packageTable.addListener(SWT.MouseDown, new Listener() {
            public void handleEvent(Event event) {
              Rectangle clientArea = namespace2packageTable.getClientArea();
              Point pt = new Point(event.x, event.y);
              int index = namespace2packageTable.getTopIndex();
              while (index < namespace2packageTable.getItemCount()) {
                boolean visible = false;
                final TableItem item = namespace2packageTable.getItem(index);
                for (int i = 0; i < namespace2packageTable.getColumnCount(); i++) {
                  Rectangle rect = item.getBounds(i);
                  if (rect.contains(pt)) {
                    final int column = i;
                    final Text text = new Text(namespace2packageTable, SWT.NONE);
                    Listener textListener = new Listener() {
                      public void handleEvent(final Event e) {
                        switch (e.type) {
                        case SWT.FocusOut:
                          item.setText(column, text.getText());
                          text.dispose();
                          break;
                        case SWT.Traverse:
                          switch (e.detail) {
                          case SWT.TRAVERSE_RETURN:
                            item
                                .setText(column, text
                                    .getText());
                          // FALL THROUGH
                          case SWT.TRAVERSE_ESCAPE:
                            text.dispose();
                            e.doit = false;
                          }
                          break;
                        }
                      }
                    };
                    text.addListener(SWT.FocusOut, textListener);
                    text.addListener(SWT.Traverse, textListener);
                    editor.setEditor(text, item, i);
                    text.setText(item.getText(i));
                    text.selectAll();
                    text.setFocus();
                    return;
                  }
View Full Code Here

        // create dn link control
        dnLink = new Hyperlink( viewer.getTable(), SWT.NONE );
        dnLink.setLayoutData( new GridData( SWT.BOTTOM, SWT.LEFT, true, true ) );
        dnLink.setText( "" );
        dnLink.setMenu( viewer.getTable().getMenu() );
        tableEditor = new TableEditor( viewer.getTable() );
        tableEditor.horizontalAlignment = SWT.LEFT;
        tableEditor.verticalAlignment = SWT.BOTTOM;
        tableEditor.grabHorizontal = true;
        tableEditor.grabVertical = true;
View Full Code Here

        .getResourceString("page2.package.caption"));
       
        namespace2packageTable.setVisible(true);
       
        // add the table editor
        final TableEditor editor = new TableEditor(namespace2packageTable);
        editor.setColumn(1);
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        //This is the cute way of making the namespaces columns editable
        namespace2packageTable.addListener(SWT.MouseDown, new Listener() {
            public void handleEvent(Event event) {
              Rectangle clientArea = namespace2packageTable.getClientArea();
              Point pt = new Point(event.x, event.y);
              int index = namespace2packageTable.getTopIndex();
              while (index < namespace2packageTable.getItemCount()) {
                boolean visible = false;
                final TableItem item = namespace2packageTable.getItem(index);
                for (int i = 0; i < namespace2packageTable.getColumnCount(); i++) {
                  Rectangle rect = item.getBounds(i);
                  if (rect.contains(pt)) {
                    final int column = i;
                    final Text text = new Text(namespace2packageTable, SWT.NONE);
                    Listener textListener = new Listener() {
                      public void handleEvent(final Event e) {
                        switch (e.type) {
                        case SWT.FocusOut:
                          item.setText(column, text.getText());
                          text.dispose();
                          break;
                        case SWT.Traverse:
                          switch (e.detail) {
                          case SWT.TRAVERSE_RETURN:
                            item
                                .setText(column, text
                                    .getText());
                          // FALL THROUGH
                          case SWT.TRAVERSE_ESCAPE:
                            text.dispose();
                            e.doit = false;
                          }
                          break;
                        }
                      }
                    };
                    text.addListener(SWT.FocusOut, textListener);
                    text.addListener(SWT.Traverse, textListener);
                    editor.setEditor(text, item, i);
                    text.setText(item.getText(i));
                    text.selectAll();
                    text.setFocus();
                    return;
                  }
View Full Code Here

    }

    private void configTable() {
        table.setHeaderVisible(true);
        table.setLinesVisible(true);
        final TableEditor tableEditor = new TableEditor(table);
        tableEditor.grabHorizontal = true;
    }
View Full Code Here

        data.right = new FormAttachment(100, 0);
        workTimeTable.setLayoutData(data);

        workTimeTable.setHeaderVisible(true);
        workTimeTable.setLinesVisible(true);
        new TableEditor(workTimeTable).grabHorizontal = true;

        createItems();
        addWorkTimeTableListener();
    }
View Full Code Here

        .getResourceString("page2.package.caption"));
       
        namespace2packageTable.setVisible(true);
       
        // add the table editor
        final TableEditor editor = new TableEditor(namespace2packageTable);
        editor.setColumn(1);
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        //This is the cute way of making the namespaces columns editable
        namespace2packageTable.addListener(SWT.MouseDown, new Listener() {
            public void handleEvent(Event event) {
              Rectangle clientArea = namespace2packageTable.getClientArea();
              Point pt = new Point(event.x, event.y);
              int index = namespace2packageTable.getTopIndex();
              while (index < namespace2packageTable.getItemCount()) {
                boolean visible = false;
                final TableItem item = namespace2packageTable.getItem(index);
                for (int i = 0; i < namespace2packageTable.getColumnCount(); i++) {
                  Rectangle rect = item.getBounds(i);
                  if (rect.contains(pt)) {
                    final int column = i;
                    final Text text = new Text(namespace2packageTable, SWT.NONE);
                    Listener textListener = new Listener() {
                      public void handleEvent(final Event e) {
                        switch (e.type) {
                        case SWT.FocusOut:
                          item.setText(column, text.getText());
                          text.dispose();
                          break;
                        case SWT.Traverse:
                          switch (e.detail) {
                          case SWT.TRAVERSE_RETURN:
                            item
                                .setText(column, text
                                    .getText());
                          // FALL THROUGH
                          case SWT.TRAVERSE_ESCAPE:
                            text.dispose();
                            e.doit = false;
                          }
                          break;
                        }
                      }
                    };
                    text.addListener(SWT.FocusOut, textListener);
                    text.addListener(SWT.Traverse, textListener);
                    editor.setEditor(text, item, i);
                    text.setText(item.getText(i));
                    text.selectAll();
                    text.setFocus();
                    return;
                  }
View Full Code Here

        // create dn link control
        dnLink = new Hyperlink( viewer.getTable(), SWT.NONE );
        dnLink.setLayoutData( new GridData( SWT.BOTTOM, SWT.LEFT, true, true ) );
        dnLink.setText( "" ); //$NON-NLS-1$
        dnLink.setMenu( viewer.getTable().getMenu() );
        tableEditor = new TableEditor( viewer.getTable() );
        tableEditor.horizontalAlignment = SWT.LEFT;
        tableEditor.verticalAlignment = SWT.BOTTOM;
        tableEditor.grabHorizontal = true;
        tableEditor.grabVertical = true;
View Full Code Here

        gridData.widthHint = 200;
        gridData.minimumWidth = 200;
        aliasesTable.setLayoutData( gridData );

        // Aliases Table Editor
        tableEditor = new TableEditor( aliasesTable );
        tableEditor.horizontalAlignment = SWT.LEFT;
        tableEditor.grabHorizontal = true;
        tableEditor.minimumWidth = 200;

        // Add Button
View Full Code Here

      }
    });
  }

  private void createEditorsForTableColumn(final Table table) {
    final TableEditor editor1 = new TableEditor(table);
    editor1.horizontalAlignment = SWT.CENTER;
    editor1.grabHorizontal = true;
    editor1.minimumWidth = 60;

    final TableEditor editor2 = new TableEditor(table);
    editor2.horizontalAlignment = SWT.CENTER;
    editor2.grabHorizontal = true;
    editor2.minimumWidth = 60;
    table.addSelectionListener(new SelectionAdapter() {

      public void widgetSelected(SelectionEvent e) {
        // Clean up any previous editor control
        Control oldEditor = editor1.getEditor();
        if (oldEditor != null) {
          oldEditor.dispose();
        }

        oldEditor = editor2.getEditor();
        if (oldEditor != null) {
          oldEditor.dispose();
        }
       
        // Identify the selected row
        final TableItem item = (TableItem) e.item;
        if (!isEditable(item)) {
          table.setSelection(new TableItem[0]);
          return;
        }
      }

      public void widgetDefaultSelected(SelectionEvent e) {
        // Clean up any previous editor control
        Control oldEditor = editor1.getEditor();
        if (oldEditor != null) {
          oldEditor.dispose();
        }

        oldEditor = editor2.getEditor();
        if (oldEditor != null) {
          oldEditor.dispose();
        }

        // Identify the selected row
        final TableItem item = (TableItem) e.item;
        if (!isEditable(item)) {
          table.setSelection(new TableItem[0]);
          return;
        }

        final NameValuePair nvp = (NameValuePair) item.getData();
        if (nvp == null) {
          Trace.err("No item's object");
          return;
        }
        final Object obj = nvp.getParent();

        if (nvp.getType() == Integer.class) {
          // For Integer Editing
          final Spinner spinner = new Spinner(table, SWT.BORDER);
          spinner.setMinimum(0);
          spinner.setMaximum(Integer.MAX_VALUE);
          String value = item.getText(1);
          if (value.equals(AEDeploymentConstants.ERROR_KIND_STRING_NO_TIMEOUT)
                  || value.equals(AEDeploymentConstants.ERROR_KIND_STRING_NO_RETRIES)
                  || value.equals(AEDeploymentConstants.ERROR_KIND_STRING_NO_THRESHOLD_COUNT)
                  || value.equals(AEDeploymentConstants.ERROR_KIND_STRING_NO_THRESHOLD_WINDOW)) {
            value = "0";
          }
          int level = Integer.parseInt(value);
          spinner.setSelection(level);
          spinner.setFocus();
          spinner.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {
            }

            public void focusLost(FocusEvent e) {
              // Clean up any previous editor control
              Control oldEditor = editor1.getEditor();
              if (oldEditor != null)
                oldEditor.dispose();

              oldEditor = editor2.getEditor();
              if (oldEditor != null)
                oldEditor.dispose();
              spinner.dispose();
            }

          });
          spinner.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
              int selection = spinner.getSelection();
              item.setText(1, Integer.toString(selection));
              int id = nvp.getId();
              if (obj instanceof GetMetadataErrors) {
                GetMetadataErrors getMetadataErrors = (GetMetadataErrors) obj;
                getMetadataErrors.setValueById(id, selection);
                getMetaDataViewer.refresh();

              } else if (obj instanceof ProcessCasErrors) {
                ProcessCasErrors processCasErrors = (ProcessCasErrors) obj;
                processCasErrors.setValueById(id, selection);
                processCasErrorsViewer.refresh();

              } else if (obj instanceof CollectionProcessCompleteErrors) {
                CollectionProcessCompleteErrors completeErrors = (CollectionProcessCompleteErrors) obj;
                completeErrors.setValueById(id, selection);
                collProcessCompleteErrorsViewer.refresh();
              }
              multiPageEditor.setFileDirty();
            }
          });
          editor1.setEditor(spinner, item, 1);

        } else if (nvp.getType() == String.class) {
          final CCombo combo = new CCombo(table, SWT.BORDER | SWT.READ_ONLY);
          combo.setItems(new String[] { "terminate", "disable" }); //$NON-NLS-1$
          combo.setText(item.getText(1));
          combo.pack();
          combo.setFocus();
          combo.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {
            }

            public void focusLost(FocusEvent e) {
              // Clean up any previous editor control
              Control oldEditor = editor1.getEditor();
              if (oldEditor != null)
                oldEditor.dispose();

              oldEditor = editor2.getEditor();
              if (oldEditor != null)
                oldEditor.dispose();
              combo.dispose();
            }

          });
          combo.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              String selection = combo.getText();
              item.setText(1, selection);
              int id = nvp.getId();
              if (obj instanceof GetMetadataErrors) {
                GetMetadataErrors getMetadataErrors = (GetMetadataErrors) obj;
                getMetadataErrors.setValueById(id, selection);
                getMetaDataViewer.refresh();

              } else if (obj instanceof ProcessCasErrors) {
                ProcessCasErrors processCasErrors = (ProcessCasErrors) obj;
                processCasErrors.setValueById(id, selection);
                processCasErrorsViewer.refresh();

              } else if (obj instanceof CollectionProcessCompleteErrors) {
                CollectionProcessCompleteErrors completeErrors = (CollectionProcessCompleteErrors) obj;
                completeErrors.setValueById(id, selection);
                collProcessCompleteErrorsViewer.refresh();
              }
              multiPageEditor.setFileDirty();
            }
          });
          editor2.setEditor(combo, item, 1);

        } else if (nvp.getType() == Boolean.class) {
          // Only for ProcessCasErrors
          if (obj instanceof ProcessCasErrors) {
            final CCombo combo = new CCombo(table, SWT.BORDER | SWT.READ_ONLY);
            combo.setItems(new String[] { Boolean.toString(true), Boolean.toString(false) }); //$NON-NLS-1$
            combo.setText(item.getText(1));
            combo.pack();
            combo.setFocus();
            combo.addFocusListener(new FocusListener() {

              public void focusGained(FocusEvent e) {
              }

              public void focusLost(FocusEvent e) {
                // Clean up any previous editor control
                Control oldEditor = editor1.getEditor();
                if (oldEditor != null)
                  oldEditor.dispose();

                oldEditor = editor2.getEditor();
                if (oldEditor != null)
                  oldEditor.dispose();
                combo.dispose();
              }

            });
            combo.addSelectionListener(new SelectionAdapter() {
              public void widgetSelected(SelectionEvent e) {
                String selection = combo.getText();
                int id = nvp.getId();
                item.setText(1,selection);
                ProcessCasErrors processCasErrors = (ProcessCasErrors) obj;
                processCasErrors.setValueById(id, selection);
                processCasErrorsViewer.refresh();
                multiPageEditor.setFileDirty();
              }
            });
            editor2.setEditor(combo, item, 1);
          }
        } else {
          Trace.err("nvp.getType(): " + nvp.getType().getClass().getName());
        }
      }
View Full Code Here

TOP

Related Classes of org.eclipse.swt.custom.TableEditor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.