Search in sources :

Example 21 with TextCellEditor

use of org.eclipse.jface.viewers.TextCellEditor in project cubrid-manager by CUBRID.

the class TableEditorPart method createGeneralTabItem.

/**
	 * Create general tab item
	 *
	 * @param tabFolder the object of TabFolder
	 */
private void createGeneralTabItem(final TabFolder tabFolder) {
    final TabItem generalTabItem = new TabItem(tabFolder, SWT.NONE);
    generalTabItem.setText(Messages.infoGeneralTab);
    final Composite compositeGenaral = new Composite(tabFolder, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    compositeGenaral.setLayout(gridLayout);
    generalTabItem.setControl(compositeGenaral);
    final Group group = new Group(compositeGenaral, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    group.setLayout(gridLayout);
    group.setText(Messages.lblTableInfo);
    final Label tableNameLabel = new Label(group, SWT.NONE);
    tableNameLabel.setData(Messages.dataNewKey, null);
    tableNameLabel.setText(Messages.lblTableName);
    tableNameComp = new Composite(group, SWT.NONE);
    {
        GridLayout gl = new GridLayout();
        gl.numColumns = 5;
        gl.marginWidth = 0;
        tableNameComp.setLayout(gl);
        tableNameComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        tableNameText = new Text(tableNameComp, SWT.BORDER);
        tableNameText.setTextLimit(ValidateUtil.MAX_SCHEMA_NAME_LENGTH);
        {
            GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
            gd.widthHint = 200;
            tableNameText.setLayoutData(gd);
        }
        tableNameText.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent event) {
                if (tableNameText.getText().length() == 0) {
                    CommonUITool.hideErrorBaloon(errorBaloon);
                } else if (verifyTableName()) {
                    String tableName = tableNameText.getText();
                    newSchemaInfo.setClassname(tableName);
                }
            }
        });
        tableNameText.addFocusListener(new FocusAdapter() {

            public void focusLost(FocusEvent e) {
                CommonUITool.hideErrorBaloon(errorBaloon);
            }
        });
        final Label ownerLabel = new Label(tableNameComp, SWT.NONE);
        ownerLabel.setText(Messages.lblOwner);
        ownerCombo = new Combo(tableNameComp, SWT.READ_ONLY);
        {
            GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
            gd.widthHint = 100;
            ownerCombo.setLayoutData(gd);
        }
        ownerCombo.setVisibleItemCount(10);
        fillOwnerCombo();
        if (supportCharset) {
            final Label collationLabel = new Label(tableNameComp, SWT.NONE);
            collationLabel.setText(Messages.lblCollation);
            collationCombo = new Combo(tableNameComp, SWT.READ_ONLY);
            {
                GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
                gd.widthHint = 100;
                collationCombo.setLayoutData(gd);
            }
            collationCombo.setVisibleItemCount(10);
            fillCollationCombo();
            String collation = collationCombo.getText();
            newSchemaInfo.setCollation(collation);
            collationCombo.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent e) {
                    String collation = collationCombo.getText();
                    newSchemaInfo.setCollation(collation);
                }

                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            if (!isNewTableFlag && newSchemaInfo.getCollation() != null) {
                collationCombo.setText(newSchemaInfo.getCollation());
            }
        } else {
            new Label(tableNameComp, SWT.NONE);
            new Label(tableNameComp, SWT.NONE);
        }
    }
    final Label tableDescLabel = new Label(group, SWT.NONE);
    tableDescLabel.setText(Messages.lblTableDesc);
    tableDescText = new Text(group, SWT.BORDER);
    tableDescText.setTextLimit(512);
    tableDescText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    if (newSchemaInfo != null && newSchemaInfo.getDescription() != null) {
        tableDescText.setText(newSchemaInfo.getDescription());
    }
    tableDescText.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            if (!isSupportTableComment) {
                CommonUITool.showErrorBaloon(group, tableDescText, errorBaloon, "", Messages.errNotSupportTableCommentNotice);
                tableDescText.setFocus();
            }
        }

        public void focusLost(FocusEvent e) {
            CommonUITool.hideErrorBaloon(errorBaloon);
        }
    });
    tableDescText.setEditable(isSupportTableComment);
    if (database == null) {
        return;
    }
    if (CompatibleUtil.isSupportReuseOID(database.getDatabaseInfo())) {
        reuseOIDBtn = new Button(group, SWT.CHECK);
        reuseOIDBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
        reuseOIDBtn.setText(Messages.btnReuseOid);
        if (!isNewTableFlag) {
            reuseOIDBtn.setEnabled(false);
        }
    }
    final Label columnsLabel = new Label(compositeGenaral, SWT.NONE);
    columnsLabel.setText(Messages.lblColumn);
    // create attribute table
    columnTableView = new TableViewer(compositeGenaral, SWT.FULL_SELECTION | SWT.BORDER);
    columnTableView.setUseHashlookup(true);
    columnTableView.setColumnProperties(columnProperites);
    columnsTable = columnTableView.getTable();
    //columnsTable.pack();
    final GridData gdColumnsTable = new GridData(SWT.FILL, SWT.FILL, true, true);
    gdColumnsTable.heightHint = 189;
    columnsTable.setLayoutData(gdColumnsTable);
    columnsTable.setLinesVisible(true);
    columnsTable.setHeaderVisible(true);
    // The empty column
    final TableColumn emptyColumn = new TableColumn(columnsTable, SWT.NONE);
    emptyColumn.setWidth(0);
    // The flag column
    final TableColumn flagColumn = new TableColumn(columnsTable, SWT.RIGHT_TO_LEFT);
    flagColumn.setWidth(28);
    // NAME
    final TableColumn nameColumn = new TableColumn(columnsTable, SWT.NONE);
    nameColumn.setWidth(140);
    nameColumn.setText(Messages.tblColumnName);
    // DATATYPE
    final TableColumn dataTypeColumn = new TableColumn(columnsTable, SWT.NONE);
    dataTypeColumn.setWidth(120);
    dataTypeColumn.setText(Messages.tblColumnDataType);
    // DEFAULT
    final TableColumn defaultColumn = new TableColumn(columnsTable, SWT.NONE);
    defaultColumn.setWidth(98);
    defaultColumn.setText(Messages.tblColumnDefault);
    defaultColumn.setToolTipText(Messages.tblColumnDefaultHint);
    // AUTO INCREMENT
    final TableColumn autoIncrTableColumn = new TableColumn(columnsTable, SWT.NONE);
    autoIncrTableColumn.setAlignment(SWT.LEFT);
    autoIncrTableColumn.setWidth(100);
    autoIncrTableColumn.setText(Messages.tblColumnAutoIncr);
    autoIncrTableColumn.setToolTipText(Messages.tblColumnAutoIncrHint);
    // NOT NULL
    final TableColumn notNullColumn = new TableColumn(columnsTable, SWT.NONE);
    notNullColumn.setWidth(65);
    notNullColumn.setText(Messages.tblColumnNotNull);
    notNullColumn.setAlignment(SWT.LEFT);
    notNullColumn.setToolTipText(Messages.tblColumnNotNullHint);
    // PK
    final TableColumn pkColumn = new TableColumn(columnsTable, SWT.NONE);
    pkColumn.setAlignment(SWT.CENTER);
    pkColumn.setWidth(90);
    pkColumn.setText(Messages.tblColumnPK);
    // UK
    final TableColumn uniqueColumn = new TableColumn(columnsTable, SWT.NONE);
    uniqueColumn.setWidth(55);
    uniqueColumn.setText(Messages.tblColumnUnique);
    uniqueColumn.setAlignment(SWT.LEFT);
    uniqueColumn.setToolTipText(Messages.tblColumnUniqueHint);
    // SHARED
    sharedColumn = new TableColumn(columnsTable, SWT.NONE);
    sharedColumn.setWidth(65);
    sharedColumn.setText(Messages.tblColumnShared);
    sharedColumn.setAlignment(SWT.LEFT);
    sharedColumn.setToolTipText(Messages.tblColumnSharedHint);
    if (supportCharset) {
        final TableColumn collationColumn = new TableColumn(columnsTable, SWT.NONE);
        collationColumn.setWidth(120);
        collationColumn.setText(Messages.tblColumnColumnCollation);
        collationColumn.setAlignment(SWT.LEFT);
    }
    final TableColumn descColumn = new TableColumn(columnsTable, SWT.NONE);
    descColumn.setWidth(180);
    descColumn.setText(Messages.tblColumnColumnDesc);
    descColumn.setAlignment(SWT.LEFT);
    boolean canEdit = true;
    if (!editor.isNewTableFlag() && !editor.isSupportChange()) {
        canEdit = false;
    }
    attrContentProvider = new AttributeContentProvider();
    attrLabelProvider = new AttributeLabelProvider(database.getDatabaseInfo(), newSchemaInfo, canEdit, editorAdaptor);
    columnTableView.setContentProvider(attrContentProvider);
    columnTableView.setLabelProvider(attrLabelProvider);
    CellEditor[] cellEditor = new CellEditor[columnProperites.length];
    {
        int index = 0;
        // Empty
        cellEditor[index++] = null;
        // Flag
        cellEditor[index++] = null;
        // NAME
        cellEditor[index++] = new TextCellEditor(columnsTable);
        // DATATYPE
        cellEditor[index++] = new DataTypeCellEditor((Composite) columnsTable, listDataTypes(), editorAdaptor);
        // DEFAULT
        cellEditor[index++] = new TextCellEditor(columnsTable);
        // AUTO INCREMENT
        cellEditor[index++] = new AutoIncrementCellEditor(columnsTable, editorAdaptor);
        // NOT NULL
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // PK
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // UK
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // SHARD
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // COLLATION
        if (supportCharset) {
            cellEditor[index++] = new ComboBoxCellEditor(columnsTable, getCollationArray(), SWT.READ_ONLY);
        }
        // MEMO
        cellEditor[index++] = new TextCellEditor(columnsTable);
    }
    columnTableView.setCellEditors(cellEditor);
    columnTableView.setCellModifier(new AttributeCellModifier(editorAdaptor));
    loadColumnData();
    CommonUITool.hackForYosemite(columnsTable);
    // Create button
    final Composite btnRowComposite = new Composite(compositeGenaral, SWT.NONE);
    btnRowComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    {
        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginWidth = 5;
        btnRowComposite.setLayout(layout);
    }
    final Composite optComposite = new Composite(btnRowComposite, SWT.NONE);
    optComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    {
        GridLayout layout = new GridLayout();
        layout.numColumns = 1;
        layout.marginWidth = 0;
        optComposite.setLayout(layout);
    }
    final Composite btnComposite = new Composite(btnRowComposite, SWT.NONE);
    btnComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    {
        GridLayout layout = new GridLayout();
        layout.marginRight = 0;
        layout.numColumns = 6;
        layout.marginWidth = 0;
        btnComposite.setLayout(layout);
    }
    final Button setPkButton = new Button(btnComposite, SWT.NONE);
    setPkButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    setPkButton.setText(Messages.btnPK);
    setPkButton.addSelectionListener(new PkBtnListenerOnGeneTab(isNewTableFlag));
    final GridData gdUpDown = new GridData(60, SWT.DEFAULT);
    upColumnBtn = new Button(btnComposite, SWT.NONE);
    upColumnBtn.setLayoutData(gdUpDown);
    upColumnBtn.setEnabled(false);
    upColumnBtn.setText(Messages.btnUp);
    upColumnBtn.addSelectionListener(new UpBtnListenerOnGeneTab());
    downColumnBtn = new Button(btnComposite, SWT.DOWN);
    downColumnBtn.setLayoutData(gdUpDown);
    downColumnBtn.setEnabled(false);
    downColumnBtn.setText(Messages.btnDown);
    downColumnBtn.addSelectionListener(new DownBtnListenerOnGeneTab());
    final Button addButton = new Button(btnComposite, SWT.NONE);
    final GridData gdAddButton = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gdAddButton.horizontalIndent = 10;
    addButton.setLayoutData(gdAddButton);
    addButton.setText(Messages.btnAddColumn);
    addButton.addSelectionListener(new AddBtnListenerOnGeneTab());
    deleteColumnBtn = new Button(btnComposite, SWT.NONE);
    final GridData gdDeleteButton = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gdDeleteButton.horizontalIndent = 10;
    deleteColumnBtn.setLayoutData(gdDeleteButton);
    deleteColumnBtn.setEnabled(false);
    deleteColumnBtn.setText(Messages.btnDelColumn);
    deleteColumnBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            deleteColumn();
        }
    });
    columnsTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            handleSelectionChangeInColumnTable();
        }
    });
    buildColumnTableMenu();
}
Also used : Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ModifyListener(org.eclipse.swt.events.ModifyListener) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) TabItem(org.eclipse.swt.widgets.TabItem) GridData(org.eclipse.swt.layout.GridData) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 22 with TextCellEditor

