Search in sources :

Example 16 with WorkflowRootEditPart

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

the class DeleteCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    // select the new ones....
    if (m_viewer != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        ((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureSelection(m_nodeIDs);
        m_viewer.deselectAll();
    }
    WorkflowManager hostWFM = getHostWFM();
    if (m_undoPersitor != null) {
        hostWFM.paste(m_undoPersitor);
    }
    for (ConnectionContainer cc : m_connections) {
        ConnectionContainer newCC = hostWFM.addConnection(cc.getSource(), cc.getSourcePort(), cc.getDest(), cc.getDestPort());
        newCC.setUIInfo(cc.getUIInfo());
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 17 with WorkflowRootEditPart

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

the class PasteFromWorkflowPersistorCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    WorkflowManager manager = m_editor.getWorkflowManager().get();
    WorkflowPersistor copyPersistor = m_clipboardObject.getCopyPersistor();
    m_pastedContent = manager.paste(copyPersistor);
    NodeID[] pastedNodes = m_pastedContent.getNodeIDs();
    WorkflowAnnotation[] pastedAnnos = m_pastedContent.getAnnotations();
    // fast lookup below
    Set<NodeID> newIDs = new HashSet<NodeID>();
    List<int[]> insertedElementBounds = new ArrayList<int[]>();
    for (NodeID i : pastedNodes) {
        NodeContainer nc = manager.getNodeContainer(i);
        NodeUIInformation ui = nc.getUIInformation();
        int[] bounds = ui.getBounds();
        insertedElementBounds.add(bounds);
    }
    for (WorkflowAnnotation a : pastedAnnos) {
        int[] bounds = new int[] { a.getX(), a.getY(), a.getWidth(), a.getHeight() };
        insertedElementBounds.add(bounds);
    }
    int[] moveDist = m_shiftCalculator.calculateShift(insertedElementBounds, manager, m_clipboardObject);
    // for redo-operations we need the exact same shift.
    m_shiftCalculator = new FixedShiftCalculator(moveDist);
    for (NodeID id : pastedNodes) {
        newIDs.add(id);
        NodeContainer nc = manager.getNodeContainer(id);
        NodeUIInformation oldUI = nc.getUIInformation();
        NodeUIInformation newUI = NodeUIInformation.builder(oldUI).translate(moveDist).build();
        nc.setUIInformation(newUI);
    }
    for (ConnectionContainer conn : manager.getConnectionContainers()) {
        if (newIDs.contains(conn.getDest()) && newIDs.contains(conn.getSource())) {
            // get bend points and move them
            ConnectionUIInformation oldUI = conn.getUIInfo();
            if (oldUI != null) {
                ConnectionUIInformation newUI = ConnectionUIInformation.builder(oldUI).translate(moveDist).build();
                conn.setUIInfo(newUI);
            }
        }
    }
    for (WorkflowAnnotation a : pastedAnnos) {
        a.shiftPosition(moveDist[0], moveDist[1]);
    }
    EditPartViewer partViewer = m_editor.getViewer();
    partViewer.deselectAll();
    // select the new ones....
    if (partViewer.getRootEditPart().getContents() != null && partViewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        WorkflowRootEditPart rootEditPart = (WorkflowRootEditPart) partViewer.getRootEditPart().getContents();
        rootEditPart.setFutureSelection(pastedNodes);
        rootEditPart.setFutureAnnotationSelection(Arrays.asList(pastedAnnos));
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) ArrayList(java.util.ArrayList) EditPartViewer(org.eclipse.gef.EditPartViewer) NodeContainer(org.knime.core.node.workflow.NodeContainer) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) HashSet(java.util.HashSet)

Example 18 with WorkflowRootEditPart

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

the class ChangeEditorUIAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    EditorUISettingsDialog dlg = new EditorUISettingsDialog(Display.getCurrent().getActiveShell(), getEditor().getCurrentEditorSettings());
    if (dlg.open() == Window.OK) {
        // store settings with the workflow (workflow is marked dirty)
        getEditor().markDirty();
        getEditor().applyEditorSettings(dlg.getSettings());
        getEditor().getWorkflowManager().get().setEditorUIInformation(dlg.getSettings());
        // refresh workflow editor
        // TODO this doesn't work - it doesn't refresh the ConnectionContainerEditParts
        // WorkflowRootEditPart editorPart = (WorkflowRootEditPart)
        // provider.getRootEditPart().getChildren().get(0);
        // editorPart.refresh();
        // workaround to refresh all connection container edit parts
        getEditor().getWorkflowManager().get().getConnectionContainers().forEach(cc -> cc.setUIInfo(cc.getUIInfo()));
    }
}
Also used : EditorUISettingsDialog(org.knime.workbench.editor2.EditorUISettingsDialog)

Example 19 with WorkflowRootEditPart

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

the class WorkflowEditPartFactory method createEditPart.

/**
 * Creates the referring edit parts for the following parts of the model.
 * <ul>
 * <li>{@link WorkflowManager}: either {@link WorkflowRootEditPart} or {@link NodeContainerEditPart} (depending on
 * the currently displayed level)</li>
 * <li>{@link SingleNodeContainer}: {@link NodeContainerEditPart}</li>
 * <li>{@link NodeInPort}: {@link NodeInPortEditPart}</li>
 * <li>{@link NodeOutPort}: {@link NodeOutPortEditPart}</li>
 * <li>{@link ConnectionContainer}: {@link ConnectionContainerEditPart}</li>
 * <li>{@link WorkflowInPort}: {@link WorkflowInPortEditPart}</li>
 * <li>{@link WorkflowOutPort}: {@link WorkflowOutPortEditPart}</li>
 * </ul>
 *
 * The {@link WorkflowRootEditPart} has its {@link NodeContainer}s and its {@link WorkflowInPort}s and
 * {@link WorkflowOutPort}s as model children. The {@link NodeContainerEditPart} has its {@link NodePort}s as its
 * children.
 *
 * @see WorkflowRootEditPart#getModelChildren()
 * @see NodeContainerEditPart#getModelChildren()
 *
 * @throws IllegalArgumentException if any other object is passed
 *
 *             {@inheritDoc}
 */
@Override
public EditPart createEditPart(final EditPart context, final Object model) {
    // instantiated here
    // correct type in the if statement
    // model at the end of method
    EditPart part = null;
    if (model instanceof WorkflowManagerUI) {
        // this is out "root" workflow manager
        if (m_isTop) {
            // all following objects of type WorkflowManager are treated as
            // metanodes and displayed as NodeContainers
            m_isTop = false;
            part = new WorkflowRootEditPart();
        } else {
            // we already have a "root" workflow manager
            // must be a metanode
            part = new SubworkflowEditPart();
        }
    } else if (model instanceof NodeAnnotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        part = new NodeAnnotationEditPart();
    } else if (model instanceof Annotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        /* workflow annotations hang off the workflow manager */
        part = new AnnotationEditPart();
    } else if (model instanceof WorkflowPortBar) {
        WorkflowPortBar bar = (WorkflowPortBar) model;
        if (bar.isInPortBar()) {
            part = new WorkflowInPortBarEditPart();
        } else {
            part = new WorkflowOutPortBarEditPart();
        }
    } else if (model instanceof SingleNodeContainerUI) {
        // SingleNodeContainer -> NodeContainerEditPart
        part = new NodeContainerEditPart();
    // we have to test for WorkflowInPort first because it's a
    // subclass of NodeInPort (same holds for WorkflowOutPort and
    // NodeOutPort)
    } else if (model instanceof WorkflowInPortUI && context instanceof WorkflowInPortBarEditPart) {
        // WorkflowInPort and context WorkflowRootEditPart ->
        // WorkflowInPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowInPort is a model child of the WorkflowRootEditPart, i.e.
             * we look at it as a workflow in port. If the context is a
             * NodeContainerEditPart the WorkflowInPort is a model child of a
             * NodeContainerEditPart and we look at it as a node in port.
             */
        WorkflowInPortUI inport = (WorkflowInPortUI) model;
        part = new WorkflowInPortEditPart(inport.getPortType(), inport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI && context instanceof WorkflowOutPortBarEditPart) {
        // WorkflowOutPort and context WorkflowRootEditPart ->
        // WorkflowOutPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowOutPort is a model child of the WorkflowRootEditPart,
             * i.e. we look at it as a workflow out port. If the context is a
             * NodeContainerEditPart the WorkflowOutPort is a model child of a
             * NodeContainerEditPart and we look at it as a node out port.
             */
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new WorkflowOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI) {
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new MetaNodeOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof NodeInPortUI) {
        // NodeInPort -> NodeInPortEditPart
        NodePortUI port = (NodeInPortUI) model;
        part = new NodeInPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof NodeOutPortUI) {
        // NodeOutPort -> NodeOutPortEditPart
        NodePortUI port = (NodeOutPortUI) model;
        part = new NodeOutPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof ConnectionContainerUI) {
        // ConnectionContainer -> ConnectionContainerEditPart
        part = new ConnectionContainerEditPart();
    } else {
        throw new IllegalArgumentException("unknown model obj: " + model);
    }
    // associate the model with the part (= the controller)
    part.setModel(model);
    return part;
}
Also used : SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowOutPortUI(org.knime.core.ui.node.workflow.WorkflowOutPortUI) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) 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) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation) NodeInPortUI(org.knime.core.ui.node.workflow.NodeInPortUI) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) NodeOutPortUI(org.knime.core.ui.node.workflow.NodeOutPortUI) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) WorkflowInPortUI(org.knime.core.ui.node.workflow.WorkflowInPortUI) NodePortUI(org.knime.core.ui.node.workflow.NodePortUI)

Example 20 with WorkflowRootEditPart

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

the class HideNodeNamesEditorAction method createAction.

/**
 * {@inheritDoc}
 */
@Override
protected AbstractNodeAction createAction(final WorkflowEditor editor) {
    WorkflowRootEditPart part = (WorkflowRootEditPart) ((editor).getViewer().getRootEditPart().getChildren().get(0));
    HideNodeNamesAction hideNodeIdsAction = new HideNodeNamesAction(editor);
    hideNodeIdsAction.setChecked(part.hideNodeNames());
    return hideNodeIdsAction;
}
Also used : HideNodeNamesAction(org.knime.workbench.editor2.actions.HideNodeNamesAction) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart)

Aggregations

WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)18 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)7 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)6 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)5 Point (org.eclipse.draw2d.geometry.Point)4 EditPart (org.eclipse.gef.EditPart)4 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 EditPartViewer (org.eclipse.gef.EditPartViewer)3 IEditorPart (org.eclipse.ui.IEditorPart)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)3 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)3 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)3 IFigure (org.eclipse.draw2d.IFigure)2 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)2 ZoomManager (org.eclipse.gef.editparts.ZoomManager)2 ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)2 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)2 NodeContainer (org.knime.core.node.workflow.NodeContainer)2 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)2