Search in sources :

Example 1 with InputColumnTableEntry

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

the class CompleteDropTargetListener method modifyExistingEntry.

/**
     * DOC amaumont Comment method "modifyExistingEntry".
     * 
     * @param uiManager
     * @param analyzer
     * @param currentLanguage
     * @param currentEntryTarget
     * @param columnIndicesToSelect
     * @param tableViewerCreatorTarget
     * @param lastEntryTarget
     * @param tableEntrySource
     * @param zoneSourceEntry
     */
private void modifyExistingEntry(UIManager uiManager, DropContextAnalyzer analyzer, IDbLanguage currentLanguage, ITableEntry currentEntryTarget, ArrayList<Integer> columnIndicesToSelect, TableViewerCreator tableViewerCreatorTarget, ITableEntry lastEntryTarget, ITableEntry tableEntrySource, Zone zoneSourceEntry) {
    boolean overwrite = (lastEntryTarget != currentEntryTarget && analyzer.isOverwriteExpression());
    modifyExistingExpression(currentLanguage, currentEntryTarget, tableEntrySource, overwrite, zoneSourceEntry);
    uiManager.parseExpression(currentEntryTarget.getExpression(), currentEntryTarget, false, true, true);
    if (currentEntryTarget instanceof InputColumnTableEntry) {
        setDefaultOperator((InputColumnTableEntry) currentEntryTarget);
    }
    int indexOfEntry = tableViewerCreatorTarget.getInputList().indexOf(currentEntryTarget);
    columnIndicesToSelect.add(indexOfEntry);
}
Also used : InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) Point(org.eclipse.swt.graphics.Point)

Example 2 with InputColumnTableEntry

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

the class InputTable method initFromExternalData.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.dbmap.model.table.AbstractInOutTable#initFromExternalData(org.talend.designer.dbmap.external
     * .data.ExternalMapperTable)
     */
@Override
public void initFromExternalData(ExternalDbMapTable externalMapperTable) {
    boolean isAliasTable = externalMapperTable != null && externalMapperTable.getAlias() != null;
    if (isAliasTable) {
        // dbmap table is alias
        setMetadataTable(connection.getTable().clone());
    } else if (connection != null) {
        // dbmap table references a physical table
        setMetadataTable(connection.getTable());
    }
    super.initFromExternalData(externalMapperTable);
    List<IMetadataColumn> columns = getMetadataTable().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);
        }
    }
    ArrayList<IMetadataColumn> columnsToRemove = new ArrayList<IMetadataColumn>();
    for (IMetadataColumn column : columns) {
        InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
        ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
        // Entry match with current column
        if (externalMapperTableEntry != null) {
            fillInputEntry(inputEntry, externalMapperTableEntry);
            nameToPerTabEntry.remove(externalMapperTableEntry.getName());
        }
        if (externalMapperTableEntry != null || !isAliasTable) {
            dataMapTableEntries.add(inputEntry);
        } else {
            columnsToRemove.add(column);
        }
    }
    columns.removeAll(columnsToRemove);
    // create unmatching entries
    for (ExternalDbMapEntry perTableEntry : nameToPerTabEntry.values()) {
        MetadataColumn column = new MetadataColumn();
        column.setLabel(perTableEntry.getName());
        InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
        ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
        fillInputEntry(inputEntry, externalMapperTableEntry);
        dataMapTableEntries.add(inputEntry);
        columns.add(column);
    }
    if (externalMapperTable != null) {
        joinType = mapperManager.getCurrentLanguage().getJoin(externalMapperTable.getJoinType());
        if (joinType == null) {
            joinType = mapperManager.getCurrentLanguage().getAvailableJoins()[0];
        }
        alias = externalMapperTable.getAlias();
        tableName = externalMapperTable.getTableName() != null ? externalMapperTable.getTableName() : connection.getName();
    }
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 3 with InputColumnTableEntry

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

the class LinkManager method unregisterLevelForRemovedLink.

/**
     * DOC amaumont Comment method "unregisterLevelForRemovedLink".
     * 
     * @param link
     * @param sourceGraphicalLinks
     */
