Search in sources :

Example 1 with MetadataTableEditor

use of org.talend.core.ui.metadata.editor.MetadataTableEditor in project tdi-studio-se by Talend.

the class UIManager method selectDataMapTableView.

/**
     * Select a table view.
     * 
     * @param dataMapTableView
     * @param useNewCommand
     * @param selectAllEntries TODO
     */
public void selectDataMapTableView(final DataMapTableView dataMapTableView, boolean useNewCommand, boolean selectAllEntries) {
    // reject table readonly
    IDataMapTable dataMapTable = dataMapTableView.getDataMapTable();
    if (dataMapTable instanceof OutputTable && ((OutputTable) dataMapTable).isErrorRejectTable()) {
        OutputTable table = (OutputTable) dataMapTable;
        if (table.getMetadataTable() != null) {
            for (IMetadataColumn column : table.getMetadataTable().getListColumns()) {
                if (mapperManager.ERROR_REJECT_MESSAGE.equals(column.getLabel()) || mapperManager.ERROR_REJECT_STACK_TRACE.equals(column.getLabel())) {
                    column.setCustom(true);
                }
            }
        }
        CustomTableManager.addCustomManagementToTable(getOutputMetaEditorView(), true);
    }
    TabFolderEditors tabFolderEditors = mapperUI.getTabFolderEditors();
    // tabFolderEditors.setSelection(TabFolderEditors.INDEX_TAB_METADATA_EDITOR);
    MetadataTableEditorView metadataTableEditorView = null;
    MetadataTableEditorView otherMetadataTableEditorView = null;
    final Zone currentZone = dataMapTableView.getZone();
    List<? extends AbstractDataMapTable> tables = null;
    DataMapTableView previousSelectedTableView = null;
    if (currentZone == Zone.INPUTS) {
        metadataTableEditorView = tabFolderEditors.getInputMetaEditorView();
        otherMetadataTableEditorView = tabFolderEditors.getOutputMetaEditorView();
        tables = mapperManager.getInputTables();
        previousSelectedTableView = this.currentSelectedInputTableView;
        this.currentSelectedInputTableView = (InputDataMapTableView) dataMapTableView;
        metadataTableEditorView.setReadOnly(this.currentSelectedInputTableView.getInputTable().hasReadOnlyMetadataColumns() || mapperManager.componentIsReadOnly() || this.currentSelectedInputTableView.getInputTable().isReadOnly());
    } else if (currentZone == Zone.OUTPUTS) {
        metadataTableEditorView = tabFolderEditors.getOutputMetaEditorView();
        otherMetadataTableEditorView = tabFolderEditors.getInputMetaEditorView();
        tables = mapperManager.getOutputTables();
        previousSelectedTableView = this.currentSelectedOutputTableView;
        this.currentSelectedOutputTableView = (OutputDataMapTableView) dataMapTableView;
        metadataTableEditorView.setReadOnly(this.currentSelectedOutputTableView.getOutputTable().hasReadOnlyMetadataColumns() || mapperManager.componentIsReadOnly());
    } else {
        this.currentSelectedVarsTableView = (VarsDataMapTableView) dataMapTableView;
    }
    if (currentZone != Zone.VARS) {
        updateToolbarButtonsStates(currentZone);
        final AbstractInOutTable abstractDataMapTable = (AbstractInOutTable) mapperManager.retrieveAbstractDataMapTable(dataMapTableView);
        MetadataTableEditor currentMetadataTableEditor = metadataTableEditorView.getMetadataTableEditor();
        final TableViewerCreator dataMapTVCreator = dataMapTableView.getTableViewerCreatorForColumns();
        final TableViewer dataMapTableViewer = dataMapTableView.getTableViewerCreatorForColumns().getTableViewer();
        if (currentMetadataTableEditor == null || currentMetadataTableEditor != null && oldSelectedView != dataMapTableView) {
            oldSelectedView = dataMapTableView;
            if (useNewCommand) {
                DataMapTableViewSelectedCommand command = new DataMapTableViewSelectedCommand(this, previousSelectedTableView, dataMapTableView);
                mapperManager.executeCommand(command);
            }
            currentMetadataTableEditor = new MetadataTableEditor(abstractDataMapTable.getMetadataTable(), abstractDataMapTable.getName());
            currentMetadataTableEditor.setModifiedBeanListenable(metadataTableEditorView.getTableViewerCreator());
            final MetadataTableEditorView metadataTableEditorViewFinal = metadataTableEditorView;
            final TableViewerCreator metadataTVCreator = metadataTableEditorViewFinal.getTableViewerCreator();
            final MetadataTableEditor metadataTableEditor = currentMetadataTableEditor;
            modifySelectionChangedListener(currentZone, metadataTableEditorViewFinal, metadataTVCreator, metadataTableEditor, dataMapTableView, previousSelectedTableView);
            // init actions listeners for list which contains metadata
            metadataTableEditor.addAfterOperationListListener(new IListenableListListener() {

                /**
                     * DOC acer Comment method "handleEvent".
                     * 
                     * @param event
                     */
                public void handleEvent(ListenableListEvent event) {
                    DataMapTableView view = mapperManager.retrieveAbstractDataMapTableView(abstractDataMapTable);
                    List<DataMapTableView> relatedOutputsTableView = getRelatedOutputsTableView(dataMapTableView);
                    if (event.type == TYPE.ADDED) {
                        // metadataEditorTableViewer.refresh();
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.addedObjects;
                        lastCreatedInOutColumnEntries.clear();
                        if (event.index != null) {
                            int index = event.index;
                            for (IMetadataColumn metadataColumn : metadataColumns) {
                                lastCreatedInOutColumnEntries.add(mapperManager.addNewColumnEntry(dataMapTableView, metadataColumn, index));
                                // handle related table view
                                for (DataMapTableView tableView : relatedOutputsTableView) {
                                    // changed for bug TDI-26551 in July 2,2013 by fwang, should use original
                                    // expression for related table.
                                    IMetadataColumn relatedMetadata = metadataColumn;
                                    if (!oldMappingMap.isEmpty()) {
                                        IDataMapTable retrieveAbstractDataMapTable = mapperManager.retrieveAbstractDataMapTable(tableView);
                                        relatedMetadata = metadataColumn.clone();
                                        String label = relatedMetadata.getLabel();
                                        String expression = oldMappingMap.get(retrieveAbstractDataMapTable.getName() + "_" + label);
                                        relatedMetadata.setExpression(expression == null ? "" : expression);
                                    }
                                    mapperManager.addNewColumnEntry(tableView, relatedMetadata, index);
                                }
                                index = index + 1;
                            }
                        } else if (event.indicesTarget != null) {
                            List<Integer> indicesTarget = event.indicesTarget;
                            int lstSize = indicesTarget.size();
                            for (int i = 0; i < lstSize; i++) {
                                Integer indice = indicesTarget.get(i);
                                IMetadataColumn metadataColumn = metadataColumns.get(i);
                                lastCreatedInOutColumnEntries.add(mapperManager.addNewColumnEntry(dataMapTableView, metadataColumn, indice));
                                // handle related table view
                                for (DataMapTableView tableView : relatedOutputsTableView) {
                                    mapperManager.addNewColumnEntry(tableView, metadataColumn, indice);
                                }
                            }
                        } else {
                            //$NON-NLS-1$
                            throw new IllegalStateException(Messages.getString("UIManager.1"));
                        }
                        refreshBackground(false, false);
                        if (event.index != null) {
                            dataMapTableViewer.refresh();
                            dataMapTVCreator.getSelectionHelper().setSelection(event.index);
                            if (dataMapTableView.canBeResizedAtPreferedSize()) {
                                dataMapTableView.changeSize(view.getPreferredSize(true, false, false), true, true);
                            }
                            // resize ralated table
                            for (DataMapTableView tableView : relatedOutputsTableView) {
                                if (tableView.canBeResizedAtPreferedSize()) {
                                    tableView.changeSize(tableView.getPreferredSize(true, false, false), true, true);
                                }
                            }
                        } else if (event.indicesTarget != null) {
                            dataMapTableViewer.refresh();
                            dataMapTableView.changeSize(view.getPreferredSize(false, true, false), true, true);
                            int[] selection = ArrayUtils.toPrimitive((Integer[]) event.indicesTarget.toArray(new Integer[0]));
                            dataMapTVCreator.getSelectionHelper().setSelection(selection);
                            for (DataMapTableView tableView : relatedOutputsTableView) {
                                tableView.changeSize(tableView.getPreferredSize(false, true, false), true, true);
                            }
                        }
                    }
                    if (event.type == TYPE.REMOVED) {
                        // metadataEditorTableViewer.refresh();
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.removedObjects;
                        for (IMetadataColumn metadataColumn : metadataColumns) {
                            ITableEntry metadataTableEntry = mapperManager.retrieveTableEntry(new TableEntryLocation(abstractDataMapTable.getName(), metadataColumn.getLabel()));
                            mapperManager.removeTableEntry(metadataTableEntry);
                            for (DataMapTableView tableView : relatedOutputsTableView) {
                                IDataMapTable retrieveAbstractDataMapTable = mapperManager.retrieveAbstractDataMapTable(tableView);
                                metadataTableEntry = mapperManager.retrieveTableEntry(new TableEntryLocation(retrieveAbstractDataMapTable.getName(), metadataColumn.getLabel()));
                                mapperManager.removeTableEntry(metadataTableEntry);
                                if (tableView.canBeResizedAtPreferedSize()) {
                                    tableView.resizeAtExpandedSize();
                                }
                            }
                        }
                        dataMapTableViewer.refresh();
                        if (dataMapTableView.canBeResizedAtPreferedSize()) {
                            dataMapTableView.resizeAtExpandedSize();
                        }
                        resizeTablesZoneViewAtComputedSize(dataMapTableView.getZone());
                        moveScrollBarZoneAtSelectedTable(dataMapTableView.getZone());
                        refreshBackground(true, false);
                    }
                    if (event.type == TYPE.SWAPED) {
                        List<Integer> listIndexTarget = event.indicesTarget;
                        abstractDataMapTable.swapColumnElements(event.indicesOrigin, listIndexTarget);
                        // handle related table view
                        for (DataMapTableView tableView : relatedOutputsTableView) {
                            AbstractDataMapTable relatedTable = (AbstractDataMapTable) tableView.getDataMapTable();
                            relatedTable.swapColumnElements(event.indicesOrigin, listIndexTarget);
                        }
                        // dataMapTableViewer.refresh();
                        refreshBackground(true, false);
                    }
                }
            });
            metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(false);
            metadataTableEditorView.setMetadataTableEditor(metadataTableEditor);
            metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(true);
            metadataTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
            dataMapTVCreator.getSelectionHelper().setActiveFireSelectionChanged(false);
            metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setSelection(dataMapTableViewer.getTable().getSelectionIndices());
            dataMapTVCreator.getSelectionHelper().setActiveFireSelectionChanged(true);
            // disable highlight for other DataMapTableView and highlight selected DataMapTableView
            for (IDataMapTable table : tables) {
                DataMapTableView otherDataMapTableView = mapperManager.retrieveAbstractDataMapTableView(table);
                otherDataMapTableView.setBackground(dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
            }
            dataMapTableView.setBackground(dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }
        if (selectAllEntries) {
            dataMapTVCreator.getTable().selectAll();
            selectAllLinks(dataMapTableView);
            if (currentZone != Zone.VARS) {
                metadataTableEditorView.getTableViewerCreator().getTable().selectAll();
                metadataTableEditorView.getToolBar().updateEnabledStateOfButtons();
            }
            if (currentZone == Zone.OUTPUTS) {
                dataMapTableView.getTableViewerCreatorForFilters().getTable().selectAll();
            }
        }
        boolean isMainSchemaRepository = false;
        if (abstractDataMapTable instanceof OutputTable) {
            OutputTable outputTable = (OutputTable) abstractDataMapTable;
            if (outputTable.getIsJoinTableOf() != null || !"".equals(outputTable.getIsJoinTableOf())) {
                final OutputTable outputTableByName = mapperManager.getOutputTableByName(outputTable.getIsJoinTableOf());
                if (outputTableByName != null && outputTableByName.getId() != null) {
                    isMainSchemaRepository = true;
                }
            }
        }
        dataMapTableView.enableDiaplayViewer(abstractDataMapTable.isRepository() || isMainSchemaRepository);
    }
    if (selectAllEntries && currentZone == Zone.VARS) {
        selectAllLinks(dataMapTableView);
        mapperManager.getUiManager().getVarsTablesView().get(0).getTableViewerCreatorForColumns().getTable().selectAll();
    }
    if (otherMetadataTableEditorView != null) {
        otherMetadataTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
    }
}
Also used : TabFolderEditors(org.talend.designer.mapper.ui.tabs.TabFolderEditors) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) AbstractDataMapTable(org.talend.designer.mapper.model.table.AbstractDataMapTable) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ArrayList(java.util.ArrayList) List(java.util.List) AbstractMetadataTableEditorView(org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView) MetadataTableEditorView(org.talend.core.ui.metadata.editor.MetadataTableEditorView) Zone(org.talend.designer.mapper.ui.visualmap.zone.Zone) InputsZone(org.talend.designer.mapper.ui.visualmap.zone.InputsZone) ToolbarOutputZone(org.talend.designer.mapper.ui.visualmap.zone.toolbar.ToolbarOutputZone) ToolbarZone(org.talend.designer.mapper.ui.visualmap.zone.toolbar.ToolbarZone) OutputsZone(org.talend.designer.mapper.ui.visualmap.zone.OutputsZone) InputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) Point(org.eclipse.swt.graphics.Point) DataMapTableViewSelectedCommand(org.talend.designer.mapper.ui.commands.DataMapTableViewSelectedCommand) TableViewer(org.eclipse.jface.viewers.TableViewer) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)

