Search in sources :

Example 1 with ITestContainerGEFService

use of org.talend.designer.core.ITestContainerGEFService in project tdi-studio-se by Talend.

the class NodesPasteCommand method createNodeContainerList.

@SuppressWarnings("unchecked")
private void createNodeContainerList() {
    int firstIndex = 0;
    int index = 0;
    nodeContainerList = new ArrayList<NodeContainer>();
    jobletNodeToExpand = new ArrayList<NodeContainer>();
    connections = new ArrayList<IConnection>();
    createdNames = new ArrayList<String>();
    Map<String, String> oldNameTonewNameMap = new HashMap<String, String>();
    Map<String, String> oldMetaToNewMeta = new HashMap<String, String>();
    // see bug 0004882: Subjob title is not copied when copying/pasting subjobs from one job to another
    Map<INode, SubjobContainer> mapping = new HashMap<INode, SubjobContainer>();
    ITestContainerGEFService testContainerService = null;
    Map<SubjobContainer, List<Node>> junitGroup = null;
    if (isJunitCreate()) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerGEFService.class)) {
            testContainerService = (ITestContainerGEFService) GlobalServiceRegister.getDefault().getService(ITestContainerGEFService.class);
            if (testContainerService != null) {
                junitGroup = testContainerService.caculateJunitGroup(nodeParts);
            }
        }
        if (nodeMap == null) {
            nodeMap = new HashMap<IGraphicalNode, IGraphicalNode>();
        }
    }
    // create the nodes
    for (NodePart copiedNodePart : nodeParts) {
        IGraphicalNode copiedNode = (IGraphicalNode) copiedNodePart.getModel();
        if (!containNodeInProcess(copiedNode)) {
            continue;
        }
        IComponent component = ComponentsFactoryProvider.getInstance().get(copiedNode.getComponent().getName(), process.getComponentsType());
        if (component == null) {
            boolean isJobletInOutComponent = false;
            if (PluginChecker.isJobLetPluginLoaded()) {
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (service != null && service.isJobletInOutComponent(copiedNode)) {
                    isJobletInOutComponent = true;
                }
            }
            if (isJobletInOutComponent) {
                component = copiedNode.getComponent();
            } else {
                component = new DummyComponent(copiedNode.getComponent().getName());
            }
        }
        IGraphicalNode pastedNode = new Node(component, process);
        if (nodeMap != null) {
            nodeMap.put(copiedNode, pastedNode);
        }
        if (isJobletRefactor() || isJunitCreate()) {
            // keep original for joblet refactor.
            process.removeUniqueNodeName(pastedNode.getUniqueName());
            pastedNode.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), copiedNode.getUniqueName());
            process.addUniqueNodeName(copiedNode.getUniqueName());
        }
        // for bug 0004882: Subjob title is not copied when copying/pasting subjobs from one job to another
        makeCopyNodeAndSubjobMapping(copiedNode, pastedNode, mapping);
        Point location = null;
        if (getCursorLocation() == null) {
            location = copiedNode.getLocation();
        } else {
            location = getCursorLocation();
            index = nodeParts.indexOf(copiedNodePart);
        }
        if (process.isGridEnabled()) {
            // replace the component to set it on the grid if it's enabled
            int tempVar = location.x / TalendEditor.GRID_SIZE;
            location.x = tempVar * TalendEditor.GRID_SIZE;
            tempVar = location.y / TalendEditor.GRID_SIZE;
            location.y = tempVar * TalendEditor.GRID_SIZE;
        }
        pastedNode.setLocation(findLocationForNode(location, copiedNode.getSize(), index, firstIndex, copiedNodePart));
        pastedNode.setSize(copiedNode.getSize());
        INodeConnector mainConnector;
        if (pastedNode.isELTComponent()) {
            mainConnector = pastedNode.getConnectorFromType(EConnectionType.TABLE);
        } else {
            mainConnector = pastedNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
        }
        if (!mainConnector.isMultiSchema()) {
            if (copiedNode.getMetadataList().size() != 0) {
                pastedNode.getMetadataList().clear();
                for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
                    IMetadataTable newMetaTable = metaTable.clone();
                    if (metaTable.getTableName().equals(copiedNode.getUniqueName())) {
                        newMetaTable.setTableName(pastedNode.getUniqueName());
                    }
                    for (IMetadataColumn column : metaTable.getListColumns()) {
                        if (column.isCustom()) {
                            IMetadataColumn newColumn = newMetaTable.getColumn(column.getLabel());
                            newColumn.setReadOnly(column.isReadOnly());
                            newColumn.setCustom(column.isCustom());
                        }
                    }
                    pastedNode.getMetadataList().add(newMetaTable);
                }
            }
        } else {
            List<IMetadataTable> copyOfMetadataList = new ArrayList<IMetadataTable>();
            for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
                IMetadataTable newTable = metaTable.clone();
                if (copiedNode.isELTComponent()) {
                    newTable.setTableName(createNewConnectionName(metaTable.getTableName(), IProcess.DEFAULT_TABLE_CONNECTION_NAME));
                } else {
                    if (metaTable.getTableName().equals(copiedNode.getUniqueName())) {
                        newTable.setTableName(createNewConnectionName(pastedNode.getUniqueName(), null));
                    } else {
                        newTable.setTableName(createNewConnectionName(metaTable.getTableName(), null));
                    }
                }
                //$NON-NLS-1$
                oldMetaToNewMeta.put(pastedNode.getUniqueName() + ":" + metaTable.getTableName(), newTable.getTableName());
                for (IMetadataColumn column : metaTable.getListColumns()) {
                    if (column.isCustom()) {
                        IMetadataColumn newColumn = newTable.getColumn(column.getLabel());
                        newColumn.setReadOnly(column.isReadOnly());
                        newColumn.setCustom(column.isCustom());
                    }
                }
                newTable.sortCustomColumns();
                copyOfMetadataList.add(newTable);
            }
            pastedNode.setMetadataList(copyOfMetadataList);
        }
        // TDQ-10039 extract this code from above "else",aslo consider tMatchGroup.
        if (mainConnector.isMultiSchema() || copiedNode.getComponent().getName().startsWith("tMatchGroup")) {
            //$NON-NLS-1$
            IExternalNode externalNode = pastedNode.getExternalNode();
            if (externalNode != null) {
                if (copiedNode.getExternalData() != null) {
                    try {
                        externalNode.setExternalData(copiedNode.getExternalData().clone());
                    } catch (CloneNotSupportedException e) {
                        ExceptionHandler.process(e);
                    }
                    ((Node) pastedNode).setExternalData(externalNode.getExternalData());
                }
                if (copiedNode.getExternalNode().getExternalEmfData() != null) {
                    externalNode.setExternalEmfData(EcoreUtil.copy(copiedNode.getExternalNode().getExternalEmfData()));
                }
                for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
                    String oldName = metaTable.getTableName();
                    //$NON-NLS-1$
                    String newName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + metaTable.getTableName());
                    externalNode.renameOutputConnection(oldName, newName);
                    CorePlugin.getDefault().getMapperService().renameJoinTable(process, externalNode.getExternalData(), createdNames);
                }
                // when copy a external node, should also copy screeshot
                if (copiedNode.getExternalNode() != null) {
                    ImageDescriptor screenshot = copiedNode.getExternalNode().getScreenshot();
                    if (screenshot != null) {
                        externalNode.setScreenshot(screenshot);
                    }
                }
            }
        }
        ((Node) pastedNode).getNodeLabel().setOffset(new Point(((Node) copiedNode).getNodeLabel().getOffset()));
        oldNameTonewNameMap.put(copiedNode.getUniqueName(), pastedNode.getUniqueName());
        if (copiedNode.getElementParametersWithChildrens() != null) {
            for (ElementParameter param : (List<ElementParameter>) copiedNode.getElementParametersWithChildrens()) {
                if (!EParameterName.UNIQUE_NAME.getName().equals(param.getName())) {
                    IElementParameter elementParameter = pastedNode.getElementParameter(param.getName());
                    if (elementParameter != null) {
                        if (param.getFieldType() == EParameterFieldType.TABLE) {
                            List<Map<String, Object>> tableValues = (List<Map<String, Object>>) param.getValue();
                            ArrayList newValues = new ArrayList();
                            for (Map<String, Object> map : tableValues) {
                                Map<String, Object> newMap = new HashMap<String, Object>();
                                newMap.putAll(map);
                                // rename schemas
                                if (!oldMetaToNewMeta.isEmpty()) {
                                    boolean isSAPBapiInputSchema = //$NON-NLS-1$
                                    "MAPPING_INPUT".equals(param.getName()) && //$NON-NLS-1$
                                    "tSAPBapi".equals(copiedNode.getComponent().getName());
                                    if (EParameterName.SCHEMAS.name().equals(param.getName()) || isSAPBapiInputSchema) {
                                        String newSchemaName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + map.get(EParameterName.SCHEMA.getName()));
                                        if (newSchemaName != null) {
                                            newMap.put(EParameterName.SCHEMA.getName(), newSchemaName);
                                        }
                                    }
                                }
                                newValues.add(newMap);
                            }
                            // fix for TDI-7988 paste tFixedFlowInput inline table
                            Object[] copiedListItem = param.getListItemsValue();
                            if (copiedListItem != null) {
                                Object[] pasetedListItem = elementParameter.getListItemsValue();
                                if (pasetedListItem == null || pasetedListItem.length != copiedListItem.length) {
                                    elementParameter.setListItemsValue(copiedListItem);
                                    elementParameter.setListItemsDisplayCodeName(param.getListItemsDisplayCodeName());
                                    elementParameter.setListItemsDisplayName(param.getListItemsDisplayName());
                                }
                            }
                            elementParameter.setValue(newValues);
                        } else {
                            if (param.getParentParameter() != null) {
                                String parentName = param.getParentParameter().getName();
                                //$NON-NLS-1$
                                pastedNode.setPropertyValue(parentName + ":" + param.getName(), param.getValue());
                            } else if (param.getName().equals("SOURCE_GENERATED_TDM_STRUCT_PATH") || param.getName().equals("TARGET_GENERATED_TDM_STRUCT_PATH") || param.getName().equals("SOURCE_TDM_STRUCT_INCARNATION") || param.getName().equals("TARGET_TDM_STRUCT_INCARNATION")) {
                                elementParameter.setReadOnly(param.getOriginalityReadOnly());
                                elementParameter.setRepositoryValueUsed(param.isRepositoryValueUsed());
                            } else {
                                pastedNode.setPropertyValue(param.getName(), param.getValue());
                                // See Bug 0005722: the pasted component don't keep the same read-only mode and
                                // didn;t
                                // hide
                                // the password.
                                elementParameter.setReadOnly(param.getOriginalityReadOnly());
                                elementParameter.setRepositoryValueUsed(param.isRepositoryValueUsed());
                            }
                        }
                    }
                }
            }
        }
        List<Node> pastedNodeList = null;
        if (junitGroup != null) {
            pastedNodeList = junitGroup.get(((Node) copiedNode).getNodeContainer().getSubjobContainer());
        }
        NodeContainer nc = ((Process) pastedNode.getProcess()).loadNodeContainer((Node) pastedNode, ((Node) copiedNode).isJunitStart() && isJunitCreate());
        if (pastedNodeList != null) {
            pastedNodeList.remove(copiedNode);
            pastedNodeList.add((Node) pastedNode);
        }
        nodeContainerList.add(nc);
        if (selectedExpandedJoblet != null && selectedExpandedJoblet.contains(copiedNodePart)) {
            jobletNodeToExpand.add(nc);
        }
    }
    ((Process) process).setCopyPasteSubjobMappings(mapping);
    Map<String, String> oldToNewConnVarMap = new HashMap<String, String>();
    // add the connections
    for (NodePart copiedNodePart : nodeParts) {
        INode copiedNode = (INode) copiedNodePart.getModel();
        for (IConnection connection : (List<IConnection>) copiedNode.getOutgoingConnections()) {
            INode pastedTargetNode = null, pastedSourceNode = null;
            String nodeSource = oldNameTonewNameMap.get(copiedNode.getUniqueName());
            for (NodeContainer nodeContainer : nodeContainerList) {
                INode node = nodeContainer.getNode();
                if (node.getUniqueName().equals(nodeSource)) {
                    pastedSourceNode = node;
                }
            }
            INode targetNode = connection.getTarget();
            // test if the target is in the nodes to paste to add the
            // connection
            // if the targeted node is not in the nodes to paste, then the
            // string will be null
            String nodeToConnect = oldNameTonewNameMap.get(targetNode.getUniqueName());
            if (nodeToConnect != null) {
                for (NodeContainer nodeContainer : nodeContainerList) {
                    INode node = nodeContainer.getNode();
                    if (node.getUniqueName().equals(nodeToConnect)) {
                        pastedTargetNode = node;
                    }
                }
            }
            if ((pastedSourceNode != null) && (pastedTargetNode != null)) {
                String newConnectionName;
                String metaTableName;
                if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
                    String newNameBuiltIn = oldMetaToNewMeta.get(//$NON-NLS-1$
                    pastedSourceNode.getUniqueName() + ":" + connection.getMetaName());
                    if (newNameBuiltIn == null) {
                        IElementParameter formatParam = pastedSourceNode.getElementParameter(EParameterName.CONNECTION_FORMAT.getName());
                        String baseName = IProcess.DEFAULT_ROW_CONNECTION_NAME;
                        if (formatParam != null) {
                            String value = (String) formatParam.getValue();
                            if (value != null && !"".equals(value)) {
                                //$NON-NLS-1$
                                baseName = value;
                            }
                        }
                        if (process.checkValidConnectionName(connection.getName(), true)) {
                            // keep the name, bug 5086
                            baseName = null;
                        }
                        newConnectionName = createNewConnectionName(connection.getName(), baseName);
                    } else {
                        newConnectionName = newNameBuiltIn;
                    }
                } else {
                    newConnectionName = connection.getName();
                }
                //$NON-NLS-1$
                String meta = oldMetaToNewMeta.get(pastedSourceNode.getUniqueName() + ":" + connection.getMetaName());
                if (meta != null) {
                    if (pastedSourceNode.getConnectorFromType(connection.getLineStyle()).isMultiSchema() && !connection.getLineStyle().equals(EConnectionType.TABLE)) {
                        newConnectionName = meta;
                    }
                    metaTableName = meta;
                } else {
                    if (pastedSourceNode.getConnectorFromType(connection.getLineStyle()).isMultiSchema()) {
                        metaTableName = pastedSourceNode.getMetadataList().get(0).getTableName();
                    } else {
                        // connection.getMetaName();
                        metaTableName = pastedSourceNode.getUniqueName();
                    }
                }
                IConnection pastedConnection;
                if (!pastedTargetNode.isELTComponent()) {
                    pastedConnection = new Connection(pastedSourceNode, pastedTargetNode, connection.getLineStyle(), connection.getConnectorName(), metaTableName, newConnectionName, connection.isMonitorConnection());
                } else {
                    pastedConnection = new Connection(pastedSourceNode, pastedTargetNode, connection.getLineStyle(), connection.getConnectorName(), metaTableName, newConnectionName, metaTableName, connection.isMonitorConnection());
                }
                connections.add(pastedConnection);
                oldNameTonewNameMap.put(connection.getUniqueName(), pastedConnection.getUniqueName());
                // pastedConnection.setActivate(pastedSourceNode.isActivate());
                for (ElementParameter param : (List<ElementParameter>) connection.getElementParameters()) {
                    // pastedConnection.getElementParameter(param.getName())
                    // .setValue(param.getValue());
                    pastedConnection.setPropertyValue(param.getName(), param.getValue());
                }
                // reset unique name param
                IElementParameter uniqueNameParam = pastedConnection.getElementParameter(EParameterName.UNIQUE_NAME.getName());
                String newName = oldNameTonewNameMap.get(connection.getUniqueName());
                if (uniqueNameParam != null && newName != null) {
                    if (!newName.equals(uniqueNameParam.getValue())) {
                        pastedConnection.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), newName);
                    }
                }
                // // keep the label (bug 3778)
                // if (pastedConnection != null) {
                // if (pastedConnection.getSourceNodeConnector().isBuiltIn()
                // && pastedConnection.getLineStyle().hasConnectionCategory(EConnectionType.FLOW)) {
                // pastedConnection.setPropertyValue(EParameterName.LABEL.getName(), connection.getName());
                // } else {
                // pastedConnection.setPropertyValue(EParameterName.LABEL.getName(), newConnectionName);
                // }
                // }
                ((Connection) pastedConnection).getConnectionLabel().setOffset(new Point(((Connection) connection).getConnectionLabel().getOffset()));
                INodeConnector connector = pastedConnection.getSourceNodeConnector();
                connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
                connector = pastedConnection.getTargetNodeConnector();
                connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
                IExternalNode externalNode = pastedTargetNode.getExternalNode();
                if (externalNode != null) {
                    externalNode.renameInputConnection(connection.getName(), newConnectionName);
                }
                // (feature 2962)
                if (pastedConnection.getMetadataTable() == null) {
                    continue;
                }
                for (IMetadataColumn column : pastedConnection.getMetadataTable().getListColumns()) {
                    //$NON-NLS-1$
                    String oldConnVar = connection.getName() + "." + column.getLabel();
                    //$NON-NLS-1$
                    String newConnVar = newConnectionName + "." + column.getLabel();
                    // String newConnVar = newConnectionName;
                    if (!oldToNewConnVarMap.containsKey(oldConnVar)) {
                        oldToNewConnVarMap.put(oldConnVar, newConnVar);
                    }
                }
            }
        }
    }
    // rename the connection data for node parameters. (feature 2962)
    for (NodeContainer nodeContainer : nodeContainerList) {
        Node node = nodeContainer.getNode();
        for (String oldConnVar : oldToNewConnVarMap.keySet()) {
            String newConnVar = oldToNewConnVarMap.get(oldConnVar);
            if (newConnVar != null) {
                node.renameData(oldConnVar, newConnVar);
            }
        }
    }
    // check if the new components use the old components name.
    Map<String, Set<String>> usedDataMap = new HashMap<String, Set<String>>();
    for (NodeContainer nodeContainer : nodeContainerList) {
        Node currentNode = nodeContainer.getNode();
        String uniqueName = currentNode.getUniqueName();
        for (String oldName : oldNameTonewNameMap.keySet()) {
            if (!oldName.equals(oldNameTonewNameMap.get(oldName)) && currentNode.useData(oldName)) {
                Set<String> oldNameSet = usedDataMap.get(uniqueName);
                if (oldNameSet == null) {
                    oldNameSet = new HashSet<String>();
                    usedDataMap.put(uniqueName, oldNameSet);
                }
                oldNameSet.add(oldName);
            }
        }
    }
    // check if the new connections use the old components name.
    Map<String, Set<String>> usedDataMapForConnections = new HashMap<String, Set<String>>();
    for (IConnection connection : connections) {
        String uniqueName = connection.getUniqueName();
        for (String oldName : oldNameTonewNameMap.keySet()) {
            if (oldName != null && !oldName.equals(oldNameTonewNameMap.get(oldName)) && UpgradeElementHelper.isUseData(connection, oldName)) {
                Set<String> oldNameSet = usedDataMapForConnections.get(uniqueName);
                if (oldNameSet == null) {
                    oldNameSet = new HashSet<String>();
                    usedDataMapForConnections.put(uniqueName, oldNameSet);
                }
                oldNameSet.add(oldName);
            }
        }
    }
    if (!usedDataMap.isEmpty() || !usedDataMapForConnections.isEmpty()) {
        MessageBox msgBox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_WARNING);
        //$NON-NLS-1$
        msgBox.setMessage(Messages.getString("NodesPasteCommand.renameMessages"));
        if (msgBox.open() == SWT.YES) {
            for (NodeContainer nodeContainer : nodeContainerList) {
                Node currentNode = nodeContainer.getNode();
                Set<String> oldNameSet = usedDataMap.get(currentNode.getUniqueName());
                if (oldNameSet != null && !oldNameSet.isEmpty()) {
                    for (String oldName : oldNameSet) {
                        currentNode.renameData(oldName, oldNameTonewNameMap.get(oldName));
                    }
                }
            }
            // Rename connections
            for (IConnection connection : connections) {
                Set<String> oldNameSet = usedDataMapForConnections.get(connection.getUniqueName());
                if (oldNameSet != null && !oldNameSet.isEmpty()) {
                    for (String oldName : oldNameSet) {
                        UpgradeElementHelper.renameData(connection, oldName, oldNameTonewNameMap.get(oldName));
                    }
                }
            }
        }
    }
    if (isJunitCreate()) {
        if (testContainerService != null) {
            testContainerService.setTestNodes(nodeMap, junitGroup, nodeContainerList);
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IConnection(org.talend.core.model.process.IConnection) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) DummyComponent(org.talend.designer.core.model.components.DummyComponent) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) IElementParameter(org.talend.core.model.process.IElementParameter) ITestContainerGEFService(org.talend.designer.core.ITestContainerGEFService) List(java.util.List) ArrayList(java.util.ArrayList) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IExternalNode(org.talend.core.model.process.IExternalNode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.draw2d.geometry.Point) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Point(org.eclipse.draw2d.geometry.Point) MessageBox(org.eclipse.swt.widgets.MessageBox) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ITestContainerGEFService

