Search in sources :

Example 16 with TableEntryLocation

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

the class TableEntriesManager method renameEntryName.

/**
     * DOC amaumont Comment method "renameEntryName".
     * 
     * @param dataMapTableEntry
     * @param newColumnName
     * @param newColumnName
     */
public void renameEntryName(ITableEntry dataMapTableEntry, String previousColumnName, String newColumnName) {
    // System.out.println(previousColumnName + " -> " + newColumnName);
    // ExceptionHandler.process(new RuntimeException("test : " + previousColumnName + " -> " + newColumnName));
    // log.info(previousColumnName + " -> " + newColumnName); //$NON-NLS-1$
    TableEntryLocation tableEntryLocationKey = new TableEntryLocation(dataMapTableEntry.getParentName(), previousColumnName);
    // TableEntriesManager.buildLocation(dataMapTableEntry);
    ITableEntry entry = tableEntries.get(tableEntryLocationKey);
    if (entry != dataMapTableEntry) {
        //$NON-NLS-1$
        log.warn(Messages.getString("TableEntriesManager.exceptionMessage.tableEntriesNotSame"));
        return;
    }
    tableEntries.remove(tableEntryLocationKey);
    tableEntryLocationKey.columnName = newColumnName;
    tableEntries.put(tableEntryLocationKey, dataMapTableEntry);
    dataMapTableEntry.setName(newColumnName);
}
Also used : ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation)

Example 17 with TableEntryLocation

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

the class MapperManager method replaceLocation.

/**
     * 
     * DOC amaumont Comment method "replaceLocation".
     * 
     * @param previousLocation
     * @param newLocation
     * @param dataMapExpressionParser
     * @param table
     * @param entry
     * @return true if expression of entry has changed
     */
private boolean replaceLocation(final TableEntryLocation previousLocation, final TableEntryLocation newLocation, DataMapExpressionParser dataMapExpressionParser, IDataMapTable table, ITableEntry entry) {
    if (entry.getExpression() == null || entry.getExpression().trim().length() == 0) {
        return false;
    }
    boolean expressionHasChanged = false;
    String currentExpression = entry.getExpression();
    TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(currentExpression);
    // loop on all locations of current expression
    for (TableEntryLocation currentLocation : tableEntryLocations) {
        if (currentLocation.equals(previousLocation)) {
            currentExpression = dataMapExpressionParser.replaceLocation(currentExpression, previousLocation, newLocation);
            expressionHasChanged = true;
        }
    }
    if (expressionHasChanged) {
        entry.setExpression(currentExpression);
        DataMapTableView dataMapTableView = retrieveAbstractDataMapTableView(table);
        TableViewerCreator tableViewerCreator = null;
        if (entry instanceof IColumnEntry || entry instanceof FilterTableEntry) {
            if (entry instanceof IColumnEntry) {
                tableViewerCreator = dataMapTableView.getTableViewerCreatorForColumns();
            } else if (entry instanceof FilterTableEntry) {
                tableViewerCreator = dataMapTableView.getTableViewerCreatorForFilters();
            }
            tableViewerCreator.getTableViewer().refresh(entry);
        } else if (entry instanceof ExpressionFilterEntry) {
            dataMapTableView.getExpressionFilterText().setText(currentExpression);
        }
        uiManager.parseExpression(currentExpression, entry, false, true, false);
        return true;
    }
    return false;
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)

Example 18 with TableEntryLocation

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

the class ExternalMapperData method getLinkedTableColumnsMapping.

