Search in sources :

Example 21 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class WorkflowEditor method addMetaNode.

/*
     * --------- methods for adding a auto-placed and auto-connected node -----
     */
/**
 * {@inheritDoc}
 * Listener interface method of the {@link NodeProvider}.
 * Called when other instances want to add a metanode to the workflow in
 * the editor. <br>
 * The implementation only adds it if the editor is active. If one other
 * node is selected in the editor, to which the new node will then be
 * connected to.
 *
 * @param sourceManager wfm to copy the metanode from
 * @param id the id of the metanode in the source manager
 * @return if the metanode was actually added
 */
@Override
public boolean addMetaNode(final WorkflowManager sourceManager, final NodeID id) {
    if (id == null || sourceManager == null) {
        return false;
    }
    if (!isEditorActive()) {
        return false;
    }
    NodeContainerEditPart preNode = getTheOneSelectedNode();
    NodeID preID = null;
    Point nodeLoc = null;
    if (preNode == null) {
        nodeLoc = getViewportCenterLocation();
        nodeLoc = toAbsolute(nodeLoc);
    } else {
        nodeLoc = getLocationRightOf(preNode);
        preID = preNode.getNodeContainer().getID();
    }
    if (getEditorSnapToGrid()) {
        nodeLoc = getClosestGridLocation(nodeLoc);
    }
    Command newNodeCmd = new CreateNewConnectedMetaNodeCommand(getViewer(), unwrapWFM(m_manager), sourceManager, id, nodeLoc, preID);
    getCommandStack().execute(newNodeCmd);
    // after adding a node the editor should get the focus
    setFocus();
    return true;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) CreateNewConnectedMetaNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand) CreateNewConnectedNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) Command(org.eclipse.gef.commands.Command) CreateNewConnectedMetaNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand) NodeID(org.knime.core.node.workflow.NodeID) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 22 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class WorkflowEditorDropTargetListener method dragOver.

/**
 * {@inheritDoc}
 *
 * Marks nodes or edges if a new node should replace an old node or should be inserted on an edge.
 */
