Search in sources :

Example 46 with IConnection

use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.

the class ComboController method createButtonCommand.

/**
     * This method is used for "Guess Query" button.
     * 
     * @return
     */
private Command createButtonCommand() {
    IMetadataTable repositoryMetadata = null;
    IMetadataTable newRepositoryMetadata = null;
    String realTableName = null;
    String realTableId = null;
    // Only for getting the real table name.
    if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
        String paramName;
        IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        Object repositoryControl = hashCurControls.get(repositorySchemaTypeParameter.getName());
        paramName = EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
        if (repositoryControl != null) {
            String selectedComboItem = ((CCombo) repositoryControl).getText();
            if (selectedComboItem != null && selectedComboItem.length() > 0) {
                //$NON-NLS-1$
                String value = new String("");
                for (int i = 0; i < elem.getElementParameters().size(); i++) {
                    IElementParameter param = elem.getElementParameters().get(i);
                    if (param.getName().equals(paramName)) {
                        for (int j = 0; j < param.getListItemsValue().length; j++) {
                            if (selectedComboItem.equals(param.getListItemsDisplayName()[j])) {
                                value = (String) param.getListItemsValue()[j];
                            }
                        }
                    }
                }
                if (elem instanceof Node) {
                    // this.dynamicProperty.updateRepositoryList();
                    String connectionId = value.toString().split(" - ")[0];
                    String tableLabel = value.toString().split(" - ")[1];
                    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                    Item item = null;
                    try {
                        IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                        if (repobj != null) {
                            Property property = repobj.getProperty();
                            if (property != null) {
                                item = property.getItem();
                            }
                        }
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                    if (item != null && item instanceof ConnectionItem) {
                        boolean findTable = false;
                        Connection connection = ((ConnectionItem) item).getConnection();
                        for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                            if (table.getLabel().equals(tableLabel)) {
                                repositoryMetadata = ConvertionHelper.convert(table);
                                findTable = true;
                                break;
                            }
                        }
                        if (!findTable) {
                            repositoryMetadata = new MetadataTable();
                        }
                    }
                // if (repositoryTableMap.containsKey(value)) {
                // repositoryMetadata = repositoryTableMap.get(value);
                // realTableName = repositoryMetadata.getTableName();
                // realTableId = repositoryMetadata.getId();
                // } else {
                // repositoryMetadata = new MetadataTable();
                // }
                }
            }
        }
    }
    // Ends
    QueryGuessCommand cmd = null;
    INode node = null;
    if (elem instanceof INode) {
        node = (INode) elem;
    } else {
        // else instanceof Connection
        node = ((IConnection) elem).getSource();
    }
    newRepositoryMetadata = node.getMetadataList().get(0);
    if (newRepositoryMetadata == null) {
        String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        if (schemaSelected != null) {
            String connectionId = schemaSelected.toString().split(" - ")[0];
            String tableLabel = schemaSelected.toString().split(" - ")[1];
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            Item item = null;
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            if (item != null && item instanceof ConnectionItem) {
                boolean findTable = false;
                Connection connection = ((ConnectionItem) item).getConnection();
                for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                    if (table.getLabel().equals(tableLabel)) {
                        repositoryMetadata = ConvertionHelper.convert(table);
                        findTable = true;
                        break;
                    }
                }
                if (!findTable) {
                    repositoryMetadata = new MetadataTable();
                }
            }
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        } else if (newRepositoryMetadata == null) {
            MessageDialog.openWarning(new Shell(), Messages.getString("ComboController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("ComboController.nothingGuess"));
            return cmd;
        }
    }
    cmd = new QueryGuessCommand(node, newRepositoryMetadata);
    /* parameter can be null,the setMaps won't use the third parameter */
    cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
    //$NON-NLS-1$
    String type = getValueFromRepositoryName("TYPE");
    cmd.setParameters(realTableId, realTableName, type);
    return cmd;
}
Also used : INode(org.talend.core.model.process.INode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Shell(org.eclipse.swt.widgets.Shell) CCombo(org.eclipse.swt.custom.CCombo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 47 with IConnection

use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.

the class ComponentListController method updateComponentList.

protected static void updateComponentList(Collection<INode> nodeList, INode currentNode, IElementParameter param, boolean isSelectDefaultItem) {
    final Collection<String> componentDisplayNames = new ArrayList<String>();
    final Collection<String> componentUniqueNames = new ArrayList<String>();
    for (INode node : nodeList) {
        if (node.getJobletNode() != null) {
            node = node.getJobletNode();
        }
        final String uniqueName = node.getUniqueName();
        if (uniqueName.equals(currentNode.getUniqueName())) {
            continue;
        }
        //$NON-NLS-1$
        String displayName = (String) node.getElementParameter("LABEL").getValue();
        if (displayName == null) {
            displayName = uniqueName;
        }
        if (displayName.indexOf("__UNIQUE_NAME__") != -1) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            displayName = displayName.replaceAll("__UNIQUE_NAME__", uniqueName);
        }
        if (!displayName.equals(uniqueName)) {
            //$NON-NLS-1$
            displayName = uniqueName + " - " + displayName;
        }
        componentUniqueNames.add(uniqueName);
        componentDisplayNames.add(displayName);
    }
    param.setListItemsDisplayName(componentDisplayNames.toArray(new String[0]));
    final String[] componentValueList = componentUniqueNames.toArray(new String[0]);
    param.setListItemsValue(componentValueList);
    Object value = param.getValue();
    if (!componentUniqueNames.contains(value) && isSelectDefaultItem) {
        String newValue = null;
        if (!param.isDynamicSettings()) {
            if (!componentUniqueNames.isEmpty()) {
                if (value == null || value.equals("")) {
                    //$NON-NLS-1$
                    currentNode.setPropertyValue(getParameterName(param), componentValueList[0]);
                    if (currentNode instanceof IGraphicalNode) {
                        IGraphicalNode node = (IGraphicalNode) currentNode;
                        node.checkAndRefreshNode();
                        ((IProcess2) node.getProcess()).setProcessModified(true);
                    } else if (currentNode instanceof IConnection) {
                        ((IProcess2) ((IConnection) currentNode).getSource().getProcess()).setProcessModified(true);
                    }
                } else {
                    newValue = componentValueList[0];
                }
            } else {
                // removed the old value.
                //$NON-NLS-1$
                newValue = "";
            }
        }
        if (!("".equals(newValue)) && newValue != null) {
            //$NON-NLS-1$
            IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
            if (part instanceof AbstractMultiPageTalendEditor) {
                AbstractTalendEditor te = ((AbstractMultiPageTalendEditor) part).getTalendEditor();
                CommandStack cmdStack = (CommandStack) te.getAdapter(CommandStack.class);
                cmdStack.execute(new PropertyChangeCommand(currentNode, getParameterName(param), ""));
            }
        }
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IEditorPart(org.eclipse.ui.IEditorPart) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) IProcess2(org.talend.core.model.process.IProcess2)

Example 48 with IConnection

use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.

the class ColumnListController method updateColumnList.

// only set synWidthWithMhaoetadataColumn =true, when use the metadataDialog to set the metadata.
// see issue 0001676
public static void updateColumnList(INode node, List<ColumnNameChanged> columnsChanged, boolean synWidthWithMetadataColumn) {
    Map<String, Boolean> customColMap = new HashMap<String, Boolean>();
    List<String> columnList = null;
    List<String> prevColumnList = getPrevColumnList(node, customColMap);
    Map<IConnection, List<String>> refColumnLists = getRefColumnLists(node, customColMap);
    String[] columnNameList = null;
    String[] prevColumnNameList = prevColumnList.toArray(new String[0]);
    String[] curColumnNameList = null;
    String[] curColumnValueList = null;
    List<String> refColumnListNamesTmp = new ArrayList<String>();
    List<String> refColumnListNamesTmpWithSourceName = new ArrayList<String>();
    List<String> refColumnListValuesTmp = new ArrayList<String>();
    for (IConnection connection : refColumnLists.keySet()) {
        String oldSourceName = connection.getSource().getUniqueName() + ".";
        //$NON-NLS-1$
        String name = connection.getName() + ".";
        for (String column : refColumnLists.get(connection)) {
            refColumnListNamesTmpWithSourceName.add(oldSourceName + column);
            refColumnListNamesTmp.add(name + column);
            refColumnListValuesTmp.add(column);
        }
    }
    String[] refColumnListNames = refColumnListNamesTmp.toArray(new String[0]);
    String[] refColumnListValues = refColumnListValuesTmp.toArray(new String[0]);
    //$NON-NLS-1$
    boolean isSCDComponent = node.getComponent().getName().endsWith("SCD");
    boolean isEdifactComponent = node.getComponent().getName().equals("tExtractEDIField");
    updateColumnsOnElement(node, columnsChanged, synWidthWithMetadataColumn, prevColumnNameList, curColumnNameList, curColumnValueList, refColumnListNamesTmpWithSourceName, refColumnListValuesTmp, refColumnListNames, refColumnListValues, isSCDComponent, isEdifactComponent, customColMap);
    for (IConnection connection : node.getOutgoingConnections()) {
        updateColumnsOnElement(connection, columnsChanged, synWidthWithMetadataColumn, prevColumnNameList, curColumnNameList, curColumnValueList, refColumnListNamesTmpWithSourceName, refColumnListValuesTmp, refColumnListNames, refColumnListValues, isSCDComponent, isEdifactComponent, customColMap);
    }
    synLengthTipFlag = null;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 49 with IConnection

use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.

the class ColumnListController method getColumnList.

private static List<String> getColumnList(IElement element, String context, Map<String, Boolean> customColMap) {
    List<String> columnList = new ArrayList<String>();
    IMetadataTable table = null;
    if (element instanceof INode) {
        table = ((INode) element).getMetadataFromConnector(context);
        if (table == null) {
            List<IMetadataTable> tableList = ((INode) element).getMetadataList();
            if (tableList.size() == 1) {
                table = tableList.get(0);
            } else {
                for (IMetadataTable itable : tableList) {
                    if (itable.getAttachedConnector() != null && !itable.getAttachedConnector().equals("REJECT")) {
                        table = itable;
                        break;
                    }
                }
            }
        // if (tableList.size() > 0) {
        // table = tableList.get(0);
        // }
        }
    } else if (element instanceof IConnection) {
        table = ((IConnection) element).getMetadataTable();
    }
    if (table != null) {
        for (IMetadataColumn column : table.getListColumns()) {
            // add for bug 12034
            String label = column.getLabel();
            //                if (element instanceof INode && ((INode) element).getComponent().getName().endsWith("tFileInputXML")) {//$NON-NLS-1$
            // if (label.length() > 1) {
            // String labelSub = label.substring(1);
            // if (labelSub != null && KeywordsValidator.isKeyword(labelSub)) {
            // label = labelSub;
            // }
            // }
            // }
            columnList.add(label);
            if (customColMap != null) {
                customColMap.put(column.getLabel(), column.isCustom());
            }
        }
    }
    return columnList;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 50 with IConnection

use of org.talend.core.model.process.IConnection in project tdi-studio-se by Talend.

the class ConnectionListController method updateConnectionList.

public static void updateConnectionList(IElement elem, IElementParameter param) {
    IConnection[] connections;
    INode source = null;
    if (elem instanceof INode) {
        source = ((INode) elem);
    } else if (elem instanceof IConnection) {
        source = ((IConnection) elem).getSource();
    } else {
        return;
    }
    String filter = param.getFilter();
    if (filter.startsWith("INPUT:")) {
        //$NON-NLS-1$
        Set<IConnection> conns = new HashSet<IConnection>();
        conns.addAll(source.getIncomingConnections());
        //$NON-NLS-1$ //$NON-NLS-2$
        String[] f = filter.substring("INPUT:".length()).split("\\|");
        List<String> filterArray = new ArrayList<String>(f.length);
        for (String element : f) {
            filterArray.add(element.trim());
        }
        for (Iterator<IConnection> iter = conns.iterator(); iter.hasNext(); ) {
            IConnection con = iter.next();
            if (!filterArray.contains(con.getLineStyle().toString())) {
                iter.remove();
            }
        }
        connections = conns.toArray(new IConnection[conns.size()]);
    } else if (filter.startsWith("OUTPUT:")) {
        //$NON-NLS-1$
        Set<IConnection> conns = new HashSet<IConnection>();
        conns.addAll(source.getOutgoingConnections());
        //$NON-NLS-1$ //$NON-NLS-2$
        String[] f = filter.substring("OUTPUT:".length()).split("\\|");
        List<String> filterArray = new ArrayList<String>(f.length);
        for (String element : f) {
            filterArray.add(element.trim());
        }
        for (Iterator<IConnection> iter = conns.iterator(); iter.hasNext(); ) {
            IConnection con = iter.next();
            if (!filterArray.contains(con.getLineStyle().toString())) {
                iter.remove();
            }
        }
        connections = conns.toArray(new IConnection[conns.size()]);
    } else {
        connections = source.getProcess().getAllConnections(filter);
    }
    String[] connectionNames = new String[connections.length + 1];
    connectionNames[0] = "";
    for (int i = 0; i < connections.length; i++) {
        connectionNames[i + 1] = connections[i].getUniqueName();
    }
    Arrays.sort(connectionNames);
    String[] connectionNameList = (String[]) ArrayUtils.clone(connectionNames);
    String[] connectionValueList = connectionNames;
    connectionNameList[0] = "<Empty>";
    param.setListItemsDisplayName(connectionNameList);
    param.setListItemsValue(connectionValueList);
    if (!ArrayUtils.contains(connectionValueList, param.getValue())) {
        //$NON-NLS-1$
        param.setValue("");
    }
}
Also used : INode(org.talend.core.model.process.INode) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

IConnection (org.talend.core.model.process.IConnection)149 ArrayList (java.util.ArrayList)79 INode (org.talend.core.model.process.INode)63 List (java.util.List)60 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)57 Node (org.talend.designer.core.ui.editor.nodes.Node)47 HashMap (java.util.HashMap)36 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)33 IElementParameter (org.talend.core.model.process.IElementParameter)31 Map (java.util.Map)25 Connection (org.talend.designer.core.ui.editor.connections.Connection)25 INodeConnector (org.talend.core.model.process.INodeConnector)24 Point (org.eclipse.swt.graphics.Point)13 Process (org.talend.designer.core.ui.editor.process.Process)13 IJobletProviderService (org.talend.core.ui.IJobletProviderService)12 HashSet (java.util.HashSet)11 MetadataTable (org.talend.core.model.metadata.MetadataTable)10 IProcess (org.talend.core.model.process.IProcess)10 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)9 IExternalNode (org.talend.core.model.process.IExternalNode)8