Search in sources :

Example 16 with NodeContainerEditPart

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

the class NewWorkflowXYLayoutPolicy method createChildEditPolicy.

/**
 * {@inheritDoc}
 */
@Override
protected EditPolicy createChildEditPolicy(final EditPart child) {
    if (child instanceof NodeContainerEditPart) {
        return new NonResizeNoHandlesEditPolicy((GraphicalEditPart) child);
    }
    if (child instanceof NodeAnnotationEditPart) {
        NonResizableEditPolicy pol = new NonResizeNoHandlesEditPolicy((GraphicalEditPart) child);
        pol.setDragAllowed(false);
        return pol;
    }
    return super.createChildEditPolicy(child);
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NonResizableEditPolicy(org.eclipse.gef.editpolicies.NonResizableEditPolicy) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Example 17 with NodeContainerEditPart

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

the class NodeMonitorView method selectionChanged.

/**
 * The method updating the content of the monitor.
 *
 * {@inheritDoc}
 */
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    IStructuredSelection structSel = (IStructuredSelection) selection;
    if (m_pinned) {
        m_lastSelectionWhilePinned = structSel;
        return;
    }
    if (structSel.equals(m_lastSelection)) {
        // selection hasn't changed - return.
        return;
    }
    m_lastSelection = structSel;
    if (structSel.size() < 1) {
        // Nothing selected
        m_title.setText("");
        m_state.setText("no node selected");
        m_table.removeAll();
        return;
    }
    if (structSel.size() > 1) {
        // too many selected items
        m_title.setText("");
        m_state.setText("more than one element selected.");
        m_table.removeAll();
        return;
    }
    // retrieve first (and only!) selection:
    Iterator<?> selIt = structSel.iterator();
    Object sel = selIt.next();
    // 
    if (sel instanceof NodeContainerEditPart) {
        // a NodeContainer was selected, display it's name and status
        NodeContainerUI nc = ((NodeContainerEditPart) sel).getNodeContainer();
        updateNodeContainerInfo(nc);
    } else {
        // unsupported selection
        unsupportedSelection(sel);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) PortObject(org.knime.core.node.port.PortObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 18 with NodeContainerEditPart

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

the class SnapIconToGrid method snapRectangle.

/**
 * {@inheritDoc}
 */
@Override
public int snapRectangle(final Request request, final int snapLocations, final PrecisionRectangle rect, final PrecisionRectangle result) {
    PrecisionRectangle r = rect;
    if (request instanceof ChangeBoundsRequest) {
        EditPart refPart = getReferencePart(((ChangeBoundsRequest) request).getEditParts(), ((ChangeBoundsRequest) request).getLocation(), ((ChangeBoundsRequest) request).getMoveDelta());
        if (refPart instanceof NodeContainerEditPart) {
            // adjust the rectangle to snap the center of the icon of the node
            NodeContainerEditPart contPart = (NodeContainerEditPart) refPart;
            NodeContainerFigure fig = (NodeContainerFigure) contPart.getFigure();
            Point iconOffset = getIconOffset(fig);
            r = rect.getPreciseCopy();
            r.translate(iconOffset);
        } else if (refPart instanceof NodeAnnotationEditPart) {
            // the rect is the annotation outline - adjust it to snap the center of the corresponding node icon
            NodeAnnotationEditPart annoPart = (NodeAnnotationEditPart) refPart;
            WorkflowRootEditPart parent = (WorkflowRootEditPart) annoPart.getParent();
            IFigure annoFig = annoPart.getFigure();
            NodeAnnotation anno = (NodeAnnotation) annoPart.getModel();
            NodeContainerEditPart nodePart = (NodeContainerEditPart) m_container.getViewer().getEditPartRegistry().get(parent.getWorkflowManager().getNodeContainer(anno.getNodeID()));
            NodeContainerFigure nodeFig = (NodeContainerFigure) nodePart.getFigure();
            Point iconOffset = getIconOffset(nodeFig);
            int xOff = nodeFig.getBounds().x - annoFig.getBounds().x;
            xOff += iconOffset.x;
            int yOff = iconOffset.y - nodeFig.getBounds().height;
            r = rect.getPreciseCopy();
            r.translate(new Point(xOff, yOff));
        }
    }
    return super.snapRectangle(request, snapLocations, r, result);
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 19 with NodeContainerEditPart

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

the class HelpView method selectionChanged.

/**
 * The method updating the content of the browser. Depending on the type of
 * the selected part(s) it will retrieve the node(s) description and set it
 * in the browser.
 *
 * {@inheritDoc}
 */
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
    if (m_browser != null && m_browser.isDisposed()) {
        // if someone closed it, unregister as selection listener
        // TODO same for text
        getViewSite().getPage().removeSelectionListener(this);
        return;
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSel = (IStructuredSelection) selection;
        IStructuredSelection lastSel = m_lastSelectionReference == null ? null : m_lastSelectionReference.get();
        // we do not clear our content if nothing is selected.
        if (structSel.size() < 1 || structSel.equals(lastSel)) {
            return;
        }
        m_lastSelectionReference = new WeakReference<>(structSel);
        // we display the full description only if a single node is selected
        boolean useSingleLine;
        if ((structSel.size() > 1) || (structSel.getFirstElement() instanceof Category)) {
            useSingleLine = true;
        } else {
            useSingleLine = false;
        }
        // construct the html page to display
        final StringBuilder content = new StringBuilder();
        if (useSingleLine) {
            // add the prefix to make it a html page
            content.append("<html><head>");
            content.append("<meta http-equiv=\"content-type\" " + "content=\"text/html; charset=UTF-8\"></meta>");
            // include stylesheet
            content.append("<style>");
            content.append(NodeFactoryHTMLCreator.instance.getCss());
            content.append("</style>");
            content.append("</head><body><dl>");
        }
        // Keep a list of already displayed objects (this works as long as
        // the selected items come in an ordered way. Ordered with item
        // containing other selected items coming before the items
        // contained. For the tree view in the repository this is the case.
        HashSet<String> ids = new HashSet<String>();
        for (Iterator<?> selIt = structSel.iterator(); selIt.hasNext(); ) {
            Object sel = selIt.next();
            if (sel instanceof Category) {
                // its a category in the node repository, display a list of
                // contained nodes
                Category cat = (Category) sel;
                if (!ids.contains(cat.getID())) {
                    ids.add(cat.getID());
                    DynamicNodeDescriptionCreator.instance().addDescription(cat, content, ids);
                }
            } else if (sel instanceof NodeTemplate) {
                // its a node selected in the repository
                NodeTemplate templ = (NodeTemplate) sel;
                if (!ids.contains(templ.getID())) {
                    ids.add(templ.getID());
                    DynamicNodeDescriptionCreator.instance().addDescription(templ, useSingleLine, content);
                }
            } else if (sel instanceof NodeContainerEditPart) {
                // if multiple nodes in the editor are selected we should
                // not show description for the same node (if used multiple
                // times) twice. We store the node name in the set.
                NodeContainerUI nc = ((NodeContainerEditPart) sel).getNodeContainer();
                if (!ids.contains(nc.getName())) {
                    ids.add(nc.getName());
                    DynamicNodeDescriptionCreator.instance().addDescription(nc, useSingleLine, content);
                }
            } else if (sel instanceof MetaNodeTemplate) {
                // TODO: add support for MetaNodeTemplates and get the
                // description out of them
                NodeContainerUI manager = ((MetaNodeTemplate) sel).getManager();
                DynamicNodeDescriptionCreator.instance().addDescription(manager, useSingleLine, content);
            }
        }
        if (useSingleLine) {
            // finish the html
            content.append("</dl></body></html>");
        }
        if (m_browser != null) {
            // FG: must always be invoked in SWT UI thread
            m_browser.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (!m_browser.isDisposed()) {
                        m_browser.setText(content.toString());
                    }
                }
            });
        } else if (m_isFallback) {
            m_text.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    m_text.setText(content.toString());
                }
            });
        }
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) Category(org.knime.workbench.repository.model.Category) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) HashSet(java.util.HashSet)

