Search in sources :

Example 46 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ChangeActivateStatusElementCommand method hasActivateInputOutput.

private boolean hasActivateInputOutput(Node node) {
    boolean hasActivateInput = false;
    for (Connection connection : (List<Connection>) node.getIncomingConnections()) {
        if (connection.isActivate() && connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
            hasActivateInput = true;
            break;
        }
    }
    boolean hasActivateOutput = false;
    for (Connection outputConnection : (List<Connection>) node.getOutgoingConnections()) {
        if (outputConnection.isActivate() && outputConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
            hasActivateOutput = true;
        }
    }
    return hasActivateOutput && hasActivateInput;
}
Also used : IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 47 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ChangeConnectionStatusCommand method execute.

public void execute() {
    INode target = connection.getTarget();
    if (connection.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
        connection.setLineStyle(EConnectionType.FLOW_REF);
    } else {
        boolean found = false;
        for (int i = 0; i < target.getIncomingConnections().size() && !found; i++) {
            Connection currentConnection = (Connection) target.getIncomingConnections().get(i);
            if (currentConnection.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
                oldMainConnection = currentConnection;
                oldMainConnection.setLineStyle(EConnectionType.FLOW_REF);
            }
        }
        connection.setLineStyle(EConnectionType.FLOW_MAIN);
    }
    if (target.getExternalNode() != null) {
        target.getExternalNode().connectionStatusChanged(connection.getLineStyle(), connection.getUniqueName());
    }
    ((Process) connection.getSource().getProcess()).checkStartNodes();
    ((Process) connection.getSource().getProcess()).checkProcess();
}
Also used : INode(org.talend.core.model.process.INode) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process)

Example 48 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class SapSchemaTypeController method createComboCommand.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
     * .eclipse.swt.custom.CCombo)
     */
@Override
protected Command createComboCommand(CCombo combo) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        /* see bug 16969 */
        // if (repositoryTableMap.containsKey(schemaSelected)) {
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // newRepositoryIdValue = schemaSelected;// + " - " + repositoryMetadata.getLabel();
        // } else {
        // if (repositoryTableMap.keySet().size() == 0) {
        // repositoryMetadata = new MetadataTable();
        // } else {
        // newRepositoryIdValue = repositoryTableMap.keySet().iterator().next();
        // // Gets the schema of the first item in repository schema type combo.
        // repositoryMetadata = repositoryTableMap.get(newRepositoryIdValue);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // // newRepositoryIdValue = newRepositoryIdValue + " - " + repositoryMetadata.getLabel();
        // }
        // }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 49 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class ComponentSettingsView method getCategories.

/**
     * yzhang Comment method "getCategories".
     * 
     * @param elem
     * @return
     */
