Search in sources :

Example 1 with AbstractInOutTableEntry

use of org.talend.designer.dbmap.model.tableentry.AbstractInOutTableEntry 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 AbstractInOutTableEntry

use of org.talend.designer.dbmap.model.tableentry.AbstractInOutTableEntry in project tdi-studio-se by Talend.

the class OutputTable method initFromExternalData.

@Override
public void initFromExternalData(ExternalDbMapTable externalMapperTable) {
    super.initFromExternalData(externalMapperTable);
    List<IMetadataColumn> columns = this.metadataTable.getListColumns();
    Map<String, ExternalDbMapEntry> nameToPerTabEntry = new HashMap<String, ExternalDbMapEntry>();
    if (externalMapperTable != null && externalMapperTable.getMetadataTableEntries() != null) {
        for (ExternalDbMapEntry perTableEntry : externalMapperTable.getMetadataTableEntries()) {
            nameToPerTabEntry.put(perTableEntry.getName(), perTableEntry);
        }
    }
    for (IMetadataColumn column : columns) {
        AbstractInOutTableEntry columnEntry = getNewTableEntry(column);
        ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(columnEntry.getMetadataColumn().getLabel());
        // Entry match with current column
        if (externalMapperTableEntry != null) {
            columnEntry.setExpression(externalMapperTableEntry.getExpression());
        }
        dataMapTableEntries.add(columnEntry);
    }
    if (externalMapperTable != null) {
        List<ExternalDbMapEntry> externalWhereConstraintTableEntries = externalMapperTable.getCustomWhereConditionsEntries();
        if (externalWhereConstraintTableEntries != null) {
            for (ExternalDbMapEntry entry : externalWhereConstraintTableEntries) {
                FilterTableEntry whereFilterTableEntry = new FilterTableEntry(this, entry.getName(), entry.getExpression(), FilterTableEntry.WHERE_FILTER);
                // mapperManager.getProblemsManager().checkProblemsForTableEntry(filterTableEntry, false);
                addWhereFilterEntry(whereFilterTableEntry);
            }
        }
        List<ExternalDbMapEntry> externalOtherConstraintTableEntries = externalMapperTable.getCustomOtherConditionsEntries();
        if (externalOtherConstraintTableEntries != null) {
            for (ExternalDbMapEntry entry : externalOtherConstraintTableEntries) {
                FilterTableEntry otherFilterTableEntry = new FilterTableEntry(this, entry.getName(), entry.getExpression(), FilterTableEntry.OTHER_FILTER);
                // mapperManager.getProblemsManager().checkProblemsForTableEntry(filterTableEntry, false);
                addOtherFilterEntry(otherFilterTableEntry);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) FilterTableEntry(org.talend.designer.dbmap.model.tableentry.FilterTableEntry) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) AbstractInOutTableEntry(org.talend.designer.dbmap.model.tableentry.AbstractInOutTableEntry) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Aggregations

AbstractInOutTableEntry (org.talend.designer.dbmap.model.tableentry.AbstractInOutTableEntry)2 HashMap (java.util.HashMap)1 Color (org.eclipse.swt.graphics.Color)1 GridData (org.eclipse.swt.layout.GridData)1 Table (org.eclipse.swt.widgets.Table)1 TableViewerCreatorColumnNotModifiable (org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable)1 DefaultTableLabelProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultTableLabelProvider)1 ITableCellValueModifiedListener (org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener)1 TableCellValueModifiedEvent (org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent)1 IListenableListListener (org.talend.commons.utils.data.list.IListenableListListener)1 ListenableListEvent (org.talend.commons.utils.data.list.ListenableListEvent)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)1 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)1 ExternalDbMapEntry (org.talend.designer.dbmap.external.data.ExternalDbMapEntry)1 AbstractInOutTable (org.talend.designer.dbmap.model.table.AbstractInOutTable)1 OutputTable (org.talend.designer.dbmap.model.table.OutputTable)1 FilterTableEntry (org.talend.designer.dbmap.model.tableentry.FilterTableEntry)1