Search in sources :

Example 6 with NodeContainerEditPart

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

the class WorkflowMarqueeSelectionTool method calculateNewSelection.

private void calculateNewSelection(final Collection<GraphicalEditPart> newSelections, final Collection<GraphicalEditPart> deselections) {
    Rectangle marqueeRect = getMarqueeSelectionRectangle();
    for (Iterator<GraphicalEditPart> itr = getAllChildren().iterator(); itr.hasNext(); ) {
        GraphicalEditPart child = itr.next();
        IFigure figure = child.getFigure();
        if (!child.isSelectable() || child.getTargetEditPart(MARQUEE_REQUEST) != child || !isFigureVisible(figure) || !figure.isShowing()) {
            continue;
        }
        if (!(child instanceof NodeContainerEditPart || child instanceof ConnectionContainerEditPart || child instanceof AbstractWorkflowPortBarEditPart || child instanceof AnnotationEditPart)) {
            continue;
        }
        Rectangle r = figure.getBounds().getCopy();
        figure.translateToAbsolute(r);
        boolean included = false;
        if (child instanceof ConnectionEditPart && marqueeRect.intersects(r)) {
            Rectangle relMarqueeRect = Rectangle.SINGLETON;
            figure.translateToRelative(relMarqueeRect.setBounds(marqueeRect));
            included = ((PolylineConnection) figure).getPoints().intersects(relMarqueeRect);
        } else if (child instanceof AnnotationEditPart) {
            // select WorkflowAnnotations only if they are fully included in the selection
            if (figure instanceof WorkflowAnnotationFigure) {
                included = marqueeRect.contains(r);
            }
        } else if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
            included = marqueeRect.intersects(r);
        } else {
            included = marqueeRect.contains(r);
        }
        if (included) {
            if (isToggle()) {
                if (wasSelected(child)) {
                    deselections.add(child);
                } else {
                    newSelections.add(child);
                }
            } else {
                newSelections.add(child);
            }
        } else if (isToggle()) {
            // readded if it was in the selection before
            if (wasSelected(child)) {
                newSelections.add(child);
            } else {
                deselections.add(child);
            }
        }
    }
    if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
        calculateConnections(newSelections, deselections);
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) WorkflowAnnotationFigure(org.knime.workbench.editor2.figures.WorkflowAnnotationFigure) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IFigure(org.eclipse.draw2d.IFigure) PolylineConnection(org.eclipse.draw2d.PolylineConnection)

Example 7 with NodeContainerEditPart

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

the class AddAnnotationAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    AddAnnotationCommand aac = new AddAnnotationCommand(getManager(), getEditor().getViewer(), new Point(m_x, m_y));
    // enables undo
    getCommandStack().execute(aac);
    // update the actions
    getEditor().updateActions();
    // Give focus to the editor again. Otherwise the actions (selection)
    // is not updated correctly.
    getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
Also used : AddAnnotationCommand(org.knime.workbench.editor2.commands.AddAnnotationCommand) Point(org.eclipse.swt.graphics.Point)

Example 8 with NodeContainerEditPart

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

the class ChangeGridAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    EditorGridSettingsDialog dlg = new EditorGridSettingsDialog(Display.getCurrent().getActiveShell(), getEditor().getCurrentEditorSettings());
    if (dlg.open() == Window.OK) {
        getEditor().markDirty();
        getEditor().applyEditorSettings(dlg.getSettings());
        getEditor().getWorkflowManager().get().setEditorUIInformation(dlg.getSettings());
    }
}
Also used : EditorGridSettingsDialog(org.knime.workbench.editor2.EditorGridSettingsDialog)

Example 9 with NodeContainerEditPart

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

the class ChangeSubNodeLinkAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    SubNodeContainer subNode = Wrapper.unwrap(nodeParts[0].getNodeContainer(), SubNodeContainer.class);
    if (Role.Link.equals(subNode.getTemplateInformation().getRole())) {
        WorkflowManager wfm = subNode.getParent();
        URI targetURI = subNode.getTemplateInformation().getSourceURI();
        LinkType linkType = LinkType.None;
        try {
            if (ResolverUtil.isMountpointRelativeURL(targetURI)) {
                linkType = LinkType.MountpointRelative;
            } else if (ResolverUtil.isWorkflowRelativeURL(targetURI)) {
                linkType = LinkType.WorkflowRelative;
            } else {
                linkType = LinkType.Absolute;
            }
        } catch (IOException e) {
            LOGGER.error("Unable to resolve current link to template " + targetURI + ": " + e.getMessage(), e);
            return;
        }
        String msg = "This is a linked (read-only) Wrapped Metanode. Only the link type can be changed.\n";
        msg += "Please select the new type of the link to the Wrapped Metanode template.\n";
        msg += "(current type: " + linkType + ", current link: " + targetURI + ")\n";
        msg += "The origin of the template will not be changed - just the way it is referenced.";
        LinkPrompt dlg = new LinkPrompt(getEditor().getSite().getShell(), msg, linkType);
        dlg.open();
        if (dlg.getReturnCode() == Window.CANCEL) {
            return;
        }
        LinkType newLinkType = dlg.getLinkType();
        if (linkType.equals(newLinkType)) {
            LOGGER.info("Link type not changes as selected type equals existing type " + targetURI);
            return;
        }
        // as the workflow is local and the template in the same mountID, it should resolve to a file
        URI newURI = null;
        NodeContext.pushContext(subNode);
        try {
            File targetFile = ResolverUtil.resolveURItoLocalFile(targetURI);
            LocalExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.fromLocalFile(targetFile);
            newURI = AbstractContentProvider.createMetanodeLinkUri(subNode, targetfs, newLinkType);
        } catch (IOException e) {
            LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } catch (CoreException e) {
            LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } finally {
            NodeContext.removeLastContext();
        }
        ChangeSubNodeLinkCommand cmd = new ChangeSubNodeLinkCommand(wfm, subNode, targetURI, newURI);
        getCommandStack().execute(cmd);
    } else {
        throw new IllegalStateException("Can only change the type of a template link if the Wrapped Metanode is actually linked to a template - " + subNode + " is not.");
    }
}
Also used : LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) CoreException(org.eclipse.core.runtime.CoreException) LinkType(org.knime.workbench.explorer.view.AbstractContentProvider.LinkType) File(java.io.File) ChangeSubNodeLinkCommand(org.knime.workbench.editor2.commands.ChangeSubNodeLinkCommand)

Example 10 with NodeContainerEditPart

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

the class ChangeSubNodeLinkAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    NodeContainer nc = Wrapper.unwrapNC(nodes[0].getNodeContainer());
    if (!(nc instanceof SubNodeContainer)) {
        return false;
    }
    SubNodeContainer subNode = (SubNodeContainer) nc;
    if (!Role.Link.equals(subNode.getTemplateInformation().getRole()) || subNode.getParent().isWriteProtected()) {
        // sub node must be linked and parent must not forbid the change
        return false;
    }
    // we can reconfigure the template link - but only if template and flow are in the same mountpoint
    URI targetURI = subNode.getTemplateInformation().getSourceURI();
    try {
        if (ResolverUtil.isMountpointRelativeURL(targetURI) || ResolverUtil.isWorkflowRelativeURL(targetURI)) {
            return true;
        }
    } catch (IOException e) {
        return false;
    }
    // we can change absolute links if the mount points of flow and template are the same
    AbstractContentProvider workflowMountPoint = null;
    WorkflowContext wfc = subNode.getProjectWFM().getContext();
    LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfc.getMountpointRoot());
    if (fs != null) {
        workflowMountPoint = fs.getContentProvider();
    }
    if (workflowMountPoint == null) {
        return false;
    }
    AbstractExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.getStore(targetURI);
    if (targetfs == null) {
        return false;
    }
    return workflowMountPoint.equals(targetfs.getContentProvider());
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) IOException(java.io.IOException) URI(java.net.URI)

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