@Override
public void dragOver(final DropTargetEvent event) {
    WorkflowManagerUI wfm = ((WorkflowRootEditPart) getViewer().getRootEditPart().getContents()).getWorkflowManager();
    m_node = null;
    m_edge = null;
    m_nodeCount = 0;
    m_edgeCount = 0;
    // edge-/nodedist
    double edgedist = Integer.MAX_VALUE;
    double nodedist = Integer.MAX_VALUE;
    Point dropLocation = getDropLocation(event);
    EditPart ep = getViewer().findObjectAt(dropLocation.getTranslated(0, 0));
    if (ep instanceof NodeContainerEditPart) {
        double temp = dropLocation.getDistance(dropLocation.getTranslated(0, 0));
        // choose nearest node to mouse position
        if (nodedist >= temp) {
            m_node = (NodeContainerEditPart) ep;
            nodedist = temp;
        }
        m_nodeCount++;
    } else if (ep instanceof ConnectionContainerEditPart) {
        double temp = dropLocation.getDistance(dropLocation.getTranslated(0, 0));
        // choose nearest edge to mouse-position
        if (edgedist >= temp) {
            m_edge = (ConnectionContainerEditPart) ep;
            edgedist = temp;
        }
        m_edgeCount++;
    }
    unmark(wfm);
    if (m_node != null && m_nodeCount >= m_edgeCount) {
        m_markedNode = m_node;
        m_markedNode.mark();
        // workaround for eclipse bug 393868 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=393868)
        WindowsDNDHelper.hideDragImage();
    } else if (m_edge != null) {
        m_edgeColor = m_edge.getFigure().getForegroundColor();
        m_edgeWidth = ((ProgressPolylineConnection) m_edge.getFigure()).getLineWidth();
        m_markedEdge = m_edge;
        ((ProgressPolylineConnection) m_markedEdge.getFigure()).setLineWidth(m_edgeWidth + 3);
        m_markedEdge.getFigure().setForegroundColor(RED);
        // workaround for eclipse bug 393868 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=393868)
        WindowsDNDHelper.hideDragImage();
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) ProgressPolylineConnection(org.knime.workbench.editor2.figures.ProgressPolylineConnection) Point(org.eclipse.draw2d.geometry.Point)

Example 23 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class VerifyingCompoundCommand method execute.

/**
 * Overrides the execute method of <code>CompoundCommand</code> to add a
 * verification dialog with the given message.
 *
 * @see org.eclipse.gef.commands.Command#execute()
 */
@Override
public void execute() {
    // before showing the confirmation dialog, mark the node part figures
    for (NodeContainerEditPart nodePart : m_nodeParts) {
        nodePart.mark();
    }
    try {
        // the following code has mainly been copied from
        // IDEWorkbenchWindowAdvisor#preWindowShellClose
        IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
        if (!store.contains(PreferenceConstants.P_CONFIRM_DELETE) || store.getBoolean(PreferenceConstants.P_CONFIRM_DELETE)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(Display.getDefault().getActiveShell(), "Confirm ...", m_dialogDisplayText, "Do not ask again", false, null, null);
            if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
                return;
            }
            if (dialog.getToggleState()) {
                store.setValue(PreferenceConstants.P_CONFIRM_DELETE, false);
                KNIMEUIPlugin.getDefault().savePluginPreferences();
            }
        }
        // in all other cases execute the commands
        LOGGER.debug("Executing <" + size() + "> commands.");
        super.execute();
    } finally {
        for (NodeContainerEditPart nodePart : m_nodeParts) {
            nodePart.unmark();
        }
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 24 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class NewWorkflowContainerEditPolicy method handleNodeDrop.

/**
 * @param manager the workflow manager
 * @param factory the ndoe factory
 * @param request the drop request
 */
private Command handleNodeDrop(final WorkflowManager manager, final NodeFactory<? extends NodeModel> factory, final CreateDropRequest request) {
    RequestType requestType = request.getRequestType();
    Point location = request.getLocation();
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    if (requestType.equals(RequestType.CREATE)) {
        // create a new node
        return new CreateNodeCommand(manager, factory, location, snapToGrid);
    } else {
        AbstractEditPart editPart = request.getEditPart();
        if (requestType.equals(RequestType.INSERT)) {
            // insert new node into connection
            InsertNodeCommand insertCommand = new InsertNodeCommand(manager, factory, location, snapToGrid, (ConnectionContainerEditPart) editPart);
            if (request.createSpace()) {
                CreateSpaceAction csa = new CreateSpaceAction((WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(), request.getDirection(), request.getDistance());
                return insertCommand.chain(csa.createCompoundCommand(csa.selectedParts()));
            } else {
                return insertCommand;
            }
        } else if (requestType.equals(RequestType.REPLACE)) {
            // replace node with a node
            return new ReplaceNodeCommand(manager, factory, location, snapToGrid, (NodeContainerEditPart) editPart);
        } else {
            return null;
        }
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) ReplaceNodeCommand(org.knime.workbench.editor2.commands.ReplaceNodeCommand) Point(org.eclipse.draw2d.geometry.Point) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) InsertNodeCommand(org.knime.workbench.editor2.commands.InsertNodeCommand) CreateSpaceAction(org.knime.workbench.editor2.actions.CreateSpaceAction) RequestType(org.knime.workbench.editor2.CreateDropRequest.RequestType)

Example 25 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class NewWorkflowContainerEditPolicy method handleMetaNodeTemplateDrop.

/**
 * @param manager the workflow manager
 * @param request the drop request
 * @param filestore the location of the metanode template
 */
private Command handleMetaNodeTemplateDrop(final WorkflowManager manager, final CreateDropRequest request, final AbstractExplorerFileStore filestore) {
    RequestType requestType = request.getRequestType();
    Point location = request.getLocation();
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    if (requestType.equals(RequestType.CREATE)) {
        // create metanode from template
        return new CreateMetaNodeTemplateCommand(manager, filestore, location, snapToGrid);
    } else {
        AbstractEditPart editPart = request.getEditPart();
        if (requestType.equals(RequestType.INSERT)) {
            // insert metanode from template into connection
            InsertMetaNodeTempalteCommand insertCommand = new InsertMetaNodeTempalteCommand(manager, filestore, location, snapToGrid, (ConnectionContainerEditPart) editPart);
            if (request.createSpace()) {
                CreateSpaceAction csa = new CreateSpaceAction((WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(), request.getDirection(), request.getDistance());
                return insertCommand.chain(csa.createCompoundCommand(csa.selectedParts()));
            } else {
                return insertCommand;
            }
        } else if (requestType.equals(RequestType.REPLACE)) {
            // replace node with metanode from template
            return new ReplaceMetaNodeTemplateCommand(manager, filestore, location, snapToGrid, (NodeContainerEditPart) editPart);
        } else {
            return null;
        }
    }
}
Also used : ReplaceMetaNodeTemplateCommand(org.knime.workbench.editor2.commands.ReplaceMetaNodeTemplateCommand) CreateMetaNodeTemplateCommand(org.knime.workbench.editor2.commands.CreateMetaNodeTemplateCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) Point(org.eclipse.draw2d.geometry.Point) InsertMetaNodeTempalteCommand(org.knime.workbench.editor2.commands.InsertMetaNodeTempalteCommand) CreateSpaceAction(org.knime.workbench.editor2.actions.CreateSpaceAction) RequestType(org.knime.workbench.editor2.CreateDropRequest.RequestType)

Aggregations

NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)77 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)28 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)24 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)16 EditPart (org.eclipse.gef.EditPart)15 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)14 Point (org.eclipse.draw2d.geometry.Point)11 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)11 NodeContainer (org.knime.core.node.workflow.NodeContainer)9 NodeID (org.knime.core.node.workflow.NodeID)9 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)9 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)9 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)9 ArrayList (java.util.ArrayList)8 GUIWorkflowCipherPrompt (org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)8 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)6 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)6 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 MessageBox (org.eclipse.swt.widgets.MessageBox)5