Search in sources :

Example 21 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class JavaSampleCodeFactory method generateJavaRowCode.

/**
     * 
     * DOC YeXiaowei Comment method "generateJavaRowCode". Generates Java code for the tJavaRow component in DI and BD.
     * 
     * @param node
     * @return
     */
private String generateJavaRowCode(final Node node) {
    boolean isSparkNode = false;
    //$NON-NLS-1$
    String sparkMapType = "MAP";
    ComponentCategory componentCategory = ComponentCategory.getComponentCategoryFromName(node.getComponent().getType());
    String primeVlue = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "// code sample:\r\n" + "//\r\n" + "// multiply by 2 the row identifier\r\n" + "// output_row.id = input_row.id * 2;\r\n" + "//\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "// lowercase the name\r\n" + //$NON-NLS-1$
    "// output_row.name = input_row.name.toLowerCase();";
    if (ComponentCategory.CATEGORY_4_SPARK == componentCategory || ComponentCategory.CATEGORY_4_SPARKSTREAMING == componentCategory) {
        isSparkNode = true;
        //$NON-NLS-1$
        sparkMapType = node.getPropertyValue("MAPTYPE").toString();
        //$NON-NLS-1$
        primeVlue = "// Please add an input to the component to generate a sample code\r\n";
    }
    if (node.getMetadataList() == null || node.getMetadataList().get(0) == null) {
        return primeVlue;
    }
    if (node.getIncomingConnections() == null || node.getIncomingConnections().isEmpty() || node.getIncomingConnections().get(0).getMetadataTable() == null) {
        return primeVlue;
    }
    IMetadataTable inputTable = node.getIncomingConnections().get(0).getMetadataTable();
    List<IMetadataColumn> inputColumns = inputTable.getListColumns();
    IMetadataTable outputTable = node.getMetadataList().get(0);
    List<IMetadataColumn> outputColumns = outputTable.getListColumns();
    if (inputColumns == null || inputColumns.isEmpty() || outputColumns == null || outputColumns.isEmpty()) {
        return primeVlue;
    }
    //$NON-NLS-1$
    String javaEnding = ";";
    //$NON-NLS-1$
    String lineSeparator = System.getProperty("line.separator");
    StringBuilder builder = new StringBuilder();
    //$NON-NLS-1$
    boolean isSelect = MessageDialog.openQuestion(null, null, Messages.getString("JavaSampleCodeFactory.askRegenerateCode"));
    if (isSelect) {
        // Add simple comment
        //$NON-NLS-1$
        builder.append(Messages.getString("JavaSampleCodeFactory.schema")).append(lineSeparator);
        int inputRowsLength = inputColumns.size();
        int ouputRowsLength = outputColumns.size();
        if (inputRowsLength == 0 || ouputRowsLength == 0) {
            return null;
        }
        if (isSparkNode && (sparkMapType.equalsIgnoreCase("FLATMAP"))) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            builder.append("Output output = new Output();\r\n");
        }
        if (inputRowsLength >= ouputRowsLength) {
            for (int i = 0; i < inputRowsLength; i++) {
                String inputLabel = inputColumns.get(i).getLabel();
                String outputLabel = null;
                if (i > ouputRowsLength - 1) {
                    outputLabel = outputColumns.get(ouputRowsLength - 1).getLabel();
                } else {
                    outputLabel = outputColumns.get(i).getLabel();
                }
                if (isSparkNode) {
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    builder.append("output.").append(outputLabel).append(" = ").append("input.").append(inputLabel).append(javaEnding);
                } else {
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    builder.append("output_row.").append(outputLabel).append(" = ").append("input_row.").append(inputLabel).append(javaEnding);
                }
                builder.append(lineSeparator);
            }
        } else {
            for (int i = 0; i < ouputRowsLength; i++) {
                String outputLabel = outputColumns.get(i).getLabel();
                String inputLabel = null;
                if (i > inputRowsLength - 1) {
                    inputLabel = inputColumns.get(inputRowsLength - 1).getLabel();
                } else {
                    inputLabel = inputColumns.get(i).getLabel();
                }
                if (isSparkNode) {
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    builder.append("output.").append(outputLabel).append(" = ").append("input.").append(inputLabel).append(javaEnding);
                } else {
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    builder.append("output_row.").append(outputLabel).append(" = ").append("input_row.").append(inputLabel).append(javaEnding);
                }
                builder.append(lineSeparator);
            }
        }
        if (isSparkNode && (sparkMapType.equalsIgnoreCase("FLATMAP"))) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            builder.append("outputList.add(output);\r\n");
        }
        return builder.toString();
    } else {
        return null;
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) ComponentCategory(org.talend.core.model.components.ComponentCategory)

