Search in sources :

Example 6 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.

the class XmlMapLabelProvider method getColumnText.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
     */
@Override
public String getColumnText(Object element, int columnIndex) {
    String returnValue = null;
    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) this.tableViewerCreator.getColumns().get(columnIndex);
    if (column.getLabelProvider() != null) {
        returnValue = column.getLabelProvider().getLabel(element);
    }
    if (returnValue == null) {
        if (column.getDisplayedValue() != null || column.getDefaultDisplayedValue() != null || column.getBeanPropertyAccessors() == null) {
            String defaultValue = column.getDefaultDisplayedValue();
            String imposedDisplayedValue = column.getDisplayedValue();
            if (imposedDisplayedValue != null) {
                returnValue = imposedDisplayedValue;
            } else if (defaultValue == null) {
                //$NON-NLS-1$
                returnValue = "";
            } else {
                returnValue = defaultValue;
            }
        } else {
            Object value = AccessorUtils.get(element, column);
            CellEditor cellEditor = column.getCellEditor();
            CellEditorValueAdapter retrieverValue = column.getCellEditorValueAdapter();
            // add for bug TDI-21505
            if (value != null && column.getCellEditorValueAdapter() != null && column.getCellEditorValueAdapter() instanceof ComboEditorValueAdapter) {
                Object returnObject = column.getCellEditorValueAdapter().getCellEditorTypedValue(column.getCellEditor(), value);
                if ("-1".equals(returnObject + "")) {
                    return "";
                }
            }
            if (cellEditor != null && retrieverValue != null && value != null) {
                if (element instanceof TreeNode) {
                    if ((((TreeNode) element).getNodeType()).equals(NodeType.ELEMENT)) {
                        returnValue = retrieverValue.getColumnText(cellEditor, element, value);
                    }
                }
            } else if (value != null) {
                returnValue = String.valueOf(value);
            } else {
                //$NON-NLS-1$
                returnValue = "";
            }
        }
        // return the type
        if (columnIndex == 3) {
            if (element instanceof TreeNode) {
                TreeNode node = (TreeNode) element;
                returnValue = TalendTypeConvert.convertToJavaType(node.getType());
            }
        }
    }
    return returnValue;
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) ComboEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ComboEditorValueAdapter) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter)

Example 7 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.

the class PropertiesTableEditorView method createColumns.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.commons.ui.swt.extended.macrotable.AbstractExtendedTableViewer#createColumns(org.talend.commons.ui
     * .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
     */
