Search in sources :

Example 16 with SubjobContainer

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

the class ConnectionPart method isSelectable.

@Override
public boolean isSelectable() {
    Connection conn = (Connection) this.getModel();
    Node source = (Node) conn.getSource();
    Node target = (Node) conn.getTarget();
    SubjobContainer sourceSubjob = source.getNodeContainer().getSubjobContainer();
    SubjobContainer targetSubjob = target.getNodeContainer().getSubjobContainer();
    if (sourceSubjob != null) {
        if ((sourceSubjob == targetSubjob) && sourceSubjob.isCollapsed()) {
            return false;
        } else if (!conn.isActivate() && sourceSubjob.isCollapsed()) {
            if (sourceSubjob.getSubjobStartNode().getUniqueName().equals(source.getUniqueName())) {
                return super.isSelectable();
            }
            return false;
        }
    }
    return super.isSelectable();
}
Also used : SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) Node(org.talend.designer.core.ui.editor.nodes.Node) IConnection(org.talend.core.model.process.IConnection)

Example 17 with SubjobContainer

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

the class ComponentSettingsView method createDynamicComposite.

/**
     * yzhang Comment method "createDynamicComposite".
     * 
     * @param parent
     * @param element
     * @param category
     */
private void createDynamicComposite(final Composite parent, Element element, EComponentCategory category) {
    // DynamicComposite dc = null;
    getParentMap().put(ComponentSettingsView.PARENT, parent);
    getCategoryMap().put(ComponentSettingsView.CATEGORY, category);
    if (element instanceof Node) {
        IComponent component = ((Node) element).getComponent();
        IGenericWizardService wizardService = null;
        boolean generic = false;
        if (EComponentType.GENERIC.equals(component.getComponentType())) {
            generic = true;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
            }
        }
        tabFactory.getTabbedPropertyComposite().setCompactViewVisible(false);
        if (category == EComponentCategory.BASIC) {
            // getElementMap().put(ComponentSettingsView.ELEMENT, element);
            createButtonListener();
            boolean isCompactView = true;
            if (ComponentSettingsView.TABLEVIEW.equals(getPreference().getString(TalendDesignerPrefConstants.VIEW_OPTIONS))) {
                isCompactView = false;
            }
            tabFactory.getTabbedPropertyComposite().setCompactViewVisible(true);
            tabFactory.getTabbedPropertyComposite().setCompactView(isCompactView);
            // Generic
            if (generic && wizardService != null) {
                Composite composite = wizardService.creatDynamicComposite(parent, element, EComponentCategory.BASIC, true);
                if (composite instanceof MultipleThreadDynamicComposite) {
                    dc = (MultipleThreadDynamicComposite) composite;
                }
            } else {
                dc = new MissingSettingsMultiThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, isCompactView);
            }
        } else if (category == EComponentCategory.DYNAMICS_SETTINGS) {
            dc = new AdvancedContextComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, element);
        } else if (category == EComponentCategory.SQL_PATTERN) {
            dc = new SQLPatternComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, element);
        } else if (category == EComponentCategory.ADVANCED) {
            dc = new MissingSettingsMultiThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, true);
            // Generic
            if (generic && wizardService != null) {
                Composite composite = wizardService.creatDynamicComposite(parent, element, EComponentCategory.ADVANCED, true);
                if (composite instanceof MultipleThreadDynamicComposite) {
                    dc = (MultipleThreadDynamicComposite) composite;
                }
            }
        } else {
            dc = new MultipleThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, true);
        }
    } else if (element instanceof Connection) {
        dc = new MainConnectionComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element);
    } else if (element instanceof Note) {
        if (category == EComponentCategory.BASIC) {
            if (parent.getLayout() instanceof FillLayout) {
                FillLayout layout = (FillLayout) parent.getLayout();
                layout.type = SWT.VERTICAL;
                layout.marginHeight = 0;
                layout.marginWidth = 0;
                layout.spacing = 0;
            }
            ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
            scrolled.setExpandHorizontal(true);
            scrolled.setExpandVertical(true);
            scrolled.setMinWidth(600);
            scrolled.setMinHeight(400);
            Composite composite = tabFactory.getWidgetFactory().createComposite(scrolled);
            scrolled.setContent(composite);
            composite.setLayout(new FormLayout());
            FormData d = new FormData();
            d.left = new FormAttachment(0, 0);
            d.right = new FormAttachment(100, 0);
            d.top = new FormAttachment(0, 0);
            d.bottom = new FormAttachment(100, 0);
            composite.setLayoutData(d);
            AbstractNotePropertyComposite c1 = new BasicNotePropertyComposite(composite, (Note) element, tabFactory);
            // AbstractNotePropertyComposite c2 = new TextNotePropertyComposite(composite, (Note) element,
            // tabFactory);
            // FormData data = new FormData();
            // data.top = new FormAttachment(c1.getComposite(), 20, SWT.DOWN);
            // data.left = new FormAttachment(0, 0);
            // data.right = new FormAttachment(100, 0);
            // c2.getComposite().setLayoutData(data);
            parent.layout();
        }
    } else if (element instanceof SubjobContainer) {
        if (category == EComponentCategory.BASIC) {
            dc = new SubjobBasicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, element);
        }
    } else {
        tabFactory.getTabbedPropertyComposite().setCompactViewVisible(false);
        dc = new MultipleThreadDynamicComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, category, element, true);
    }
    if (parent.getChildren().length == 0) {
        if (parent.getLayout() instanceof FillLayout) {
            FillLayout layout = (FillLayout) parent.getLayout();
            layout.type = SWT.VERTICAL;
            layout.marginHeight = 0;
            layout.marginWidth = 0;
            layout.spacing = 0;
        }
        Composite composite = tabFactory.getWidgetFactory().createComposite(parent);
        composite.setLayout(new FormLayout());
        FormData d = new FormData();
        d.left = new FormAttachment(2, 0);
        d.right = new FormAttachment(100, 0);
        d.top = new FormAttachment(5, 0);
        d.bottom = new FormAttachment(100, 0);
        composite.setLayoutData(d);
        Label alertText = new Label(composite, SWT.NONE);
        //$NON-NLS-1$
        alertText.setText(Messages.getString("ComponentSettingsView.noAdvancedSetting"));
        alertText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
        parent.layout();
    }
    if (dc != null) {
        dc.refresh();
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) MainConnectionComposite(org.talend.designer.core.ui.editor.properties.connections.MainConnectionComposite) Composite(org.eclipse.swt.widgets.Composite) SubjobBasicComposite(org.talend.designer.core.ui.views.subjob.SubjobBasicComposite) AbstractNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.AbstractNotePropertyComposite) MissingSettingsMultiThreadDynamicComposite(org.talend.designer.core.ui.views.properties.composites.MissingSettingsMultiThreadDynamicComposite) BasicNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.BasicNotePropertyComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) AbstractNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.AbstractNotePropertyComposite) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) Label(org.eclipse.swt.widgets.Label) MissingSettingsMultiThreadDynamicComposite(org.talend.designer.core.ui.views.properties.composites.MissingSettingsMultiThreadDynamicComposite) FillLayout(org.eclipse.swt.layout.FillLayout) SubjobBasicComposite(org.talend.designer.core.ui.views.subjob.SubjobBasicComposite) BasicNotePropertyComposite(org.talend.designer.core.ui.editor.properties.notes.BasicNotePropertyComposite) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) Note(org.talend.designer.core.ui.editor.notes.Note) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MainConnectionComposite(org.talend.designer.core.ui.editor.properties.connections.MainConnectionComposite) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 18 with SubjobContainer

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

