Search in sources :

Example 21 with ConnectionPart

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

the class GEFDeleteAction method createDeleteCommand.

@Override
public Command createDeleteCommand(List objects) {
    objects = filterSameObject(objectsToDelete);
    if (objects.isEmpty()) {
        return null;
    }
    if (!(objects.get(0) instanceof EditPart)) {
        return null;
    }
    EditPart object = (EditPart) objects.get(0);
    // for TUP-1015
    boolean isConnAttachedJLTriggerComp = false;
    ConnectionPart connectionPart = null;
    if (object instanceof ConnectionPart) {
        connectionPart = (ConnectionPart) object;
    } else if (object instanceof ConnLabelEditPart) {
        connectionPart = (ConnectionPart) object.getParent();
    }
    if (connectionPart != null) {
        Node srcNode = null;
        Object srcModel = connectionPart.getSource().getModel();
        if (srcModel instanceof Node) {
            srcNode = (Node) srcModel;
        }
        Node tarNode = null;
        Object tarModel = connectionPart.getTarget().getModel();
        if (tarModel instanceof Node) {
            tarNode = (Node) tarModel;
        }
        if (srcNode == null || tarNode == null) {
            return null;
        }
        IProcess process = srcNode.getProcess();
        if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
            IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
            if (service != null && (service.isTriggerNode(srcNode) || service.isTriggerNode(tarNode))) {
                isConnAttachedJLTriggerComp = true;
            }
        }
    }
    IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
    String preKey = TalendDesignerPrefConstants.NOT_SHOW_WARNING_WHEN_DELETE_LINK_WITH_JOBLETTRIGGERLINKCOMPONENT;
    if (isConnAttachedJLTriggerComp && !preferenceStore.getBoolean(preKey)) {
        MessageDialogWithToggle jlTriggerConfirmDialog = new MessageDialogWithToggle(null, //$NON-NLS-1$
        Messages.getString("GEFDeleteAction.deleteConnectionDialog.title"), // accept the default window icon
        null, Messages.getString("GEFDeleteAction.deleteConnectionDialog.msg"), MessageDialog.WARNING, new String[] { //$NON-NLS-1$
        IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, //$NON-NLS-1$
        Messages.getString("GEFDeleteAction.deleteConnectionDialog.toggleMsg"), preferenceStore.getDefaultBoolean(preKey));
        jlTriggerConfirmDialog.setPrefStore(preferenceStore);
        jlTriggerConfirmDialog.setPrefKey(preKey);
        if (jlTriggerConfirmDialog.open() != IDialogConstants.YES_ID) {
            return null;
        }
        preferenceStore.setValue(preKey, jlTriggerConfirmDialog.getToggleState());
    }
    List nodeParts = new ArrayList();
    List noteParts = new ArrayList();
    List others = new ArrayList(objects);
    for (Object o : objects) {
        if (o instanceof NodePart) {
            others.remove(o);
            Node model = (Node) ((NodePart) o).getModel();
            if (model.getJobletNode() != null) {
                continue;
            }
            if (model.getJunitNode() != null) {
                continue;
            }
            nodeParts.add(o);
        } else if (o instanceof NoteEditPart) {
            noteParts.add(o);
            others.remove(o);
        } else if (o instanceof SubjobContainerPart) {
            others.remove(o);
            SubjobContainerPart subjob = (SubjobContainerPart) o;
            for (Iterator iterator = subjob.getChildren().iterator(); iterator.hasNext(); ) {
                NodeContainerPart nodeContainerPart = (NodeContainerPart) iterator.next();
                if (nodeContainerPart instanceof JobletContainerPart) {
                    JobletContainer jobletCon = (JobletContainer) ((JobletContainerPart) nodeContainerPart).getModel();
                    JobletContainerFigure jobletFigure = (JobletContainerFigure) ((JobletContainerPart) nodeContainerPart).getFigure();
                    if (!jobletCon.isCollapsed()) {
                        jobletFigure.doCollapse();
                    }
                }
                NodePart nodePart = nodeContainerPart.getNodePart();
                if (nodePart != null) {
                    Node model = (Node) nodePart.getModel();
                    if (model.getJunitNode() != null) {
                        continue;
                    }
                    nodeParts.add(nodePart);
                }
            }
        }
    }
    if (others.size() == 0) {
        // so notes & nodes only
        CompoundCommand cpdCmd = new CompoundCommand();
        //$NON-NLS-1$
        cpdCmd.setLabel(Messages.getString("GEFDeleteAction.DeleteItems"));
        if (nodeParts.size() != 0) {
            GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
            deleteReq.setEditParts(nodeParts);
            cpdCmd.add(((NodePart) nodeParts.get(0)).getCommand(deleteReq));
        }
        if (noteParts.size() != 0) {
            GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
            deleteReq.setEditParts(noteParts);
            cpdCmd.add(((NoteEditPart) noteParts.get(0)).getCommand(deleteReq));
        }
        return cpdCmd;
    } else {
        GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
        deleteReq.setEditParts(objects);
        Command cmd = object.getCommand(deleteReq);
        return cmd;
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) JobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainer) Node(org.talend.designer.core.ui.editor.nodes.Node) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) ArrayList(java.util.ArrayList) 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) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) GroupRequest(org.eclipse.gef.requests.GroupRequest) Iterator(java.util.Iterator) JobletContainerFigure(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerFigure) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ArrayList(java.util.ArrayList) List(java.util.List) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) IProcess(org.talend.core.model.process.IProcess)

