Search in sources :

Example 21 with IDataMapTable

use of org.talend.designer.abstractmap.model.table.IDataMapTable in project tdi-studio-se by Talend.

the class ExternalDataConverter method loadInExternalData.

private void loadInExternalData(Collection<? extends AbstractDataMapTable> tables) {
    for (IDataMapTable table : tables) {
        ExternalMapperTable externalMapperTable = new ExternalMapperTable();
        fillExternalTable(table, externalMapperTable);
        ArrayList<ExternalMapperTableEntry> perTableEntries = new ArrayList<ExternalMapperTableEntry>();
        boolean isVarTable = table instanceof VarsTable;
        boolean isInputTable = table instanceof InputTable;
        for (ITableEntry dataMapTableEntry : table.getColumnEntries()) {
            ExternalMapperTableEntry externalMapperTableEntry = new ExternalMapperTableEntry();
            externalMapperTableEntry.setExpression(dataMapTableEntry.getExpression());
            externalMapperTableEntry.setName(dataMapTableEntry.getName());
            if (isVarTable) {
                externalMapperTableEntry.setType(((VarTableEntry) dataMapTableEntry).getType());
                externalMapperTableEntry.setNullable(((VarTableEntry) dataMapTableEntry).isNullable());
            } else {
                externalMapperTableEntry.setType(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().getTalendType());
                externalMapperTableEntry.setNullable(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().isNullable());
            }
            if (isInputTable) {
                externalMapperTableEntry.setOperator(((InputColumnTableEntry) dataMapTableEntry).getOperator());
            }
            perTableEntries.add(externalMapperTableEntry);
        }
        externalMapperTable.setMetadataTableEntries(perTableEntries);
    }
}
Also used : InputTable(org.talend.designer.mapper.model.table.InputTable) VarsTable(org.talend.designer.mapper.model.table.VarsTable) ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) AbstractInOutTableEntry(org.talend.designer.mapper.model.tableentry.AbstractInOutTableEntry)

Example 22 with IDataMapTable

use of org.talend.designer.abstractmap.model.table.IDataMapTable in project tdi-studio-se by Talend.

the class ExternalDataConverter method loadInExternalData.

private void loadInExternalData(List<? extends AbstractDataMapTable> tables, List<? extends AbstractDataMapTable> intables) {
    // for (int i = 0; i < tables.size(); i++) {
    if (tables.size() <= 0 || intables.size() <= 0) {
        return;
    }
    IDataMapTable outtable = tables.get(0);
    IDataMapTable intable = intables.get(0);
    ExternalMapperTable externalMapperTable = new ExternalMapperTable();
    fillExternalTable(outtable, externalMapperTable);
    ArrayList<ExternalMapperTableEntry> perTableEntries = new ArrayList<ExternalMapperTableEntry>();
    List<IMetadataColumn> columnList = null;
    if (mapperManager != null && mapperManager.getAbstractMapComponent() != null) {
        List<? extends IConnection> connList = mapperManager.getAbstractMapComponent().getOutgoingConnections();
        if (connList != null && connList.size() >= 1) {
            List<IMetadataTable> metaList = connList.get(0).getTarget().getMetadataList();
            if (metaList != null && metaList.size() >= 1) {
                columnList = metaList.get(0).getListColumns();
            }
        }
    }
    for (ITableEntry dataMapTableEntry : intable.getColumnEntries()) {
        if (columnList != null) {
            boolean find = false;
            for (IMetadataColumn column : columnList) {
                if (dataMapTableEntry.getName().equals(column.getLabel())) {
                    find = true;
                    break;
                }
            }
            if (find) {
                ExternalMapperTableEntry externalMapperTableEntry = new ExternalMapperTableEntry();
                externalMapperTableEntry.setExpression(intable.getName() + "." + dataMapTableEntry.getName());
                externalMapperTableEntry.setName(dataMapTableEntry.getName());
                externalMapperTableEntry.setType(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().getTalendType());
                externalMapperTableEntry.setNullable(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().isNullable());
                perTableEntries.add(externalMapperTableEntry);
            }
        } else {
            ExternalMapperTableEntry externalMapperTableEntry = new ExternalMapperTableEntry();
            externalMapperTableEntry.setExpression(intable.getName() + "." + dataMapTableEntry.getName());
            externalMapperTableEntry.setName(dataMapTableEntry.getName());
            externalMapperTableEntry.setType(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().getTalendType());
            externalMapperTableEntry.setNullable(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().isNullable());
            perTableEntries.add(externalMapperTableEntry);
        }
    }
    externalMapperTable.setMetadataTableEntries(perTableEntries);
// }
}
Also used : ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) AbstractInOutTableEntry(org.talend.designer.mapper.model.tableentry.AbstractInOutTableEntry)

