Search in sources :

Example 16 with ComboBoxCellEditor

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

the class TableController method updateColumnList.

private void updateColumnList(IElementParameter param) {
    if (elem instanceof Node) {
        ColumnListController.updateColumnList((Node) elem, null);
    } else if (elem instanceof Connection) {
        ColumnListController.updateColumnList(((Connection) elem).getSource(), null);
    }
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
                    if ((j + 1) >= colList.size()) {
                        break;
                    }
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CellEditor cellEditor = column.getCellEditor();
                    String[] oldItems = null;
                    if (cellEditor instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) cellEditor.getControl();
                        oldItems = combo.getItems();
                        combo.setItems(tmpParam.getListItemsDisplayName());
                    }
                    List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
                    String[] items = param.getListItemsDisplayCodeName();
                    for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
                        Map<String, Object> currentLine = paramValues.get(currentIndex);
                        Object o = currentLine.get(items[j]);
                        if (o instanceof Integer) {
                            Integer nb = (Integer) o;
                            if ((nb >= oldItems.length) || (nb == -1)) {
                                nb = new Integer(tmpParam.getIndexOfItemFromList((String) tmpParam.getDefaultClosedListValue()));
                                currentLine.put(items[j], nb);
                            } else {
                                nb = new Integer(tmpParam.getIndexOfItemFromList(oldItems[nb]));
                                currentLine.put(items[j], nb);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Node(org.talend.designer.core.ui.editor.nodes.Node) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with ComboBoxCellEditor

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

the class VarsDataMapTableView method initColumnsOfTableColumns.

@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
    ECodeLanguage codeLanguage = LanguageProvider.getCurrentLanguage().getCodeLanguage();
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.expression"));
    column.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
    expressionCellEditor = createExpressionCellEditor(tableViewerCreatorForColumns, column, new Zone[] { Zone.INPUTS, Zone.VARS }, false);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {

        public String get(VarTableEntry bean) {
            return bean.getExpression();
        }

        public void set(VarTableEntry bean, String value) {
            bean.setExpression(value);
            mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
        }
    });
    column.setModifiable(!mapperManager.componentIsReadOnly());
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    if (codeLanguage == ECodeLanguage.JAVA) {
        column.setWeight(40);
    } else {
        column.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
    }
    if (codeLanguage == ECodeLanguage.JAVA) {
        String[] arrayTalendTypes = new String[0];
        try {
            arrayTalendTypes = MetadataTalendType.getTalendTypesLabels();
            arrayTalendTypes = this.talendTypeFilter.filter(arrayTalendTypes);
        } catch (NoClassDefFoundError e) {
            // shouln't be happend
            // e.printStackTrace();
            ExceptionHandler.process(e);
        } catch (ExceptionInInitializerError e) {
            // shouln't be happend
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
        IBeanPropertyAccessors<VarTableEntry, Boolean> nullableAccessors = new IBeanPropertyAccessors<VarTableEntry, Boolean>() {

            public Boolean get(VarTableEntry bean) {
                return bean.isNullable() ? Boolean.TRUE : Boolean.FALSE;
            }

            public void set(VarTableEntry bean, Boolean value) {
                bean.setNullable(value.booleanValue());
            }
        };
        CellEditorValueAdapter comboValueAdapter = new JavaTypeComboValueAdapter(JavaTypesManager.getDefaultJavaType(), nullableAccessors, this.talendTypeFilter);
        column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
        //$NON-NLS-1$
        column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.type"));
        column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {

            public String get(VarTableEntry bean) {
                return bean.getType();
            }

            public void set(VarTableEntry bean, String value) {
                bean.setType(value);
                mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
            }
        });
        column.setModifiable(!mapperManager.componentIsReadOnly());
        column.setWeight(18);
        column.setCellEditor(new ComboBoxCellEditor(tableViewerCreatorForColumns.getTable(), arrayTalendTypes), comboValueAdapter);
        column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
        //$NON-NLS-1$
        column.setTitle("Nullable");
        column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, Boolean>() {

            public Boolean get(VarTableEntry bean) {
                return bean.isNullable();
            }

            public void set(VarTableEntry bean, Boolean value) {
                bean.setNullable(value);
                mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
            }
        });
        column.setModifiable(!mapperManager.componentIsReadOnly());
        column.setWidth(WindowSystem.isWIN32() ? 12 : 20);
        //$NON-NLS-1$
        column.setDisplayedValue("");
        column.setResizable(false);
        CheckboxTableEditorContent checkboxTableEditorContent = new CheckboxTableEditorContent();
        //$NON-NLS-1$
        String nullable = Messages.getString("VarsDataMapTableView.nullable");
        checkboxTableEditorContent.setToolTipText(nullable);
        column.setTableEditorContent(checkboxTableEditorContent);
        column.setToolTipHeader(nullable);
    }
    column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.variable"));
    column.setId(DataMapTableView.ID_NAME_COLUMN);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {

        public String get(VarTableEntry bean) {
            return bean.getName();
        }

        public void set(VarTableEntry bean, String value) {
            bean.setName(value);
        }
    });
    column.setModifiable(!mapperManager.componentIsReadOnly());
    if (codeLanguage == ECodeLanguage.JAVA) {
        column.setWeight(25);
    } else {
        column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
    }
    final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreatorForColumns.getTable());
    cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {

        @Override
        public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
            if (state == CELL_EDITOR_STATE.APPLYING) {
                ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
                String originalValue = (String) modifiedObjectInfo.getOriginalPropertyBeanValue();
                Object currentModifiedBean = modifiedObjectInfo.getCurrentModifiedBean();
                mapperManager.getUiManager().processColumnNameChanged(originalValue.toString(), newValue.toString(), VarsDataMapTableView.this, (ITableEntry) currentModifiedBean);
            }
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            return ((VarsTable) getDataMapTable()).validateColumnName(newValue, beanPosition);
        }
    });
    column.setCellEditor(cellEditor);
}
Also used : CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) Zone(org.talend.designer.mapper.ui.visualmap.zone.Zone) DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) VarTableEntry(org.talend.designer.mapper.model.tableentry.VarTableEntry) CheckboxTableEditorContent(org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent) JavaTypeComboValueAdapter(org.talend.core.ui.metadata.celleditor.JavaTypeComboValueAdapter) IBeanPropertyAccessors(org.talend.commons.utils.data.bean.IBeanPropertyAccessors) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ExtendedTextCellEditor(org.talend.commons.ui.runtime.swt.tableviewer.celleditor.ExtendedTextCellEditor) ModifiedObjectInfo(org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 18 with ComboBoxCellEditor

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

the class InputDataMapTableView method getMapSettingValueAccess.

@Override
protected IBeanPropertyAccessors<GlobalMapEntry, Object> getMapSettingValueAccess(final CellEditor cellEditor) {
    return new IBeanPropertyAccessors<GlobalMapEntry, Object>() {

        public Object get(GlobalMapEntry bean) {
            IDataMapTable parent = bean.getParent();
            InputTable inputTable = (InputTable) parent;
            if (cellEditor instanceof ComboBoxCellEditor) {
                ComboBoxCellEditor functComboBox = (ComboBoxCellEditor) cellEditor;
                if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
                    IUILookupMode[] availableJoins = { TMAP_LOOKUP_MODE.LOAD_ONCE, TMAP_LOOKUP_MODE.RELOAD, TMAP_LOOKUP_MODE.CACHE_OR_RELOAD };
                    List<String> names = new ArrayList<String>();
                    for (IUILookupMode availableJoin : availableJoins) {
                        names.add(availableJoin.getLabel());
                    }
                    functComboBox.setItems(names.toArray(new String[names.size()]));
                    final IUILookupMode lookupMode = ((InputTable) parent).getLookupMode();
                    if (lookupMode != null) {
                        return lookupMode.getLabel();
                    }
                } else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
                    IUIMatchingMode[] matchModel = getMatchModel();
                    List<String> names = new ArrayList<String>();
                    for (IUIMatchingMode element : matchModel) {
                        names.add(element.getLabel());
                    }
                    functComboBox.setItems(names.toArray(new String[names.size()]));
                    IUIMatchingMode matchingMode = ((InputTable) parent).getMatchingMode();
                    if (names.contains(matchingMode.getLabel())) {
                        return matchingMode.getLabel();
                    }
                } else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
                    String[] items = new String[] { INNER_JOIN, LEFT_OUTER_JOIN };
                    functComboBox.setItems(items);
                    boolean innerJoin = ((InputTable) parent).isInnerJoin();
                    if (innerJoin) {
                        return items[0];
                    }
                    return items[1];
                } else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
                    functComboBox.setItems(new String[] { "true", "false" });
                    boolean persistent = ((InputTable) parent).isPersistent();
                    return String.valueOf(persistent);
                }
            } else if (cellEditor instanceof CustomDialogCellEditor) {
                CustomDialogCellEditor customDialogCellEditor = (CustomDialogCellEditor) cellEditor;
                if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.LOOKUP_MODEL);
                    final IUILookupMode lookupMode = inputTable.getLookupMode();
                    if (lookupMode != null) {
                        return lookupMode.getLabel();
                    }
                } else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.MATCH_MODEL);
                    IUIMatchingMode matchingMode = inputTable.getMatchingMode();
                    if (matchingMode != null) {
                        return matchingMode.getLabel();
                    }
                } else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.JOIN_MODEL);
                    boolean innerJoin = inputTable.isInnerJoin();
                    return innerJoin ? INNER_JOIN : LEFT_OUTER_JOIN;
                } else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.BOOL);
                    boolean persistent = inputTable.isPersistent();
                    return String.valueOf(persistent);
                } else if (SCHEMA_TYPE.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.SCHEMA_TYPE);
                    enableDiaplayViewer(inputTable.isRepository());
                    return inputTable.isRepository() ? REPOSITORY : BUILT_IN;
                } else if (SCHEMA_ID.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.SCHEMA_ID);
                    return getSchemaDisplayName(inputTable.getId());
                }
            }
            return "";
        }

        public void set(GlobalMapEntry bean, Object value) {
            IDataMapTable parent = bean.getParent();
            InputTable inputTable = (InputTable) parent;
            if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
                IUILookupMode[] availableJoins = { TMAP_LOOKUP_MODE.LOAD_ONCE, TMAP_LOOKUP_MODE.RELOAD, TMAP_LOOKUP_MODE.CACHE_OR_RELOAD };
                for (final IUILookupMode lookupMode : availableJoins) {
                    if (value != null && value.equals(lookupMode.getLabel())) {
                        inputTable.setLookupMode(lookupMode);
                        if (TMAP_LOOKUP_MODE.CACHE_OR_RELOAD == lookupMode) {
                            persistentCheckEditable = false;
                        } else {
                            persistentCheckEditable = true;
                        }
                        if (lookupMode == TMAP_LOOKUP_MODE.RELOAD || lookupMode == TMAP_LOOKUP_MODE.CACHE_OR_RELOAD) {
                            showTableGlobalMap(true);
                        } else {
                            showTableGlobalMap(false);
                        }
                        enableDisablePersistentMode((TMAP_LOOKUP_MODE) lookupMode);
                        mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
                        checkChangementsAfterEntryModifiedOrAdded(true);
                    }
                }
            } else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
                for (IUIMatchingMode model : TMAP_MATCHING_MODE.values()) {
                    if (value != null && value.equals(model.getLabel())) {
                        inputTable.setMatchingMode(model);
                        previousMatchingModeSelected = model;
                    }
                }
            } else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
                if (LEFT_OUTER_JOIN.equals(value)) {
                    ((InputTable) parent).setInnerJoin(false);
                    previousInnerJoinSelection = false;
                } else {
                    ((InputTable) parent).setInnerJoin(true);
                    previousInnerJoinSelection = true;
                }
            } else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
                if ("true".equals(value) || "false".equals(value)) {
                    ((InputTable) parent).setPersistent(Boolean.valueOf(value.toString()));
                    previousValidPersistentMode = Boolean.valueOf(value.toString());
                }
            } else if (SCHEMA_TYPE.equals(bean.getName())) {
                inputTable.setRepository(REPOSITORY.equals(value));
                showSchemaIDSetting(REPOSITORY.equals(value));
                enableDiaplayViewer(REPOSITORY.equals(value));
            } else if (SCHEMA_ID.equals(bean.getName())) {
                inputTable.setId(String.valueOf(value));
            }
            refreshCondensedImage((InputTable) bean.getParent(), bean.getName());
        }
    };
}
Also used : IUILookupMode(org.talend.designer.mapper.model.table.IUILookupMode) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) IUIMatchingMode(org.talend.designer.mapper.model.table.IUIMatchingMode) InputTable(org.talend.designer.mapper.model.table.InputTable) IBeanPropertyAccessors(org.talend.commons.utils.data.bean.IBeanPropertyAccessors) List(java.util.List) ArrayList(java.util.ArrayList) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry)