public Map<String, Set<String>> getLinkedTableColumnsMapping() {
    Map<String, Set<String>> tableColumnsMapping = new HashMap<String, Set<String>>();
    DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
    List<ExternalMapperTable> tablesHasFilter = new ArrayList<ExternalMapperTable>();
    tablesHasFilter.addAll(inputTables);
    tablesHasFilter.addAll(outputTables);
    for (ExternalMapperTable table : tablesHasFilter) {
        TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(table.getExpressionFilter());
        for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
            if (!tableColumnsMapping.containsKey(tableEntryLocation.tableName)) {
                Set<String> columns = new HashSet<String>();
                columns.add(tableEntryLocation.columnName);
                tableColumnsMapping.put(tableEntryLocation.tableName, columns);
            } else {
                tableColumnsMapping.get(tableEntryLocation.tableName).add(tableEntryLocation.columnName);
            }
        }
    }
    List<ExternalMapperTable> tablesHasColumnExpression = new ArrayList<ExternalMapperTable>();
    tablesHasColumnExpression.addAll(varsTables);
    tablesHasColumnExpression.addAll(outputTables);
    for (ExternalMapperTable table : tablesHasColumnExpression) {
        List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
        for (ExternalMapperTableEntry entry : metadataTableEntries) {
            TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(entry.getExpression());
            for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
                if (!tableColumnsMapping.containsKey(tableEntryLocation.tableName)) {
                    Set<String> columns = new HashSet<String>();
                    columns.add(tableEntryLocation.columnName);
                    tableColumnsMapping.put(tableEntryLocation.tableName, columns);
                } else {
                    tableColumnsMapping.get(tableEntryLocation.tableName).add(tableEntryLocation.columnName);
                }
            }
        }
    }
    return tableColumnsMapping;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataMapExpressionParser(org.talend.designer.mapper.utils.DataMapExpressionParser) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) HashSet(java.util.HashSet)

Example 19 with TableEntryLocation

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

the class MapperComponent method renameMetadataColumnName.

@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
    if (conectionName == null || oldColumnName == null || newColumnName == null) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        // rename metadata column name
        List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
        tables.addAll(externalData.getOutputTables());
        ExternalMapperTable tableFound = null;
        for (ExternalMapperTable table : tables) {
            if (table.getName().equals(conectionName)) {
                List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
                for (ExternalMapperTableEntry entry : metadataTableEntries) {
                    if (entry.getName().equals(oldColumnName)) {
                        entry.setName(newColumnName);
                        tableFound = table;
                        break;
                    }
                }
                break;
            }
        }
        // it is necessary to update expressions only if renamed column come from input table
        if (tableFound != null && externalData.getInputTables().indexOf(tableFound) != -1) {
            TableEntryLocation oldLocation = new TableEntryLocation(conectionName, oldColumnName);
            TableEntryLocation newLocation = new TableEntryLocation(conectionName, newColumnName);
            replaceLocationsInAllExpressions(oldLocation, newLocation, false);
        }
    }
}
Also used : ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ArrayList(java.util.ArrayList) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Example 20 with TableEntryLocation

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

the class MapperComponent method renameInputConnection.

public void renameInputConnection(String oldConnectionName, String newConnectionName) {
    if (oldConnectionName == null || newConnectionName == null) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        List<ExternalMapperTable> inputTables = externalData.getInputTables();
        for (ExternalMapperTable table : inputTables) {
            if (table.getName().equals(oldConnectionName)) {
                table.setName(newConnectionName);
                TableEntryLocation oldLocation = new TableEntryLocation(oldConnectionName, null);
                TableEntryLocation newLocation = new TableEntryLocation(newConnectionName, null);
                replaceLocationsInAllExpressions(oldLocation, newLocation, true);
                break;
            }
        }
    }
}
Also used : TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Aggregations

TableEntryLocation (org.talend.designer.mapper.model.tableentry.TableEntryLocation)33 Test (org.junit.Test)14 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)7 ArrayList (java.util.ArrayList)6 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)6 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)5 InputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView)5 OutputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)5 VarsDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView)5 HashSet (java.util.HashSet)4 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)4 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)3 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)3 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)3 DataMapExpressionParser (org.talend.designer.mapper.utils.DataMapExpressionParser)3 HashMap (java.util.HashMap)2 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Point (org.eclipse.swt.graphics.Point)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2