Example 23 with IDataMapTable

use of org.talend.designer.abstractmap.model.table.IDataMapTable in project tdi-studio-se by Talend.

the class MapperManager method addNewColumnEntry.

/**
     * This method is called when "addMetadataTableEditorEntry" is called (event on list of MetadataEditor) , so if you
     * want keep synchronisation between inputs/outputs DataMaps and MetadataEditors don't call this method.
     * 
     * @param dataMapTableView
     * @param metadataColumn, can be null if added in VarsTable
     * @param index
     */
public IColumnEntry addNewColumnEntry(DataMapTableView dataMapTableView, IMetadataColumn metadataColumn, Integer index) {
    IDataMapTable abstractDataMapTable = dataMapTableView.getDataMapTable();
    IColumnEntry dataMapTableEntry = null;
    if (dataMapTableView.getZone() == Zone.INPUTS) {
        dataMapTableEntry = new InputColumnTableEntry(abstractDataMapTable, metadataColumn);
    } else if (dataMapTableView.getZone() == Zone.OUTPUTS) {
        String expression = metadataColumn.getExpression();
        if (expression != null && !"".equals(expression)) {
            dataMapTableEntry = new OutputColumnTableEntry(abstractDataMapTable, metadataColumn, expression);
        } else {
            dataMapTableEntry = new OutputColumnTableEntry(abstractDataMapTable, metadataColumn);
        }
    } else {
        //$NON-NLS-1$
        throw new IllegalArgumentException(Messages.getString("MapperManager.exceptionMessage.useOtherSignature"));
    }
    tableEntriesManager.addTableEntry(dataMapTableEntry, index);
    return dataMapTableEntry;
}
Also used : IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) OutputColumnTableEntry(org.talend.designer.mapper.model.tableentry.OutputColumnTableEntry) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)

Example 24 with IDataMapTable

use of org.talend.designer.abstractmap.model.table.IDataMapTable 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)

Example 25 with IDataMapTable

use of org.talend.designer.abstractmap.model.table.IDataMapTable in project tdi-studio-se by Talend.

the class UIManager method refreshSqlExpression.

/**
     * Refresh Sql select query in the bottom tab and its title.
     */
public void refreshSqlExpression() {
    if (getTabFolderEditors().getSelectionIndex() == 2) {
        mapperManager.getComponent().restoreMapperModelFromInternalData();
        OutputDataMapTableView selectedOutputTableView = getCurrentSelectedOutputTableView();
        if (selectedOutputTableView == null) {
        } else {
            IDataMapTable dataMapTable = selectedOutputTableView.getDataMapTable();
            String tableName = dataMapTable.getName();
            DbGenerationManager generationMnager = mapperManager.getComponent().getGenerationManager();
            String sql = generationMnager.buildSqlSelect(mapperManager.getComponent(), tableName);
            getTabFolderEditors().getItem(2).setText(//$NON-NLS-1$
            Messages.getString("TabFolderEditors.SqlSelectQuery", new Object[] { tableName }));
            getTabFolderEditors().getStyledSqlText().setText(sql);
        }
    }
}
Also used : DbGenerationManager(org.talend.designer.dbmap.language.generation.DbGenerationManager) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) OutputDataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)

Aggregations

IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)39 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)14 ArrayList (java.util.ArrayList)9 OutputTable (org.talend.designer.mapper.model.table.OutputTable)8 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)7 OutputTable (org.talend.designer.dbmap.model.table.OutputTable)7 GlobalMapEntry (org.talend.designer.mapper.model.tableentry.GlobalMapEntry)6 InputTable (org.talend.designer.dbmap.model.table.InputTable)5 FilterTableEntry (org.talend.designer.dbmap.model.tableentry.FilterTableEntry)5 FilterTableEntry (org.talend.designer.mapper.model.tableentry.FilterTableEntry)5 List (java.util.List)4 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)4 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)4 DataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView)4 OutputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)4 AbstractInOutTable (org.talend.designer.mapper.model.table.AbstractInOutTable)4 InputTable (org.talend.designer.mapper.model.table.InputTable)4 VarsTable (org.talend.designer.mapper.model.table.VarsTable)4 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)4 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)3