Search in sources :

Example 31 with TableViewerCreatorColumn

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn 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)

Example 32 with TableViewerCreatorColumn

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.

the class SetLoopFunctionDialog method createDialogArea.

public Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.BORDER);
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    composite.setLayoutData(data);
    tableViwer = new AbstractDataTableEditorView<TreeSchemaTableEntry>(composite, SWT.NONE, tableModel, false, true, false) {

        @Override
        protected void createColumns(TableViewerCreator<TreeSchemaTableEntry> tableViewerCreator, Table table) {
            TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
            column.setTitle("Sequence");
            column.setWeight(40);
            column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeSchemaTableEntry, Object>() {

                public Object get(TreeSchemaTableEntry bean) {
                    int index = getExtendedTableModel().getBeansList().indexOf(bean);
                    return getExtendedTableModel().getBeansList().indexOf(bean);
                }

                public void set(TreeSchemaTableEntry bean, Object value) {
                // do nothing
                }
            });
            column = new TableViewerCreatorColumn(tableViewerCreator);
            column.setTitle("Xpath");
            column.setWeight(60);
            String[] items = new String[inputLoops.size()];
            for (int i = 0; i < inputLoops.size(); i++) {
                items[i] = inputLoops.get(i).getXpath();
            }
            CellEditorValueAdapter comboValueAdapter = CellEditorValueAdapterFactory.getComboAdapterForComboCellEditor("String");
            ComboBoxCellEditor cellEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), items, SWT.READ_ONLY);
            column.setModifiable(true);
            column.setCellEditor(cellEditor, comboValueAdapter);
            column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeSchemaTableEntry, Object>() {

                public Object get(TreeSchemaTableEntry bean) {
                    return bean.getXPath();
                }

                public void set(TreeSchemaTableEntry bean, Object value) {
                    for (TreeNode loopNode : inputLoops) {
                        if (loopNode.getXpath().equals(value)) {
                            bean.setTreeNode(loopNode);
                        }
                    }
                }
            });
        }

        @Override
        protected ExtendedToolbarView initToolBar() {
            ExtendedToolbarView toolbarView = new ExtendedToolbarView(getMainComposite(), SWT.NONE, this.getExtendedTableViewer()) {

                @Override
                protected CopyPushButton createCopyPushButton() {
                    return null;
                }

                @Override
                protected AddPushButton createAddPushButton() {
                    return new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {

                        @Override
                        public boolean getEnabledState() {
                            return super.getEnabledState();
                        }

                        @Override
                        protected Object getObjectToAdd() {
                            TreeNode loopNodetoAdd = null;
                            for (TreeNode loopNode : inputLoops) {
                                boolean found = false;
                                for (TreeSchemaTableEntry extendedModel : getExtendedTableModel().getBeansList()) {
                                    if (loopNode.getXpath().equals(extendedModel.getXPath())) {
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found) {
                                    loopNodetoAdd = loopNode;
                                    break;
                                }
                            }
                            if (loopNodetoAdd == null && !inputLoops.isEmpty()) {
                                loopNodetoAdd = inputLoops.get(0);
                            }
                            if (loopNodetoAdd != null) {
                                TreeSchemaTableEntry entry = new TreeSchemaTableEntry(loopNodetoAdd);
                                return entry;
                            }
                            return null;
                        }
                    };
                }
            };
            return super.initToolBar();
        }
    };
    tableViwer.setGridDataSize(400, 120);
    statusLabel = new Label(composite, SWT.NONE);
    statusLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableModel.addAfterOperationListListener(new IListenableListListener<TreeSchemaTableEntry>() {

        public void handleEvent(ListenableListEvent<TreeSchemaTableEntry> event) {
            updateStatus(true);
        }
    });
    tableModel.setModifiedBeanListenable(tableViwer.getTableViewerCreator());
    tableModel.addModifiedBeanListener(new IModifiedBeanListener<TreeSchemaTableEntry>() {

        public void handleEvent(ModifiedBeanEvent<TreeSchemaTableEntry> event) {
            updateStatus(false);
        }
    });
    return composite;
}
Also used : AddPushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButton) Table(org.eclipse.swt.widgets.Table) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) InputLoopNodesTable(org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) GridLayout(org.eclipse.swt.layout.GridLayout) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) GridData(org.eclipse.swt.layout.GridData) IBeanPropertyAccessors(org.talend.commons.utils.data.bean.IBeanPropertyAccessors) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) CopyPushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.CopyPushButton) TreeSchemaTableEntry(org.talend.designer.xmlmap.ui.tabs.table.TreeSchemaTableEntry) ExtendedToolbarView(org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)

Example 33 with TableViewerCreatorColumn

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn 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 34 with TableViewerCreatorColumn

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.

the class ExtractionFieldsWithJSONXPathEditorView method createColumns.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.commons.ui.swt.advanced.macrotable.AbstractExtendedTableViewer#createColumns(org.talend.commons.ui
     * .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
     */