@SuppressWarnings("unchecked")
@Override
protected void createColumns(final TableViewerCreator<B> tableViewerCreator, final Table table) {
    // there's two lists of values, one that will be in the table
    // and the other will be stored as the current value in the property
    // there is two lists because of the undo / redo capabilities
    PropertiesTableEditorModel model = getModel();
    TalendProposalProvider processProposalProvider = new TalendProposalProvider(model.getProcess());
    String[] titles = model.getTitles();
    final Object[] itemsValue = model.getItemsValue();
    final String[] items = model.getItems();
    // final Element elem = model.getElement();
    final IElementParameter param = model.getElemParameter();
    final IElement element = model.getElement();
    for (int i = 0; i < titles.length; i++) {
        final int curCol = i;
        final IElementParameter currentParam = (IElementParameter) itemsValue[i];
        // if all is empty, show it always.
        boolean toDisplay = currentParam.isShow(currentParam.getShowIf(), currentParam.getNotShowIf(), element.getElementParameters());
        if (!toDisplay) {
            List<Map<String, Object>> fullTable = (List<Map<String, Object>>) param.getValue();
            for (int curLine = 0; curLine < fullTable.size(); curLine++) {
                ((ElementParameter) currentParam).setCurrentRow(curLine);
                if (currentParam.isShow(element.getElementParameters())) {
                    toDisplay = true;
                    break;
                }
            }
        }
        if (toDisplay) {
            final TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
            column.setTitle(titles[i]);
            column.setModifiable(true);
            column.setMinimumWidth(100);
            column.setWeight(20);
            switch(currentParam.getFieldType()) {
                case CONTEXT_PARAM_NAME_LIST:
                case CLOSED_LIST:
                case LOOKUP_COLUMN_LIST:
                case COLUMN_LIST:
                case CONNECTION_LIST:
                case DBTYPE_LIST:
                case COMPONENT_LIST:
                case PREV_COLUMN_LIST:
                    final ComboBoxCellEditor cellEditor = new ComboBoxCellEditor(table, currentParam.getListItemsDisplayName());
                    final IElementParameter copyOfTmpParam = currentParam;
                    ((CCombo) cellEditor.getControl()).setEditable(false);
                    ((CCombo) cellEditor.getControl()).setEnabled(!(param.isRepositoryValueUsed() || param.isReadOnly() || currentParam.isReadOnly()));
                    column.setCellEditor(cellEditor, new CellEditorValueAdapter() {

                        @Override
                        public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorValue) {
                            return (String) cellEditorValue;
                        }

                        @Override
                        public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
                            Object returnedValue = null;
                            if (cellEditorTypedValue != null && cellEditorTypedValue instanceof Integer) {
                                int index = (Integer) cellEditorTypedValue;
                                String[] namesSet = ((CCombo) cellEditor.getControl()).getItems();
                                if (namesSet.length > 0 && index > -1 && index < namesSet.length) {
                                    returnedValue = namesSet[index];
                                } else {
                                    returnedValue = null;
                                }
                            } else {
                                returnedValue = null;
                            }
                            return returnedValue;
                        }

                        ;

                        @Override
                        public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
                            CCombo combo = (CCombo) cellEditor.getControl();
                            int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
                            String[] listToDisplay = getItemsToDisplay(element, copyOfTmpParam, rowNumber);
                            if (!Arrays.equals(listToDisplay, ((ComboBoxCellEditor) cellEditor).getItems())) {
                                ((ComboBoxCellEditor) cellEditor).setItems(listToDisplay);
                            }
                            Object returnedValue = 0;
                            if (originalTypedValue != null) {
                                String[] namesSet = listToDisplay;
                                for (int j = 0; j < namesSet.length; j++) {
                                    if (namesSet[j].equals(originalTypedValue)) {
                                        returnedValue = j;
                                        break;
                                    }
                                }
                            }
                            return returnedValue;
                        }

                        ;
                    });
                    break;
                case OPENED_LIST:
                    final EditableComboBoxCellEditor editCellEditor = new EditableComboBoxCellEditor(table, currentParam.getListItemsDisplayName());
                    table.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            String oldValue = null;
                            if (editCellEditor != null) {
                                if (!(editCellEditor.getValue() instanceof String)) {
                                    return;
                                }
                                oldValue = (String) editCellEditor.getValue();
                            }
                            String[] columnItems = null;
                            if (table.getSelection() != null && table.getSelection().length > 0) {
                                TableItem tableItem = table.getSelection()[0];
                                if (tableItem.getData() instanceof Map) {
                                    Map map = (Map) tableItem.getData();
                                    if (currentParam.getFilter() != null && map.get(currentParam.getFilter()) instanceof String) {
                                        String value = (String) map.get(currentParam.getFilter());
                                        if (element instanceof Node) {
                                            List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
                                            for (IConnection con : listConnection) {
                                                if (con.getName().equals(value)) {
                                                    List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
                                                    columnItems = new String[columns.size()];
                                                    for (int i = 0; i < columns.size(); i++) {
                                                        columnItems[i] = columns.get(i).getLabel();
                                                    }
                                                    if (editCellEditor != null) {
                                                        List<String> ret = new ArrayList<String>();
                                                        for (String columnItem : columnItems) {
                                                            ret.add(columnItem);
                                                        }
                                                        for (int i = 0; i < currentParam.getListItemsDisplayName().length; i++) {
                                                            ret.add(currentParam.getListItemsDisplayName()[i]);
                                                        }
                                                        editCellEditor.setItems(ret.toArray(new String[0]));
                                                        editCellEditor.setValue(oldValue);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    });
                    column.setCellEditor(editCellEditor);
                    break;
                case MODULE_LIST:
                    column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    ModuleListCellEditor moduleEditor = new ModuleListCellEditor(table, currentParam, param);
                    moduleEditor.setTableEditorView(this);
                    column.setCellEditor(moduleEditor);
                    break;
                case COLOR:
                    column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    // column.setDisplayedValue("");
                    column.setLabelProvider(null);
                    column.setCellEditor(new ColorCellEditor(table) {

                        @Override
                        protected void doSetValue(Object value) {
                            if (value instanceof String) {
                                super.doSetValue(ColorUtils.stringToRGB((String) value));
                            } else {
                                super.doSetValue(value);
                            }
                        }

                        @Override
                        protected void updateContents(Object value) {
                            if (value != null) {
                                if (value instanceof String) {
                                    super.updateContents(ColorUtils.stringToRGB((String) value));
                                } else {
                                    super.updateContents(value);
                                }
                            }
                        }
                    });
                    column.setColorProvider(new IColumnColorProvider() {

                        @Override
                        public Color getBackgroundColor(Object bean) {
                            Object value = ((Map<String, Object>) bean).get(items[curCol]);
                            if (value == null || (!(value instanceof String))) {
                                return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
                            }
                            return new Color(null, ColorUtils.stringToRGB((String) value));
                        }

                        @Override
                        public Color getForegroundColor(Object bean) {
                            return null;
                        }
                    });
                    break;
                case CHECK:
                    column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    CheckColumnSelectionListener tableColumnSelectionListener = new CheckColumnSelectionListener(column, tableViewerCreator, currentParam);
                    if (!currentParam.isReadOnly()) {
                        column.setTableColumnSelectionListener(tableColumnSelectionListener);
                    }
                    column.setTableEditorContent(new CheckboxTableEditorContent());
                    Boolean curValue = (Boolean) currentParam.getValue();
                    if (curValue == null) {
                        curValue = Boolean.FALSE;
                    }
                    tableColumnSelectionListener.setChecked(curValue.booleanValue());
                    if (curValue.booleanValue()) {
                        column.setImageHeader(ImageProvider.getImage(EImage.CHECKED_ICON));
                    } else {
                        column.setImageHeader(ImageProvider.getImage(EImage.UNCHECKED_ICON));
                    }
                    //$NON-NLS-1$
                    column.setDisplayedValue("");
                    break;
                case SCHEMA_TYPE:
                case SCHEMA_REFERENCE:
                    column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    final INode node = (INode) element;
                    // List<IMetadataTable> tables = node.getMetadataList();
                    // if (isEBCDICNode(node)) { // ebcdic
                    column.setLabelProvider(new IColumnLabelProvider() {

                        @Override
                        public String getLabel(Object bean) {
                            if (bean instanceof Map) {
                                Map<String, Object> valueMap = (Map<String, Object>) bean;
                                String value = (String) valueMap.get(IEbcdicConstant.FIELD_SCHEMA);
                                if (value != null && !"".equals(value)) {
                                    //$NON-NLS-1$
                                    IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeTableName(node, value);
                                    if (metadataTable != null) {
                                        if (isEBCDICNode(node)) {
                                            if (isRepositorySchemaLine(node, valueMap)) {
                                                //$NON-NLS-1$ //$NON-NLS-2$
                                                return "Repository (" + metadataTable.getTableName() + ")";
                                            } else {
                                                //$NON-NLS-1$ //$NON-NLS-2$
                                                return "Built-In (" + metadataTable.getTableName() + ")";
                                            }
                                        } else {
                                            return metadataTable.getTableName();
                                        }
                                    } else {
                                        return value;
                                    }
                                }
                            }
                            //$NON-NLS-1$
                            return "";
                        }
                    });
                    // } else {
                    // column.setLabelProvider(null);
                    // }
                    SchemaCellEditor schemaEditor = new SchemaCellEditor(table, node);
                    schemaEditor.setTableEditorView(this);
                    column.setCellEditor(schemaEditor);
                    break;
                case SAP_SCHEMA_TYPE:
                    column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    final INode sapNode = (INode) element;
                    column.setLabelProvider(new IColumnLabelProvider() {

                        @Override
                        public String getLabel(Object bean) {
                            if (bean instanceof Map) {
                                Map<String, Object> valueMap = (Map<String, Object>) bean;
                                String value = (String) valueMap.get(IEbcdicConstant.FIELD_SCHEMA);
                                if (value != null && !"".equals(value)) {
                                    //$NON-NLS-1$
                                    IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeTableName(sapNode, value);
                                    if (metadataTable != null) {
                                        if (isEBCDICNode(sapNode)) {
                                            if (isRepositorySchemaLine(sapNode, valueMap)) {
                                                //$NON-NLS-1$ //$NON-NLS-2$
                                                return "Repository (" + metadataTable.getTableName() + ")";
                                            } else {
                                                //$NON-NLS-1$ //$NON-NLS-2$
                                                return "Built-In (" + metadataTable.getTableName() + ")";
                                            }
                                        } else if (isSAPNode(sapNode)) {
                                            Object type = valueMap.get(ISAPConstant.TYPE);
                                            if (type instanceof Integer) {
                                                return "";
                                            }
                                            if (type.toString().equals(SINGLE) || type.toString().equals(STRUCTURE)) {
                                                List<IMetadataColumn> columns = metadataTable.getListColumns(true);
                                                StringBuffer values = new StringBuffer();
                                                values.append(metadataTable.getTableName() + ":");
                                                if (metadataTable.getListColumns(true).size() > 0) {
                                                    for (IMetadataColumn column : columns) {
                                                        values.append(column.getDefault() + ",");
                                                    }
                                                    String ret = values.toString();
                                                    return ret.substring(0, ret.length() - 1);
                                                }
                                            } else {
                                                return metadataTable.getTableName();
                                            }
                                        } else {
                                            return metadataTable.getTableName();
                                        }
                                    } else {
                                        return value;
                                    }
                                }
                            }
                            //$NON-NLS-1$
                            return "";
                        }
                    });
                    schemaEditor = new SchemaCellEditor(table, sapNode);
                    schemaEditor.setTableEditorView(this);
                    column.setCellEditor(schemaEditor);
                    break;
                // hywang add for feature 6484
                case RULE_TYPE:
                    //$NON-NLS-1$
                    column.setTitle("Rule");
                    column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    final INode node1 = (INode) element;
                    column.setLabelProvider(new IColumnLabelProvider() {

                        @Override
                        public String getLabel(Object bean) {
                            if (bean instanceof Map) {
                                Map<String, Object> valueMap = (Map<String, Object>) bean;
                                String value = (String) valueMap.get(IRuleConstant.FIELD_RULE);
                                if (value != null && !"".equals(value)) {
                                    //$NON-NLS-1$
                                    IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeTableName(node1, value);
                                    if (metadataTable != null) {
                                        return metadataTable.getTableName();
                                    } else {
                                        return value;
                                    }
                                }
                            }
                            //$NON-NLS-1$
                            return "";
                        }
                    });
                    RuleCellEditor ruleEditor = new RuleCellEditor(table, node1);
                    ruleEditor.setTableEditorView(this);
                    column.setCellEditor(ruleEditor);
                    break;
                case SCHEMA_XPATH_QUERYS:
                    column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    final INode node2 = (INode) element;
                    SchemaXPathQuerysCellEditor schemaXPathEditor = new SchemaXPathQuerysCellEditor(table, node2);
                    schemaXPathEditor.setTableEditorView(this);
                    column.setCellEditor(schemaXPathEditor);
                    break;
                case MULTI_PATTERN:
                    column.setModifiable(true);
                    PatternCellEditor patternEditor = new PatternCellEditor(table, element);
                    patternEditor.setTableEditorView(this);
                    column.setCellEditor(patternEditor);
                    break;
                case PATTERN_PROPERTY:
                    column.setModifiable(true);
                    PatternPropertyCellEditor patternPropertyEditor = new PatternPropertyCellEditor(table, element);
                    patternPropertyEditor.setTableEditorView(this);
                    column.setCellEditor(patternPropertyEditor);
                    break;
                default:
                    // TEXT
                    TextCellEditor tcEditor = null;
                    if (((i == 0) && (param.isBasedOnSchema() || param.isBasedOnSubjobStarts())) || (param.isRepositoryValueUsed()) || (param.isReadOnly()) || currentParam.isReadOnly()) {
                        // read only cell
                        if (!param.getElement().isReadOnly() && (param.getName().equals("HADOOP_ADVANCED_PROPERTIES") || param.getName().equals("SPARK_ADVANCED_PROPERTIES") || param.getName().equals("HBASE_PARAMETERS"))) {
                            if (currentParam.isNoContextAssist()) {
                                tcEditor = new TextCellEditor(table);
                            } else {
                                TextCellEditorWithProposal textCellEditor = new TextCellEditorWithProposal(table, column);
                                textCellEditor.setContentProposalProvider(processProposalProvider);
                                tcEditor = textCellEditor;
                            }
                        }
                    } else {
                        // writable cell
                        if (currentParam.isNoContextAssist()) {
                            tcEditor = new TextCellEditor(table);
                        } else {
                            TextCellEditorWithProposal textCellEditor = new TextCellEditorWithProposal(table, column);
                            textCellEditor.setContentProposalProvider(processProposalProvider);
                            tcEditor = textCellEditor;
                        }
                    }
                    if (tcEditor != null) {
                        column.setCellEditor(tcEditor);
                        column.setModifiable((!param.isRepositoryValueUsed()) && (!param.isReadOnly()) && (!currentParam.isReadOnly()));
                    }
            }
            // for all kinds of column, check if read only or not when edit the field.
            column.setColumnCellModifier(new ColumnCellModifier(column) {

                @Override
                public boolean canModify(Object bean) {
                    if (param.getName().equals("HADOOP_ADVANCED_PROPERTIES") || param.getName().equals("SPARK_ADVANCED_PROPERTIES") || param.getName().equals("HBASE_PARAMETERS")) {
                        boolean canModify = super.canModify(bean);
                        if (canModify) {
                            Map<String, Object> valueMap = (Map<String, Object>) bean;
                            List<Map<String, Object>> fullValues = (List<Map<String, Object>>) param.getValue();
                            ((ElementParameter) currentParam).setCurrentRow(fullValues.indexOf(valueMap));
                            if (currentParam.isReadOnly(element.getElementParameters())) {
                                return false;
                            }
                        } else {
                            Map<String, Object> valueMap = (Map<String, Object>) bean;
                            if (valueMap.get("BUILDIN") != null && valueMap.get("BUILDIN").equals("TRUE")) {
                                return true;
                            } else {
                                return false;
                            }
                        }
                        return canModify;
                    }
                    boolean canModify = super.canModify(bean);
                    if (canModify) {
                        Map<String, Object> valueMap = (Map<String, Object>) bean;
                        List<Map<String, Object>> fullValues = (List<Map<String, Object>>) param.getValue();
                        ((ElementParameter) currentParam).setCurrentRow(fullValues.indexOf(valueMap));
                        if (currentParam.isReadOnly(element.getElementParameters())) {
                            return false;
                        }
                    }
                    return canModify;
                }
            });
            column.setColorProvider(new IColumnColorProvider<B>() {

                @Override
                public Color getBackgroundColor(B bean) {
                    Map<String, Object> valueMap = (Map<String, Object>) bean;
                    List<Map<String, Object>> fullValues = (List<Map<String, Object>>) param.getValue();
                    // hyWang add varriable index for bug 7294
                    int index = fullValues.indexOf(valueMap);
                    if (index >= 0) {
                        ((ElementParameter) currentParam).setCurrentRow(index);
                        if (currentParam.isReadOnly(element.getElementParameters())) {
                            return AbstractMetadataTableEditorView.READONLY_CELL_BG_COLOR;
                        }
                    }
                    if (param.getName().equals("HADOOP_ADVANCED_PROPERTIES") || param.getName().equals("SPARK_ADVANCED_PROPERTIES") || param.getName().equals("HBASE_PARAMETERS")) {
                        if (valueMap.get("BUILDIN") == null || valueMap.get("BUILDIN") != null && valueMap.get("BUILDIN").equals("")) {
                            return Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
                        }
                    }
                    if (currentParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                        Object value = ((Map<String, Object>) bean).get(items[curCol]);
                        boolean found = false;
                        Object[] items = currentParam.getListItemsValue();
                        for (Object item : items) {
                            if (item.equals(value)) {
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
                        }
                    }
                    return null;
                }

                @Override
                public Color getForegroundColor(B bean) {
                    return null;
                }
            });
            column.setBeanPropertyAccessors(new IBeanPropertyAccessors<B, Object>() {

                @Override
                public Object get(B bean) {
                    Object value = ((Map<String, Object>) bean).get(items[curCol]);
                    if (value == null) {
                        //$NON-NLS-1$
                        return "";
                    }
                    if (itemsValue[curCol] instanceof IElementParameter) {
                        IElementParameter tmpParam = (IElementParameter) itemsValue[curCol];
                        boolean hideValue = false;
                        if (!tmpParam.isReadOnly()) {
                            if ((tmpParam.getReadOnlyIf() != null || tmpParam.getNotReadOnlyIf() != null) && tmpParam.isReadOnly(element.getElementParameters())) {
                                hideValue = true;
                            }
                        }
                        switch(tmpParam.getFieldType()) {
                            case CONTEXT_PARAM_NAME_LIST:
                            case CLOSED_LIST:
                            case COMPONENT_LIST:
                            case COLUMN_LIST:
                            case CONNECTION_LIST:
                            case LOOKUP_COLUMN_LIST:
                            case PREV_COLUMN_LIST:
                            case DBTYPE_LIST:
                                if (hideValue) {
                                    //$NON-NLS-1$
                                    return "";
                                }
                                String[] namesSet = tmpParam.getListItemsDisplayName();
                                if (namesSet.length == 0) {
                                    return tmpParam.getDefaultClosedListValue();
                                }
                                if (value instanceof String) {
                                    boolean found = false;
                                    int index = 0;
                                    if (currentParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                                        // if not found, won't use first(index 0) instead
                                        index = -1;
                                    }
                                    Object[] items = currentParam.getListItemsValue();
                                    for (int j = 0; j < items.length && !found; j++) {
                                        if (items[j].equals(value)) {
                                            found = true;
                                            index = j;
                                        }
                                    }
                                    value = new Integer(index);
                                }
                                if (value != null && ((Integer) value) >= 0) {
                                    return namesSet[(Integer) value];
                                }
                                return null;
                            case OPENED_LIST:
                                if (hideValue) {
                                    //$NON-NLS-1$
                                    return "";
                                }
                                String[] listItemsValue = tmpParam.getListItemsDisplayName();
                                if (listItemsValue.length == 0) {
                                    return value;
                                }
                                int index = -1;
                                if (value instanceof String) {
                                    boolean found = false;
                                    Object[] items = ((IElementParameter) itemsValue[curCol]).getListItemsValue();
                                    for (int j = 0; j < items.length && !found; j++) {
                                        if (items[j].equals(value)) {
                                            found = true;
                                            index = j;
                                        }
                                    }
                                }
                                Integer count = new Integer(index);
                                if (count >= 0) {
                                    return listItemsValue[count];
                                } else if (count < 0) {
                                    return value;
                                }
                                return value;
                            case CHECK:
                                if (hideValue) {
                                    return false;
                                }
                                if (value instanceof String) {
                                    return new Boolean((String) value);
                                }
                                return value;
                            case RADIO:
                                if (hideValue) {
                                    return false;
                                }
                                if (value instanceof String) {
                                    return new Boolean((String) value);
                                }
                                return value;
                            case COLOR:
                                if (value instanceof String) {
                                    return ColorUtils.stringToRGB((String) value);
                                }
                                // already RGB
                                return value;
                            default:
                                // TEXT
                                if (hideValue) {
                                    //$NON-NLS-1$
                                    return "";
                                }
                                return value;
                        }
                    }
                    return value;
                }

                @Override
                public void set(B bean, Object value) {
                    Object finalValue = value;
                    IElementParameter tmpParam = (IElementParameter) itemsValue[curCol];
                    // TODO should test if this parameter is contained in any other show if / not show if, etc..
                    boolean included = false;
                    for (Object object : param.getListItemsValue()) {
                        if (object instanceof IElementParameter) {
                            if (((IElementParameter) object).getShowIf() != null && ((IElementParameter) object).getShowIf().contains(tmpParam.getName())) {
                                included = true;
                                break;
                            }
                            if (((IElementParameter) object).getNotShowIf() != null && ((IElementParameter) object).getNotShowIf().contains(tmpParam.getName())) {
                                included = true;
                                break;
                            }
                            if (((IElementParameter) object).getReadOnlyIf() != null && ((IElementParameter) object).getReadOnlyIf().contains(tmpParam.getName())) {
                                included = true;
                                break;
                            }
                            if (((IElementParameter) object).getNotReadOnlyIf() != null && ((IElementParameter) object).getNotReadOnlyIf().contains(tmpParam.getName())) {
                                included = true;
                                break;
                            }
                        }
                    }
                    if (included) {
                        IElementParameter param = element.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName());
                        if (param != null) {
                            param.setValue(Boolean.TRUE);
                        }
                    }
                    boolean isNeedReCheck = false;
                    switch(tmpParam.getFieldType()) {
                        case CONTEXT_PARAM_NAME_LIST:
                        case CLOSED_LIST:
                        case COLUMN_LIST:
                        case COMPONENT_LIST:
                        case CONNECTION_LIST:
                        case LOOKUP_COLUMN_LIST:
                        case PREV_COLUMN_LIST:
                            isNeedReCheck = true;
                            if (value instanceof String) {
                                Object[] itemNames = ((IElementParameter) itemsValue[curCol]).getListItemsDisplayName();
                                Object[] itemValues = ((IElementParameter) itemsValue[curCol]).getListItemsValue();
                                boolean found = false;
                                int index = 0;
                                for (int j = 0; j < itemNames.length && !found; j++) {
                                    if (itemNames[j].equals(value)) {
                                        found = true;
                                        index = j;
                                    }
                                }
                                if (value != null && (index >= 0)) {
                                    finalValue = itemValues[new Integer(index)];
                                }
                            }
                            break;
                        case OPENED_LIST:
                            if (value instanceof String) {
                                Object[] itemNames = ((IElementParameter) itemsValue[curCol]).getListItemsDisplayName();
                                Object[] itemValues = ((IElementParameter) itemsValue[curCol]).getListItemsValue();
                                boolean found = false;
                                int index = -1;
                                for (int j = 0; j < itemNames.length && !found; j++) {
                                    if (itemNames[j].equals(value)) {
                                        found = true;
                                        index = j;
                                    }
                                }
                                if (value != null && (index >= 0)) {
                                    finalValue = itemValues[new Integer(index)];
                                } else if (value != null && (index < 0)) {
                                    finalValue = value;
                                }
                            }
                            break;
                        case COLOR:
                            if (value instanceof RGB) {
                                RGB rgb = (RGB) value;
                                //$NON-NLS-1$ //$NON-NLS-2$
                                finalValue = rgb.red + ";" + rgb.green + ";" + rgb.blue;
                            }
                        default:
                    }
                    ((Map<String, Object>) bean).put(items[curCol], finalValue);
                    resetValuesIfNeeded(element, param, (Map<String, Object>) bean);
                    /*
                         * TDI-6568, in fact, no need reset the value. just want to enable
                         * "firePropertyChange(RETURNS_CHANGED, null, null)" in Node.
                         */
                    if (param.getFieldType().equals(EParameterFieldType.TABLE)) {
                        element.setPropertyValue(param.getName(), param.getValue());
                    }
                    if (isNeedReCheck && element instanceof Node) {
                        IProcess process = ((Node) element).getProcess();
                        if (process instanceof IProcess2) {
                            ((IProcess2) process).checkProcess();
                        }
                        // enable to refresh component setting after change modules.
                        // so far, for cMessagingEndpoint (TUP-1119)
                        final IElementParameter copyOfTmpParam = currentParam;
                        if (element != null && "LIBPATH".equals(copyOfTmpParam.getName())) {
                            //$NON-NLS-1$
                            IElementParameter updateComponentsParam = element.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName());
                            if (updateComponentsParam != null) {
                                updateComponentsParam.setValue(Boolean.TRUE);
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : TalendProposalProvider(org.talend.core.ui.proposal.TalendProposalProvider) TableItem(org.eclipse.swt.widgets.TableItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) SchemaCellEditor(org.talend.core.ui.metadata.celleditor.SchemaCellEditor) ColorCellEditor(org.eclipse.jface.viewers.ColorCellEditor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) IColumnColorProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider) IProcess(org.talend.core.model.process.IProcess) PatternPropertyCellEditor(org.talend.designer.core.ui.celleditor.PatternPropertyCellEditor) IElement(org.talend.core.model.process.IElement) Color(org.eclipse.swt.graphics.Color) EditableComboBoxCellEditor(org.talend.commons.ui.swt.tableviewer.celleditor.EditableComboBoxCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) RGB(org.eclipse.swt.graphics.RGB) CCombo(org.eclipse.swt.custom.CCombo) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Map(java.util.Map) INode(org.talend.core.model.process.INode) RGB(org.eclipse.swt.graphics.RGB) CellEditor(org.eclipse.jface.viewers.CellEditor) SchemaCellEditor(org.talend.core.ui.metadata.celleditor.SchemaCellEditor) PatternPropertyCellEditor(org.talend.designer.core.ui.celleditor.PatternPropertyCellEditor) ColorCellEditor(org.eclipse.jface.viewers.ColorCellEditor) ModuleListCellEditor(org.talend.core.ui.metadata.celleditor.ModuleListCellEditor) EditableComboBoxCellEditor(org.talend.commons.ui.swt.tableviewer.celleditor.EditableComboBoxCellEditor) PatternCellEditor(org.talend.designer.core.ui.celleditor.PatternCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) RuleCellEditor(org.talend.core.ui.metadata.celleditor.RuleCellEditor) SchemaXPathQuerysCellEditor(org.talend.core.ui.metadata.celleditor.SchemaXPathQuerysCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) CheckColumnSelectionListener(org.talend.designer.core.ui.event.CheckColumnSelectionListener) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) RuleCellEditor(org.talend.core.ui.metadata.celleditor.RuleCellEditor) IConnection(org.talend.core.model.process.IConnection) ModuleListCellEditor(org.talend.core.ui.metadata.celleditor.ModuleListCellEditor) ColumnCellModifier(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier) IElementParameter(org.talend.core.model.process.IElementParameter) PatternCellEditor(org.talend.designer.core.ui.celleditor.PatternCellEditor) IColumnLabelProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnLabelProvider) SchemaXPathQuerysCellEditor(org.talend.core.ui.metadata.celleditor.SchemaXPathQuerysCellEditor) TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) CheckboxTableEditorContent(org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent) IProcess2(org.talend.core.model.process.IProcess2) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) EditableComboBoxCellEditor(org.talend.commons.ui.swt.tableviewer.celleditor.EditableComboBoxCellEditor)

Example 8 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.

the class DataMapTableView method createExpressionCellEditor.

protected TextCellEditor createExpressionCellEditor(final TableViewerCreator tableViewerCreator, TableViewerCreatorColumn column, final Zone[] zones, boolean isConstraintExpressionCellEditor) {
    final TextCellEditorWithProposal cellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.MULTI | SWT.BORDER, column);
    final Text expressionTextEditor = (Text) cellEditor.getControl();
    if (isConstraintExpressionCellEditor) {
    // moved to it's caller to execute
    // constraintExpressionTextEditor = expressionTextEditor;
    } else {
        columnExpressionTextEditor = expressionTextEditor;
    }
    cellEditor.addListener(new ICellEditorListener() {

        Text text = (Text) cellEditor.getControl();

        @Override
        public void applyEditorValue() {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
            mapperManager.getUiManager().parseNewExpression(text.getText(), (ITableEntry) modifiedObjectInfo.getCurrentModifiedBean(), true);
        }

        @Override
        public void cancelEditor() {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
            text.setText((String) modifiedObjectInfo.getOriginalPropertyBeanValue());
            ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
            String originalExpression = (String) modifiedObjectInfo.getOriginalPropertyBeanValue();
            mapperManager.getUiManager().parseNewExpression(originalExpression, tableEntry, true);
        }

        @Override
        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
            if (expressionTextEditor.isFocusControl() || lastExpressionEditorTextWhichLostFocus == expressionTextEditor) {
                ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
                ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
                mapperManager.getUiManager().parseNewExpression(text.getText(), tableEntry, false);
                resizeTextEditor(text, tableViewerCreator);
            }
        }
    });
    expressionTextEditor.addControlListener(new ControlListener() {

        ExecutionLimiter executionLimiter = null;

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            if (executionLimiter == null) {
                executionLimiter = new ExecutionLimiter(50, true) {

                    @Override
                    public void execute(boolean isFinalExecution, Object data) {
                        if (isFinalExecution && !expressionTextEditor.isDisposed()) {
                            expressionTextEditor.getDisplay().syncExec(new Runnable() {

                                @Override
                                public void run() {
                                    if (expressionTextEditor.isDisposed()) {
                                        return;
                                    }
                                    resizeTextEditor(expressionTextEditor, tableViewerCreator);
                                }
                            });
                        }
                    }
                };
            }
            executionLimiter.startIfExecutable();
        }
    });
    expressionTextEditor.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            ITableEntry currentModifiedEntry = (ITableEntry) tableViewerCreator.getModifiedObjectInfo().getCurrentModifiedBean();
            initExpressionProposals(cellEditor, zones, tableViewerCreator, currentModifiedEntry);
            resizeTextEditor(expressionTextEditor, tableViewerCreator);
            StyledTextHandler styledTextHandler = mapperManager.getUiManager().getTabFolderEditors().getStyledTextHandler();
            styledTextHandler.setCurrentEntry(currentModifiedEntry);
            //$NON-NLS-1$
            styledTextHandler.setTextWithoutNotifyListeners(currentModifiedEntry.getExpression() == null ? "" : currentModifiedEntry.getExpression());
        }

        @Override
        public void focusLost(FocusEvent e) {
            expressionEditorTextSelectionBeforeFocusLost = expressionTextEditor.getSelection();
            lastExpressionEditorTextWhichLostFocus = expressionTextEditor;
        }
    });
    column.setCellEditor(cellEditor, new CellEditorValueAdapter() {

        @Override
        public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
            return super.getCellEditorTypedValue(cellEditor, originalTypedValue);
        }

        @Override
        public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorTypedValue) {
            //$NON-NLS-1$ //$NON-NLS-2$
            return super.getColumnText(cellEditor, bean, cellEditorTypedValue).replaceAll("[\r\n\t]+", " ... ");
        }

        @Override
        public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
            return super.getOriginalTypedValue(cellEditor, cellEditorTypedValue);
        }
    });
    return cellEditor;
}
Also used : TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) StyledTextHandler(org.talend.designer.dbmap.ui.tabs.StyledTextHandler) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) FocusEvent(org.eclipse.swt.events.FocusEvent) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) ControlListener(org.eclipse.swt.events.ControlListener) ModifiedObjectInfo(org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo) ExecutionLimiter(org.talend.commons.utils.threading.ExecutionLimiter) ControlEvent(org.eclipse.swt.events.ControlEvent) FocusListener(org.eclipse.swt.events.FocusListener)

