Search in sources :

Example 6 with NoteEditPart

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

the class MultiplePasteCommand method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.commands.CompoundCommand#execute()
     */
@Override
public void execute() {
    AbstractMultiPageTalendEditor multiPageTalendEditor = (AbstractMultiPageTalendEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    GraphicalViewer viewer = multiPageTalendEditor.getTalendEditor().getViewer();
    oldSelection = new ArrayList<EditPart>();
    for (EditPart editPart : (List<EditPart>) viewer.getSelectedEditParts()) {
        oldSelection.add(editPart);
    }
    // remove the old selection
    viewer.deselectAll();
    super.execute();
    EditPart processPart = (EditPart) viewer.getRootEditPart().getChildren().get(0);
    if (processPart instanceof ProcessPart) {
        // can only be ProcessPart but still test
        List<EditPart> sel = new ArrayList<EditPart>();
        for (EditPart editPart : (List<EditPart>) processPart.getChildren()) {
            if (editPart instanceof NodePart) {
                Node currentNode = (Node) editPart.getModel();
                if (nodeCmd.getNodeContainerList().contains(currentNode.getNodeContainer())) {
                    sel.add(editPart);
                }
            } else if (editPart instanceof NoteEditPart) {
                Note currentNode = (Note) editPart.getModel();
                if (noteCmd.getNoteList().contains(currentNode)) {
                    sel.add(editPart);
                }
            } else if (editPart instanceof SubjobContainerPart) {
                // add for the bug TDI-7706
                for (EditPart subjobChildsPart : (List<EditPart>) editPart.getChildren()) {
                    if (subjobChildsPart instanceof NodeContainerPart) {
                        if (nodeCmd.getNodeContainerList().contains(((NodeContainerPart) subjobChildsPart).getModel())) {
                            NodePart nodePart = ((NodeContainerPart) subjobChildsPart).getNodePart();
                            if (nodePart != null) {
                                sel.add(nodePart);
                            }
                        }
                    }
                }
            }
        }
        StructuredSelection s = new StructuredSelection(sel);
        viewer.setSelection(s);
    }
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) Node(org.talend.designer.core.ui.editor.nodes.Node) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) Note(org.talend.designer.core.ui.editor.notes.Note) ArrayList(java.util.ArrayList) List(java.util.List) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart)

Example 7 with NoteEditPart

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

the class ZorderAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    List editparts = getSelectedObjects();
    if (editparts.size() == 1) {
        if (editparts.get(0) instanceof NoteEditPart || editparts.get(0) instanceof SubjobContainerPart) {
            editPart = (EditPart) editparts.get(0);
            createZOrderCommand();
            return zorderCommand.canExecute();
        }
    }
    return false;
}
Also used : NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) List(java.util.List) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)

Example 8 with NoteEditPart

use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tesb-studio-se by Talend.

the class RoutePasteAction method run.

