Search in sources :

Example 21 with TableViewerCreatorColumn

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

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

the class AbstractHL7MetadataTableEditorView method configureDefaultColumn.

/**
     * DOC amaumont Comment method "configureDefaultColumn".
     * 
     * @param tableViewerCreator
     */
protected void configureDefaultColumn(TableViewerCreator<B> tableViewerCreator) {
    TableViewerCreatorColumn column;
    column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("MetadataTableEditorView.DefaultTitle"));
    //$NON-NLS-1$
    column.setToolTipHeader(Messages.getString("MetadataTableEditorView.DefaultTitle"));
    column.setId(ID_COLUMN_DEFAULT);
    column.setBeanPropertyAccessors(getDefaultValueAccessor());
    column.setWeight(8);
    column.setModifiable(!isReadOnly());
    column.setMinimumWidth(30);
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    column.setCellEditor(new TextCellEditor(tableViewerCreator.getTable()));
}
Also used : TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 23 with TableViewerCreatorColumn

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

the class AbstractHL7MetadataTableEditorView method configureDbColumnName.

/**
     * DOC amaumont Comment method "configureNameColumn".
     * 
     * @param tableViewerCreator
     */
protected void configureDbColumnName(TableViewerCreator<B> tableViewerCreator) {
    TableViewerCreatorColumn column;
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setId(ID_COLUMN_DBCOLUMNNAME);
    //$NON-NLS-1$ 
    column.setTitle("Mapping Column");
    //$NON-NLS-1$
    column.setToolTipHeader(Messages.getString("MetadataTableEditorView.ColumnTitle"));
    column.setBeanPropertyAccessors(getDbColumnNameAccessor());
    column.setWeight(25);
    column.setModifiable(!isReadOnly());
    column.setMinimumWidth(45);
    final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
    column.setCellEditor(cellEditor);
    column.setColumnCellModifier(new ColumnCellModifier(column) {

        @Override
        public boolean canModify(Object bean) {
            return super.canModify(bean) && canModifyDBColumn(bean);
        }
    });
    column.setCellEditorAppliedListener(new ITableCellValueModifiedListener() {

        public void cellValueModified(TableCellValueModifiedEvent e) {
            linker.getMainui().redrawLinkers();
            linker.getBackgroundRefresher().refreshBackground();
        }
    });
    if (!dbColumnNameWritable) {
        column.setColorProvider(new IColumnColorProvider() {

            public Color getBackgroundColor(Object bean) {
                return READONLY_CELL_BG_COLOR;
            }

            public Color getForegroundColor(Object bean) {
                return null;
            }
        });
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) IColumnColorProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) ColumnCellModifier(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier)

Example 24 with TableViewerCreatorColumn

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

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

the class AbstractHL7MetadataTableEditorView method configurePrecisionColumn.

/**
     * DOC amaumont Comment method "configurePrecisionColumn".
     * 
     * @param tableViewerCreator
     */
protected void configurePrecisionColumn(TableViewerCreator<B> tableViewerCreator) {
    TableViewerCreatorColumn column;
    column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("MetadataTableEditorView.PrecisionTitle"));
    //$NON-NLS-1$
    column.setToolTipHeader(Messages.getString("MetadataTableEditorView.PrecisionTitle"));
    column.setId(ID_COLUMN_PRECISION);
    column.setBeanPropertyAccessors(getPrecisionAccessor());
    column.setModifiable(!isReadOnly());
    column.setWeight(10);
    column.setMinimumWidth(10);
    column.setCellEditor(new TextCellEditor(tableViewerCreator.getTable()), CellEditorValueAdapterFactory.getPositiveIntAdapter());
}
Also used : TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

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