Search in sources :

Example 11 with IMapperLink

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

the class MapperManager method changeDependentSourcesAndTargetEntriesState.

/**
     * 
     * DOC amaumont Comment method "changeDependentSourcesAndTargetEntriesState".
     * 
     * @param entryCauseOfChange
     * @param currentLink
     * @param removedLink
     */
private void changeDependentSourcesAndTargetEntriesState(ITableEntry entryCauseOfChange, IMapperLink currentLink, boolean removedLink) {
    boolean sourceIsCauseOfChange = false;
    if (currentLink.getPointLinkDescriptor1().getTableEntry() == entryCauseOfChange) {
        sourceIsCauseOfChange = true;
    } else if (currentLink.getPointLinkDescriptor2().getTableEntry() == entryCauseOfChange) {
        sourceIsCauseOfChange = false;
    } else {
        //$NON-NLS-1$
        throw new IllegalArgumentException(Messages.getString("MapperManager.exceptionMessage.mustBeSourceOrTarget"));
    }
    if (sourceIsCauseOfChange) {
        Set<IMapperLink> dependentLinks = linkManager.getLinksFromSource(entryCauseOfChange);
        for (IMapperLink dependentLink : dependentLinks) {
            changeDependentEntriesState(currentLink, dependentLink.getPointLinkDescriptor2().getTableEntry(), removedLink);
        }
    } else {
        Set<IMapperLink> dependentLinks = linkManager.getLinksFromTarget(entryCauseOfChange);
        for (IMapperLink dependentLink : dependentLinks) {
            changeDependentEntriesState(currentLink, dependentLink.getPointLinkDescriptor1().getTableEntry(), removedLink);
        }
    }
    changeDependentEntriesState(currentLink, entryCauseOfChange, removedLink);
}
Also used : IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)

Example 12 with IMapperLink

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

the class UIManager method selectLinks.

/**
     * Highlight links and linked cells which have are referenced by the selected items.
     * 
     * @param dataMapTableView
     * @param selectedMetadataTableEntries, source or targets entries which must be highlighted, can be null to select
     * all links of a same DataMapTableView
     * @param isFilterTableSelected TODO
     * @param forceResetHighlightLinksForOtherTables TODO
     */
