Search in sources :

Example 1 with TableViewerCreatorColumnNotModifiable

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

the class DataMapTableView method createTableForColumns.

/**
     * DOC amaumont Comment method "createTableForColumns".
     * 
     * @param parent
     */
private void createTableForColumns(Composite parent) {
    this.extendedTableViewerForColumns = new AbstractExtendedTableViewer<IColumnEntry>(abstractDataMapTable.getTableColumnsEntriesModel(), parent) {

        @Override
        protected void createColumns(TableViewerCreator<IColumnEntry> tableViewerCreator, Table table) {
            initColumnsOfTableColumns(tableViewerCreator);
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer#initTableListeners()
             */
        @Override
        protected void initTableListeners() {
            super.initTableListeners();
            getTableViewerCreator().addCellValueModifiedListener(new ITableCellValueModifiedListener() {

                @Override
                public void cellValueModified(TableCellValueModifiedEvent e) {
                    // System.out.println();
                    // System.out.println(getTable().hashCode());
                    // System.out.println(e.tableItem.getParent().hashCode());
                    // if (e.tableItem.getParent().isFocusControl()) {
                    // only if table of item is actually the focus control
                    getTableViewerCreator().getSelectionHelper().deselectAll();
                    getTable().forceFocus();
                // }
                }
            });
        }

        /*
             * (non-Javadoc)
             * 
             * @see
             * org.talend.commons.ui.swt.extended.macrotable.AbstractExtendedTableViewer#setTableViewerCreatorOptions
             * (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)
             */
        @Override
        protected void setTableViewerCreatorOptions(final TableViewerCreator<IColumnEntry> newTableViewerCreator) {
            super.setTableViewerCreatorOptions(newTableViewerCreator);
            newTableViewerCreator.setColumnsResizableByDefault(true);
            newTableViewerCreator.setBorderVisible(false);
            newTableViewerCreator.setLayoutMode(LAYOUT_MODE.FILL_HORIZONTAL);
            newTableViewerCreator.setKeyboardManagementForCellEdition(false);
            // tableViewerCreatorForColumns.setUseCustomItemColoring(this.getDataMapTable() instanceof
            // AbstractInOutTable);
            newTableViewerCreator.setFirstColumnMasked(true);
            if (getDataMapTable() instanceof AbstractInOutTable) {
                if (imageKey == null) {
                    imageKey = org.talend.commons.ui.runtime.image.ImageProvider.getImage(EImage.KEY_ICON);
                }
                if (imageEmpty == null) {
                    imageEmpty = org.talend.commons.ui.runtime.image.ImageProvider.getImage(EImage.EMPTY);
                }
            }
            newTableViewerCreator.setLabelProvider(new DefaultTableLabelProvider(newTableViewerCreator) {

                @Override
                public Color getBackground(Object element, int columnIndex) {
                    Color backgroundCellColor = getBackgroundCellColor(newTableViewerCreator, element, columnIndex);
                    if (backgroundCellColor != null) {
                        return backgroundCellColor;
                    }
                    return super.getBackground(element, columnIndex);
                }

                @Override
                public Color getForeground(Object element, int columnIndex) {
                    Color foregroundCellColor = getForegroundCellColor(newTableViewerCreator, element, columnIndex);
                    if (foregroundCellColor != null) {
                        return foregroundCellColor;
                    }
                    return getForegroundCellColor(newTableViewerCreator, element, columnIndex);
                }

                @Override
                public Image getColumnImage(Object element, int columnIndex) {
                    return getColumnImageExecute(element, columnIndex);
                }

                /**
                     * DOC amaumont Comment method "getColumnImageExecute".
                     * 
                     * @param element
                     * @param columnIndex
                     * @return
                     */
                private Image getColumnImageExecute(Object element, int columnIndex) {
                    if (getDataMapTable() instanceof AbstractInOutTable) {
                        AbstractInOutTableEntry entry = (AbstractInOutTableEntry) element;
                        TableViewerCreatorColumnNotModifiable column = newTableViewerCreator.getColumns().get(columnIndex);
                        if (column.getId().equals(ID_NAME_COLUMN)) {
                            if (entry.getMetadataColumn().isKey()) {
                                return imageKey;
                            } else {
                                return imageEmpty;
                            }
                        }
                    }
                    return null;
                }
            });
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer#initModelListeners()
             */
        @Override
        protected void initModelListeners() {
            super.initModelListeners();
            getExtendedTableModel().addAfterOperationListListener(100, new IListenableListListener<IColumnEntry>() {

                @Override
                public void handleEvent(ListenableListEvent<IColumnEntry> event) {
                    if (tableViewerCreator.getTable() != null && !tableViewerCreator.getTable().isDisposed()) {
                        if (event.type == TYPE.ADDED) {
                            Collection<IColumnEntry> addedObjects = event.addedObjects;
                            for (IColumnEntry tableEntry : addedObjects) {
                                mapperManager.getProblemsManager().checkProblemsForTableEntry(tableEntry, false);
                            }
                        }
                    }
                }
            });
        }
    };
    tableViewerCreatorForColumns = this.extendedTableViewerForColumns.getTableViewerCreator();
    this.extendedTableViewerForColumns.setCommandStack(mapperManager.getCommandStack());
    tableForEntries = tableViewerCreatorForColumns.getTable();
    GridData tableEntriesGridData = new GridData(GridData.FILL_BOTH);
    tableEntriesGridData.grabExcessVerticalSpace = true;
    tableEntriesGridData.minimumHeight = tableForEntries.getHeaderHeight() + tableForEntries.getItemHeight();
    // tableEntriesGridData.heightHint = 50;
    // tableEntriesGridData.grabExcessVerticalSpace = false;
    tableForEntries.setLayoutData(tableEntriesGridData);
    addTablesListeners();
}
Also used : ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) AbstractInOutTable(org.talend.designer.dbmap.model.table.AbstractInOutTable) OutputTable(org.talend.designer.dbmap.model.table.OutputTable) Table(org.eclipse.swt.widgets.Table) Color(org.eclipse.swt.graphics.Color) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) AbstractInOutTable(org.talend.designer.dbmap.model.table.AbstractInOutTable) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) DefaultTableLabelProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultTableLabelProvider) GridData(org.eclipse.swt.layout.GridData) AbstractInOutTableEntry(org.talend.designer.dbmap.model.tableentry.AbstractInOutTableEntry)