Example 2 with MetadataTableEditor

use of org.talend.core.ui.metadata.editor.MetadataTableEditor in project tdi-studio-se by Talend.

the class UIManager method modifySelectionChangedListener.

private void modifySelectionChangedListener(final Zone currentZone, final MetadataTableEditorView metadataTableEditorViewFinal, final TableViewerCreator metadataTVCreator, final MetadataTableEditor metadataTableEditor, final DataMapTableView dataMapTableView, DataMapTableView previousSelectedTableView) {
    final TableViewer tableViewer = dataMapTableView.getTableViewerCreatorForColumns().getTableViewer();
    IModifiedBeanListener<IMetadataColumn> modifiedBeanListener = new IModifiedBeanListener<IMetadataColumn>() {

        @Override
        public void handleEvent(ModifiedBeanEvent<IMetadataColumn> event) {
            if (AbstractMetadataTableEditorView.ID_COLUMN_NAME.equals(event.column.getId()) && !event.previousValue.equals(event.newValue)) {
                IMetadataColumn modifiedObject = event.bean;
                if (modifiedObject != null) {
                    TableEntryLocation tableEntryLocation = new TableEntryLocation(dataMapTableView.getDataMapTable().getName(), (String) event.previousValue);
                    final ITableEntry dataMapTableEntry = mapperManager.retrieveTableEntry(tableEntryLocation);
                    processColumnNameChanged((String) event.previousValue, (String) event.newValue, dataMapTableView, dataMapTableEntry, false);
                }
                // dataMapTableViewer.refresh(event.bean, true);
                tableViewer.refresh(true);
                mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
            } else if (AbstractMetadataTableEditorView.ID_COLUMN_KEY.equals(event.column.getId())) {
                tableViewer.refresh(true);
                IColumnEntry entry = dataMapTableView.getDataMapTable().getColumnEntries().get(event.index);
                parseExpression(entry.getExpression(), entry, false, false, false);
            } else if (AbstractMetadataTableEditorView.ID_COLUMN_TYPE.equals(event.column.getId()) || AbstractMetadataTableEditorView.ID_COLUMN_NULLABLE.equals(event.column.getId())) {
                mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
            }
        }
    };
    ILineSelectionListener metadataEditorViewerSelectionChangedListener = new ILineSelectionListener() {

        @Override
        public void handle(LineSelectionEvent e) {
            if (metadataTableEditorViewFinal.getTableViewerCreator() == e.source) {
                if (metadataTableEditorViewFinal.getExtendedTableViewer().isExecuteSelectionEvent()) {
                    mapperManager.getUiManager().selectLinkedTableEntries(metadataTableEditor.getMetadataTable(), metadataTVCreator.getTable().getSelectionIndices());
                }
            } else {
            // if (dataMapTableView.getExtendedTableViewerForColumns().isExecuteSelectionEvent()) {
            // int[] selectionIndices =
            // dataMapTableView.getTableViewerCreatorForColumns().getTable().getSelectionIndices();
            // mapperManager.getUiManager().selectLinkedMetadataEditorEntries(dataMapTableView,
            // selectionIndices);
            // }
            }
        }
    };
    // ISelectionChangedListener previousSelectionChangedListener = null;
    ILineSelectionListener previousSelectionChangedListener = null;
    IModifiedBeanListener<IMetadataColumn> previousModifiedBeanListener = null;
    if (currentZone == Zone.INPUTS) {
        previousSelectionChangedListener = inputsSelectionChangedListener;
        previousModifiedBeanListener = inputModifiedBeanListener;
    } else if (currentZone == Zone.OUTPUTS) {
        previousSelectionChangedListener = outputsSelectionChangedListener;
        previousModifiedBeanListener = outputModifiedBeanListener;
    }
    if (previousSelectionChangedListener != null) {
        // metadataTVCreator.removeSelectionChangedListener(previousSelectionChangedListener);
        metadataTVCreator.getSelectionHelper().removeAfterSelectionListener(previousSelectionChangedListener);
        if (previousSelectedTableView != null) {
            previousSelectedTableView.getTableViewerCreatorForColumns().getSelectionHelper().removeAfterSelectionListener(previousSelectionChangedListener);
        }
    }
    if (previousModifiedBeanListener != null) {
        metadataTableEditor.removeModifiedBeanListener(previousModifiedBeanListener);
    }
    if (currentZone == Zone.INPUTS) {
        inputsSelectionChangedListener = metadataEditorViewerSelectionChangedListener;
        inputModifiedBeanListener = modifiedBeanListener;
    } else if (currentZone == Zone.OUTPUTS) {
        outputsSelectionChangedListener = metadataEditorViewerSelectionChangedListener;
        outputModifiedBeanListener = modifiedBeanListener;
    }
    // metadataTVCreator.addSelectionChangedListener(metadataEditorViewerSelectionChangedListener);
    metadataTVCreator.getSelectionHelper().addAfterSelectionListener(metadataEditorViewerSelectionChangedListener);
    dataMapTableView.getTableViewerCreatorForColumns().getSelectionHelper().addAfterSelectionListener(metadataEditorViewerSelectionChangedListener);
    metadataTableEditor.addModifiedBeanListener(modifiedBeanListener);
    if (this.commonMetadataDisposeListener == null) {
        this.commonMetadataDisposeListener = new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (inputsSelectionChangedListener != null) {
                    getMetadataEditorView(Zone.INPUTS).getTableViewerCreator().getSelectionHelper().removeAfterSelectionListener(inputsSelectionChangedListener);
                }
                if (outputsSelectionChangedListener != null) {
                    getMetadataEditorView(Zone.OUTPUTS).getTableViewerCreator().getSelectionHelper().removeAfterSelectionListener(outputsSelectionChangedListener);
                }
                if (inputModifiedBeanListener != null) {
                    MetadataTableEditor metadataTableEditor = getMetadataEditorView(Zone.INPUTS).getMetadataTableEditor();
                    if (metadataTableEditor != null) {
                        metadataTableEditor.removeModifiedBeanListener(inputModifiedBeanListener);
                    }
                }
                if (outputModifiedBeanListener != null) {
                    MetadataTableEditor metadataTableEditor = getMetadataEditorView(Zone.OUTPUTS).getMetadataTableEditor();
                    if (metadataTableEditor != null) {
                        metadataTableEditor.removeModifiedBeanListener(outputModifiedBeanListener);
                    }
                }
            }
        };
        metadataTVCreator.getTable().addDisposeListener(this.commonMetadataDisposeListener);
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IModifiedBeanListener(org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifiedBeanEvent(org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with MetadataTableEditor

use of org.talend.core.ui.metadata.editor.MetadataTableEditor in project tdi-studio-se by Talend.

the class MapperManager method addMetadataTableEditorEntry.

/**
     * DOC amaumont Comment method "addTableEntry".
     * 
     * @param dataMapTableEntry
     * @param index
     */
public void addMetadataTableEditorEntry(MetadataTableEditorView metadataTableEditorView, IMetadataColumn metadataColumn, Integer index) {
    MetadataTableEditor metadataTableEditor = metadataTableEditorView.getMetadataTableEditor();
    metadataTableEditor.add(metadataColumn, index);
}
Also used : MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor)

Example 4 with MetadataTableEditor

use of org.talend.core.ui.metadata.editor.MetadataTableEditor in project tdi-studio-se by Talend.

the class MetadataExtPasteCommand method createPastableBeansList.

@Override
public List createPastableBeansList(ExtendedTableModel extendedTable, List copiedObjectsList) {
    ArrayList list = new ArrayList();
    ArrayList countList = new ArrayList();
    ArrayList<String> labelsExisted = getLabelsExisted(extendedTable);
    for (Object current : copiedObjectsList) {
        if (current instanceof IMetadataColumn) {
            IMetadataColumn copy = ((IMetadataColumn) current).clone();
            String nextGeneratedColumnName = ((MetadataTableEditor) extendedTable).getNextGeneratedColumnName(copy.getLabel());
            if (labelsExisted.contains(nextGeneratedColumnName)) {
                nextGeneratedColumnName = validateColumnName(nextGeneratedColumnName, labelsExisted);
            }
            labelsExisted.add(nextGeneratedColumnName);
            copy.setLabel(nextGeneratedColumnName);
            if (copy instanceof MetadataColumnExt) {
                list.add(copy);
            } else {
                MetadataColumnExt metadataColumnExt = new MetadataColumnExt((MetadataColumn) copy);
                metadataColumnExt.setFunction(functionManagerExt.getDefaultFunction(metadataColumnExt, metadataColumnExt.getTalendType()));
                list.add(metadataColumnExt);
            }
        } else if (current instanceof org.talend.core.model.metadata.builder.connection.MetadataColumn) {
            MetadataTableEditor tableEditor = (MetadataTableEditor) extendedTable;
            org.talend.core.model.metadata.builder.connection.MetadataColumn metadataColumn = (org.talend.core.model.metadata.builder.connection.MetadataColumn) current;
            String nextGeneratedColumnName = metadataColumn.getLabel();
            //$NON-NLS-1$
            String tempNewColumnName = "";
            boolean iMetaColumnUnique = false;
            boolean metaColumnUnique = false;
            while (iMetaColumnUnique == false || metaColumnUnique == false) {
                nextGeneratedColumnName = tableEditor.getNextGeneratedColumnName(nextGeneratedColumnName, null);
                iMetaColumnUnique = true;
                metaColumnUnique = false;
                if (list.size() == 0)
                    metaColumnUnique = true;
                else {
                    tempNewColumnName = this.getUniqueString(list, nextGeneratedColumnName);
                    if (tempNewColumnName.equals(nextGeneratedColumnName))
                        metaColumnUnique = true;
                    else {
                        metaColumnUnique = false;
                        nextGeneratedColumnName = tempNewColumnName;
                    }
                }
            }
            org.talend.core.model.metadata.builder.connection.MetadataColumn newColumnCopy = new ConnectionFactoryImpl().copy(metadataColumn, nextGeneratedColumnName);
            IMetadataColumn copy = (ConvertionHelper.convertToIMetaDataColumn(newColumnCopy)).clone();
            copy.setLabel(nextGeneratedColumnName);
            MetadataColumnExt metadataColumnExt = new MetadataColumnExt((MetadataColumn) copy);
            metadataColumnExt.setFunction(functionManagerExt.getDefaultFunction(metadataColumnExt, metadataColumnExt.getTalendType()));
            list.add(metadataColumnExt);
            countList.add(nextGeneratedColumnName);
        }
    }
    return list;
}
Also used : MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) ConnectionFactoryImpl(org.talend.core.model.metadata.builder.connection.impl.ConnectionFactoryImpl)

