Search in sources :

Example 1 with ConnectionLabel

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

the class ComponentSettingsView method createPartControl.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
     */
@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    tabFactory.initComposite(parent, true);
    tabFactory.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            TalendPropertyTabDescriptor descriptor = (TalendPropertyTabDescriptor) selection.getFirstElement();
            if (descriptor == null) {
                return;
            }
            if (currentSelectedTab != null && (!currentSelectedTab.getData().equals(descriptor.getData()) || currentSelectedTab.getCategory() != descriptor.getCategory())) {
                for (Control curControl : tabFactory.getTabComposite().getChildren()) {
                    curControl.dispose();
                }
            }
            if (element == null || !element.equals(descriptor.getData()) || currentSelectedTab == null || currentSelectedTab.getCategory() != descriptor.getCategory() || selectedPrimary) {
                element = (Element) descriptor.getData();
                currentSelectedTab = descriptor;
                if (descriptor.getData() instanceof ConnectionLabel) {
                    createDynamicComposite(tabFactory.getTabComposite(), ((ConnectionLabel) descriptor.getData()).getConnection(), descriptor.getCategory());
                } else {
                    createDynamicComposite(tabFactory.getTabComposite(), (Element) descriptor.getData(), descriptor.getCategory());
                }
                selectedPrimary = false;
            }
        }
    });
}
Also used : Control(org.eclipse.swt.widgets.Control) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Element(org.talend.core.model.process.Element) IElement(org.talend.core.model.process.IElement) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TalendPropertyTabDescriptor(org.talend.core.ui.properties.tab.TalendPropertyTabDescriptor) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel)

Example 2 with ConnectionLabel

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

the class ActivateElementAction method canPerformAction.

/**
     * Test if the selected item is a node.
     * 
     * @return true / false
     */
private boolean canPerformAction() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    }
    List parts = getSelectedObjects();
    if (parts.size() >= 1) {
        Object o = parts.get(0);
        nodeList = new ArrayList<Node>();
        for (int i = 0; i < parts.size(); i++) {
            if (parts.get(i) instanceof NodePart) {
                Node node = ((Node) ((NodePart) parts.get(i)).getModel());
                if ((!node.isReadOnly()) && (node.getPropertyValue(EParameterName.ACTIVATE.getName()) != null)) {
                    nodeList.add(node);
                }
            }
        }
        connectionList = new ArrayList<Connection>();
        for (int i = 0; i < parts.size(); i++) {
            if (parts.get(i) instanceof ConnectionPart) {
                Connection connection = ((Connection) ((ConnectionPart) parts.get(i)).getModel());
                if (!connection.isReadOnly() && connection.getSource().isActivate() && connection.getTarget().isActivate()) {
                    connectionList.add(connection);
                }
            }
            if (parts.get(i) instanceof ConnLabelEditPart) {
                Connection connection = ((ConnectionLabel) ((ConnLabelEditPart) parts.get(i)).getModel()).getConnection();
                if (!connection.isReadOnly() && connection.getSource().isActivate() && connection.getTarget().isActivate()) {
                    connectionList.add(connection);
                }
            }
        }
        if ((nodeList.size() == 0) && (connectionList.size() == 0)) {
            return false;
        }
        for (Node node : nodeList) {
            if (node.getJobletNode() != null) {
                return false;
            }
        }
        for (Connection conn : connectionList) {
            if (conn.getTarget().getJobletNode() != null && conn.getSource().getJobletNode() != null) {
                return false;
            }
        }
        if (nodeList.size() != 0) {
            if (nodeList.get(0).isActivate()) {
                if (nodeList.size() == 1) {
                    //$NON-NLS-1$
                    setText(TEXT_REM_ACTIVATE + " " + nodeList.get(0).getLabel());
                } else {
                    setText(TEXT_REM_ACTIVATE);
                }
            } else {
                if (nodeList.size() == 1) {
                    //$NON-NLS-1$
                    setText(TEXT_SET_ACTIVATE + " " + nodeList.get(0).getLabel());
                } else {
                    setText(TEXT_SET_ACTIVATE);
                }
                activate = true;
            }
        } else {
            // connections only
            if (connectionList.get(0).isActivate()) {
                if (connectionList.size() == 1) {
                    //$NON-NLS-1$
                    setText(TEXT_REM_ACTIVATE + " " + connectionList.get(0).getName());
                } else {
                    setText(TEXT_REM_ACTIVATE);
                }
            } else {
                if (connectionList.size() == 1) {
                    //$NON-NLS-1$
                    setText(TEXT_SET_ACTIVATE + " " + connectionList.get(0).getName());
                } else {
                    setText(TEXT_SET_ACTIVATE);
                }
                activate = true;
            }
        }
        return true;
    }
    return false;
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) List(java.util.List) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 3 with ConnectionLabel

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

the class ComponentSettingsView method getCategories.

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

Example 4 with ConnectionLabel

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

