Search in sources :

Example 1 with CELL_EDITOR_STATE

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

the class ExtractionLoopWithJSONXPathEditorView 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<JSONXPathLoopDescriptor> 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;
    column.setTitle("Absolute path expression");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<JSONXPathLoopDescriptor, String>() {

        @Override
        public String get(JSONXPathLoopDescriptor bean) {
            return bean.getAbsoluteXPathQuery();
        }

        @Override
        public void set(JSONXPathLoopDescriptor bean, String value) {
            String currentFlag = ConvertJSONString.getCurrentFlag();
            bean.setAbsoluteXPathQuery(value);
            bean.setFlag(currentFlag);
        }
    });
    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.APPLYING) {
            // linker.onXPathValueChanged(table, newValue.toString(), itemIndex);
            }
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            return linker.validateXPathExpression(newValue);
        }
    });
    column.setModifiable(true);
    column.setWeight(30);
    column.setMinimumWidth(50);
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    // //////////////////////////////////////////////////////////////////////////////////////
    // //////////////////////////////////////////////////////////////////////////////////////
    // Loop limit
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Loop limit");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<JSONXPathLoopDescriptor, Integer>() {

        @Override
        public Integer get(JSONXPathLoopDescriptor bean) {
            return bean.getLimitBoucle();
        }

        @Override
        public void set(JSONXPathLoopDescriptor bean, Integer value) {
            if (value != null) {
                bean.setLimitBoucle(value.intValue());
            } else {
                bean.setLimitBoucle(0);
            }
        }
    });
    column.setModifiable(true);
    column.setWidth(59);
    column.setCellEditor(new TextCellEditor(table), intValueAdapter);
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) 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) ConvertJSONString(org.talend.repository.json.util.ConvertJSONString) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 2 with CELL_EDITOR_STATE

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

the class AbstractHL7MetadataTableEditorView method configureNameColumn.

/**
     * DOC amaumont Comment method "configureNameColumn".
     * 
     * @param tableViewerCreator
     */
protected void configureNameColumn(TableViewerCreator<B> tableViewerCreator) {
    TableViewerCreatorColumn column;
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setId(ID_COLUMN_NAME);
    //$NON-NLS-1$
    column.setTitle("User Column(Click to edit)");
    //$NON-NLS-1$
    column.setToolTipHeader(Messages.getString("MetadataTableEditorView.ColumnTitle"));
    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((B) element)) {
                return imageKey;
            } else {
                return imageEmpty;
            }
        }
    });
    column.setWeight(25);
    column.setModifiable(!isReadOnly());
    column.setMinimumWidth(45);
    // 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 validateColumnName(newValue, beanPosition);
    // }
    //
    // });
    // column.setCellEditor(cellEditor);
    nameColumn = column;
}
Also used : 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) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage)

Example 3 with CELL_EDITOR_STATE

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE 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 4 with CELL_EDITOR_STATE

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE 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 5 with CELL_EDITOR_STATE

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

Aggregations

CELL_EDITOR_STATE (org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE)6 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)6 DialogErrorForCellEditorListener (org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener)6 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)5 CellEditorValueAdapter (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter)3 TextCellEditorWithProposal (org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal)3 CellEditor (org.eclipse.jface.viewers.CellEditor)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 Image (org.eclipse.swt.graphics.Image)2 EImage (org.talend.commons.ui.runtime.image.EImage)2 IColumnImageProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnImageProvider)2 CheckboxTableEditorContent (org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent)2 CCombo (org.eclipse.swt.custom.CCombo)1 Color (org.eclipse.swt.graphics.Color)1 CheckColumnSelectionListener (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CheckColumnSelectionListener)1 ColumnCellModifier (org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier)1 IColumnColorProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider)1 IColumnLabelProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnLabelProvider)1 ExtendedTextCellEditor (org.talend.commons.ui.runtime.swt.tableviewer.celleditor.ExtendedTextCellEditor)1 ModifiedObjectInfo (org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo)1