Search in sources :

Example 11 with InputColumnTableEntry

use of org.talend.designer.mapper.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) {
    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)

Example 12 with InputColumnTableEntry

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

the class CompleteDropTargetTableListener method drop.

// private void showInfos(DropTargetEvent event) {
// System.out.println(event);
// System.out.println("event.feedback=" + event.feedback);
// System.out.println("event.detail=" + event.detail);
// System.out.println("event.operations=" + event.operations);
//
// System.out.println("DND.DROP_DEFAULT=" + DND.DROP_DEFAULT);
// System.out.println("DND.DROP_COPY=" + DND.DROP_COPY);
// System.out.println("DND.DROP_MOVE=" + DND.DROP_MOVE);
// System.out.println("DND.DROP_LINK=" + DND.DROP_LINK);
// System.out.println("DND.DROP_TARGET_MOVE=" + DND.DROP_TARGET_MOVE);
// }
//
@Override
public void drop(DropTargetEvent event) {
    super.drop(event);
    retrieveInsertionIndicator().setVisible(false);
    UIManager uiManager = getUiManager();
    DraggedData draggedData = TableEntriesTransfer.getInstance().getDraggedData();
    DropContextAnalyzer analyzer = analyzeDropTarget(event, draggedData);
    // System.out.println("\n>>drop");
    // System.out.println(event);
    Point cursorPosition = new Point(event.x, event.y);
    // int startInsertAtThisIndex = getItemIndexWhereInsertFromPosition(cursorPosition);
    int startInsertAtThisIndex = TableUtils.getItemIndexWhereInsertFromPosition(draggableTargetControl, cursorPosition);
    ILanguage currentLanguage = LanguageProvider.getCurrentLanguage();
    DataMapTableView dataMapTableViewTarget = getMapperManager().retrieveDataMapTableView(draggableTargetControl);
    Zone zoneTarget = dataMapTableViewTarget.getZone();
    uiManager.selectDataMapTableView(dataMapTableViewTarget, true, false);
    MetadataTableEditorView metadataEditorView = getUiManager().getMetadataEditorView(dataMapTableViewTarget.getZone());
    List<TransferableEntry> transferableEntryList = draggedData.getTransferableEntryList();
    int currentIndex = startInsertAtThisIndex;
    uiManager.clearLastCreatedInOutColumnEntries();
    draggableTargetControl.deselectAll();
    ITableEntry currentEntryTarget = getEntryFromPosition(cursorPosition);
    ArrayList<String> columnsBeingAdded = new ArrayList<String>();
    ArrayList<Integer> columnIndicesToSelect = new ArrayList<Integer>();
    ArrayList<ITableEntry> sourceEntriesOfEntriesBeingAdded = new ArrayList<ITableEntry>();
    ArrayList<IMetadataColumn> metadataColumnsBeingAdded = new ArrayList<IMetadataColumn>();
    boolean targetTableIsFiltersTable = analyzer.targetTableIsFiltersTable();
    boolean targetTableIsGlobalMapTable = analyzer.targetTableIsGlobalMapTable();
    boolean atLeastOneEntryInserted = false;
    boolean insertionEntryMode = analyzer.isInsertionEntryMode();
    boolean mapEachSourceToNextTargets = analyzer.isMapOneToOneMode();
    TableViewerCreator tableViewerCreatorTarget = null;
    if (!analyzer.targetIsExpressionFilterText()) {
        if (targetTableIsFiltersTable) {
            tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForFilters();
        } else if (targetTableIsGlobalMapTable) {
            tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForGlobalMap();
        } else {
            tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForColumns();
        }
    }
    uiManager.applyActivatedCellEditors(tableViewerCreatorTarget);
    // MapperDropCommand dropCommand = new MapperDropCommand();
    // MetadataEditorEvent metadataEditorEvent = new MetadataEditorEvent(MetadataEditorEvent.TYPE.ADD);
    ITableEntry lastEntryTarget = null;
    for (TransferableEntry transferableEntry : transferableEntryList) {
        ITableEntry tableEntrySource = transferableEntry.getTableEntrySource();
        IMetadataColumn metadataColumnDragged = transferableEntry.getMetadataColumn();
        Zone zoneSourceEntry = (Zone) transferableEntry.getZoneSourceEntry();
        TableEntryLocation tableEntryLocationTarget = new TableEntryLocation(dataMapTableViewTarget.getDataMapTable().getName(), tableEntrySource.getName());
        if (zoneSourceEntry == Zone.INPUTS && zoneTarget == Zone.INPUTS && tableEntrySource.getParentName().equals(tableEntryLocationTarget.tableName)) {
            continue;
        } else if (currentEntryTarget != null && !insertionEntryMode) {
            // set the default operator.
            if (currentEntryTarget instanceof InputColumnTableEntry) {
                ((InputColumnTableEntry) currentEntryTarget).setOperator(Operator.EQUALS.getLiteral());
            }
            boolean overwrite = (lastEntryTarget != currentEntryTarget && analyzer.isOverwriteExpression());
            modifyExistingExpression(currentLanguage, currentEntryTarget, tableEntrySource, overwrite, zoneSourceEntry);
            uiManager.parseExpression(currentEntryTarget.getExpression(), currentEntryTarget, false, true, true);
            int indexOfEntry = tableViewerCreatorTarget.getInputList().indexOf(currentEntryTarget);
            columnIndicesToSelect.add(indexOfEntry);
        } else {
            String columnName = transferableEntry.getTableEntrySource().getName();
            tableEntryLocationTarget = getMapperManager().findUniqueLocation(tableEntryLocationTarget, dataMapTableViewTarget.getDataMapTable());
            columnName = tableEntryLocationTarget.columnName;
            if (currentEntryTarget == null && analyzer.isMapOneToOneMode()) {
                currentIndex = tableViewerCreatorTarget.getInputList().size();
                columnIndicesToSelect.add(currentIndex);
            }
            if (zoneSourceEntry == Zone.INPUTS && zoneTarget == Zone.VARS || zoneSourceEntry == Zone.VARS && zoneTarget == Zone.VARS) {
                columnIndicesToSelect.add(currentIndex);
                currentIndex = insertNewVarEntry(currentLanguage, dataMapTableViewTarget, currentIndex, tableEntrySource, columnName);
                atLeastOneEntryInserted = true;
            } else if (zoneSourceEntry == Zone.VARS && zoneTarget == Zone.OUTPUTS) {
                insertNewOutputEntryFromVarEntry(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
                tableEntrySource, columnName);
                atLeastOneEntryInserted = true;
            } else if (zoneSourceEntry == Zone.INPUTS && targetTableIsGlobalMapTable) {
                insertNewGlobalMapEntryFromInputEntry(currentLanguage, dataMapTableViewTarget, currentIndex, tableEntrySource);
                atLeastOneEntryInserted = true;
            } else if (zoneSourceEntry == Zone.INPUTS && zoneTarget != Zone.VARS) {
                insertNewInOutEntryFromInputEntry(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
                tableEntrySource, metadataColumnDragged, columnName);
                atLeastOneEntryInserted = true;
            } else if (zoneSourceEntry == Zone.OUTPUTS && zoneTarget == Zone.VARS) {
            // nothing
            } else if (zoneSourceEntry == Zone.OUTPUTS && zoneTarget == Zone.OUTPUTS) {
                insertOutpuEntryCopyToOtherOutput(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
                tableEntrySource, metadataColumnDragged, columnName);
                atLeastOneEntryInserted = true;
            } else {
            // throw new IllegalStateException("Drop case not found !");
            }
            columnsBeingAdded.add(columnName);
        }
        lastEntryTarget = currentEntryTarget;
        if (mapEachSourceToNextTargets && currentEntryTarget != null) {
            currentEntryTarget = getNextEntryTarget(currentEntryTarget, tableViewerCreatorTarget);
        }
    }
    if (!atLeastOneEntryInserted) {
        tableViewerCreatorTarget.getTableViewer().refresh();
    } else {
        updateExpressionsOfInsertedEntries(currentLanguage, metadataEditorView, currentIndex, sourceEntriesOfEntriesBeingAdded, targetTableIsFiltersTable, tableViewerCreatorTarget, // , metadataEditorEvent
        metadataColumnsBeingAdded);
        for (int i = currentIndex; i < currentIndex + sourceEntriesOfEntriesBeingAdded.size(); i++) {
            columnIndicesToSelect.add(i);
        }
    }
    if (zoneTarget == Zone.VARS) {
        dataMapTableViewTarget.resizeAtExpandedSize();
    }
    if (targetTableIsGlobalMapTable) {
        dataMapTableViewTarget.updateGridDataHeightForTableGlobalMap();
        dataMapTableViewTarget.resizeAtExpandedSize();
    }
    uiManager.unselectAllEntriesOfAllTables();
    uiManager.refreshBackground(true, false);
    if (metadataEditorView != null && !targetTableIsFiltersTable) {
        metadataEditorView.getTableViewerCreator().getTableViewer().refresh();
    }
    int[] selection = ArrayUtils.toPrimitive(columnIndicesToSelect.toArray(new Integer[0]));
    tableViewerCreatorTarget.getSelectionHelper().setSelection(selection);
    ISelection iselection = tableViewerCreatorTarget.getTableViewer().getSelection();
    List<ITableEntry> selectedEntries = uiManager.extractSelectedTableEntries(iselection);
    tableViewerCreatorTarget.getTable().deselectAll();
    uiManager.unselectAllOutputMetaDataEntries();
    uiManager.unselectAllInputMetaDataEntries();
    uiManager.parseAllExpressionsForAllTables();
    getMapperManager().getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
    getMapperManager().getProblemsManager().checkLookupExpressionProblem();
    uiManager.selectLinks(dataMapTableViewTarget, selectedEntries, true, false);
    dataMapTableViewTarget.checkChangementsAfterEntryModifiedOrAdded(false);
    tableViewerCreatorTarget.getTable().setFocus();
    uiManager.setDragging(false);
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ArrayList(java.util.ArrayList) AbstractUIManager(org.talend.designer.abstractmap.managers.AbstractUIManager) UIManager(org.talend.designer.mapper.managers.UIManager) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ISelection(org.eclipse.jface.viewers.ISelection) MetadataTableEditorView(org.talend.core.ui.metadata.editor.MetadataTableEditorView) TransferableEntry(org.talend.designer.abstractmap.ui.dnd.TransferableEntry) Zone(org.talend.designer.mapper.ui.visualmap.zone.Zone) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) DraggedData(org.talend.designer.abstractmap.ui.dnd.DraggedData) Point(org.eclipse.swt.graphics.Point) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Point(org.eclipse.swt.graphics.Point) ILanguage(org.talend.designer.mapper.language.ILanguage) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)