Example 9 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.

the class JSONFileOutputStep2Form method addJSONFileViewer.

private void addJSONFileViewer(final Composite mainComposite, final int width, final int height) {
    final Group group = Form.createGroup(mainComposite, 1, "Linker Target", height);
    GridData data = new GridData(GridData.FILL_BOTH);
    Composite composite = new Composite(group, SWT.BORDER);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(data);
    JSONViewer = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    data = new GridData(GridData.FILL_BOTH);
    JSONViewer.getControl().setLayoutData(data);
    JSONViewer.setUseHashlookup(true);
    Tree tree = JSONViewer.getTree();
    if (isReadOnly()) {
        tree.setEnabled(false);
    }
    tree.setLinesVisible(true);
    tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("JSON Tree");
    column1.setWidth(120);
    TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
    column2.setText("Related Column");
    column2.setWidth(100);
    TreeColumn column3 = new TreeColumn(tree, SWT.CENTER);
    column3.setText("Node Status");
    column3.setWidth(100);
    TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
    column4.setText("Default Value");
    column4.setWidth(100);
    tree.setHeaderVisible(true);
    JSONFileTreeViewerProvider provider = new JSONFileTreeViewerProvider();
    JSONViewer.setLabelProvider(provider);
    JSONViewer.setCellModifier(new ICellModifier() {

        public void modify(Object element, String property, Object value) {
            TreeItem treeItem = (TreeItem) element;
            FOXTreeNode node = (FOXTreeNode) treeItem.getData();
            if (property.equals("C1")) {
                node.setLabel((String) value);
            }
            if (property.equals("C4")) {
                node.setDefaultValue((String) value);
            }
            JSONViewer.refresh(node);
        }

        public Object getValue(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                //$NON-NLS-1$
                return node.getLabel();
            }
            if (property.equals("C4")) {
                //$NON-NLS-1$
                return node.getDefaultValue();
            }
            return null;
        }

        public boolean canModify(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                if (node.getLabel() != null && node.getLabel().length() > 0) {
                    return true;
                }
            }
            if (property.equals("C4")) {
                if (node.getDefaultValue() != null && node.getDefaultValue().length() > 0) {
                    return true;
                }
            }
            return false;
        }
    });
    JSONViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
    CellEditor editor = new TextCellEditor(JSONViewer.getTree());
    editor.addListener(new DialogErrorJSONLabelCellEditor(editor, "C1"));
    CellEditor editorDefault = new TextCellEditor(JSONViewer.getTree());
    editorDefault.addListener(new DialogErrorJSONLabelCellEditor(editorDefault, "C4"));
    JSONViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
    JSONViewer.setContentProvider(provider);
    // JSONViewer.setInput(treeData);
    JSONViewer.expandAll();
    createAction();
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(JSONViewer.getControl());
    JSONViewer.getControl().setMenu(menu);
    JSONViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });
    initToolBar(composite);
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) GridLayout(org.eclipse.swt.layout.GridLayout) JSONFileTreeViewerProvider(org.talend.repository.json.ui.wizards.view.JSONFileTreeViewerProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Tree(org.eclipse.swt.widgets.Tree) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 10 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.

the class BusinessAssignmentComposite method createControls.

public void createControls(Composite parent) {
    composite = widgetFactory.createFlatFormComposite(parent);
    adapterFactory = new BusinessItemProviderAdapterFactory();
    tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
    tableViewer.setLabelProvider(new RepositoryFactoryProxyLabelProvider(adapterFactory));
    Table table = tableViewer.getTable();
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final String[] columnProperties = new String[] { Messages.getString("AssignmentPropertySection.Type"), Messages.getString("AssignmentPropertySection.Name"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Messages.getString("AssignmentPropertySection.Comment") };
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column1.setText(columnProperties[0]);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column2.setText(columnProperties[1]);
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnWeightData(1, 150, true));
    column3.setText(columnProperties[2]);
    tableViewer.setColumnProperties(columnProperties);
    final IItemPropertyDescriptor itemPropertyDescriptor = getItemPropertyDescriptor();
    tableViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            return property.equals(columnProperties[2]);
        }

        @Override
        public Object getValue(Object element, String property) {
            return EmfPropertyHelper.getValue(itemPropertyDescriptor, element);
        }

        @Override
        public void modify(Object element, String property, Object value) {
            if (element instanceof TableItem) {
                TableItem tableItem = (TableItem) element;
                itemPropertyDescriptor.setPropertyValue(tableItem.getData(), value);
            }
        }
    });
    CellEditor[] cellEditors = new CellEditor[3];
    cellEditors[2] = new TextCellEditor(table);
    tableViewer.setCellEditors(cellEditors);
    // createKeyListener(table);
    createSelectionListener();
    createPopupMenu();
    createDoubleClickListener();
    handleLayout(parent, table, column1, column2, column3);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Table(org.eclipse.swt.widgets.Table) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) RepositoryFactoryProxyLabelProvider(org.talend.designer.business.diagram.custom.properties.RepositoryFactoryProxyLabelProvider) TableItem(org.eclipse.swt.widgets.TableItem) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) BusinessItemProviderAdapterFactory(org.talend.designer.business.model.business.provider.BusinessItemProviderAdapterFactory) ICellModifier(org.eclipse.jface.viewers.ICellModifier) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IItemPropertyDescriptor(org.eclipse.emf.edit.provider.IItemPropertyDescriptor) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Aggregations

CellEditor (org.eclipse.jface.viewers.CellEditor)142 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)88 TableViewer (org.eclipse.jface.viewers.TableViewer)45 GridData (org.eclipse.swt.layout.GridData)44 Composite (org.eclipse.swt.widgets.Composite)37 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)35 ICellModifier (org.eclipse.jface.viewers.ICellModifier)32 GridLayout (org.eclipse.swt.layout.GridLayout)30 SelectionEvent (org.eclipse.swt.events.SelectionEvent)29 TableColumn (org.eclipse.swt.widgets.TableColumn)29 CheckboxCellEditor (org.eclipse.jface.viewers.CheckboxCellEditor)25 Table (org.eclipse.swt.widgets.Table)24 Button (org.eclipse.swt.widgets.Button)23 ArrayList (java.util.ArrayList)21 Label (org.eclipse.swt.widgets.Label)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)20 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)20 Text (org.eclipse.swt.widgets.Text)19 Map (java.util.Map)18 EditingSupport (org.eclipse.jface.viewers.EditingSupport)18