Search in sources :

Example 1 with DefaultTableLabelProvider

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

the class OutputDataMapTableView method createFiltersTable.

protected void createFiltersTable() {
    this.extendedTableViewerForFilters = new AbstractExtendedTableViewer<FilterTableEntry>(((OutputTable) abstractDataMapTable).getTableFiltersEntriesModel(), centerComposite) {

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

        /*
             * (non-Javadoc)
             * 
             * @see
             * org.talend.commons.ui.swt.extended.macrotable.AbstractExtendedTableViewer#setTableViewerCreatorOptions
             * (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)
             */
        @Override
        protected void setTableViewerCreatorOptions(TableViewerCreator<FilterTableEntry> newTableViewerCreator) {
            super.setTableViewerCreatorOptions(newTableViewerCreator);
            newTableViewerCreator.setColumnsResizableByDefault(false);
            newTableViewerCreator.setBorderVisible(false);
            newTableViewerCreator.setLayoutMode(LAYOUT_MODE.FILL_HORIZONTAL);
            newTableViewerCreator.setKeyboardManagementForCellEdition(true);
            // tableViewerCreatorForColumns.setUseCustomItemColoring(this.getDataMapTable()
            // instanceof
            // AbstractInOutTable);
            newTableViewerCreator.setFirstColumnMasked(true);
        }
    };
    tableViewerCreatorForFilters = this.extendedTableViewerForFilters.getTableViewerCreator();
    this.extendedTableViewerForFilters.setCommandStack(mapperManager.getCommandStack());
    tableForConstraints = tableViewerCreatorForFilters.getTable();
    tableForConstraintsGridData = new GridData(GridData.FILL_HORIZONTAL);
    tableForConstraints.setLayoutData(tableForConstraintsGridData);
    boolean tableConstraintsVisible = false;
    if (abstractDataMapTable instanceof OutputTable) {
        tableConstraintsVisible = ((OutputTable) abstractDataMapTable).getFilterEntries().size() > 0;
    }
    tableForConstraintsGridData.exclude = !tableConstraintsVisible;
    tableForConstraints.setVisible(tableConstraintsVisible);
    if (!mapperManager.componentIsReadOnly()) {
        new DragNDrop(mapperManager, tableForConstraints, false, true);
    }
    tableViewerCreatorForFilters.addCellValueModifiedListener(new ITableCellValueModifiedListener() {

        public void cellValueModified(TableCellValueModifiedEvent e) {
            unselectAllEntriesIfErrorDetected(e);
        }
    });
    final TableViewer tableViewer = tableViewerCreatorForFilters.getTableViewer();
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            selectThisDataMapTableView();
            UIManager uiManager = mapperManager.getUiManager();
            uiManager.selectLinks(OutputDataMapTableView.this, uiManager.extractSelectedTableEntries(selection), false, false);
        }
    });
    tableForConstraints.addListener(SWT.KeyDown, new Listener() {

        public void handleEvent(Event event) {
            processEnterKeyDown(tableViewerCreatorForFilters, event);
        }
    });
    tableViewerCreatorForFilters.setLabelProvider(new DefaultTableLabelProvider(tableViewerCreatorForFilters) {

        @Override
        public Color getBackground(Object element, int columnIndex) {
            return getBackgroundCellColor(tableViewerCreator, element, columnIndex);
        }

        @Override
        public Color getForeground(Object element, int columnIndex) {
            return getForegroundCellColor(tableViewerCreator, element, columnIndex);
        }
    });
    initShowMessageErrorListener(tableForConstraints);
}
Also used : IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) Table(org.eclipse.swt.widgets.Table) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Color(org.eclipse.swt.graphics.Color) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) UIManager(org.talend.designer.mapper.managers.UIManager) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) OutputTable(org.talend.designer.mapper.model.table.OutputTable) DragNDrop(org.talend.designer.mapper.ui.dnd.DragNDrop) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) DefaultTableLabelProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultTableLabelProvider) FocusEvent(org.eclipse.swt.events.FocusEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) Event(org.eclipse.swt.widgets.Event) TableViewer(org.eclipse.jface.viewers.TableViewer) AbstractExtendedTableViewer(org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer)

Example 2 with DefaultTableLabelProvider

use of org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultTableLabelProvider 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 3 with DefaultTableLabelProvider

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

the class InputDataMapTableView method createGlobalMapTable.