Example 19 with ComboBoxCellEditor

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

the class PropertiesTableByRowEditorView method createColumns.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.commons.ui.swt.advanced.dataeditor.AbstractDataTableEditorView#createColumns(org.talend.commons.ui
     * .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
     */
@Override
protected void createColumns(TableViewerCreator<B> tableViewerCreator, 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 = null;
    // final Element elem = model.getElement();
    final IElementParameter param = model.getElemParameter();
    final IElement element = model.getElement();
    if (element instanceof Node) {
        List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
        List<String> names = new ArrayList<String>();
        for (IConnection con : listConnection) {
            names.add(con.getName());
        }
        titles = new String[names.size()];
        for (int i = 0; i < names.size(); i++) {
            titles[i] = names.get(i);
        }
    }
    if (titles != null && titles.length > 0) {
        for (int i = 0; i < titles.length; i++) {
            final int curCol = i;
            boolean toDisplay = true;
            if (toDisplay) {
                final TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
                column.setTitle(titles[i]);
                column.setModifiable(true);
                column.setMinimumWidth(100);
                column.setWeight(20);
                String[] stringToDisplay = null;
                if (element instanceof Node) {
                    List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
                    for (IConnection con : listConnection) {
                        if (con.getName().equals(titles[i])) {
                            List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
                            stringToDisplay = new String[columns.size()];
                            for (int j = 0; j < columns.size(); j++) {
                                stringToDisplay[j] = columns.get(j).getLabel();
                            }
                        }
                    }
                }
                final EditableComboBoxCellEditor cellEditor = new EditableComboBoxCellEditor(table, stringToDisplay);
                // column.setLabelProvider(new IColumnLabelProvider() {
                //
                // @Override
                // public String getLabel(Object bean) {
                // if (bean instanceof Map) {
                // Map valueMap = (Map) bean;
                // String columnName = column.getTitle();
                // if (valueMap.containsKey(columnName)) {
                // String value = (String) valueMap.get(columnName);
                // return value;
                // }
                // }
                //                            return ""; //$NON-NLS-1$
                // }
                // });
                // column.setCellEditor(cellEditor);
                column.setCellEditor(cellEditor, new CellEditorValueAdapter() {

                    @Override
                    public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorValue) {
                        Map valueMap = (Map) bean;
                        String columnName = column.getTitle();
                        if (valueMap.containsKey(columnName)) {
                            String value = (String) valueMap.get(columnName);
                            return value;
                        }
                        return "";
                    }

                    @Override
                    public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
                        Object returnedValue = null;
                        CCombo combo = (CCombo) cellEditor.getControl();
                        int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
                        String[] listToDisplay = getItem(element, column.getTitle());
                        if (!Arrays.equals(listToDisplay, ((ComboBoxCellEditor) cellEditor).getItems())) {
                            ((ComboBoxCellEditor) cellEditor).setItems(listToDisplay);
                        }
                        if (cellEditorTypedValue != null && cellEditorTypedValue instanceof String) {
                            return cellEditorTypedValue;
                        }
                        return "";
                    }

                    ;

                    @Override
                    public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
                        CCombo combo = (CCombo) cellEditor.getControl();
                        int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
                        String[] listToDisplay = getItem(element, column.getTitle());
                        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;
                    }

                    ;

                    private String[] getItem(IElement element, String columnName) {
                        List<String> stringToDisplay = new ArrayList<String>();
                        if (element instanceof Node) {
                            List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
                            for (IConnection con : listConnection) {
                                if (con.getName().equals(columnName)) {
                                    List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
                                    for (IMetadataColumn column : columns) {
                                        stringToDisplay.add(column.getLabel());
                                    }
                                }
                            }
                        }
                        String[] listToDisplay = stringToDisplay.toArray(new String[0]);
                        return listToDisplay;
                    }
                });
                column.setColumnCellModifier(new ColumnCellModifier(column) {

                    @Override
                    public boolean canModify(Object bean) {
                        boolean canModify = super.canModify(bean);
                        return canModify;
                    }

                    @Override
                    public Object getValue(Object bean) {
                        Map valueMap = (Map) bean;
                        String columnName = column.getTitle();
                        if (valueMap.containsKey(columnName)) {
                            String value = (String) valueMap.get(columnName);
                            return value;
                        }
                        return "";
                    }
                });
                column.setBeanPropertyAccessors(new IBeanPropertyAccessors<B, Object>() {

                    @Override
                    public Object get(B bean) {
                        Map valueMap = (Map) bean;
                        String columnName = column.getTitle();
                        if (valueMap.containsKey(columnName)) {
                            return valueMap.get(columnName);
                        }
                        return "";
                    }

                    @Override
                    public void set(B bean, Object value) {
                        if (value == null) {
                            return;
                        }
                        Map valueMap = (Map) bean;
                        String columnName = column.getTitle();
                        if (valueMap.containsKey(columnName)) {
                            valueMap.remove(columnName);
                            valueMap.put(columnName, value);
                        } else {
                            valueMap.put(columnName, value);
                        }
                    }
                });
            }
        }
    }
}
Also used : TalendProposalProvider(org.talend.core.ui.proposal.TalendProposalProvider) EditableComboBoxCellEditor(org.talend.commons.ui.swt.tableviewer.celleditor.EditableComboBoxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) IConnection(org.talend.core.model.process.IConnection) ColumnCellModifier(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IElement(org.talend.core.model.process.IElement) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) CCombo(org.eclipse.swt.custom.CCombo) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) EditableComboBoxCellEditor(org.talend.commons.ui.swt.tableviewer.celleditor.EditableComboBoxCellEditor) Map(java.util.Map)