protected void unregisterLevelForRemovedLink(IMapperLink link, Set<IMapperLink> sourceGraphicalLinks) {
    ITableEntry targetEntry = link.getPointLinkDescriptor2().getTableEntry();
    boolean hasSameZone = link.getPointLinkDescriptor1().getTableEntry().getClass() == targetEntry.getClass();
    if (hasSameZone) {
        boolean isInput = targetEntry instanceof InputColumnTableEntry;
        boolean isOutput = targetEntry instanceof OutputColumnTableEntry;
        List<List<IMapperLink>> leveledLinks = null;
        if (isInput) {
            leveledLinks = getInputLinksForLevels();
        }
        if (isOutput) {
            leveledLinks = getOutputLinksForLevels();
        }
        boolean breakAll = false;
        int lstSize = leveledLinks.size();
        for (int indexOfLeveledLink = 0; indexOfLeveledLink < lstSize; indexOfLeveledLink++) {
            List<IMapperLink> linksFromLevelsList = leveledLinks.get(indexOfLeveledLink);
            if (linksFromLevelsList != null && linksFromLevelsList.size() > 0) {
                int lstSizeInternal = linksFromLevelsList.size();
                for (int i = 0; i < lstSizeInternal; i++) {
                    IMapperLink currentLink = linksFromLevelsList.get(i);
                    if (currentLink == link) {
                        linksFromLevelsList.remove(i);
                        if (linksFromLevelsList.size() == 0) {
                            leveledLinks.set(indexOfLeveledLink, null);
                        }
                        breakAll = true;
                        break;
                    }
                }
                // for (int i = 0; i < lstSizeInternal; i++) {
                if (breakAll) {
                    break;
                }
            }
        }
    // for (int indexOfLeveledLink = 0; indexOfLeveledLink < lstSize; indexOfLeveledLink++) {
    }
}
Also used : ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) OutputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.OutputColumnTableEntry) List(java.util.List) ArrayList(java.util.ArrayList) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry)

Example 4 with InputColumnTableEntry

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

the class ProblemsManager method checkProblemsForTableEntry.

public void checkProblemsForTableEntry(ITableEntry tableEntry, boolean forceRefreshData) {
    // if (forceRefreshData) {
    // mapperManager.getComponent().refreshMapperConnectorData();
    // checkProblems();
    // }
    List<Problem> problems = new ArrayList<Problem>(0);
    String expression = tableEntry.getExpression();
    if (tableEntry instanceof InputColumnTableEntry) {
        InputColumnTableEntry inputEntry = (InputColumnTableEntry) tableEntry;
        IDbOperatorManager operatorsManager = mapperManager.getCurrentLanguage().getOperatorsManager();
        IDbOperator dbOperator = operatorsManager.getOperatorFromValue(inputEntry.getOperator());
        boolean operatorIsSet = dbOperator != null;
        boolean expressionIsSet = expression != null && expression.trim().length() > 0;
        Problem problem = null;
        String errorMessage = null;
        String key = null;
        if (!operatorIsSet && expressionIsSet) {
            errorMessage = //$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "ProblemsManager.operatorNotSet", new Object[] { inputEntry.getName() });
            key = KEY_OPERATOR_EMPTY;
            problem = new Problem(null, errorMessage, ProblemStatus.ERROR);
            problem.setKey(key);
            problems.add(problem);
        }
        if (operatorIsSet && !expressionIsSet && !dbOperator.isMonoOperand()) {
            errorMessage = //$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "ProblemsManager.inputExpressionEmpty", new Object[] { inputEntry.getParentName(), inputEntry.getName() });
            key = KEY_INPUT_EXPRESSION_EMPTY;
            problem = new Problem(null, errorMessage, ProblemStatus.ERROR);
            problem.setKey(key);
            problems.add(problem);
        }
        Problem warningProblem = null;
        if (inputEntry.isUnmatchingEntry()) {
            InputTable inputTable = (InputTable) inputEntry.getParent();
            String message = //$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "ProblemsManager.entryDoesntMatch", new Object[] { inputEntry.getParentName(), inputEntry.getName(), inputTable.getTableName() });
            warningProblem = new Problem(null, message, ProblemStatus.WARNING);
            warningProblem.setKey(KEY_NO_MATCHING);
            problems.add(warningProblem);
        }
    } else if (tableEntry instanceof OutputColumnTableEntry) {
        String errorMessage = null;
        Problem problem = null;
        if (expression == null || EMPTY_STRING.equals(expression.trim())) {
            errorMessage = //$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "ProblemsManager.outputExpressionEmpty", new Object[] { tableEntry.getParentName(), tableEntry.getName() });
        }
        if (errorMessage != null) {
            problem = new Problem(null, errorMessage, ProblemStatus.ERROR);
            problem.setKey(KEY_OUTPUT_EXPRESSION_EMPTY);
            problems.add(problem);
        }
    }
    tableEntry.setProblems(problems.size() > 0 ? problems : null);
}
Also used : InputTable(org.talend.designer.dbmap.model.table.InputTable) ArrayList(java.util.ArrayList) Problem(org.talend.core.model.process.Problem) OutputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.OutputColumnTableEntry) IDbOperator(org.talend.designer.dbmap.language.operator.IDbOperator) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) IDbOperatorManager(org.talend.designer.dbmap.language.operator.IDbOperatorManager)