@Override
protected void createColumns(TableViewerCreator<SchemaTarget> tableViewerCreator, final Table table) {
    CellEditorValueAdapter intValueAdapter = new CellEditorValueAdapter() {

        @Override
        public Object getOriginalTypedValue(final CellEditor cellEditor, Object value) {
            try {
                return new Integer(value.toString());
            } catch (Exception ex) {
                return null;
            }
        }

        @Override
        public Object getCellEditorTypedValue(final CellEditor cellEditor, Object value) {
            if (value != null) {
                return String.valueOf(value);
            }
            //$NON-NLS-1$
            return "";
        }
    };
    // //////////////////////////////////////////////////////////////////////////////////////
    // column for mouse selection
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle("");
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    column.setWidth(15);
    // //////////////////////////////////////////////////////////////////////////////////////
    // X Path Query
    column = new TableViewerCreatorColumn(tableViewerCreator);
    xPathColumn = column;
    //$NON-NLS-1$
    column.setTitle("Relative or absolute path expression");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<SchemaTarget, String>() {

        @Override
        public String get(SchemaTarget bean) {
            return bean.getRelativeXPathQuery();
        }

        @Override
        public void set(SchemaTarget bean, String value) {
            bean.setRelativeXPathQuery(value);
        }
    });
    xPathCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.NONE, column);
    column.setCellEditor(xPathCellEditor);
    xPathCellEditor.addListener(new DialogErrorForCellEditorListener(xPathCellEditor, column) {

        @Override
        public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
            if (state == CELL_EDITOR_STATE.EDITING) {
                linker.onXPathValueChanged(table, newValue.toString(), itemIndex);
            }
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            String currentLoopXPath = linker.getCurrentLoopXPath();
            String value = null;
            if (newValue.trim().length() == 0) {
                return null;
            } else if (newValue.trim().startsWith(linker.getRootSeperator())) {
                value = newValue;
            } else {
                value = currentLoopXPath + linker.getFieldSeperator() + newValue;
            }
            return linker.validateXPathExpression(value);
        }
    });
    column.setModifiable(true);
    column.setWeight(30);
    column.setMinimumWidth(50);
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    // //////////////////////////////////////////////////////////////////////////////////////
    // //////////////////////////////////////////////////////////////////////////////////////
    // Tag Name
    column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle("Column Name");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<SchemaTarget, String>() {

        @Override
        public String get(SchemaTarget bean) {
            return bean.getTagName();
        }

        @Override
        public void set(SchemaTarget bean, String value) {
            bean.setTagName(value);
        }
    });
    column.setModifiable(true);
    column.setWeight(10);
    column.setMinimumWidth(50);
    // column.setCellEditor(new TextCellEditor(table));
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    final TextCellEditorWithProposal tagNameCellEditor = createTagNameEditor(tableViewerCreator, column);
    column.setCellEditor(tagNameCellEditor);
}
Also used : TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) CellEditor(org.eclipse.jface.viewers.CellEditor) DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) SchemaTarget(org.talend.repository.model.json.SchemaTarget) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 35 with TableViewerCreatorColumn

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.

the class JSONFileOutputMetadataEmfTableEditorView method configureNameColumn.

protected void configureNameColumn(TableViewerCreator<MetadataColumn> tableViewerCreator) {
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setId(ID_COLUMN_NAME);
    //$NON-NLS-1$
    column.setTitle("Schema List");
    column.setWidth(100);
    column.setToolTipHeader("Column");
    column.setBeanPropertyAccessors(getLabelAccessor());
    final Image imageKey = ImageProvider.getImage(EImage.KEY_ICON);
    final Image imageEmpty = org.talend.commons.ui.runtime.image.ImageProvider.getImage(EImage.EMPTY);
    final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
    column.setCellEditor(cellEditor);
    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 validateColumnName(newValue, beanPosition);
        }
    });
    column.setImageProvider(new IColumnImageProvider() {

        public Image getImage(Object element) {
            if (getKeyAccesor().get((MetadataColumn) element)) {
                return imageKey;
            } else {
                return imageEmpty;
            }
        }
    });
    column.setWeight(25);
    column.setModifiable(!isReadOnly());
    column.setMinimumWidth(20);
// nameColumn = column;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IColumnImageProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnImageProvider) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) EImage(org.talend.commons.ui.runtime.image.EImage) Image(org.eclipse.swt.graphics.Image)

Aggregations

TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)38 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)14 CellEditorValueAdapter (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter)9 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)8 CCombo (org.eclipse.swt.custom.CCombo)6 Color (org.eclipse.swt.graphics.Color)6 IColumnColorProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider)6 TextCellEditorWithProposal (org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal)6 CheckboxTableEditorContent (org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent)6 List (java.util.List)5 ColumnCellModifier (org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier)5 CELL_EDITOR_STATE (org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE)5 DialogErrorForCellEditorListener (org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener)5 CellEditor (org.eclipse.jface.viewers.CellEditor)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Image (org.eclipse.swt.graphics.Image)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3