the class ComponentSettingsView method setPropertiesViewerTitle.

/**
     * yzhang Comment method "setPropertiesViewerTitle".
     * 
     * @param elem
     */
private void setPropertiesViewerTitle(Element elem) {
    String label = null;
    Image image = null;
    if (elem instanceof Node) {
        label = ((Node) elem).getLabel();
        String uniqueName = ((Node) elem).getUniqueName();
        if (!label.equals(uniqueName)) {
            //$NON-NLS-1$ //$NON-NLS-2$
            label = label + "(" + uniqueName + ")";
        }
        image = CoreImageProvider.getComponentIcon(((Node) elem).getComponent(), ICON_SIZE.ICON_24);
    } else if (elem instanceof Connection) {
        label = ((Connection) elem).getElementName();
        image = ImageProvider.getImage(EImage.RIGHT_ICON);
    } else if (elem instanceof Note) {
        //$NON-NLS-1$
        label = Messages.getString("ComponentSettingsView.note");
        image = ImageProvider.getImage(EImage.PASTE_ICON);
    } else if (elem instanceof SubjobContainer) {
        //$NON-NLS-1$
        label = Messages.getString("ComponentSettingsView.subjob");
        image = ImageProvider.getImage(EImage.PASTE_ICON);
    } else if (elem instanceof ConnectionLabel) {
        label = ((ConnectionLabel) elem).getConnection().getElementName();
        image = ImageProvider.getImage(EImage.RIGHT_ICON);
    }
    tabFactory.setTitle(label, image);
    super.setTitleToolTip(label);
}
Also used : SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) Note(org.talend.designer.core.ui.editor.notes.Note) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage)

Example 19 with SubjobContainer

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

the class NodePartKeyHander method navigateTo.