Example 2 with TableViewerCreatorColumnNotModifiable

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

the class MetadataTableEditorViewExt method updateHeader.

public void updateHeader(String id, String currTitle, boolean isHide) {
    final TableViewerCreatorColumnNotModifiable funColumn = getTableViewerCreator().getColumn(id);
    if (isHide) {
        final TableEditorContentNotModifiable tableEditorContent = funColumn.getTableEditorContent();
        if (tableEditorContent != null && tableEditorContent instanceof CheckboxTableEditorContent) {
            funColumn.setTableEditorContent(null);
        }
        //$NON-NLS-1$
        funColumn.getTableColumn().setText("");
        funColumn.getTableColumn().setWidth(0);
        funColumn.setWidth(0);
        funColumn.getTableColumn().setResizable(false);
        funColumn.setMoveable(false);
        if ((id.equals(ID_COLUMN_FUNCTION) && getTableViewerCreator().getColumn(ID_COLUMN_PARAMETER).getTableColumn().getWidth() == 0) || ((id.equals(ID_COLUMN_PARAMETER)) && getTableViewerCreator().getColumn(ID_COLUMN_FUNCTION).getTableColumn().getWidth() == 0)) {
            funCom.setVisible(false);
        }
        if (id.equals(ID_COLUMN_PREVIEW)) {
            preCom.setVisible(false);
        }
        getTableViewerCreator().refreshTableEditorControls();
    } else {
        final TableEditorContentNotModifiable tableEditorContent = funColumn.getTableEditorContent();
        if (tableEditorContent == null && (funColumn.getId().equals(ID_COLUMN_KEY) || funColumn.getId().equals(ID_COLUMN_NULLABLE))) {
            final CheckboxTableEditorContent checkboxTableEditorContent = new CheckboxTableEditorContent();
            checkboxTableEditorContent.setToolTipText(currTitle);
            checkboxTableEditorContent.createTableEditor(getTable());
            funColumn.setTableEditorContent(checkboxTableEditorContent);
        }
        funColumn.setModifiable(!isReadOnly());
        funColumn.setMinimumWidth(35);
        funColumn.getTableColumn().setWidth(65);
        funColumn.getTableColumn().setText(currTitle);
        funColumn.getTableColumn().setResizable(true);
        funColumn.setTitle(currTitle);
        funColumn.setMoveable(true);
        if (id.equals(ID_COLUMN_FUNCTION) || id.equals(ID_COLUMN_PARAMETER)) {
            funCom.setVisible(true);
        }
        if (id.equals(ID_COLUMN_PREVIEW)) {
            preCom.setVisible(true);
        }
        getTableViewerCreator().refreshTableEditorControls();
    }
    attachLabelPosition();
}
Also used : TableEditorContentNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.tableeditor.TableEditorContentNotModifiable) CheckboxTableEditorContent(org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable)

