Search in sources :

Example 1 with PointLinkDescriptor

use of org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor 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)

Example 2 with PointLinkDescriptor

use of org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor in project tdi-studio-se by Talend.

the class StyleLinkFactory method getStyleLink.

// public static DrawableLinkFactory getInstance() {
// if (instance == null) {
// instance = new DrawableLinkFactory();
// }
// return instance;
// }
//
// public IDrawableLink getDrawableLink(IMapperLink link) {
// IDrawableLink drawableLink = null;
// PointLinkDescriptor pointLinkDescriptorSource = link.getPointLinkDescriptorSource();
// PointLinkDescriptor pointLinkDescriptorTarget = link.getPointLinkDescriptorTarget();
// if (pointLinkDescriptorSource.getZone() != pointLinkDescriptorTarget.getZone()) {
// drawableLink = new HorizontalBezierLink();
// } else if (pointLinkDescriptorSource.getZone() == pointLinkDescriptorTarget.getZone()) {
// drawableLink = new VerticalRoundedCornerLink();
// }
// return drawableLink;
// }
//
public IStyleLink getStyleLink(IMapperLink link) {
    ILinkState linkState = link.getState();
    PointLinkDescriptor pointLinkDescriptorSource = link.getPointLinkDescriptor1();
    PointLinkDescriptor pointLinkDescriptorTarget = link.getPointLinkDescriptor2();
    ITableEntry targetTableEntry = pointLinkDescriptorTarget.getTableEntry();
    boolean targetIsConstraint = false;
    if (targetTableEntry instanceof FilterTableEntry) {
        targetIsConstraint = true;
    }
    IStyleLink style = null;
    if (pointLinkDescriptorSource.getZone() != pointLinkDescriptorTarget.getZone()) {
        if (linkState == LinkState.SELECTED) {
            if (targetIsConstraint) {
                style = selectedFilterStyle;
            } else {
                style = selectedZoneToZoneStyle;
            }
        } else if (linkState == LinkState.UNSELECTED) {
            if (targetIsConstraint) {
                style = unselectedFilterStyle;
            } else {
                style = unselectedZoneToZoneStyle;
            }
        }
    } else if ((pointLinkDescriptorSource.getZone() == Zone.INPUTS || pointLinkDescriptorSource.getZone() == Zone.OUTPUTS) && pointLinkDescriptorSource.getZone() == pointLinkDescriptorTarget.getZone()) {
        if (linkState == LinkState.SELECTED) {
            style = selectedSameInputZoneStyle;
        } else if (linkState == LinkState.UNSELECTED) {
            style = unselectedSameZoneStyle;
        }
    }
    return style;
}
Also used : PointLinkDescriptor(org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ILinkState(org.talend.designer.abstractmap.ui.visualmap.link.ILinkState) FilterTableEntry(org.talend.designer.dbmap.model.tableentry.FilterTableEntry) IStyleLink(org.talend.commons.ui.swt.drawing.link.IStyleLink)

Example 3 with PointLinkDescriptor

use of org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor in project tdi-studio-se by Talend.

the class StyleLinkFactory method getStyleLink.

// public static DrawableLinkFactory getInstance() {
// if (instance == null) {
// instance = new DrawableLinkFactory();
// }
// return instance;
// }
//
// public IDrawableLink getDrawableLink(IMapperLink link) {
// IDrawableLink drawableLink = null;
// PointLinkDescriptor pointLinkDescriptorSource = link.getPointLinkDescriptorSource();
// PointLinkDescriptor pointLinkDescriptorTarget = link.getPointLinkDescriptorTarget();
// if (pointLinkDescriptorSource.getZone() != pointLinkDescriptorTarget.getZone()) {
// drawableLink = new HorizontalBezierLink();
// } else if (pointLinkDescriptorSource.getZone() == pointLinkDescriptorTarget.getZone()) {
// drawableLink = new VerticalRoundedCornerLink();
// }
// return drawableLink;
// }
//
public IStyleLink getStyleLink(IMapperLink link) {
    ILinkState linkState = link.getState();
    PointLinkDescriptor pointLinkDescriptorSource = link.getPointLinkDescriptor1();
    PointLinkDescriptor pointLinkDescriptorTarget = link.getPointLinkDescriptor2();
    ITableEntry targetTableEntry = pointLinkDescriptorTarget.getTableEntry();
    boolean targetIsConstraint = false;
    if (targetTableEntry instanceof FilterTableEntry || targetTableEntry instanceof ExpressionFilterEntry) {
        targetIsConstraint = true;
    }
    boolean targetIsGlobalMap = false;
    if (targetTableEntry instanceof GlobalMapEntry) {
        targetIsGlobalMap = true;
    }
    IStyleLink style = null;
    if (pointLinkDescriptorSource.getZone() != pointLinkDescriptorTarget.getZone()) {
        if (linkState == LinkState.SELECTED) {
            if (targetIsConstraint) {
                style = selectedZoneToZoneFilterStyle;
            } else {
                style = selectedZoneToZoneStyle;
            }
        } else if (linkState == LinkState.UNSELECTED) {
            if (targetIsConstraint) {
                style = unselectedZoneToZoneFilterStyle;
            } else {
                style = unselectedZoneToZoneStyle;
            }
        }
    } else if (pointLinkDescriptorSource.getZone() == Zone.INPUTS && pointLinkDescriptorSource.getZone() == pointLinkDescriptorTarget.getZone()) {
        if (linkState == LinkState.SELECTED) {
            if (pointLinkDescriptorTarget.getTableEntry() instanceof ExpressionFilterEntry) {
                style = selectedSameZoneFilterStyle;
            } else if (pointLinkDescriptorTarget.getTableEntry() instanceof GlobalMapEntry) {
                style = selectedSameZoneGlobalMapStyle;
            } else {
                style = selectedSameInputZoneStyle;
            }
        } else if (linkState == LinkState.UNSELECTED) {
            if (pointLinkDescriptorTarget.getTableEntry() instanceof ExpressionFilterEntry) {
                style = unselectedSameZoneFilterStyle;
            } else if (pointLinkDescriptorTarget.getTableEntry() instanceof GlobalMapEntry) {
                style = unselectedSameZoneGlobalMapStyle;
            } else {
                style = unselectedSameInputZoneStyle;
            }
        }
    } else if (pointLinkDescriptorSource.getZone() == Zone.VARS && pointLinkDescriptorSource.getZone() == pointLinkDescriptorTarget.getZone()) {
        if (linkState == LinkState.SELECTED) {
            style = selectedSameVarsZoneStyle;
        } else if (linkState == LinkState.UNSELECTED) {
            style = unselectedSameVarsZoneStyle;
        }
    }
    return style;
}
Also used : PointLinkDescriptor(org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ILinkState(org.talend.designer.abstractmap.ui.visualmap.link.ILinkState) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) IStyleLink(org.talend.commons.ui.swt.drawing.link.IStyleLink) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry)