Example 22 with ConnectionPart

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

the class ConnectionSetAsMainRef method calculateEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
     */
@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    }
    List parts = getSelectedObjects();
    if (parts.size() == 1) {
        Object o = parts.get(0);
        /*
             * if (!(o instanceof ConnectionPart) && !(o instanceof ConnLabelEditPart)) { return false; }
             */
        ConnectionPart part = null;
        if (o instanceof ConnectionPart) {
            part = (ConnectionPart) o;
        } else {
            if (o instanceof ConnLabelEditPart) {
                part = (ConnectionPart) ((ConnLabelEditPart) o).getParent();
            } else {
                return false;
            }
        }
        if (!(part.getModel() instanceof Connection)) {
            return false;
        }
        connection = (Connection) part.getModel();
        if (!connection.isActivate()) {
            return false;
        }
        if (connection.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
            int nbTargetFlowIn = 0;
            INode node = connection.getTarget();
            for (IConnection currentConnec : node.getIncomingConnections()) {
                if (currentConnec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || currentConnec.getLineStyle().equals(EConnectionType.FLOW_REF)) {
                    nbTargetFlowIn++;
                }
            }
            if (nbTargetFlowIn <= 1) {
                return false;
            }
            setText(TEXT_SET_REF);
        } else {
            if (connection.getLineStyle().equals(EConnectionType.FLOW_REF)) {
                setText(TEXT_SET_MAIN);
            } else {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) List(java.util.List) IConnection(org.talend.core.model.process.IConnection) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Aggregations

ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)22 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)17 List (java.util.List)15 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)14 Connection (org.talend.designer.core.ui.editor.connections.Connection)13 ArrayList (java.util.ArrayList)9 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)8 Node (org.talend.designer.core.ui.editor.nodes.Node)7 NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)7 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)7 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)7 Point (org.eclipse.draw2d.geometry.Point)6 EditPart (org.eclipse.gef.EditPart)6 IConnection (org.talend.core.model.process.IConnection)6 PolylineConnection (org.eclipse.draw2d.PolylineConnection)5 NodeLabelEditPart (org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart)5 INode (org.talend.core.model.process.INode)4 ConnectionTraceEditPart (org.talend.designer.core.ui.editor.connections.ConnectionTraceEditPart)4 PointList (org.eclipse.draw2d.geometry.PointList)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3