Example 5 with MetadataTableEditor

use of org.talend.core.ui.metadata.editor.MetadataTableEditor in project tdi-studio-se by Talend.

the class UIManager method selectDataMapTableView.

/**
     * Select a table view.
     * 
     * @param dataMapTableView
     * @param useNewCommand
     * @param selectAllEntries TODO
     */
public void selectDataMapTableView(final DataMapTableView dataMapTableView, boolean useNewCommand, boolean selectAllEntries) {
    TabFolderEditors tabFolderEditors = mapperUI.getTabFolderEditors();
    // tabFolderEditors.setSelection(TabFolderEditors.INDEX_TAB_METADATA_EDITOR);
    MetadataTableEditorView metadataTableEditorView = null;
    MetadataTableEditorView otherMetadataTableEditorView = null;
    final Zone currentZone = dataMapTableView.getZone();
    List<? extends IDataMapTable> tables = null;
    DataMapTableView previousSelectedTableView = null;
    DataMapTableView newSelectedTableView = null;
    if (currentZone == Zone.INPUTS) {
        metadataTableEditorView = tabFolderEditors.getInputMetaEditor();
        otherMetadataTableEditorView = tabFolderEditors.getOutputMetaEditor();
        tables = mapperManager.getInputTables();
        previousSelectedTableView = this.currentSelectedInputTableView;
        setCurrentSelectedInputTableView((InputDataMapTableView) dataMapTableView);
        newSelectedTableView = dataMapTableView;
    } else if (currentZone == Zone.OUTPUTS) {
        metadataTableEditorView = tabFolderEditors.getOutputMetaEditor();
        otherMetadataTableEditorView = tabFolderEditors.getInputMetaEditor();
        tables = mapperManager.getOutputTables();
        previousSelectedTableView = this.currentSelectedOutputTableView;
        newSelectedTableView = dataMapTableView;
        setCurrentSelectedOutputTableView((OutputDataMapTableView) dataMapTableView);
    }
    updateToolbarButtonsStates(currentZone);
    final AbstractInOutTable abstractDataMapTable = (AbstractInOutTable) mapperManager.retrieveIDataMapTable(dataMapTableView);
    MetadataTableEditor currentMetadataTableEditor = metadataTableEditorView.getMetadataTableEditor();
    final TableViewerCreator dataMapTVCreator = dataMapTableView.getTableViewerCreatorForColumns();
    final TableViewer dataMapTableViewer = dataMapTableView.getTableViewerCreatorForColumns().getTableViewer();
    if (currentMetadataTableEditor == null || currentMetadataTableEditor != null && newSelectedTableView != previousSelectedTableView) {
        if (useNewCommand) {
            DataMapTableViewSelectedCommand command = new DataMapTableViewSelectedCommand(this, previousSelectedTableView, dataMapTableView);
            mapperManager.executeCommand(command);
        }
        currentMetadataTableEditor = new MetadataTableEditor(abstractDataMapTable.getMetadataTable(), abstractDataMapTable.getTitle());
        currentMetadataTableEditor.setModifiedBeanListenable(metadataTableEditorView.getTableViewerCreator());
        final MetadataTableEditorView metadataTableEditorViewFinal = metadataTableEditorView;
        final TableViewerCreator metadataTVCreator = metadataTableEditorViewFinal.getTableViewerCreator();
        final MetadataTableEditor metadataTableEditor = currentMetadataTableEditor;
        modifySelectionChangedListener(currentZone, metadataTableEditorViewFinal, metadataTVCreator, metadataTableEditor, dataMapTableView, previousSelectedTableView);
        // init actions listeners for list which contains metadata
        metadataTableEditor.addAfterOperationListListener(new IListenableListListener() {

            /**
                 * DOC acer Comment method "handleEvent".
                 * 
                 * @param event
                 */
            @Override
            public void handleEvent(ListenableListEvent event) {
                DataMapTableView view = mapperManager.retrieveIDataMapTableView(abstractDataMapTable);
                if (event.type == TYPE.ADDED) {
                    // metadataEditorTableViewer.refresh();
                    List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.addedObjects;
                    lastCreatedInOutColumnEntries.clear();
                    if (event.index != null) {
                        int index = event.index;
                        for (IMetadataColumn metadataColumn : metadataColumns) {
                            lastCreatedInOutColumnEntries.add(mapperManager.addNewColumnEntry(dataMapTableView, metadataColumn, index++));
                        }
                    } else if (event.indicesTarget != null) {
                        List<Integer> indicesTarget = event.indicesTarget;
                        int lstSize = indicesTarget.size();
                        for (int i = 0; i < lstSize; i++) {
                            Integer indice = indicesTarget.get(i);
                            IMetadataColumn metadataColumn = metadataColumns.get(i);
                            lastCreatedInOutColumnEntries.add(mapperManager.addNewColumnEntry(dataMapTableView, metadataColumn, indice));
                        }
                    } else {
                        //$NON-NLS-1$
                        throw new IllegalStateException(Messages.getString("UIManager.1"));
                    }
                    refreshBackground(false, false);
                    if (event.index != null) {
                        dataMapTableView.changeSize(view.getPreferredSize(true, false, false), true, true);
                        dataMapTableViewer.refresh();
                        dataMapTVCreator.getSelectionHelper().setSelection(event.index);
                    } else if (event.indicesTarget != null) {
                        dataMapTableViewer.refresh();
                        dataMapTableView.changeSize(view.getPreferredSize(false, true, false), true, true);
                        int[] selection = ArrayUtils.toPrimitive((Integer[]) event.indicesTarget.toArray(new Integer[0]));
                        dataMapTVCreator.getSelectionHelper().setSelection(selection);
                    }
                    mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
                }
                if (event.type == TYPE.REMOVED) {
                    // metadataEditorTableViewer.refresh();
                    List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.removedObjects;
                    for (IMetadataColumn metadataColumn : metadataColumns) {
                        ITableEntry metadataTableEntry = mapperManager.retrieveTableEntry(new TableEntryLocation(abstractDataMapTable.getName(), metadataColumn.getLabel()));
                        mapperManager.removeTableEntry(metadataTableEntry);
                    }
                    dataMapTableViewer.refresh();
                    dataMapTableView.resizeAtExpandedSize();
                    resizeTablesZoneViewAtComputedSize(dataMapTableView.getZone());
                    moveScrollBarZoneAtSelectedTable(dataMapTableView.getZone());
                    refreshBackground(true, false);
                    mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
                }
                if (event.type == TYPE.SWAPED) {
                    List<Integer> listIndexTarget = event.indicesTarget;
                    abstractDataMapTable.swapColumnElements(event.indicesOrigin, listIndexTarget);
                    // dataMapTableViewer.refresh();
                    refreshBackground(true, false);
                }
            }
        });
        metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(false);
        metadataTableEditorView.setMetadataTableEditor(metadataTableEditor);
        metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(true);
        metadataTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
        dataMapTVCreator.getSelectionHelper().setActiveFireSelectionChanged(false);
        metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setSelection(dataMapTableViewer.getTable().getSelectionIndices());
        dataMapTVCreator.getSelectionHelper().setActiveFireSelectionChanged(true);
        // disable highlight for other DataMapTableView and highlight selected DataMapTableView
        for (IDataMapTable table : tables) {
            DataMapTableView otherDataMapTableView = mapperManager.retrieveIDataMapTableView(table);
            otherDataMapTableView.setBackground(dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
        }
        dataMapTableView.setBackground(dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
    }
    if (selectAllEntries) {
        dataMapTVCreator.getTable().selectAll();
        selectAllLinks(dataMapTableView);
        metadataTableEditorView.getTableViewerCreator().getTable().selectAll();
        metadataTableEditorView.getToolBar().updateEnabledStateOfButtons();
        if (currentZone == Zone.OUTPUTS) {
            dataMapTableView.getTableViewerCreatorForWhereFilters().getTable().selectAll();
            dataMapTableView.getTableViewerCreatorForOtherFilters().getTable().selectAll();
        }
    }
    if (otherMetadataTableEditorView != null) {
        otherMetadataTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
    }
}
Also used : TabFolderEditors(org.talend.designer.dbmap.ui.tabs.TabFolderEditors) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) OutputsZone(org.talend.designer.dbmap.ui.visualmap.zone.OutputsZone) InputsZone(org.talend.designer.dbmap.ui.visualmap.zone.InputsZone) Zone(org.talend.designer.dbmap.ui.visualmap.zone.Zone) ToolbarInputZone(org.talend.designer.dbmap.ui.visualmap.zone.toolbar.ToolbarInputZone) ToolbarOutputZone(org.talend.designer.dbmap.ui.visualmap.zone.toolbar.ToolbarOutputZone) ToolbarZone(org.talend.designer.dbmap.ui.visualmap.zone.toolbar.ToolbarZone) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) AbstractInOutTable(org.talend.designer.dbmap.model.table.AbstractInOutTable) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) InputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.InputDataMapTableView) OutputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView) DataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) Point(org.eclipse.swt.graphics.Point) DataMapTableViewSelectedCommand(org.talend.designer.dbmap.ui.commands.DataMapTableViewSelectedCommand) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) List(java.util.List) ArrayList(java.util.ArrayList) MetadataTableEditorView(org.talend.core.ui.metadata.editor.MetadataTableEditorView) AbstractMetadataTableEditorView(org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView) TableViewer(org.eclipse.jface.viewers.TableViewer) OutputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)

Aggregations

MetadataTableEditor (org.talend.core.ui.metadata.editor.MetadataTableEditor)12 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)8 MetadataTableEditorView (org.talend.core.ui.metadata.editor.MetadataTableEditorView)6 ArrayList (java.util.ArrayList)5 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)5 List (java.util.List)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4 IModifiedBeanListener (org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener)4 ModifiedBeanEvent (org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent)4 IListenableListListener (org.talend.commons.utils.data.list.IListenableListListener)4 ListenableListEvent (org.talend.commons.utils.data.list.ListenableListEvent)4 AbstractMetadataTableEditorView (org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView)4 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)4 HashMap (java.util.HashMap)3 EList (org.eclipse.emf.common.util.EList)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 Point (org.eclipse.swt.graphics.Point)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2