use of org.eclipse.jface.viewers.TextCellEditor in project cubrid-manager by CUBRID.

the class ShardConnectionPanel method linkEditorForTable.

/**
	 * Links the editable column of table
	 */
private void linkEditorForTable() {
    connectionTableViewer.setColumnProperties(columnNameArrs);
    CellEditor[] editors = new CellEditor[3];
    editors[0] = new TextCellEditor(connectionTable);
    editors[1] = new TextCellEditor(connectionTable);
    editors[2] = new TextCellEditor(connectionTable);
    connectionTableViewer.setCellEditors(editors);
    connectionTableViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        @SuppressWarnings("unchecked")
        public Object getValue(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            if (property.equals(columnNameArrs[0])) {
                return map.get("0");
            } else if (property.equals(columnNameArrs[1])) {
                return map.get("1");
            } else if (property.equals(columnNameArrs[2])) {
                return map.get("2");
            }
            return null;
        }

        public void modify(Object element, String property, Object value) {
            Object obj = null;
            if (element instanceof Item) {
                obj = ((Item) element).getData();
            }
            if (obj == null) {
                return;
            }
            @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) obj;
            boolean isValid = true;
            if (property.equals(columnNameArrs[0])) {
                isValid = ValidateUtil.isInteger(value.toString());
                if (isValid) {
                    for (Map<String, String> paras : parameterList) {
                        if (paras == obj) {
                            continue;
                        }
                        if (paras.get("0").equals(value)) {
                            isValid = false;
                            CommonUITool.openErrorBox(Messages.bind(Messages.errShardIdExist, new Object[] { value.toString() }));
                            break;
                        }
                    }
                } else {
                    CommonUITool.openErrorBox(Messages.errShardIdNotNumeric);
                }
                if (isValid) {
                    map.put("0", value.toString());
                }
            } else if (property.equals(columnNameArrs[1])) {
                map.put("1", value.toString());
            } else if (property.equals(columnNameArrs[2])) {
                map.put("2", value.toString());
            }
            connectionTableViewer.refresh();
            // Notice the upper layer
            modifyListener.modifyText(null);
        }
    });
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ToolItem(org.eclipse.swt.widgets.ToolItem) Item(org.eclipse.swt.widgets.Item) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with TextCellEditor