Example 22 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class ParallelExecutionUtils method copyTable.

public static void copyTable(IMetadataTable source, IMetadataTable target) {
    if (source == null || target == null) {
        return;
    }
    List<IMetadataColumn> columnsToRemove = new ArrayList<IMetadataColumn>();
    List<String> readOnlycolumns = new ArrayList<String>();
    for (IMetadataColumn column : target.getListColumns(true)) {
        if (!column.isCustom()) {
            columnsToRemove.add(column);
        }
        if (column.isReadOnly()) {
            readOnlycolumns.add(column.getLabel());
        }
    }
    target.getListColumns().removeAll(columnsToRemove);
    target.getListUnusedColumns().removeAll(columnsToRemove);
    List<IMetadataColumn> columnsTAdd = new ArrayList<IMetadataColumn>();
    for (IMetadataColumn column : source.getListColumns(true)) {
        IMetadataColumn targetColumn = target.getColumn(column.getLabel());
        IMetadataColumn newTargetColumn = column.clone();
        if (targetColumn == null) {
            columnsTAdd.add(newTargetColumn);
            newTargetColumn.setReadOnly(target.isReadOnly() || readOnlycolumns.contains(newTargetColumn.getLabel()));
        } else {
            if (!targetColumn.isReadOnly()) {
                target.getListColumns().remove(targetColumn);
                newTargetColumn.setCustom(targetColumn.isCustom());
                newTargetColumn.setCustomId(targetColumn.getCustomId());
                columnsTAdd.add(newTargetColumn);
            }
        }
    }
    target.getListColumns().addAll(columnsTAdd);
    target.sortCustomColumns();
    target.setLabel(source.getLabel());
}
Also used : ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 23 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class CompleteDropTargetListener method insertNewInOutEntryFromInputEntry.

private void insertNewInOutEntryFromInputEntry(ArrayList<ITableEntry> sources, ArrayList<IMetadataColumn> metadataColumnsBeingAdded, // MetadataEditorEvent metadataEditorEvent,
ITableEntry tableEntrySource, IMetadataColumn metadataColumnDragged, String columnName) {
    MetadataColumn metadataColumn = new MetadataColumn(metadataColumnDragged);
    metadataColumn.setLabel(columnName);
    metadataColumnsBeingAdded.add(metadataColumn);
    // metadataEditorEvent.entries.add(metadataColumn);
    sources.add(tableEntrySource);
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn)

Example 24 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn 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 25 with IMetadataColumn

use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.

the class CompleteDropTargetListener method insertNewOutputEntryFromVarEntry.

private void insertNewOutputEntryFromVarEntry(ArrayList<ITableEntry> sources, ArrayList<IMetadataColumn> metadataColumnsBeingAdded, ITableEntry tableEntrySource, String columnName) {
    MetadataColumn metadataColumn = new MetadataColumn();
    metadataColumn.setLabel(columnName);
    metadataColumn.setTalendType(((VarTableEntry) tableEntrySource).getType());
    metadataColumn.setNullable(((VarTableEntry) tableEntrySource).isNullable());
    metadataColumnsBeingAdded.add(metadataColumn);
    sources.add(tableEntrySource);
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn)

Aggregations

IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)149 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)82 ArrayList (java.util.ArrayList)73 List (java.util.List)34 IConnection (org.talend.core.model.process.IConnection)34 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)31 HashMap (java.util.HashMap)30 IElementParameter (org.talend.core.model.process.IElementParameter)26 Map (java.util.Map)24 INode (org.talend.core.model.process.INode)24 MetadataTable (org.talend.core.model.metadata.MetadataTable)23 Node (org.talend.designer.core.ui.editor.nodes.Node)16 Point (org.eclipse.swt.graphics.Point)15 Connection (org.talend.designer.core.ui.editor.connections.Connection)10 INodeConnector (org.talend.core.model.process.INodeConnector)9 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)9 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)9 MetadataTableEditor (org.talend.core.ui.metadata.editor.MetadataTableEditor)8 IComponent (org.talend.core.model.components.IComponent)7 IODataComponent (org.talend.core.model.components.IODataComponent)7