the class GEFDeleteAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    objectsToDelete = new ArrayList();
    List objects = getSelectedObjects();
    objectsToDelete.addAll(objects);
    if (objects.isEmpty() || (objects.size() == 1 && objects.get(0) instanceof ProcessPart)) {
        return false;
    }
    if (!(objects.get(0) instanceof EditPart)) {
        return false;
    }
    AbstractTalendEditor editor = (AbstractTalendEditor) this.getWorkbenchPart();
    AbstractProcessProvider pProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
    if (pProvider != null) {
        Map<JobletContainerPart, List<NodePart>> jobletMap = new HashMap<JobletContainerPart, List<NodePart>>();
        boolean nodeInJoblet = false;
        boolean allJunitnode = true;
        boolean hasNode = false;
        int i = 0;
        for (Object o : objects) {
            if (o instanceof NodePart) {
                hasNode = true;
                NodePart nodePart = (NodePart) o;
                Node no = (Node) ((NodePart) o).getModel();
                if (no.getProcess().isReadOnly()) {
                    return false;
                }
                if (no.isReadOnly()) {
                    i++;
                }
                if (no.getJunitNode() == null) {
                    allJunitnode = false;
                }
                if (!pProvider.canDeleteNode(no)) {
                    return false;
                }
                boolean isCollapsedNode = false;
                if (editor.getProcess().getGraphicalNodes().contains(nodePart.getModel())) {
                    isCollapsedNode = true;
                }
                if (!isCollapsedNode && nodePart.getParent() instanceof JobletContainerPart) {
                    JobletContainerPart jobletContainer = (JobletContainerPart) nodePart.getParent();
                    List<NodePart> jobletNodeParts = jobletMap.get(jobletContainer);
                    if (jobletNodeParts == null) {
                        jobletNodeParts = new ArrayList<NodePart>();
                        jobletMap.put(jobletContainer, jobletNodeParts);
                    }
                    jobletNodeParts.add(nodePart);
                }
            } else if (o instanceof ConnectionPart) {
                Connection conn = (Connection) ((ConnectionPart) o).getModel();
                if (conn.getSource().getProcess().isReadOnly()) {
                    return false;
                }
                if (conn.isReadOnly()) {
                    i++;
                }
            } else if (o instanceof ConnLabelEditPart) {
                ConnectionLabel connLabel = (ConnectionLabel) ((ConnLabelEditPart) o).getModel();
                if (connLabel.getConnection().getSource().getProcess().isReadOnly()) {
                    return false;
                }
                if (connLabel.getConnection().isReadOnly()) {
                    i++;
                }
            } else if (o instanceof NoteEditPart) {
                allJunitnode = false;
                Note note = (Note) ((NoteEditPart) o).getModel();
                if (note.isReadOnly()) {
                    i++;
                }
            } else if (o instanceof SubjobContainerPart) {
                SubjobContainer subjob = (SubjobContainer) ((SubjobContainerPart) o).getModel();
                if (subjob.getProcess().isReadOnly()) {
                    return false;
                }
                if (subjob.isReadOnly()) {
                    i++;
                    continue;
                }
                boolean isAllReadonly = true;
                boolean subjobAllJunit = true;
                for (NodeContainer nc : subjob.getNodeContainers()) {
                    Node node = nc.getNode();
                    if (!node.isReadOnly()) {
                        isAllReadonly = false;
                    }
                    if (node.getJunitNode() == null) {
                        subjobAllJunit = false;
                    }
                }
                if (isAllReadonly || subjobAllJunit) {
                    i++;
                }
            }
        }
        for (JobletContainerPart jobletContainer : jobletMap.keySet()) {
            boolean copyJobletNode = true;
            List<NodePart> list = jobletMap.get(jobletContainer);
            for (Object obj : jobletContainer.getChildren()) {
                if (obj instanceof NodePart) {
                    if (!list.contains(obj)) {
                        copyJobletNode = false;
                        break;
                    }
                }
            }
            if (copyJobletNode) {
                objectsToDelete.removeAll(list);
                PartFactory factory = new PartFactory();
                NodePart createEditPart = (NodePart) factory.createEditPart(jobletContainer, ((NodeContainer) jobletContainer.getModel()).getNode());
                createEditPart.setParent(jobletContainer);
                createEditPart.installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeEditPolicy());
                objectsToDelete.add(createEditPart);
            } else {
                nodeInJoblet = true;
            }
        }
        if (((nodeInJoblet || allJunitnode) && hasNode) || i == objects.size()) {
            return false;
        }
    }
    return true;
}
Also used : HashMap(java.util.HashMap) PartFactory(org.talend.designer.core.ui.editor.PartFactory) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) NodeEditPolicy(org.talend.designer.core.ui.editor.nodes.NodeEditPolicy) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) ArrayList(java.util.ArrayList) List(java.util.List) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) 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) Note(org.talend.designer.core.ui.editor.notes.Note) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 5 with ConnectionLabel

use of org.talend.designer.core.ui.editor.connections.ConnectionLabel 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)

Aggregations

ConnectionLabel (org.talend.designer.core.ui.editor.connections.ConnectionLabel)7 Connection (org.talend.designer.core.ui.editor.connections.Connection)5 Node (org.talend.designer.core.ui.editor.nodes.Node)5 Note (org.talend.designer.core.ui.editor.notes.Note)4 SubjobContainer (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer)4 ArrayList (java.util.ArrayList)3 EditPart (org.eclipse.gef.EditPart)3 IConnection (org.talend.core.model.process.IConnection)3 INode (org.talend.core.model.process.INode)3 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)3 ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)3 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)3 List (java.util.List)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Element (org.talend.core.model.process.Element)2 IProcess2 (org.talend.core.model.process.IProcess2)2 JobletContainerPart (org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart)2 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)2 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)2 NodeLabel (org.talend.designer.core.ui.editor.nodes.NodeLabel)2