@Override
protected void navigateTo(EditPart part, KeyEvent event) {
    // PTODO need be removed
    SubjobContainerPart subPart = null;
    NoteEditPart noPart = null;
    boolean displayVa = true;
    if (part instanceof SubjobContainerPart) {
        // NodeContainerPart
        SubjobContainerPart focusPart = (SubjobContainerPart) part;
        List subList = focusPart.getParent().getChildren();
        for (int j = 0; j < subList.size(); j++) {
            if (subList.get(j) instanceof SubjobContainerPart) {
                subPart = (SubjobContainerPart) subList.get(j);
                SubjobContainer subContainer = (SubjobContainer) subPart.getModel();
                if (subContainer.isDisplayed() == false) {
                    displayVa = false;
                }
            } else if (subList.get(j) instanceof NoteEditPart) {
                displayVa = false;
            }
        }
        if (displayVa == false) {
            part = (EditPart) part.getChildren().get(0);
            if (part != null) {
                // NodePart
                part = (EditPart) part.getChildren().get(0);
            }
            if (part == null) {
                return;
            }
        }
    }
    super.navigateTo(part, event);
}
Also used : SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) List(java.util.List) ArrayList(java.util.ArrayList) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)

Example 20 with SubjobContainer

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

the class NodesMoveCommond method createNodeContainerList.

@SuppressWarnings("unchecked")
private void createNodeContainerList() {
    int firstIndex = 0;
    int index = 0;
    nodeContainerList = 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>();
    IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
    // create the nodes
    for (INode copiedNode : nodes) {
        // IGraphicalNode copiedNode = (IGraphicalNode) copiedNodePart.getModel();
        if (!containNodeInProcess(copiedNode)) {
            continue;
        }
        IComponent component = ComponentsFactoryProvider.getInstance().get(copiedNode.getComponent().getName(), copiedNode.getProcess().getComponentsType());
        if (component == null) {
            component = copiedNode.getComponent();
        }
        IGraphicalNode pastedNode = new Node(component, process);
        if (isJobletRefactor()) {
            // keep original for joblet refactor.
            process.removeUniqueNodeName(pastedNode.getUniqueName());
            pastedNode.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), copiedNode.getUniqueName());
            process.addUniqueNodeName(copiedNode.getUniqueName());
        }
        if (service != null) {
            if (service.isJobletInOutComponent(pastedNode)) {
                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 = (Point) ((Node) copiedNode).getLocation();
        } else {
            location = getCursorLocation();
            index = nodes.indexOf(copiedNode);
        }
        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, (Dimension) ((Node) copiedNode).getSize(), index, firstIndex, ((Node) copiedNode)));
        pastedNode.setSize(((Node) 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 {
                    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);
            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());
                }
                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 (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 (EParameterName.SCHEMAS.name().equals(param.getName()) && !oldMetaToNewMeta.isEmpty()) {
                                String newSchemaName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + map.get(EParameterName.SCHEMA.getName()));
                                if (newSchemaName != null) {
                                    newMap.put(EParameterName.SCHEMA.getName(), newSchemaName);
                                }
                            }
                            newValues.add(newMap);
                        }
                        elementParameter.setValue(newValues);
                    } else {
                        if (param.getParentParameter() != null) {
                            String parentName = param.getParentParameter().getName();
                            //$NON-NLS-1$
                            pastedNode.setPropertyValue(parentName + ":" + param.getName(), param.getValue());
                        } 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());
                        }
                    }
                }
            }
        }
        NodeContainer nc = ((Process) pastedNode.getProcess()).loadNodeContainer((Node) pastedNode, false);
        ;
        nodeContainerList.add(nc);
    }
    ((Process) process).setCopyPasteSubjobMappings(mapping);
    Map<String, String> oldToNewConnVarMap = new HashMap<String, String>();
    // add the connections
    for (INode copiedNode : nodes) {
        // 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));
                    }
                }
            }
        }
    }
}
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) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) IElementParameter(org.talend.core.model.process.IElementParameter) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) List(java.util.List) ArrayList(java.util.ArrayList) 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) Dimension(org.eclipse.draw2d.geometry.Dimension) 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) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SubjobContainer (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer)21 Node (org.talend.designer.core.ui.editor.nodes.Node)17 List (java.util.List)11 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)10 ArrayList (java.util.ArrayList)9 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)9 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)8 IConnection (org.talend.core.model.process.IConnection)7 INode (org.talend.core.model.process.INode)7 Connection (org.talend.designer.core.ui.editor.connections.Connection)7 Note (org.talend.designer.core.ui.editor.notes.Note)5 HashMap (java.util.HashMap)4 EditPart (org.eclipse.gef.EditPart)4 ConnectionLabel (org.talend.designer.core.ui.editor.connections.ConnectionLabel)4 NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)4 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)4 Point (org.eclipse.draw2d.geometry.Point)3 IComponent (org.talend.core.model.components.IComponent)3 ISubjobContainer (org.talend.core.model.process.ISubjobContainer)3 IGraphicalNode (org.talend.core.ui.process.IGraphicalNode)3