Example 20 with ComboBoxCellEditor

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

the class XmlTreeSchemaTableView method createColumns.

@Override
protected void createColumns(final TableViewerCreator<TreeNode> tableViewerCreator, Table table) {
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("XPath");
    column.setId(ID_COLUMN_XPATH);
    column.setWeight(20);
    column.setModifiable(true);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Object>() {

        @Override
        public Object get(TreeNode bean) {
            return bean.getXpath();
        }

        @Override
        public void set(TreeNode bean, Object value) {
            if (isValidName) {
                bean.setName((String) value);
                // String xPath = bean.getXPath();
                // xPath = xPath.substring(0, xPath.lastIndexOf(XmlMapUtil.XPATH_SEPARATOR) + 1);
                // NodeType nodeType = bean.getTreeNode().getNodeType();
                // String typedValue = null;
                // if (NodeType.ATTRIBUT.equals(nodeType)) {
                // typedValue = xPath + XmlMapUtil.XPATH_ATTRIBUTE + bean.getName();
                // } else if (NodeType.NAME_SPACE.equals(nodeType)) {
                // typedValue = xPath + XmlMapUtil.XPATH_NAMESPACE + bean.getName();
                // } else {
                // typedValue = xPath + bean.getName();
                // }
                // bean.setXPath(typedValue);
                XmlMapData mapperData = XmlMapUtil.getXmlMapData(bean);
                XmlMapExpressionManager expressionManager = new XmlMapExpressionManager();
                XmlMapUtil.updateXPathAndExpression(mapperData, expressionManager, bean, bean.getName(), XmlMapUtil.getXPathLength(bean.getXpath()), true);
                if (!bean.getChildren().isEmpty()) {
                    refresh();
                }
            }
        }
    });
    final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
    cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {

        @Override
        public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            return validateXPath(newValue, beanPosition);
        }
    });
    column.setCellEditor(cellEditor);
    column.setColumnCellModifier(new ColumnCellModifier(column) {

        @Override
        public Object getValue(Object bean) {
            TreeNode entry = (TreeNode) bean;
            return entry.getName();
        }

        @Override
        public boolean modify(Object bean, Object value) {
            return false;
        }
    });
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Key");
    column.setToolTipHeader("Key");
    column.setId(ID_COLUMN_KEY);
    //$NON-NLS-1$
    column.setDisplayedValue("");
    column.setWeight(10);
    column.setModifiable(true);
    CheckboxTableEditorContent checkbox = new CheckboxTableEditorContent();
    column.setTableEditorContent(checkbox);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Boolean>() {

        @Override
        public Boolean get(TreeNode bean) {
            return bean.isKey();
        }

        @Override
        public void set(TreeNode bean, Boolean value) {
            bean.setKey(value);
        }
    });
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Type");
    column.setToolTipHeader("Type");
    column.setId(ID_COLUMN_TYPE);
    column.setBeanPropertyAccessors(getTalendTypeAccessor());
    column.setModifiable(true);
    column.setWeight(20);
    TreeSchemaJavaTypeComboValueAdapter comboValueAdapter = new TreeSchemaJavaTypeComboValueAdapter<TreeNode>(JavaTypesManager.getDefaultJavaType(), getNullableAccessor());
    ComboBoxCellEditor typeComboEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), comboValueAdapter.getTalendTypesLabels(), SWT.READ_ONLY);
    CCombo typeCombo = (CCombo) typeComboEditor.getControl();
    typeCombo.setEditable(false);
    column.setCellEditor(typeComboEditor, comboValueAdapter);
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Nullable");
    column.setToolTipHeader("Nullable");
    column.setId(ID_COLUMN_NULLABLE);
    column.setBeanPropertyAccessors(getNullableAccessor());
    column.setWeight(20);
    //$NON-NLS-1$
    column.setDisplayedValue("");
    column.setModifiable(true);
    column.setTableColumnSelectionListener(new CheckColumnSelectionListener(column, tableViewerCreator));
    column.setImageHeader(ImageProvider.getImage(EImage.CHECKED_ICON));
    CheckboxTableEditorContent nullableCheckbox = new CheckboxTableEditorContent();
    column.setTableEditorContent(nullableCheckbox);
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Pattern");
    column.setId(ID_COLUMN_PATTERN);
    column.setWeight(20);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, String>() {

        @Override
        public String get(TreeNode bean) {
            return bean.getPattern();
        }

        @Override
        public void set(TreeNode bean, String value) {
            bean.setPattern(value);
        }
    });
    final ColumnCellModifier columnCellModifier = new ColumnCellModifier(column) {

        @Override
        public boolean canModify(Object bean) {
            boolean typeIsDate = currentBeanHasJavaDateType(bean) && !isReadOnly();
            return typeIsDate;
        }
    };
    column.setColorProvider(new IColumnColorProvider() {

        @Override
        public Color getBackgroundColor(Object bean) {
            if (!columnCellModifier.canModify(bean)) {
                return READONLY_CELL_BG_COLOR;
            }
            return null;
        }

        @Override
        public Color getForegroundColor(Object bean) {
            return null;
        }
    });
    column.setLabelProvider(new IColumnLabelProvider() {

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.commons.ui.swt.tableviewer.behavior.IColumnLabelProvider#getLabel(java.lang.Object)
             */
        @Override
        public String getLabel(Object bean) {
            if (!currentBeanHasJavaDateType(bean)) {
                //$NON-NLS-1$
                return "";
            }
            return null;
        }
    });
    column.setColumnCellModifier(columnCellModifier);
    JavaSimpleDateFormatProposalProvider proposalProvider = new JavaSimpleDateFormatProposalProvider();
    TextCellEditorWithProposal patternCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), column);
    ContentProposalAdapterExtended contentProposalAdapter = patternCellEditor.getContentProposalAdapter();
    contentProposalAdapter.setFilterStyle(ContentProposalAdapterExtended.FILTER_NONE);
    contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapterExtended.PROPOSAL_INSERT);
    patternCellEditor.setContentProposalProvider(proposalProvider);
    column.setCellEditor(patternCellEditor, CellEditorValueAdapterFactory.getNullToEmptyStringTextAdapater());
    tableViewerCreator.setCellModifier(new XmlCellModifier(tableViewerCreator));
}
Also used : DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) CheckColumnSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CheckColumnSelectionListener) JavaSimpleDateFormatProposalProvider(org.talend.core.ui.proposal.JavaSimpleDateFormatProposalProvider) ColumnCellModifier(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier) ContentProposalAdapterExtended(org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlMapExpressionManager(org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager) IColumnColorProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData) IColumnLabelProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnLabelProvider) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) Color(org.eclipse.swt.graphics.Color) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) CCombo(org.eclipse.swt.custom.CCombo) CheckboxTableEditorContent(org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Aggregations

ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)25 CellEditor (org.eclipse.jface.viewers.CellEditor)15 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)13 CCombo (org.eclipse.swt.custom.CCombo)10 Composite (org.eclipse.swt.widgets.Composite)8 CellEditorValueAdapter (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter)8 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 List (java.util.List)6 GridData (org.eclipse.swt.layout.GridData)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Label (org.eclipse.swt.widgets.Label)6 HashMap (java.util.HashMap)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 Button (org.eclipse.swt.widgets.Button)4 Text (org.eclipse.swt.widgets.Text)4 IBeanPropertyAccessors (org.talend.commons.utils.data.bean.IBeanPropertyAccessors)4 IConnection (org.talend.core.model.process.IConnection)4