Search in sources :

Example 1 with EntryState

use of org.talend.designer.dbmap.ui.visualmap.table.EntryState 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Color (org.eclipse.swt.graphics.Color)1 Point (org.eclipse.swt.graphics.Point)1 TableItem (org.eclipse.swt.widgets.TableItem)1 AbstractUIManager (org.talend.designer.abstractmap.managers.AbstractUIManager)1 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)1 IMapperLink (org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)1 LinkState (org.talend.designer.abstractmap.ui.visualmap.link.LinkState)1 DataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView)1 EntryState (org.talend.designer.dbmap.ui.visualmap.table.EntryState)1 InputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.InputDataMapTableView)1 OutputDataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.OutputDataMapTableView)1 InputsZone (org.talend.designer.dbmap.ui.visualmap.zone.InputsZone)1 OutputsZone (org.talend.designer.dbmap.ui.visualmap.zone.OutputsZone)1 Zone (org.talend.designer.dbmap.ui.visualmap.zone.Zone)1 ToolbarInputZone (org.talend.designer.dbmap.ui.visualmap.zone.toolbar.ToolbarInputZone)1 ToolbarOutputZone (org.talend.designer.dbmap.ui.visualmap.zone.toolbar.ToolbarOutputZone)1 ToolbarZone (org.talend.designer.dbmap.ui.visualmap.zone.toolbar.ToolbarZone)1