Search in sources :

Example 1 with AbstractJobletContainer

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

the class GEFPasteAction method canPasteJobletNode.

private boolean canPasteJobletNode(IProcess2 curNodeProcess, Node copiedNode) {
    Item temIten = curNodeProcess.getProperty().getItem();
    if (!(temIten instanceof JobletProcessItem)) {
        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (service != null) {
            if (service.isJobletInOutComponent(copiedNode)) {
                MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Paste Error", "Can not paste joblet component in job!");
                return false;
            }
        }
    }
    Node jobletNode = (Node) copiedNode.getJobletNode();
    AbstractJobletContainer jnc = (AbstractJobletContainer) jobletNode.getNodeContainer();
    List<NodeContainer> ncs = jnc.getNodeContainers();
    if (ncs != null) {
        for (NodeContainer nc : ncs) {
            if (nc.getNode() == copiedNode) {
                return true;
            }
        }
    }
    return false;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) Node(org.talend.designer.core.ui.editor.nodes.Node) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer)

Example 2 with AbstractJobletContainer

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

the class ExternalNodeChangeCommand method changeCollapsedState.

private void changeCollapsedState(boolean state, Map<String, Boolean> map, INode node) {
    if (node instanceof Node) {
        NodeContainer nc = ((Node) node).getNodeContainer();
        if ((nc instanceof AbstractJobletContainer) && nc.getNode().isJoblet()) {
            if (((AbstractJobletContainer) nc).isCollapsed() && !state) {
                map.put(nc.getNode().getUniqueName(), false);
                ((AbstractJobletContainer) nc).setCollapsed(state);
            } else if (!((AbstractJobletContainer) nc).isCollapsed() && state) {
                if (map.get(nc.getNode().getUniqueName()) != null && !map.get(nc.getNode().getUniqueName())) {
                    ((AbstractJobletContainer) nc).setCollapsed(state);
                }
            }
        }
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer)

Example 3 with AbstractJobletContainer

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

the class UpdateJobletNodeCommand method execute.

/**
     * this function is moved from the method updateGraphicalNodes.
     */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    Object job = result.getJob();
    if (job == null) {
        return;
    }
    if (job instanceof Process) {
        Process process = (Process) job;
        Object parameter = result.getParameter();
        // update property change events
        if (parameter instanceof PropertyChangeEvent) {
            PropertyChangeEvent evt = (PropertyChangeEvent) parameter;
            updatePropertyChangeEvents(process, evt);
        } else {
            //
            IUpdateItemType updateType = result.getUpdateType();
            if (updateType instanceof EUpdateItemType) {
                switch((EUpdateItemType) updateType) {
                    case JOBLET_RENAMED:
                        if (!(parameter instanceof List)) {
                            return;
                        }
                        List<Object> params = (List<Object>) parameter;
                        if (params.size() != 3) {
                            return;
                        }
                        final String oldName = (String) params.get(1);
                        final String newName = (String) params.get(2);
                        updateRenaming(process, oldName, newName);
                        break;
                    case RELOAD:
                        List<Node> jobletNodes = (List<Node>) result.getUpdateObject();
                        if (jobletNodes != null && !jobletNodes.isEmpty()) {
                            for (Node node : jobletNodes) {
                                IComponent newComponent = ComponentsFactoryProvider.getInstance().get(node.getComponent().getName(), process.getComponentsType());
                                if (newComponent == null) {
                                    continue;
                                }
                                // node loaded is from loading in the check.
                                // need to get the instance from process, or this process will be done with wrong
                                // instance
                                // of node.
                                Node currentNode = getOriginalNodeFromProcess(node);
                                boolean neesPro = needPropagate(currentNode);
                                if (currentNode.isJoblet() || currentNode.isMapReduce()) {
                                    // maybe no need modify
                                    List<IElementParameter> tempList = new ArrayList<IElementParameter>(currentNode.getElementParameters());
                                    if (result.isNeedReloadJoblet()) {
                                        reloadNode(currentNode, newComponent);
                                    }
                                    if (currentNode.getNodeContainer() instanceof AbstractJobletContainer) {
                                        for (IElementParameter para : tempList) {
                                            currentNode.getElementParameter(para.getName()).setValue(para.getValue());
                                        }
                                        ((AbstractJobletContainer) currentNode.getNodeContainer()).updateJobletNodes(true);
                                    }
                                } else {
                                    reloadNode(currentNode, newComponent);
                                }
                                propagate(currentNode, neesPro);
                            }
                            process.checkProcess();
                        }
                        break;
                    case JOBLET_SCHEMA:
                        updateSchema(process, (Node) result.getUpdateObject());
                        break;
                    default:
                }
            }
        // else { // for extension
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) IElementParameter(org.talend.core.model.process.IElementParameter) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with AbstractJobletContainer

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

the class ChangeActivateStatusElementCommand method getAllMiddleConnections.

private Map<List<INode>, List<IConnection>> getAllMiddleConnections() {
    Map<List<INode>, List<IConnection>> middConnMap = new HashMap<List<INode>, List<IConnection>>();
    Process process;
    if (nodeList.size() > 0) {
        process = (Process) nodeList.get(0).getProcess();
    } else {
        process = (Process) connectionList.get(0).getSource().getProcess();
    }
    List<? extends INode> nodes = process.getGraphicalNodes();
    List<INode> jobletandnodeList = new ArrayList<INode>();
    for (INode node : nodes) {
        if (((Node) node).isJoblet() && !((Node) node).getNodeContainer().isCollapsed() && (((Node) node).getNodeContainer() instanceof AbstractJobletContainer)) {
            for (NodeContainer nc : ((AbstractJobletContainer) ((Node) node).getNodeContainer()).getNodeContainers()) {
                jobletandnodeList.add(nc.getNode());
            }
        } else {
            jobletandnodeList.add(node);
        }
    }
    for (INode node : jobletandnodeList) {
        if (node.isActivate()) {
            Map<IConnection, Node> outMiddleNodes = getAllOutMiddleNodes(node);
            Map<IConnection, Node> inMiddleNodes = getAllInMiddleNodes(node);
            Set<Entry<IConnection, Node>> outSet = outMiddleNodes.entrySet();
            Iterator<Entry<IConnection, Node>> outIte = outSet.iterator();
            boolean haveActivateTarget = false;
            List<INode> nodeList = new ArrayList<INode>();
            List<IConnection> connList = new ArrayList<IConnection>();
            while (outIte.hasNext()) {
                Entry<IConnection, Node> en = outIte.next();
                Node enNode = en.getValue();
                IConnection enConn = en.getKey();
                if (enNode != null) {
                    haveActivateTarget = true;
                    if (!nodeList.contains(node)) {
                        nodeList.add(node);
                    }
                    if (!nodeList.contains(enNode)) {
                        nodeList.add(enNode);
                    }
                }
                if (enConn != null && !connList.contains(enConn)) {
                    connList.add(enConn);
                }
            }
            if (!haveActivateTarget) {
                outMiddleNodes.clear();
            }
            if (!nodeList.isEmpty() && !connList.isEmpty()) {
                Set<Entry<List<INode>, List<IConnection>>> middSet = middConnMap.entrySet();
                Iterator<Entry<List<INode>, List<IConnection>>> middIte = middSet.iterator();
                boolean exist = false;
                while (middIte.hasNext()) {
                    Entry<List<INode>, List<IConnection>> entry = middIte.next();
                    List<INode> enNodeList = entry.getKey();
                    if (enNodeList.size() == 2 && nodeList.size() == 2) {
                        if (enNodeList.get(0).getUniqueName().equals(nodeList.get(1).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(0).getUniqueName())) {
                            exist = true;
                        } else if (enNodeList.get(0).getUniqueName().equals(nodeList.get(0).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(1).getUniqueName())) {
                            exist = true;
                        }
                    }
                }
                if (!exist) {
                    middConnMap.put(nodeList, connList);
                }
            }
            Set<Entry<IConnection, Node>> inSet = inMiddleNodes.entrySet();
            Iterator<Entry<IConnection, Node>> inIte = inSet.iterator();
            boolean haveActivateSource = false;
            nodeList = new ArrayList<INode>();
            connList = new ArrayList<IConnection>();
            while (inIte.hasNext()) {
                Entry<IConnection, Node> en = inIte.next();
                Node enNode = en.getValue();
                IConnection enConn = en.getKey();
                if (enNode != null) {
                    haveActivateSource = true;
                    if (!nodeList.contains(node)) {
                        nodeList.add(node);
                    }
                    if (!nodeList.contains(enNode)) {
                        nodeList.add(enNode);
                    }
                }
                if (enConn != null && !connList.contains(enConn)) {
                    connList.add(enConn);
                }
            }
            if (!haveActivateSource) {
                inMiddleNodes.clear();
            }
            if (!nodeList.isEmpty() && !connList.isEmpty()) {
                Set<Entry<List<INode>, List<IConnection>>> middSet = middConnMap.entrySet();
                Iterator<Entry<List<INode>, List<IConnection>>> middIte = middSet.iterator();
                boolean exist = false;
                while (middIte.hasNext()) {
                    Entry<List<INode>, List<IConnection>> entry = middIte.next();
                    List<INode> enNodeList = entry.getKey();
                    if (enNodeList.size() == 2 && nodeList.size() == 2) {
                        if (enNodeList.get(0).getUniqueName().equals(nodeList.get(1).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(0).getUniqueName())) {
                            exist = true;
                        } else if (enNodeList.get(0).getUniqueName().equals(nodeList.get(0).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(1).getUniqueName())) {
                            exist = true;
                        }
                    }
                }
                if (!exist) {
                    middConnMap.put(nodeList, connList);
                }
            }
        }
    }
    return middConnMap;
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Process(org.talend.designer.core.ui.editor.process.Process) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with AbstractJobletContainer

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

the class NodeContainer method prepareStatus.

private Rectangle prepareStatus(Point nodeLocation, Dimension nodeSize) {
    Rectangle statusRectangle = null;
    Rectangle breakpointRectangle, warningRectangle, infoRectangle, parallelLocationRectangle, windowLocationRectangle, validationRuleRectangle, collapseRectangle;
    int status = node.getStatus();
    if ((status & Process.BREAKPOINT_STATUS) != 0) {
        breakpointLocation.x = nodeLocation.x - breakpointSize.width;
        breakpointLocation.y = nodeLocation.y - breakpointSize.height;
        breakpointRectangle = new Rectangle(breakpointLocation, breakpointSize);
        statusRectangle = breakpointRectangle;
    }
    if ((status & Process.ERROR_STATUS) != 0) {
        errorLocation.x = nodeLocation.x + nodeSize.width;
        errorLocation.y = nodeLocation.y - errorSize.height;
        errorRectangle = new Rectangle(errorLocation, errorSize);
        if (statusRectangle == null) {
            statusRectangle = errorRectangle;
        } else {
            statusRectangle.union(errorRectangle);
        }
    }
    if ((status & Process.WARNING_STATUS) != 0) {
        warningLocation.x = nodeLocation.x + nodeSize.width;
        warningLocation.y = nodeLocation.y - warningSize.height;
        warningRectangle = new Rectangle(warningLocation, warningSize);
        if (statusRectangle == null) {
            statusRectangle = warningRectangle;
        } else {
            statusRectangle.union(warningRectangle);
        }
    }
    if (this instanceof AbstractJobletContainer) {
        Dimension collapseSize = new Dimension(20, 20);
        collapseLocation.x = nodeLocation.x - 20;
        collapseLocation.y = nodeLocation.y - collapseSize.height;
        collapseRectangle = new Rectangle(collapseLocation, collapseSize);
        if (statusRectangle == null) {
            Point extendPoint = new Point();
            extendPoint.x = nodeLocation.x + nodeSize.width;
            extendPoint.y = nodeLocation.y - warningSize.height;
            Rectangle extendRectangle = new Rectangle(extendPoint, warningSize);
            statusRectangle = extendRectangle;
        }
        statusRectangle.union(collapseRectangle);
    }
    if ((status & Process.INFO_STATUS) != 0) {
        infoLocation.x = nodeLocation.x + nodeSize.width;
        infoLocation.y = nodeLocation.y - infoSize.height;
        infoRectangle = new Rectangle(infoLocation, infoSize);
        if (statusRectangle == null) {
            statusRectangle = infoRectangle;
        } else {
            statusRectangle.union(infoRectangle);
        }
    }
    if ((status & Process.VALIDATION_RULE_STATUS) != 0) {
        validationRuleLocation.x = nodeLocation.x + nodeSize.width / 2 + nodeSize.width / 4;
        validationRuleLocation.y = nodeLocation.y - validationRuleSize.height / 2;
        validationRuleRectangle = new Rectangle(validationRuleLocation, validationRuleSize);
        if (statusRectangle == null) {
            statusRectangle = validationRuleRectangle;
        } else {
            statusRectangle.union(validationRuleRectangle);
        }
    }
    if (node.isErrorFlag()) {
        markLocation.x = nodeLocation.x - nodeSize.width / 2;
        markLocation.y = nodeLocation.y;
        errorMarkLocation.x = nodeLocation.x - (errorMarkSize.width - nodeSize.width) / 2;
        errorMarkLocation.y = markLocation.y - errorMarkSize.height;
        errorMarkRectangle = new Rectangle(errorMarkLocation, errorMarkSize);
        if (statusRectangle == null) {
            statusRectangle = errorMarkRectangle;
        } else {
            statusRectangle.union(errorMarkRectangle);
        }
    }
    boolean parallelize = false;
    IElementParameter enableParallelizeParameter = node.getElementParameter(EParameterName.PARALLELIZE.getName());
    if (enableParallelizeParameter != null) {
        parallelize = (Boolean) enableParallelizeParameter.getValue();
    }
    if (parallelize) {
        parallelLocation.x = nodeLocation.x - parallelSize.width;
        parallelLocation.y = nodeLocation.y - parallelSize.height;
        parallelLocationRectangle = new Rectangle(parallelLocation, parallelSize);
        if (statusRectangle == null) {
            statusRectangle = parallelLocationRectangle;
        } else {
            statusRectangle.union(parallelLocationRectangle);
        }
    }
    IElementParameter window = node.getElementParameter(EParameterName.WINDOW_DURATION.getName());
    String windowDuration = null;
    if (window != null) {
        windowDuration = (String) window.getValue();
    }
    if (windowDuration != null) {
        windowLocation.x = nodeLocation.x - ((nodeLocation.x + (windowSize.width / 2)) - (nodeLocation.x + (nodeSize.width / 2)));
        windowLocation.y = nodeLocation.y - windowSize.height;
        windowLocationRectangle = new Rectangle(windowLocation, windowSize);
        if (statusRectangle == null) {
            statusRectangle = windowLocationRectangle;
        } else {
            statusRectangle.union(windowLocationRectangle);
        }
    }
    return statusRectangle;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) IElementParameter(org.talend.core.model.process.IElementParameter) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

AbstractJobletContainer (org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer)8 INode (org.talend.core.model.process.INode)5 Node (org.talend.designer.core.ui.editor.nodes.Node)5 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)4 Dimension (org.eclipse.draw2d.geometry.Dimension)3 Point (org.eclipse.draw2d.geometry.Point)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 Process (org.talend.designer.core.ui.editor.process.Process)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 IComponent (org.talend.core.model.components.IComponent)1 AbstractNode (org.talend.core.model.process.AbstractNode)1 IConnection (org.talend.core.model.process.IConnection)1 IExternalNode (org.talend.core.model.process.IExternalNode)1 IProcess (org.talend.core.model.process.IProcess)1 Item (org.talend.core.model.properties.Item)1