protected void createGlobalMapTable() {
    this.extendedTableViewerForGlobalMap = new AbstractExtendedTableViewer<GlobalMapEntry>(((InputTable) abstractDataMapTable).getTableGlobalMapEntriesModel(), centerComposite) {

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

        /*
             * (non-Javadoc)
             * 
             * @see
             * org.talend.commons.ui.swt.extended.macrotable.AbstractExtendedTableViewer#setTableViewerCreatorOptions
             * (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)
             */
        @Override
        protected void setTableViewerCreatorOptions(TableViewerCreator<GlobalMapEntry> newTableViewerCreator) {
            super.setTableViewerCreatorOptions(newTableViewerCreator);
            newTableViewerCreator.setColumnsResizableByDefault(true);
            newTableViewerCreator.setShowLineSelection(SHOW_ROW_SELECTION.FULL);
            newTableViewerCreator.setBorderVisible(false);
            newTableViewerCreator.setLayoutMode(LAYOUT_MODE.FILL_HORIZONTAL);
            newTableViewerCreator.setKeyboardManagementForCellEdition(true);
            newTableViewerCreator.setHorizontalScroll(false);
            newTableViewerCreator.setVerticalScroll(false);
            // tableViewerCreatorForColumns.setUseCustomItemColoring(this.getDataMapTable()
            // instanceof
            // AbstractInOutTable);
            newTableViewerCreator.setFirstColumnMasked(true);
        }
    };
    tableViewerCreatorForGlobalMap = this.extendedTableViewerForGlobalMap.getTableViewerCreator();
    if (mapperManager.componentIsReadOnly()) {
        tableViewerCreatorForGlobalMap.setReadOnly(true);
    }
    this.extendedTableViewerForGlobalMap.setCommandStack(mapperManager.getCommandStack());
    tableForGlobalMap = tableViewerCreatorForGlobalMap.getTable();
    tableForGlobalMapGridData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    tableForGlobalMap.setLayoutData(tableForGlobalMapGridData);
    boolean tableGlobalMapVisible = false;
    if (abstractDataMapTable instanceof InputTable) {
        IUILookupMode lookupMode = ((InputTable) abstractDataMapTable).getLookupMode();
        tableGlobalMapVisible = lookupMode == TMAP_LOOKUP_MODE.RELOAD || lookupMode == TMAP_LOOKUP_MODE.CACHE_OR_RELOAD;
    }
    tableForGlobalMapGridData.exclude = !tableGlobalMapVisible;
    tableForGlobalMap.setVisible(tableGlobalMapVisible);
    if (!mapperManager.componentIsReadOnly()) {
        new DragNDrop(mapperManager, tableForGlobalMap, false, true);
    }
    tableViewerCreatorForGlobalMap.addCellValueModifiedListener(new ITableCellValueModifiedListener() {

        public void cellValueModified(TableCellValueModifiedEvent e) {
            unselectAllEntriesIfErrorDetected(e);
        }
    });
    final TableViewer tableViewer = tableViewerCreatorForGlobalMap.getTableViewer();
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            selectThisDataMapTableView();
            UIManager uiManager = mapperManager.getUiManager();
            uiManager.selectLinks(InputDataMapTableView.this, uiManager.extractSelectedTableEntries(selection), false, false);
        }
    });
    tableForGlobalMap.addListener(SWT.KeyDown, new Listener() {

        public void handleEvent(Event event) {
            processEnterKeyDown(tableViewerCreatorForGlobalMap, event);
        }
    });
    tableViewerCreatorForGlobalMap.setLabelProvider(new DefaultTableLabelProvider(tableViewerCreatorForGlobalMap) {

        @Override
        public Color getBackground(Object element, int columnIndex) {
            return getBackgroundCellColor(tableViewerCreator, element, columnIndex);
        }

        @Override
        public Color getForeground(Object element, int columnIndex) {
            return getForegroundCellColor(tableViewerCreator, element, columnIndex);
        }
    });
    initShowMessageErrorListener(tableForGlobalMap);
}
Also used : IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) InputTable(org.talend.designer.mapper.model.table.InputTable) Table(org.eclipse.swt.widgets.Table) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) DefaultHeaderColumnSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultHeaderColumnSelectionListener) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArmListener(org.eclipse.swt.events.ArmListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) IUILookupMode(org.talend.designer.mapper.model.table.IUILookupMode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Color(org.eclipse.swt.graphics.Color) UIManager(org.talend.designer.mapper.managers.UIManager) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) Point(org.eclipse.swt.graphics.Point) InputTable(org.talend.designer.mapper.model.table.InputTable) DragNDrop(org.talend.designer.mapper.ui.dnd.DragNDrop) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) DefaultTableLabelProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultTableLabelProvider) FocusEvent(org.eclipse.swt.events.FocusEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry) TableViewer(org.eclipse.jface.viewers.TableViewer) AbstractExtendedTableViewer(org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer)

Aggregations

Color (org.eclipse.swt.graphics.Color)3 GridData (org.eclipse.swt.layout.GridData)3 Table (org.eclipse.swt.widgets.Table)3 DefaultTableLabelProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultTableLabelProvider)3 ITableCellValueModifiedListener (org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener)3 TableCellValueModifiedEvent (org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent)3 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)3 ISelection (org.eclipse.jface.viewers.ISelection)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 FocusEvent (org.eclipse.swt.events.FocusEvent)2 FocusListener (org.eclipse.swt.events.FocusListener)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 AbstractExtendedTableViewer (org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer)2 UIManager (org.talend.designer.mapper.managers.UIManager)2 AbstractInOutTable (org.talend.designer.mapper.model.table.AbstractInOutTable)2 DragNDrop (org.talend.designer.mapper.ui.dnd.DragNDrop)2 ArmEvent (org.eclipse.swt.events.ArmEvent)1