use of org.talend.designer.core.ITestContainerGEFService in project tdi-studio-se by Talend.

the class SubjobContainer method getSubjobContainerRectangle.

/**
     * DOC nrousseau Comment method "getSubjobContainerRectangle".
     * 
     * @return
     */
public Rectangle getSubjobContainerRectangle() {
    Rectangle totalRectangle = null;
    boolean collapsed = isCollapsed();
    boolean isTestContainer = false;
    ITestContainerGEFService testContainerService = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerGEFService.class)) {
        testContainerService = (ITestContainerGEFService) GlobalServiceRegister.getDefault().getService(ITestContainerGEFService.class);
        if (testContainerService != null) {
            isTestContainer = testContainerService.isTestContainer(this.process);
        }
    }
    // boolean hasJoblet = false;
    for (NodeContainer container : nodeContainers) {
        Rectangle curRect = null;
        if (container instanceof AbstractJobletContainer) {
            curRect = ((AbstractJobletContainer) container).getJobletContainerRectangle();
        } else if (isTestContainer && testContainerService != null) {
            curRect = testContainerService.getJunitContainerRectangle(container);
        } else {
            curRect = container.getNodeContainerRectangle();
        }
        if ((curRect.x + curRect.width) == (container.getNode().getPosX() + container.getNode().getSize().width)) {
            curRect.setSize(curRect.getSize().width + TalendEditor.GRID_SIZE, curRect.getSize().height);
        }
        if ((curRect.y + curRect.height) == (container.getNode().getPosY() + container.getNode().getSize().height)) {
            curRect.setSize(curRect.getSize().width, curRect.getSize().height + TalendEditor.GRID_SIZE);
        }
        if (curRect.y == container.getNode().getPosY()) {
            // means have totally no other status or such on the top of the node in the NodeContainerFigure, then we
            // add one more space on the top of the subjob
            // this could be done only once, but to simplify the calculation, just do for every node
            curRect.setLocation(curRect.getLocation().x, curRect.getLocation().y - TalendEditor.GRID_SIZE);
            curRect.setSize(curRect.getSize().width, curRect.getSize().height + TalendEditor.GRID_SIZE);
        }
        if (curRect.x == container.getNode().getPosX()) {
            // means if the node container figure is just at the border of the size of the component
            // then we add one more space on the left of the component, just to avoid have one subjob background
            // "too small" (too close to component)
            // this could be done only once, but to simplify the calculation, just do for every node
            curRect.setLocation(curRect.getLocation().x - TalendEditor.GRID_SIZE, curRect.getLocation().y);
            curRect.setSize(curRect.getSize().width + TalendEditor.GRID_SIZE, curRect.getSize().height);
        }
        if (collapsed && totalRectangle == null) {
            totalRectangle = curRect.getCopy();
        } else if (!collapsed) {
            if (totalRectangle == null) {
                totalRectangle = curRect.getCopy();
            } else {
                totalRectangle = totalRectangle.getUnion(curRect);
            }
        } else if (collapsed && testContainerService != null && testContainerService.isJunitContainer(container)) {
            INode startNode = this.getSubjobStartNode().getJunitNode();
            INode containerNode = container.getNode().getJunitNode();
            if (startNode != null && containerNode != null && startNode == containerNode) {
                totalRectangle = testContainerService.getJunitContainerRectangle(container).getCopy();
            }
        }
        if (isTestContainer && !collapsed) {
            if (curRect.x == totalRectangle.x) {
                totalRectangle.setLocation(totalRectangle.getLocation().x - TalendEditor.GRID_SIZE, totalRectangle.getLocation().y);
                totalRectangle.setSize(totalRectangle.getSize().width + TalendEditor.GRID_SIZE, totalRectangle.getSize().height);
            }
            if (curRect.y == totalRectangle.y) {
                totalRectangle.setLocation(totalRectangle.getLocation().x, totalRectangle.getLocation().y - TalendEditor.GRID_SIZE);
                totalRectangle.setSize(totalRectangle.getSize().width, totalRectangle.getSize().height + TalendEditor.GRID_SIZE);
            }
        }
    }
    if (totalRectangle == null) {
        return null;
    }
    Point location = totalRectangle.getLocation();
    Point newLocation = new Point();
    newLocation.x = (location.x / TalendEditor.GRID_SIZE) * TalendEditor.GRID_SIZE;
    newLocation.y = (location.y / TalendEditor.GRID_SIZE) * TalendEditor.GRID_SIZE;
    // bug 5158
    if (newLocation.y <= 0 && location.y < 0) {
        newLocation.y = newLocation.y - TalendEditor.GRID_SIZE;
    }
    if (newLocation.x <= 0 && location.x < 0) {
        newLocation.x = newLocation.x - TalendEditor.GRID_SIZE;
    }
    totalRectangle.setLocation(newLocation);
    Dimension diff = location.getDifference(newLocation);
    Dimension size = totalRectangle.getSize().expand(diff);
    if ((size.height % TalendEditor.GRID_SIZE) == 0) {
        size.height = (size.height / TalendEditor.GRID_SIZE) * TalendEditor.GRID_SIZE;
    } else {
        size.height = ((size.height / TalendEditor.GRID_SIZE) + 1) * TalendEditor.GRID_SIZE;
    }
    if ((size.width % TalendEditor.GRID_SIZE) == 0) {
        size.width = (size.width / TalendEditor.GRID_SIZE) * TalendEditor.GRID_SIZE;
    } else {
        size.width = ((size.width / TalendEditor.GRID_SIZE) + 1) * TalendEditor.GRID_SIZE;
    }
    // if (hasJoblet) {
    // size.width = size.width + TalendEditor.GRID_SIZE;
    // }
    totalRectangle.setSize(size);
    return totalRectangle;
}
Also used : INode(org.talend.core.model.process.INode) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ITestContainerGEFService(org.talend.designer.core.ITestContainerGEFService) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 3 with ITestContainerGEFService