use of org.eclipse.jface.viewers.TextCellEditor in project sling by apache.

the class ArchetypeParametersWizardPage method createControl.

/**
	 * @see IDialogPage#createControl(Composite)
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    layout.verticalSpacing = 9;
    Label label = new Label(container, SWT.NULL);
    label.setText("&Group Id:");
    groupId = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    groupId.setLayoutData(gd);
    groupId.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
            if (!javaPackageModified) {
                if (artifactId.getText().length() == 0) {
                    javaPackage.setText(getDefaultJavaPackage(groupId.getText(), ""));
                } else {
                    javaPackage.setText(getDefaultJavaPackage(groupId.getText(), artifactId.getText()));
                }
            }
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText("&Artifact Id:");
    artifactId = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    artifactId.setLayoutData(gd);
    artifactId.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
            if (javaPackageModified) {
                return;
            }
            if (groupId.getText().length() == 0) {
                javaPackage.setText(getDefaultJavaPackage("", artifactId.getText()));
            } else {
                javaPackage.setText(getDefaultJavaPackage(groupId.getText(), artifactId.getText()));
            }
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText("&Version:");
    version = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    version.setLayoutData(gd);
    version.setText("0.0.1-SNAPSHOT");
    version.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText("&Package:");
    javaPackage = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    javaPackage.setLayoutData(gd);
    javaPackageModified = false;
    javaPackage.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            javaPackageModified = true;
        }
    });
    javaPackage.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    label = new Label(container, SWT.NULL);
    gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
    label.setLayoutData(gd);
    label.setText("&Parameters:");
    propertiesViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION);
    propertiesTable = propertiesViewer.getTable();
    propertiesTable.setLinesVisible(true);
    propertiesTable.setHeaderVisible(true);
    propertiesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2));
    CellNavigationStrategy strategy = new CellNavigationStrategy();
    TableViewerFocusCellManager focusCellMgr = new TableViewerFocusCellManager(propertiesViewer, new FocusCellOwnerDrawHighlighter(propertiesViewer), strategy);
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(propertiesViewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK;
    TableViewerEditor.create(propertiesViewer, focusCellMgr, actSupport, features);
    TableColumn propertiesTableNameColumn = new TableColumn(propertiesTable, SWT.NONE);
    propertiesTableNameColumn.setWidth(130);
    propertiesTableNameColumn.setText("Name");
    TableColumn propertiesTableValueColumn = new TableColumn(propertiesTable, SWT.NONE);
    propertiesTableValueColumn.setWidth(230);
    propertiesTableValueColumn.setText("Value");
    propertiesViewer.setColumnProperties(new String[] { KEY_PROPERTY, VALUE_PROPERTY });
    propertiesViewer.setCellEditors(new CellEditor[] { new TextCellEditor(propertiesTable, SWT.NONE), new TextCellEditor(propertiesTable, SWT.NONE) });
    propertiesViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        public void modify(Object element, String property, Object value) {
            if (element instanceof TableItem) {
                ((TableItem) element).setText(getTextIndex(property), String.valueOf(value));
                dialogChanged();
            }
        }

        public Object getValue(Object element, String property) {
            if (element instanceof TableItem) {
                return ((TableItem) element).getText(getTextIndex(property));
            }
            return null;
        }
    });
    initialize();
    setPageComplete(false);
    setControl(container);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) CellNavigationStrategy(org.eclipse.jface.viewers.CellNavigationStrategy) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 24 with TextCellEditor

use of org.eclipse.jface.viewers.TextCellEditor in project bndtools by bndtools.

the class MapEntryCellModifier method addCellEditorsToViewer.

public void addCellEditorsToViewer() {
    CellEditor[] cellEditors = new CellEditor[PROPS.length];
    for (int i = 0; i < PROPS.length; i++) {
        cellEditors[i] = new TextCellEditor(viewer.getTable());
    }
    viewer.setCellEditors(cellEditors);
}
Also used : TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 25 with TextCellEditor

use of org.eclipse.jface.viewers.TextCellEditor in project sling by apache.

the class MVPEditor method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    // now add the node type dropbox-combo
    Composite header = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.numColumns = 3;
    header.setLayout(layout);
    Label label = new Label(header, SWT.WRAP);
    label.setText("Modify property " + property.getName() + ":");
    GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    label.setLayoutData(data);
    label.setFont(parent.getFont());
    ToolBar buttonBar = new ToolBar(header, SWT.NONE);
    ToolItem invisible = new ToolItem(buttonBar, SWT.NONE);
    ToolItem plus = new ToolItem(buttonBar, SWT.NONE);
    plus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD).createImage());
    plus.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            plus();
        }
    });
    final ToolItem minus = new ToolItem(buttonBar, SWT.NONE);
    minus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE).createImage());
    minus.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            minus();
        }
    });
    minus.setEnabled(false);
    Composite tableParent = new Composite(composite, SWT.NONE);
    final GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 150;
    tableParent.setLayoutData(layoutData);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableParent.setLayout(tableLayout);
    viewer = new TableViewer(tableParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    // accessing property here directly, instead of going via (JcrProperty)inputElement;
    String[] rawLines = property.getValuesAsString();
    // convert raw lines to Line objects for easier editing management
    for (int i = 0; i < rawLines.length; i++) {
        lines.add(new Line(rawLines[i]));
    }
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return lines.toArray();
        }
    });
    TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
    column0.getColumn().setText("Type");
    column0.getColumn().setResizable(true);
    column0.getColumn().setWidth(100);
    tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(20, 100));
    column0.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            try {
                cell.setText(property.getTypeAsString());
                cell.setForeground(greyColor);
            } catch (Exception e) {
                cell.setText("n/a");
                cell.setForeground(greyColor);
            }
        }
    });
    TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
    column1.getColumn().setText("Value");
    column1.getColumn().setResizable(true);
    column1.getColumn().setWidth(200);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(80, 200));
    column1.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Line line = (Line) cell.getElement();
            cell.setText(line.getValue());
        }
    });
    column1.setEditingSupport(new EditingSupport(viewer) {

        @Override
        protected void setValue(Object element, Object value) {
            Line line = (Line) element;
            line.setValue(String.valueOf(value));
            // trigger a refresh:
            viewer.setInput(property);
        }

        @Override
        protected Object getValue(Object element) {
            final Line line = (Line) element;
            final String value = line.getValue();
            System.out.println("Value=" + value);
            return value;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(viewer.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            // all values are editable
            return true;
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                if (iss.isEmpty()) {
                    minus.setEnabled(false);
                } else {
                    minus.setEnabled(true);
                }
            } else {
                minus.setEnabled(false);
            }
        }
    });
    viewer.setInput(property);
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ToolItem(org.eclipse.swt.widgets.ToolItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)61 CellEditor (org.eclipse.jface.viewers.CellEditor)46 GridData (org.eclipse.swt.layout.GridData)22 ICellModifier (org.eclipse.jface.viewers.ICellModifier)21 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 Composite (org.eclipse.swt.widgets.Composite)21 GridLayout (org.eclipse.swt.layout.GridLayout)19 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)15 TableViewer (org.eclipse.jface.viewers.TableViewer)14 Label (org.eclipse.swt.widgets.Label)14 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)14 Map (java.util.Map)13 Button (org.eclipse.swt.widgets.Button)12 HashMap (java.util.HashMap)11 Item (org.eclipse.swt.widgets.Item)11 TableColumn (org.eclipse.swt.widgets.TableColumn)10 TableItem (org.eclipse.swt.widgets.TableItem)10 Text (org.eclipse.swt.widgets.Text)10 Group (org.eclipse.swt.widgets.Group)8