Example 4 with PointLinkDescriptor

use of org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor 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) {
    if (currentModifiedITableEntry instanceof InputColumnTableEntry) {
        InputColumnTableEntry entry = (InputColumnTableEntry) currentModifiedITableEntry;
        if (StringUtils.trimToNull(expression) == null) {
            entry.setOperator(null);
        }
    }
    DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(currentModifiedITableEntry);
    boolean linkHasBeenAdded = false;
    boolean linkHasBeenRemoved = false;
    DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.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;
    ECodeLanguage codeLanguage = LanguageProvider.getCurrentLanguage().getCodeLanguage();
    for (TableEntryLocation tableEntriesLocationsSource : tableEntriesLocationsSources) {
        TableEntryLocation location = tableEntriesLocationsSource;
        // tests to know if link must be removed if key is unchecked
        boolean dontRemoveLink = (!isInputEntry || isInputEntry && (inputExpressionAppliedOrCanceled || !inputExpressionAppliedOrCanceled && !mapperManager.checkEntryHasInvalidUncheckedKey((InputColumnTableEntry) currentModifiedITableEntry)));
        if (!alreadyProcessed.contains(location) && checkSourceLocationIsValid(location, currentModifiedITableEntry) && (mapperManager.isAdvancedMap() || !mapperManager.isAdvancedMap() && dontRemoveLink)) {
            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();
    if (!mapperManager.isAdvancedMap()) {
        if (dataMapTableView.getZone() == Zone.INPUTS) {
            if (linkHasBeenAdded || linkHasBeenRemoved) {
                checkTargetInputKey(currentModifiedITableEntry, checkInputKeyAutomatically, inputExpressionAppliedOrCanceled);
            }
            if (inputExpressionAppliedOrCanceled) {
                openChangeKeysDialog((InputDataMapTableView) dataMapTableView);
            }
        }
    }
    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.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) ParseExpressionResult(org.talend.designer.mapper.utils.ParseExpressionResult) DataMapExpressionParser(org.talend.designer.mapper.utils.DataMapExpressionParser) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) Link(org.talend.designer.mapper.ui.visualmap.link.Link) HashSet(java.util.HashSet) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)4 PointLinkDescriptor (org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor)4 HashSet (java.util.HashSet)2 IStyleLink (org.talend.commons.ui.swt.drawing.link.IStyleLink)2 ILinkState (org.talend.designer.abstractmap.ui.visualmap.link.ILinkState)2 IMapperLink (org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)1 FilterTableEntry (org.talend.designer.dbmap.model.tableentry.FilterTableEntry)1 InputColumnTableEntry (org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry)1 TableEntryLocation (org.talend.designer.dbmap.model.tableentry.TableEntryLocation)1 Link (org.talend.designer.dbmap.ui.visualmap.link.Link)1 DataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView)1 InputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.InputDataMapTableView)1 OutputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)1 DataMapExpressionParser (org.talend.designer.dbmap.utils.DataMapExpressionParser)1 ParseExpressionResult (org.talend.designer.dbmap.utils.ParseExpressionResult)1 ExpressionFilterEntry (org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)1 FilterTableEntry (org.talend.designer.mapper.model.tableentry.FilterTableEntry)1 GlobalMapEntry (org.talend.designer.mapper.model.tableentry.GlobalMapEntry)1 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)1