@SuppressWarnings("unchecked")
public void selectLinks(DataMapTableView dataMapTableView, List<ITableEntry> selectedMetadataTableEntries, boolean isFilterTableSelected, boolean forceResetHighlightLinksForOtherTables) {
    boolean selectColumnAndFiltersLinks = (selectedMetadataTableEntries == null);
    UIManager uiManager = mapperManager.getUiManager();
    TableViewerCreator<ITableEntry> currentTableViewer = null;
    TableViewerCreator<ITableEntry> whereFilterCreator = null;
    TableViewerCreator<ITableEntry> otherFilterCreator = null;
    if (isFilterTableSelected) {
        currentTableViewer = dataMapTableView.getTableViewerCreatorForWhereFilters();
    } else {
        currentTableViewer = dataMapTableView.getTableViewerCreatorForColumns();
    }
    // Color selectedColor = dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
    Color unselectedColor = dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    Zone currentZone = dataMapTableView.getZone();
    Set<ITableEntry> hashSelectedMetadataTableEntries = new HashSet<ITableEntry>();
    if (selectColumnAndFiltersLinks) {
        hashSelectedMetadataTableEntries.addAll(dataMapTableView.getTableViewerCreatorForColumns().getInputList());
        if (currentZone == Zone.OUTPUTS) {
            hashSelectedMetadataTableEntries.addAll(dataMapTableView.getTableViewerCreatorForWhereFilters().getInputList());
            hashSelectedMetadataTableEntries.addAll(dataMapTableView.getTableViewerCreatorForOtherFilters().getInputList());
        }
    } else {
        hashSelectedMetadataTableEntries.addAll(selectedMetadataTableEntries);
    }
    // ////////////////////////////////////////////////////////////////////////
    // Unselect all links and tableEntries if Ctrl or Shift keys are not pressed or if zone different of last
    // selection
    boolean zoneHasChanged = previousSelectedZone == Zone.INPUTS && currentZone == Zone.OUTPUTS || currentZone == Zone.INPUTS && previousSelectedZone == Zone.OUTPUTS;
    boolean tableTypeHasChanged = previousSelectedTableIsConstraint != isFilterTableSelected && currentZone == Zone.OUTPUTS;
    boolean resetHighlightObjectsForOtherTables = !uiManager.isDragging() && (!uiManager.isCtrlPressed() && !uiManager.isShiftPressed() || zoneHasChanged);
    if (resetHighlightObjectsForOtherTables || forceResetHighlightLinksForOtherTables) {
        for (IMapperLink link : mapperManager.getLinks()) {
            if (!hashSelectedMetadataTableEntries.contains(link.getPointLinkDescriptor1().getTableEntry()) && !hashSelectedMetadataTableEntries.contains(link.getPointLinkDescriptor2().getTableEntry())) {
                link.setState(LinkState.UNSELECTED);
                ITableEntry sourceITableEntry = link.getPointLinkDescriptor1().getTableEntry();
                TableItem tableItem = mapperManager.retrieveTableItem(sourceITableEntry);
                tableItem.setBackground(unselectedColor);
                ITableEntry targetITableEntry = link.getPointLinkDescriptor2().getTableEntry();
                tableItem = mapperManager.retrieveTableItem(targetITableEntry);
                tableItem.setBackground(unselectedColor);
            }
        }
        if (currentZone == Zone.INPUTS) {
            unselectAllOutputMetaDataEntries();
        } else if (currentZone == Zone.OUTPUTS) {
            unselectAllInputMetaDataEntries();
        }
        Collection<DataMapTableView> tablesToDeselectEntries = mapperManager.getTablesView();
        for (DataMapTableView viewToDeselectEntries : tablesToDeselectEntries) {
            if (viewToDeselectEntries != dataMapTableView) {
                viewToDeselectEntries.unselectAllEntries();
            } else if (viewToDeselectEntries == dataMapTableView && tableTypeHasChanged) {
                if (isFilterTableSelected) {
                    viewToDeselectEntries.unselectAllColumnEntries();
                } else {
                    viewToDeselectEntries.unselectAllConstraintEntries();
                }
            }
        }
    }
    // ////////////////////////////////////////////////////////////////////////
    // ////////////////////////////////////////////////////////////////////////
    // Select or unselect links and tableEntries
    List<ITableEntry> allEntriesOfCurrentTableView = new ArrayList<ITableEntry>();
    if (currentTableViewer != null) {
        allEntriesOfCurrentTableView.addAll(currentTableViewer.getInputList());
        if (selectColumnAndFiltersLinks && currentZone == Zone.OUTPUTS) {
            allEntriesOfCurrentTableView.addAll(dataMapTableView.getTableViewerCreatorForWhereFilters().getInputList());
            allEntriesOfCurrentTableView.addAll(dataMapTableView.getTableViewerCreatorForOtherFilters().getInputList());
        }
    }
    int lstSize = allEntriesOfCurrentTableView.size();
    Set<IMapperLink> linksAlreadySelected = new HashSet<IMapperLink>();
    for (int i = 0; i < lstSize; i++) {
        ITableEntry entry = allEntriesOfCurrentTableView.get(i);
        Set<IMapperLink> linksFromSource = mapperManager.getGraphicalLinksFromSource(entry);
        Set<IMapperLink> linksFromTarget = mapperManager.getGraphicalLinksFromTarget(entry);
        LinkState linkState = null;
        if (hashSelectedMetadataTableEntries.contains(entry)) {
            linkState = LinkState.SELECTED;
        } else {
            linkState = LinkState.UNSELECTED;
        }
        for (IMapperLink link : linksFromSource) {
            ITableEntry targetITableEntry = link.getPointLinkDescriptor2().getTableEntry();
            if (linkState == LinkState.SELECTED || !linksAlreadySelected.contains(link) && linkState == LinkState.UNSELECTED) {
                link.setState(linkState);
                if (linkState == LinkState.SELECTED) {
                    linksAlreadySelected.add(link);
                }
            }
            EntryState entryState = (link.getState() == LinkState.SELECTED ? EntryState.HIGHLIGHT : EntryState.NONE);
            setEntryState(mapperManager, entryState, targetITableEntry);
        }
        for (IMapperLink link : linksFromTarget) {
            ITableEntry sourceITableEntry = link.getPointLinkDescriptor1().getTableEntry();
            if (linkState == LinkState.SELECTED || !linksAlreadySelected.contains(link) && linkState == LinkState.UNSELECTED) {
                link.setState(linkState);
                if (linkState == LinkState.SELECTED) {
                    linksAlreadySelected.add(link);
                }
            }
            EntryState entryState = (link.getState() == LinkState.SELECTED ? EntryState.HIGHLIGHT : EntryState.NONE);
            setEntryState(mapperManager, entryState, sourceITableEntry);
        }
    }
    // ////////////////////////////////////////////////////////////////////////
    // order links to place selected links at last position (last drawn)
    mapperManager.orderLinks();
    uiManager.refreshBackground(false, false);
    previousSelectedZone = dataMapTableView.getZone();
    previousSelectedTableIsConstraint = isFilterTableSelected;
}
Also used : ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) 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) Color(org.eclipse.swt.graphics.Color) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) AbstractUIManager(org.talend.designer.abstractmap.managers.AbstractUIManager) 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) Point(org.eclipse.swt.graphics.Point) LinkState(org.talend.designer.abstractmap.ui.visualmap.link.LinkState) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) EntryState(org.talend.designer.dbmap.ui.visualmap.table.EntryState) HashSet(java.util.HashSet)

Example 13 with IMapperLink

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