private EComponentCategory[] getCategories(Element elem) {
    if (elem instanceof Connection) {
        EComponentCategory[] categories = EElementType.CONNECTION.getCategories();
        if (PluginChecker.isTeamEdition()) {
            Object propertyValue = elem.getPropertyValue(Connection.LINESTYLE_PROP);
            if (propertyValue instanceof EConnectionType && ((EConnectionType) propertyValue).hasConnectionCategory(IConnectionCategory.FLOW)) {
                // if (((Connection) elem).checkTraceShowEnable()) {
                final List<EComponentCategory> list = new ArrayList<EComponentCategory>(Arrays.asList(categories));
                boolean isMRProcess = false;
                IProcess process = ((Connection) elem).getSource().getProcess();
                if (process instanceof IProcess2) {
                    IProcess2 process2 = (IProcess2) process;
                    if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process2.getComponentsType())) {
                        isMRProcess = true;
                    }
                }
                boolean isStormProcess = false;
                process = ((Connection) elem).getSource().getProcess();
                if (process instanceof IProcess2) {
                    IProcess2 process2 = (IProcess2) process;
                    if (ComponentCategory.CATEGORY_4_STORM.getName().equals(process2.getComponentsType())) {
                        isStormProcess = true;
                    }
                }
                // mrjob and stormjob not add breakpoint
                if (!isStormProcess && !isMRProcess) {
                    list.add(EComponentCategory.BREAKPOINT);
                }
                if (elem.getElementParameter(EParameterName.DEPARTITIONER.getName()) != null || elem.getElementParameter(EParameterName.PARTITIONER.getName()) != null || elem.getElementParameter(EParameterName.REPARTITIONER.getName()) != null) {
                    list.add(EComponentCategory.PARALLELIZATION);
                }
                // if it mr group line then add errorRecovery
                if (isMRProcess && isMrGroupLine(elem)) {
                    list.add(EComponentCategory.RESUMING);
                }
                return list.toArray(new EComponentCategory[0]);
            // }
            } else if (propertyValue.equals(EConnectionType.ON_COMPONENT_OK) || propertyValue.equals(EConnectionType.ON_COMPONENT_ERROR) || propertyValue.equals(EConnectionType.RUN_IF) || propertyValue.equals(EConnectionType.ON_SUBJOB_OK) || propertyValue.equals(EConnectionType.ON_SUBJOB_ERROR) || propertyValue.equals(EConnectionType.ROUTE_WHEN) || propertyValue.equals(EConnectionType.ROUTE_CATCH) || propertyValue.equals(EConnectionType.STARTS)) {
                boolean isMRProcess = false;
                IProcess process = ((Connection) elem).getSource().getProcess();
                if (process instanceof IProcess2) {
                    IProcess2 process2 = (IProcess2) process;
                    if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process2.getComponentsType())) {
                        isMRProcess = true;
                    }
                }
                boolean isStormProcess = false;
                process = ((Connection) elem).getSource().getProcess();
                if (process instanceof IProcess2) {
                    IProcess2 process2 = (IProcess2) process;
                    if (ComponentCategory.CATEGORY_4_STORM.getName().equals(process2.getComponentsType())) {
                        isStormProcess = true;
                    }
                }
                int length = categories.length;
                EComponentCategory[] newCategories;
                boolean isNormalJobNeedRecovery = (!isMRProcess && !isStormProcess && !isAvoidRecoveryByConditions(elem));
                boolean isMrStormJobNeedRecovery = isMRProcess || isStormProcess;
                if (isNeedRecoveryCategory(propertyValue, isNormalJobNeedRecovery, isMrStormJobNeedRecovery)) {
                    newCategories = new EComponentCategory[length + 1];
                    for (int i = 0; i < length; i++) {
                        newCategories[i] = categories[i];
                    }
                    EComponentCategory resuming = EComponentCategory.RESUMING;
                    newCategories[length] = resuming;
                } else {
                    newCategories = new EComponentCategory[length];
                    for (int i = 0; i < length; i++) {
                        newCategories[i] = categories[i];
                    }
                }
                return newCategories;
            }
        }
        return categories;
    } else if (elem instanceof Node) {
        // if (isAdvancedType(elem)) {
        if (((Node) elem).isELTComponent()) {
            if (//$NON-NLS-1$
            !((Node) elem).getComponent().getName().endsWith("Output") && //$NON-NLS-1$
            !((Node) elem).getComponent().getName().endsWith("Input") && //$NON-NLS-1$
            !((Node) elem).getComponent().getName().endsWith("Map") && //$NON-NLS-1$
            !((Node) elem).getComponent().getName().endsWith("TableList") && !((Node) elem).getComponent().getName().endsWith("ColumnList")) {
                //$NON-NLS-1$
                return EElementType.ELT_NODE.getCategories();
            }
        }
        EComponentCategory[] categories = EElementType.ADVANCED_NODE.getCategories();
        // add for bug TDI-8476
        if (((Node) elem).getComponent() != null) {
            String paletteType = ((Node) elem).getComponent().getPaletteType();
            if (ComponentCategory.CATEGORY_4_CAMEL.getName().equals(paletteType)) {
                categories = EElementType.NODE.getCategories();
            }
        }
        if (PluginChecker.isValidationrulesPluginLoaded() && isSupportValidationRuleNode((Node) elem)) {
            // show
            EComponentCategory[] newCategories = new EComponentCategory[categories.length + 1];
            System.arraycopy(categories, 0, newCategories, 0, categories.length);
            newCategories[categories.length] = EComponentCategory.VALIDATION_RULES;
            return newCategories;
        }
        return categories;
    } else if (elem instanceof Note) {
        return EElementType.NOTE.getCategories();
    } else if (elem instanceof SubjobContainer) {
        return EElementType.SUBJOB.getCategories();
    } else if (elem instanceof ConnectionLabel) {
        return getCategories(((ConnectionLabel) elem).getConnection());
    }
    return null;
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) ArrayList(java.util.ArrayList) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) Note(org.talend.designer.core.ui.editor.notes.Note) IProcess2(org.talend.core.model.process.IProcess2) EConnectionType(org.talend.core.model.process.EConnectionType) IProcess(org.talend.core.model.process.IProcess) EComponentCategory(org.talend.core.model.process.EComponentCategory)

Example 50 with Connection

use of org.talend.designer.core.ui.editor.connections.Connection in project tdi-studio-se by Talend.

the class CreateComponentOnLinkHelper method getConnection.

public static List<Connection> getConnection(SubjobContainerPart containerPart, Point point, Node node) {
    List<Connection> connectionList = new ArrayList<Connection>();
    List<Connection> connList = new ArrayList<Connection>();
    List children = containerPart.getChildren();
    for (int i = 0; i < children.size(); i++) {
        Object object = children.get(i);
        if (object instanceof NodeContainerPart) {
            NodeContainerPart nodePart = (NodeContainerPart) object;
            Object o = nodePart.getChildren().get(0);
            if (o instanceof NodePart) {
                List connections = ((NodePart) o).getSourceConnections();
                for (int j = 0; j < connections.size(); j++) {
                    Object connection = connections.get(j);
                    if (connection instanceof ConnectionPart) {
                        ConnectionPart connPart = (ConnectionPart) connection;
                        Connection conn = (Connection) connPart.getModel();
                        if (canCreateNodeOnLink(conn, node)) {
                            Rectangle bounds = ((ConnectionPart) connection).getFigure().getBounds();
                            // System.out.println("location:" + point);
                            if (bounds.contains(point)) {
                                // System.out.println("bounds:" + bounds);
                                connectionList.add(conn);
                            }
                            if (containsPoint(bounds, point)) {
                                // System.out.println("contains");
                                connList.add(conn);
                            }
                        }
                    }
                }
            }
        }
    }
    if (!connectionList.isEmpty()) {
        return connectionList;
    } else {
        return connList;
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) PolylineConnection(org.eclipse.draw2d.PolylineConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Connection (org.talend.designer.core.ui.editor.connections.Connection)84 IConnection (org.talend.core.model.process.IConnection)52 ArrayList (java.util.ArrayList)47 List (java.util.List)46 Node (org.talend.designer.core.ui.editor.nodes.Node)44 INode (org.talend.core.model.process.INode)35 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)28 Process (org.talend.designer.core.ui.editor.process.Process)24 IElementParameter (org.talend.core.model.process.IElementParameter)20 INodeConnector (org.talend.core.model.process.INodeConnector)18 HashMap (java.util.HashMap)12 IComponent (org.talend.core.model.components.IComponent)12 ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)12 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)11 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)11 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)10 Property (org.talend.core.model.properties.Property)10 Test (org.junit.Test)9 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)9 Map (java.util.Map)8