Example 20 with NodeContainerEditPart

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

the class WorkflowEditor method onF2Pressed.

/**
 * Opens editor for (node) annotation (given that a single node or
 * annotation is selected).
 */
private void onF2Pressed() {
    ISelectionProvider provider = getEditorSite().getSelectionProvider();
    if (provider == null) {
        return;
    }
    ISelection sel = provider.getSelection();
    if (!(sel instanceof IStructuredSelection)) {
        return;
    }
    Set<AnnotationEditPart> selectedAnnoParts = new HashSet<AnnotationEditPart>();
    @SuppressWarnings("rawtypes") Iterator selIter = ((IStructuredSelection) sel).iterator();
    while (selIter.hasNext()) {
        Object next = selIter.next();
        if (next instanceof AnnotationEditPart) {
            selectedAnnoParts.add((AnnotationEditPart) next);
        } else if (next instanceof NodeContainerEditPart) {
            NodeAnnotationEditPart nodeAnnoPart = ((NodeContainerEditPart) next).getNodeAnnotationEditPart();
            if (nodeAnnoPart != null) {
                selectedAnnoParts.add(nodeAnnoPart);
            }
        } else {
            // unknown type selected
            return;
        }
    }
    if (selectedAnnoParts.size() == 1) {
        AnnotationEditPart next = selectedAnnoParts.iterator().next();
        next.performEdit();
    }
}
Also used : NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) EventObject(java.util.EventObject) ContentObject(org.knime.workbench.explorer.view.ContentObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) HashSet(java.util.HashSet)

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