the class MapperManager method removeLinksOf.

/**
     * Remove links from the given entry in the linkManager.
     * 
     * @param dataMapTableEntry
     */
public void removeLinksOf(ITableEntry dataMapTableEntry) {
    Set<IMapperLink> links = linkManager.getLinksFromSource(dataMapTableEntry);
    links.addAll(linkManager.getLinksFromTarget(dataMapTableEntry));
    for (IMapperLink link : links) {
        removeLink(link, dataMapTableEntry);
    }
}
Also used : IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)

Example 14 with IMapperLink

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

the class LinkManager method registerLevelForNewLink.

/**
     * DOC amaumont Comment method "registerLevelForNewLink".
     * 
     * @param link
     * @param graphicalLinksFromTarget
     */
protected void registerLevelForNewLink(IMapperLink link, Set<IMapperLink> graphicalLinksFromTarget) {
    boolean hasAlreadyInputTarget = false;
    boolean hasAlreadyVarTarget = false;
    ITableEntry sourceEntry = link.getPointLinkDescriptor1().getTableEntry();
    ITableEntry targetEntry = link.getPointLinkDescriptor2().getTableEntry();
    boolean hasSameZone = sourceEntry.getClass() == targetEntry.getClass();
    boolean isInput = targetEntry instanceof InputColumnTableEntry;
    boolean isOutput = targetEntry instanceof OutputColumnTableEntry;
    if (hasSameZone) {
        List<List<IMapperLink>> leveledLinks = null;
        if (isInput) {
            leveledLinks = getInputLinksForLevels();
        }
        if (isOutput) {
            leveledLinks = getOutputLinksForLevels();
        }
        int lstSize = leveledLinks.size();
        for (int indexOfLeveledLink = 0; indexOfLeveledLink < lstSize; indexOfLeveledLink++) {
            List<IMapperLink> linksFromLevelsList = leveledLinks.get(indexOfLeveledLink);
            if (linksFromLevelsList != null && linksFromLevelsList.size() > 0) {
                IMapperLink linkFromLevelsList = linksFromLevelsList.get(0);
                ITableEntry sourceTableEntry = linkFromLevelsList.getPointLinkDescriptor1().getTableEntry();
                ITableEntry targetTableEntry = linkFromLevelsList.getPointLinkDescriptor2().getTableEntry();
                if (targetEntry == targetTableEntry) {
                    if (sourceTableEntry instanceof InputColumnTableEntry && targetTableEntry instanceof InputColumnTableEntry) {
                        hasAlreadyInputTarget = true;
                    }
                    if (sourceTableEntry instanceof VarTableEntry && targetTableEntry instanceof VarTableEntry) {
                        hasAlreadyVarTarget = true;
                    }
                    if (hasAlreadyInputTarget || hasAlreadyVarTarget) {
                        linksFromLevelsList.add(link);
                        link.setLevel(indexOfLeveledLink + 1);
                        break;
                    }
                }
            }
        }
        if (isInput && !hasAlreadyInputTarget) {
            ArrayList<IMapperLink> list = new ArrayList<IMapperLink>();
            int firstEmptyIndex = searchFirstEmptyIndexLeveledList(leveledLinks);
            link.setLevel(firstEmptyIndex + 1);
            list.add(link);
            if (firstEmptyIndex < leveledLinks.size()) {
                leveledLinks.set(firstEmptyIndex, list);
            } else {
                leveledLinks.add(list);
            }
        }
    }
}
Also used : ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ArrayList(java.util.ArrayList) 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) VarTableEntry(org.talend.designer.dbmap.model.tableentry.VarTableEntry) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry)

Example 15 with IMapperLink

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

the class UIManager method parseFilterColumn.

public ParseExpressionResult parseFilterColumn(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);
            if (sourceTableEntry != null && sourcesForTarget.contains(sourceTableEntry)) {
                Set<IMapperLink> targets = mapperManager.getGraphicalLinksFromTarget(currentModifiedITableEntry);
                Set<IMapperLink> linksFromTarget = new HashSet<IMapperLink>(targets);
                for (IMapperLink link : linksFromTarget) {
                    link.calculate();
                }
            }
        }
    }
    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 : 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) HashSet(java.util.HashSet) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

IMapperLink (org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)17 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)11 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 List (java.util.List)4 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)4 InputColumnTableEntry (org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry)3 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)3 InputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView)3 OutputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)3 VarsDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView)3 Color (org.eclipse.swt.graphics.Color)2 Point (org.eclipse.swt.graphics.Point)2 TableItem (org.eclipse.swt.widgets.TableItem)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 AbstractUIManager (org.talend.designer.abstractmap.managers.AbstractUIManager)2 LinkState (org.talend.designer.abstractmap.ui.visualmap.link.LinkState)2 PointLinkDescriptor (org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor)2 OutputColumnTableEntry (org.talend.designer.dbmap.model.tableentry.OutputColumnTableEntry)2 DataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView)2