@SuppressWarnings("unchecked")
@Override
public void run() {
    Object clipBoardContent;
    try {
        clipBoardContent = Clipboard.getDefault().getContents();
    } catch (RuntimeException e) {
        return;
    }
    org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
    Object systemObject = systemClipboard.getContents(TextTransfer.getInstance());
    if (clipBoardContent instanceof List) {
        List<EditPart> partsList = (List<EditPart>) clipBoardContent;
        if (partsList == null || partsList.isEmpty()) {
            return;
        }
        List<NodePart> nodeParts = new ArrayList<NodePart>();
        List<NoteEditPart> noteParts = new ArrayList<NoteEditPart>();
        for (Object o : partsList) {
            if (o instanceof NodePart) {
                if (!nodeParts.contains(o)) {
                    nodeParts.add((NodePart) o);
                }
            } else if (o instanceof NoteEditPart) {
                noteParts.add((NoteEditPart) o);
            }
        }
        CamelTalendEditor editor = (CamelTalendEditor) this.getWorkbenchPart();
        org.eclipse.draw2d.geometry.Point gefPoint = getCursorLocation();
        AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
        if (findProcessProviderFromPID != null) {
            boolean isDuplicateRoutelet = false;
            String duplicateRouteletName = "";
            for (NodePart copiedNodePart : nodeParts) {
                Node copiedNode = (Node) copiedNodePart.getModel();
                // add for bug TDI-20207.if copy joblet/job to itself,then return.
                EComponentType componentType = null;
                String copideNodeId = null;
                String editorProcessId = null;
                if (copiedNode.getComponent() != null) {
                    componentType = copiedNode.getComponent().getComponentType();
                    if (copiedNode.getComponent().getProcess() != null) {
                        copideNodeId = copiedNode.getComponent().getProcess().getId();
                    }
                }
                if (editor.getProcess() != null) {
                    editorProcessId = editor.getProcess().getId();
                }
                for (IElementParameter element : copiedNode.getElementParametersFromField(EParameterFieldType.PROCESS_TYPE)) {
                    for (Map.Entry<String, IElementParameter> entry : element.getChildParameters().entrySet()) {
                        if (("PROCESS_TYPE_PROCESS").equals(entry.getKey())) {
                            if (editorProcessId != null && editorProcessId.equals(entry.getValue().getValue())) {
                                return;
                            }
                        }
                    }
                }
                if ((EComponentType.JOBLET).equals(componentType)) {
                    // Check if is copying routelet in itself
                    if (editorProcessId != null && editorProcessId.equals(copideNodeId)) {
                        return;
                    }
                    // Check if is duplicate routelet
                    if (editor.getProcess().getNodesOfType(copiedNode.getComponent().getName()).size() > 0) {
                        isDuplicateRoutelet = true;
                        // $NON-NLS-1$
                        duplicateRouteletName += " ," + copiedNode.getComponent().getName();
                    }
                }
                // Check if it's Camel component
                if (!ComponentCategory.CATEGORY_4_CAMEL.getName().equals(copiedNode.getComponent().getType())) {
                    return;
                }
            }
            if (isDuplicateRoutelet) {
                MessageDialog.openInformation(editor.getEditorSite().getShell(), // $NON-NLS-1$
                "Copying Routelet", // $NON-NLS-1$
                "Do not allow duplicate Routelets\nRoutelet \"" + duplicateRouteletName.substring(2) + "\" already exist.");
                return;
            }
        }
        if (nodeParts.size() != 0 && noteParts.size() != 0) {
            MultiplePasteCommand mpc = new MultiplePasteCommand(nodeParts, noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
            mpc.setSelectedSubjobs(new ArrayList<SubjobContainerPart>());
            execute(mpc);
        } else if (nodeParts.size() != 0) {
            NodesPasteCommand cmd = new NodesPasteCommand(nodeParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
            cmd.setSelectedSubjobs(new ArrayList<SubjobContainerPart>());
            execute(cmd);
        } else if (noteParts.size() != 0) {
            NotesPasteCommand cmd = new NotesPasteCommand(noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint, false, null);
            execute(cmd);
        }
        setCursorLocation(null);
    } else if (clipBoardContent instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) clipBoardContent;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    } else if (systemObject != null && systemObject instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) systemObject;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) MultiplePasteCommand(org.talend.designer.core.ui.editor.cmd.MultiplePasteCommand) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) EComponentType(org.talend.core.model.components.EComponentType) NotesPasteCommand(org.talend.designer.core.ui.editor.cmd.NotesPasteCommand) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) NodesPasteCommand(org.talend.designer.core.ui.editor.cmd.NodesPasteCommand) CamelTalendEditor(org.talend.camel.designer.ui.editor.CamelTalendEditor) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) Text(org.eclipse.swt.widgets.Text) Clipboard(org.eclipse.gef.ui.actions.Clipboard) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) Map(java.util.Map) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 9 with NoteEditPart

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

the class ProcessLayoutEditPolicy method createChangeConstraintCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart,
     * java.lang.Object)
     */
