Search in sources :

Example 1 with IDbLanguage

use of org.talend.designer.dbmap.language.IDbLanguage in project tdi-studio-se by Talend.

the class CompleteDropTargetListener 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(draggableTable, cursorPosition);
    IDbLanguage currentLanguage = getMapperManager().getCurrentLanguage();
    DataMapTableView dataMapTableViewTarget = getMapperManager().retrieveDataMapTableView(draggableTable);
    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();
    draggableTable.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 atLeastOneEntryInserted = false;
    boolean insertionEntryMode = analyzer.isInsertionEntryMode();
    boolean mapEachSourceToNextTargets = analyzer.isMapOneToOneMode();
    TableViewerCreator tableViewerCreatorTarget = null;
    if (targetTableIsFiltersTable) {
        if (analyzer.targetTableIsWhereFiltersTable()) {
            tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForWhereFilters();
        } else {
            tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForOtherFilters();
        }
    } else {
        tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForColumns();
    }
    // 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) {
            modifyExistingEntry(uiManager, analyzer, currentLanguage, currentEntryTarget, columnIndicesToSelect, tableViewerCreatorTarget, lastEntryTarget, tableEntrySource, zoneSourceEntry);
        } 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.OUTPUTS) {
                insertNewInOutEntryFromInputEntry(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
                tableEntrySource, metadataColumnDragged, columnName);
                atLeastOneEntryInserted = true;
            } 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);
        }
    }
    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);
    uiManager.unselectAllOutputMetaDataEntries();
    uiManager.unselectAllInputMetaDataEntries();
    uiManager.parseAllExpressionsForAllTables();
    getMapperManager().getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
    getUiManager().refreshSqlExpression();
    uiManager.selectLinks(dataMapTableViewTarget, selectedEntries, targetTableIsFiltersTable, true);
    tableViewerCreatorTarget.getTable().setFocus();
    uiManager.setDragging(false);
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) IDbLanguage(org.talend.designer.dbmap.language.IDbLanguage) ArrayList(java.util.ArrayList) AbstractUIManager(org.talend.designer.abstractmap.managers.AbstractUIManager) UIManager(org.talend.designer.dbmap.managers.UIManager) TableEntryLocation(org.talend.designer.dbmap.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.dbmap.ui.visualmap.zone.Zone) DataMapTableView(org.talend.designer.dbmap.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)

Example 2 with IDbLanguage

use of org.talend.designer.dbmap.language.IDbLanguage in project tdi-studio-se by Talend.

the class AutoMapper method map.

/**
     * DOC amaumont Comment method "map".
     */
public void map() {
    List<InputTable> inputTables = mapperManager.getInputTables();
    List<OutputTable> outputTables = mapperManager.getOutputTables();
    IDbLanguage currentLanguage = mapperManager.getCurrentLanguage();
    HashMap<String, InputTable> nameToInputTable = new HashMap<String, InputTable>(inputTables.size());
    for (InputTable inputTable : inputTables) {
        nameToInputTable.put(inputTable.getName(), inputTable);
    }
    // output tables are the references
    for (OutputTable outputTable : outputTables) {
        List<IColumnEntry> outputEntries = outputTable.getColumnEntries();
        boolean mapFound = false;
        for (IColumnEntry outputEntry : outputEntries) {
            mapFound = false;
            if (mapperManager.checkEntryHasEmptyExpression(outputEntry)) {
                String outputColumnName = outputEntry.getName();
                for (InputTable inputTable : inputTables) {
                    List<IColumnEntry> inputColumnEntries = inputTable.getColumnEntries();
                    for (IColumnEntry inputEntry : inputColumnEntries) {
                        if (inputEntry.getName().equalsIgnoreCase(outputColumnName)) {
                            outputEntry.setExpression(currentLanguage.getLocation(inputTable.getName(), inputEntry.getName()));
                            mapFound = true;
                            break;
                        }
                    }
                    if (mapFound) {
                        break;
                    }
                }
            }
        }
        DataMapTableView view = mapperManager.retrieveIDataMapTableView(outputTable);
        view.getTableViewerCreatorForColumns().getTableViewer().refresh();
    }
    mapperManager.getProblemsManager().checkProblems();
    List<DataMapTableView> outputsTablesView = mapperManager.getUiManager().getOutputsTablesView();
    for (DataMapTableView view : outputsTablesView) {
        mapperManager.getUiManager().parseAllExpressions(view, true);
        mapperManager.getProblemsManager().checkProblemsForAllEntries(view, true);
    }
    mapperManager.getUiManager().refreshBackground(true, false);
}
Also used : HashMap(java.util.HashMap) IDbLanguage(org.talend.designer.dbmap.language.IDbLanguage) DataMapTableView(org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) OutputTable(org.talend.designer.dbmap.model.table.OutputTable) InputTable(org.talend.designer.dbmap.model.table.InputTable)

Aggregations

IDbLanguage (org.talend.designer.dbmap.language.IDbLanguage)2 DataMapTableView (org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ISelection (org.eclipse.jface.viewers.ISelection)1 Point (org.eclipse.swt.graphics.Point)1 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 MetadataTableEditorView (org.talend.core.ui.metadata.editor.MetadataTableEditorView)1 AbstractUIManager (org.talend.designer.abstractmap.managers.AbstractUIManager)1 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)1 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)1 DraggedData (org.talend.designer.abstractmap.ui.dnd.DraggedData)1 TransferableEntry (org.talend.designer.abstractmap.ui.dnd.TransferableEntry)1 UIManager (org.talend.designer.dbmap.managers.UIManager)1 InputTable (org.talend.designer.dbmap.model.table.InputTable)1 OutputTable (org.talend.designer.dbmap.model.table.OutputTable)1 TableEntryLocation (org.talend.designer.dbmap.model.tableentry.TableEntryLocation)1 Zone (org.talend.designer.dbmap.ui.visualmap.zone.Zone)1