use of org.talend.designer.core.ITestContainerGEFService in project tdi-studio-se by Talend.

the class PartFactory method createEditPart.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, java.lang.Object)
     */
@Override
public EditPart createEditPart(EditPart context, Object model) {
    EditPart part = null;
    if (model instanceof SubjobContainer) {
        part = new SubjobContainerPart();
    } else if (model instanceof Process) {
        part = new ProcessPart();
    } else if (model instanceof Node) {
        part = new NodePart();
    } else if (model instanceof Connection) {
        part = new ConnectionPart();
    } else if (model instanceof ConnectionLabel) {
        part = new ConnLabelEditPart();
    } else if (model instanceof MonitorConnectionLabel) {
        part = new MonitorConnectionLabelPart();
    } else if (model instanceof ConnectionPerformance) {
        part = new ConnectionPerformanceEditPart();
    } else if (model instanceof ConnectionTrace) {
        part = new ConnectionTraceEditPart();
    } else if (model instanceof ConnectionResuming) {
        part = new ConnectionResumingEditPart();
    } else if (model instanceof NodeLabel) {
        part = new NodeLabelEditPart();
    } else if (model instanceof NodeContainer) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerGEFService.class)) {
            ITestContainerGEFService testContainerService = (ITestContainerGEFService) GlobalServiceRegister.getDefault().getService(ITestContainerGEFService.class);
            if (testContainerService != null) {
                part = testContainerService.createEditorPart(model);
                if (part != null) {
                    part.setModel(model);
                    return part;
                }
            }
        }
        if (((NodeContainer) model).getNode().isSparkJoblet()) {
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkJobletProviderService.class)) {
                ISparkJobletProviderService sparkService = (ISparkJobletProviderService) GlobalServiceRegister.getDefault().getService(ISparkJobletProviderService.class);
                if (sparkService != null) {
                    part = (EditPart) sparkService.createEditorPart(model);
                    if (part != null) {
                        part.setModel(model);
                        return part;
                    }
                }
            }
        } else if (((NodeContainer) model).getNode().isSparkStreamingJoblet()) {
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkStreamingJobletProviderService.class)) {
                ISparkStreamingJobletProviderService sparkService = (ISparkStreamingJobletProviderService) GlobalServiceRegister.getDefault().getService(ISparkStreamingJobletProviderService.class);
                if (sparkService != null) {
                    part = (EditPart) sparkService.createEditorPart(model);
                    if (part != null) {
                        part.setModel(model);
                        return part;
                    }
                }
            }
        } else if (((NodeContainer) model).getNode().isStandardJoblet()) {
            part = new JobletContainerPart();
        } else if (((NodeContainer) model).getNode().isMapReduce()) {
            part = new JobletContainerPart();
        } else {
            part = new NodeContainerPart();
        }
    } else if (model instanceof Note) {
        part = new NoteEditPart();
    } else if (model instanceof NodeError) {
        part = new NodeErrorEditPart();
    } else if (model instanceof NodeProgressBar) {
        part = new NodeProgressBarPart();
    } else {
        return null;
    }
    // tell the newly created part about the model object
    part.setModel(model);
    return part;
}
Also used : NodeError(org.talend.designer.core.ui.editor.nodes.NodeError) NodeProgressBar(org.talend.designer.core.ui.editor.nodes.NodeProgressBar) NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) NodeProgressBarPart(org.talend.designer.core.ui.editor.nodes.NodeProgressBarPart) Node(org.talend.designer.core.ui.editor.nodes.Node) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) Process(org.talend.designer.core.ui.editor.process.Process) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) MonitorConnectionLabel(org.talend.designer.core.ui.editor.connections.MonitorConnectionLabel) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) ConnectionResuming(org.talend.designer.core.ui.editor.connections.ConnectionResuming) ConnectionResumingEditPart(org.talend.designer.core.ui.editor.connections.ConnectionResumingEditPart) NodeLabel(org.talend.designer.core.ui.editor.nodes.NodeLabel) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) MonitorConnectionLabel(org.talend.designer.core.ui.editor.connections.MonitorConnectionLabel) ITestContainerGEFService(org.talend.designer.core.ITestContainerGEFService) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) ISparkJobletProviderService(org.talend.core.ui.ISparkJobletProviderService) NodeErrorEditPart(org.talend.designer.core.ui.editor.nodes.NodeErrorEditPart) ConnectionPerformanceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionPerformanceEditPart) ConnectionResumingEditPart(org.talend.designer.core.ui.editor.connections.ConnectionResumingEditPart) NodeErrorEditPart(org.talend.designer.core.ui.editor.nodes.NodeErrorEditPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) ConnectionPerformanceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionPerformanceEditPart) ConnectionTraceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionTraceEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) Connection(org.talend.designer.core.ui.editor.connections.Connection) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) JobletContainerPart(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) ConnectionPerformance(org.talend.designer.core.ui.editor.connections.ConnectionPerformance) ConnectionTrace(org.talend.designer.core.ui.editor.connections.ConnectionTrace) ConnectionTraceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionTraceEditPart) ISparkStreamingJobletProviderService(org.talend.core.ui.ISparkStreamingJobletProviderService) Note(org.talend.designer.core.ui.editor.notes.Note) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) MonitorConnectionLabelPart(org.talend.designer.core.ui.editor.connections.MonitorConnectionLabelPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Aggregations

ITestContainerGEFService (org.talend.designer.core.ITestContainerGEFService)3 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)3 Point (org.eclipse.draw2d.geometry.Point)2 INode (org.talend.core.model.process.INode)2 Connection (org.talend.designer.core.ui.editor.connections.Connection)2 Node (org.talend.designer.core.ui.editor.nodes.Node)2 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)2 Process (org.talend.designer.core.ui.editor.process.Process)2 SubjobContainer (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 EditPart (org.eclipse.gef.EditPart)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1