Example 13 with InputColumnTableEntry

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

the class CompleteDropTargetTableListener method insertNewVarEntry.

private int insertNewVarEntry(ILanguage currentLanguage, DataMapTableView dataMapTableViewTarget, int currentIndex, ITableEntry tableEntrySource, String columnName) {
    ITableEntry dataMapTableEntry;
    String type = null;
    if (tableEntrySource.getParent() instanceof InputTable) {
        type = ((InputColumnTableEntry) tableEntrySource).getMetadataColumn().getTalendType();
    } else if (tableEntrySource.getParent() instanceof VarsTable) {
        type = ((VarTableEntry) tableEntrySource).getType();
    }
    dataMapTableEntry = getMapperManager().addNewVarEntry(dataMapTableViewTarget, columnName, currentIndex++, type);
    String location = currentLanguage.getLocation(tableEntrySource.getParentName(), tableEntrySource.getName());
    //$NON-NLS-1$
    dataMapTableEntry.setExpression(location + " ");
    return currentIndex;
}
Also used : InputTable(org.talend.designer.mapper.model.table.InputTable) VarsTable(org.talend.designer.mapper.model.table.VarsTable) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) VarTableEntry(org.talend.designer.mapper.model.tableentry.VarTableEntry) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)

Aggregations

InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)13 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)6 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 InputTable (org.talend.designer.mapper.model.table.InputTable)5 IMapperLink (org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)4 VarTableEntry (org.talend.designer.mapper.model.tableentry.VarTableEntry)4 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)4 ArrayList (java.util.ArrayList)3 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)3 GlobalMapEntry (org.talend.designer.mapper.model.tableentry.GlobalMapEntry)3 TableEntryLocation (org.talend.designer.mapper.model.tableentry.TableEntryLocation)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 HashSet (java.util.HashSet)2 List (java.util.List)2 Point (org.eclipse.swt.graphics.Point)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)2 ILanguage (org.talend.designer.mapper.language.ILanguage)2