@Override
public Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
    // return a command to move the part to the location given by the constraint
    if (child instanceof NodePart) {
        if (((Node) child.getModel()).isReadOnly()) {
            return null;
        }
        MoveNodeCommand locationCommand = new MoveNodeCommand((Node) child.getModel(), ((Rectangle) constraint).getLocation());
        return locationCommand;
    }
    if (child instanceof NoteEditPart) {
        if (((Note) child.getModel()).isReadOnly()) {
            return null;
        }
        MoveNoteCommand locationCommand = new MoveNoteCommand((Note) child.getModel(), ((Rectangle) constraint).getLocation());
        return locationCommand;
    }
    if (child instanceof SubjobContainerPart) {
        SubjobContainer sjc = (SubjobContainer) child.getModel();
        Point sjcLocation = sjc.getSubjobContainerRectangle().getLocation();
        Point translationNeeded = new Point(((Rectangle) constraint).getLocation().x - sjcLocation.x, ((Rectangle) constraint).getLocation().y - sjcLocation.y);
        CompoundCommand cc = new CompoundCommand();
        for (NodeContainer nc : sjc.getNodeContainers()) {
            if (nc.isReadOnly()) {
                return null;
            }
            IGraphicalNode node = nc.getNode();
            Point nodeLocation = node.getLocation();
            MoveNodeCommand locationCommand = new MoveNodeCommand(nc.getNode(), nodeLocation.getTranslated(translationNeeded));
            cc.add(locationCommand);
        }
        return cc;
    }
    return null;
}
Also used : MoveNodeCommand(org.talend.designer.core.ui.editor.cmd.MoveNodeCommand) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) Node(org.talend.designer.core.ui.editor.nodes.Node) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) Note(org.talend.designer.core.ui.editor.notes.Note) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) MoveNoteCommand(org.talend.designer.core.ui.editor.cmd.MoveNoteCommand) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Point(org.eclipse.draw2d.geometry.Point) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 10 with NoteEditPart

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

the class SubjobContainerLayoutEditPolicy method createAddCommand.

// ------------------------------------------------------------------------
// Abstract methods from ConstrainedLayoutEditPolicy
/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createAddCommand(org.eclipse.gef.EditPart,
     * java.lang.Object)
     */
protected Command createAddCommand(final EditPart child, final Object constraint) {
    if (child instanceof NoteEditPart) {
        if (((Note) child.getModel()).isReadOnly()) {
            return null;
        }
        MoveNoteCommand locationCommand = new MoveNoteCommand((Note) child.getModel(), ((Rectangle) constraint).getLocation());
        return locationCommand;
    }
    if (child instanceof NodeLabelEditPart) {
        boolean nodeSelected;
        // if (((NodeLabelEditPart) child).getNodePart().getSelected() != 0) {
        // nodeSelected = true;
        // } else {
        nodeSelected = false;
        // }
        MoveNodeLabelCommand locationCommand = new MoveNodeLabelCommand((NodeLabel) child.getModel(), ((Rectangle) constraint).getLocation(), nodeSelected);
        return locationCommand;
    } else if (child instanceof NodePart) {
        if (((Node) child.getModel()).isReadOnly()) {
            return null;
        }
        MoveNodeCommand locationCommand = new MoveNodeCommand((Node) child.getModel(), ((Rectangle) constraint).getLocation());
        return locationCommand;
    } else {
        return null;
    }
}
Also used : MoveNodeLabelCommand(org.talend.designer.core.ui.editor.cmd.MoveNodeLabelCommand) MoveNodeCommand(org.talend.designer.core.ui.editor.cmd.MoveNodeCommand) Note(org.talend.designer.core.ui.editor.notes.Note) Node(org.talend.designer.core.ui.editor.nodes.Node) Rectangle(org.eclipse.draw2d.geometry.Rectangle) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) MoveNoteCommand(org.talend.designer.core.ui.editor.cmd.MoveNoteCommand) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart)

Aggregations

NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)21 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)14 List (java.util.List)12 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)12 ArrayList (java.util.ArrayList)11 Node (org.talend.designer.core.ui.editor.nodes.Node)11 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)9 NodeLabelEditPart (org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart)9 Note (org.talend.designer.core.ui.editor.notes.Note)9 EditPart (org.eclipse.gef.EditPart)8 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)7 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)6 ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)5 Clipboard (org.eclipse.gef.ui.actions.Clipboard)4 JobletContainerPart (org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart)4 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)4 SubjobContainer (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer)4 Point (org.eclipse.draw2d.geometry.Point)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3