Example 3 with TableViewerCreatorColumnNotModifiable

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

the class TableByRowController method updateConnectionList.

private void updateConnectionList(IElementParameter param) {
    // update table values
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null && itemsValue != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if ((j + 1) >= colList.size()) {
                break;
            }
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.CONNECTION_LIST) {
                    String[] contextParameterNames = null;
                    ConnectionListController.updateConnectionList(elem, tmpParam);
                    contextParameterNames = tmpParam.getListItemsDisplayName();
                    tmpParam.setListItemsDisplayCodeName(contextParameterNames);
                    // tmpParam.setListItemsValue(contextParameterNames);
                    if (contextParameterNames.length > 0) {
                        tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
                    } else {
                        //$NON-NLS-1$
                        tmpParam.setDefaultClosedListValue("");
                    }
                    // j + 1 because first column is masked
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CCombo combo = (CCombo) column.getCellEditor().getControl();
                    String[] oldItems = combo.getItems();
                    combo.setItems(contextParameterNames);
                    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) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with TableViewerCreatorColumnNotModifiable

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

the class TableByRowController 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 && itemsValue != 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) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) 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) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with TableViewerCreatorColumnNotModifiable

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

the class DropContextAnalyzer method analyzeCursorOverExpressionCell.

/**
     * .
     */
@SuppressWarnings("unchecked")
private void analyzeCursorOverExpressionCell() {
    DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(currentTableTarget);
    TableViewerCreator tableViewerCreatorForColumns = dataMapTableView.getTableViewerCreatorForColumns();
    Point pointCursor = currentTableTarget.toControl(event.x, event.y);
    if (tableViewerCreatorForColumns.getTable() != currentTableTarget) {
        isCursorOverExpressionCell = false;
        return;
    }
    int maxY = (WindowSystem.isWIN32() && currentTableTarget.getHeaderVisible() ? currentTableTarget.getHeaderHeight() : 0) + (currentTableTarget.getItemCount() * (currentTableTarget.getItemHeight() + currentTableTarget.getBorderWidth() + (WindowSystem.isGTK() ? 2 : 0)));
    if (pointCursor.y < 0 || pointCursor.y >= maxY) {
        isCursorOverExpressionCell = false;
        return;
    }
    // searching current column index
    int currentColumnIndex = 0;
    TableColumn[] columns = currentTableTarget.getColumns();
    for (int i = 0, width = 0; i < columns.length; i++) {
        TableColumn column = columns[i];
        int widthColumn = column.getWidth();
        if (pointCursor.x >= width && pointCursor.x <= width + widthColumn) {
            currentColumnIndex = i;
            break;
        }
        width += widthColumn;
    }
    List<TableViewerCreatorColumnNotModifiable> viewerColumns = tableViewerCreatorForColumns.getColumns();
    TableViewerCreatorColumnNotModifiable viewerColumn = viewerColumns.get(currentColumnIndex);
    if (DataMapTableView.ID_EXPRESSION_COLUMN.equals(viewerColumn.getId())) {
        isCursorOverExpressionCell = true;
    } else {
        isCursorOverExpressionCell = false;
    }
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) DataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point)

Aggregations

TableViewerCreatorColumnNotModifiable (org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable)23 List (java.util.List)11 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)11 Point (org.eclipse.swt.graphics.Point)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 CCombo (org.eclipse.swt.custom.CCombo)8 IElementParameter (org.talend.core.model.process.IElementParameter)8 CellEditor (org.eclipse.jface.viewers.CellEditor)3 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 ExtendedTextCellEditor (org.talend.commons.ui.runtime.swt.tableviewer.celleditor.ExtendedTextCellEditor)2 ButtonPushImageTableEditorContent (org.talend.commons.ui.runtime.swt.tableviewer.tableeditor.ButtonPushImageTableEditorContent)2 ExtendedTableRemoveCommand (org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTableRemoveCommand)2 IConnection (org.talend.core.model.process.IConnection)2 IContext (org.talend.core.model.process.IContext)2 IContextParameter (org.talend.core.model.process.IContextParameter)2