Example 5 with InputColumnTableEntry

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

the class UIManager method parseExpression.

/**
     * 
     * 
     * @param expression
     * @param currentModifiedITableEntry
     * @param linkMustHaveSelectedState
     * @param checkInputKeyAutomatically TODO
     * @param inputExpressionAppliedOrCanceled TODO
     * @param newSelectedDataMapTableView
     * @return true if a link has been added or removed, false else
     */
public ParseExpressionResult parseExpression(String expression, ITableEntry currentModifiedITableEntry, boolean linkMustHaveSelectedState, boolean checkInputKeyAutomatically, boolean inputExpressionAppliedOrCanceled) {
    DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(currentModifiedITableEntry);
    boolean linkHasBeenAdded = false;
    boolean linkHasBeenRemoved = false;
    DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(mapperManager.getCurrentLanguage());
    TableEntryLocation[] tableEntriesLocationsSources = dataMapExpressionParser.parseTableEntryLocations(expression);
    Set<TableEntryLocation> alreadyProcessed = new HashSet<TableEntryLocation>();
    Set<ITableEntry> sourcesForTarget = mapperManager.getSourcesForTarget(currentModifiedITableEntry);
    Set<ITableEntry> sourcesForTargetToDelete = new HashSet<ITableEntry>(sourcesForTarget);
    boolean isInputEntry = currentModifiedITableEntry instanceof InputColumnTableEntry;
    for (TableEntryLocation tableEntriesLocationsSource : tableEntriesLocationsSources) {
        TableEntryLocation location = tableEntriesLocationsSource;
        if (!alreadyProcessed.contains(location) && checkSourceLocationIsValid(location, currentModifiedITableEntry)) {
            ITableEntry sourceTableEntry = mapperManager.retrieveTableEntry(location);
            sourcesForTargetToDelete.remove(sourceTableEntry);
            if (sourceTableEntry != null && !sourcesForTarget.contains(sourceTableEntry)) {
                DataMapTableView sourceDataMapTableView = mapperManager.retrieveDataMapTableView(sourceTableEntry);
                IMapperLink link = new Link(new PointLinkDescriptor(sourceTableEntry, sourceDataMapTableView.getZone()), new PointLinkDescriptor(currentModifiedITableEntry, dataMapTableView.getZone()), mapperManager);
                link.setState(linkMustHaveSelectedState ? LinkState.SELECTED : LinkState.UNSELECTED);
                mapperManager.addLink(link);
                linkHasBeenAdded = true;
            }
            alreadyProcessed.add(location);
        }
    }
    Set<IMapperLink> targets = mapperManager.getGraphicalLinksFromTarget(currentModifiedITableEntry);
    Set<IMapperLink> linksFromTarget = new HashSet<IMapperLink>(targets);
    for (IMapperLink link : linksFromTarget) {
        if (sourcesForTargetToDelete.contains(link.getPointLinkDescriptor1().getTableEntry())) {
            mapperManager.removeLink(link, link.getPointLinkDescriptor2().getTableEntry());
            linkHasBeenRemoved = true;
        }
    }
    mapperManager.orderLinks();
    return new ParseExpressionResult(linkHasBeenAdded, linkHasBeenRemoved);
}
Also used : PointLinkDescriptor(org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) 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) ParseExpressionResult(org.talend.designer.dbmap.utils.ParseExpressionResult) DataMapExpressionParser(org.talend.designer.dbmap.utils.DataMapExpressionParser) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) Link(org.talend.designer.dbmap.ui.visualmap.link.Link) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) HashSet(java.util.HashSet)

Aggregations

InputColumnTableEntry (org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry)11 ArrayList (java.util.ArrayList)4 OutputColumnTableEntry (org.talend.designer.dbmap.model.tableentry.OutputColumnTableEntry)4 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 IMapperLink (org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)3 List (java.util.List)2 Point (org.eclipse.swt.graphics.Point)2 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)2 IDbOperator (org.talend.designer.dbmap.language.operator.IDbOperator)2 IDbOperatorManager (org.talend.designer.dbmap.language.operator.IDbOperatorManager)2 InputTable (org.talend.designer.dbmap.model.table.InputTable)2 VarTableEntry (org.talend.designer.dbmap.model.tableentry.VarTableEntry)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)1 Color (org.eclipse.swt.graphics.Color)1 Combo (org.eclipse.swt.widgets.Combo)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1 ComboxCellEditorImproved (org.talend.commons.ui.runtime.swt.celleditor.ComboxCellEditorImproved)1