Search in sources :

Example 36 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class InsertHelper method reconnect.

/**
 * Guesses the incoming/outgoing connections of the new node based on the connections of the old node.
 * The connections are added from port 0 to port n. If no port type matches no connection is added.
 * @param container of the new created node
 * @param snapToGrid should new node snap to grid
 * @param x coordinate of the new node
 * @param y coordinate of the new node
 */
public void reconnect(final NodeContainer container, final boolean snapToGrid, final int x, final int y) {
    // reset node position
    NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(x, y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(snapToGrid).setIsDropLocation(false).build();
    container.setUIInformation(info);
    // skip fv port of nodes for now
    int p = (container instanceof WorkflowManager) ? 0 : 1;
    while (!hostWFM.canAddConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), p)) {
        // search for a valid connection of the source node to this node
        p++;
        if (p >= container.getNrInPorts()) {
            break;
        }
    }
    if (p < container.getNrInPorts()) {
        hostWFM.addConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), p);
    } else if (!(container instanceof WorkflowManager)) {
        // try if the fv port of nodes would work
        if (hostWFM.canAddConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), 0)) {
            hostWFM.addConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), 0);
        }
    }
    // skip fv port of nodes for now;
    int pout = (container instanceof WorkflowManager) ? 0 : 1;
    while (!hostWFM.canAddConnection(container.getID(), pout, m_edge.getDest(), m_edge.getDestPort())) {
        // search for a valid connection of this node to the destination node of the edge
        pout++;
        if (pout >= container.getNrOutPorts()) {
            break;
        }
    }
    if (pout < container.getNrOutPorts()) {
        hostWFM.addConnection(container.getID(), pout, m_edge.getDest(), m_edge.getDestPort());
    } else if (!(container instanceof WorkflowManager)) {
        // try if the fv port of nodes would work
        if (hostWFM.canAddConnection(container.getID(), 0, m_edge.getDest(), m_edge.getDestPort())) {
            hostWFM.addConnection(container.getID(), 0, m_edge.getDest(), m_edge.getDestPort());
        }
    }
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 37 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager 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 38 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class PasteFromWorkflowPersistorCommand method canUndo.

/**
 * {@inheritDoc}
 */
@Override
public boolean canUndo() {
    WorkflowManager manager = m_editor.getWorkflowManager().get();
    NodeID[] pastedNodes = m_pastedContent.getNodeIDs();
    Annotation[] pastedAnnos = m_pastedContent.getAnnotations();
    if ((pastedNodes == null || pastedNodes.length == 0) && (pastedAnnos == null || pastedAnnos.length == 0)) {
        return false;
    }
    for (NodeID id : pastedNodes) {
        if (!manager.canRemoveNode(id)) {
            return false;
        }
    }
    return true;
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) Annotation(org.knime.core.node.workflow.Annotation) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 39 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class KnimeResourceContentProvider method getChildren.

/**
 * {@inheritDoc}
 */
@Override
public Object[] getChildren(final Object element) {
    if (element instanceof IFile) {
        return EMPTY_ARRAY;
    }
    if (isKNIMEWorkflow(element)) {
        IContainer project = (IContainer) element;
        NodeContainerUI workflow = ProjectWorkflowMap.getWorkflowUI(project.getLocationURI());
        if (workflow != null) {
            // the number of contained nodes is returned
            return getSortedNodeContainers(((WorkflowManagerUI) workflow).getNodeContainers());
        }
    } else if (element instanceof WorkflowManager) {
        return getSortedNodeContainers(((WorkflowManagerUI) element).getNodeContainers());
    }
    return getFolders(element);
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) IFile(org.eclipse.core.resources.IFile) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) IContainer(org.eclipse.core.resources.IContainer)

Example 40 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class OpenCredentialVariablesDialogAction method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    super.run();
    // get workflow
    final WorkflowManager wf = getWorkflow();
    // open the dialog
    final Display d = Display.getDefault();
    // run in UI thread
    d.asyncExec(new Runnable() {

        @Override
        public void run() {
            CredentialsStore store = wf.getCredentialsStore();
            CredentialVariablesDialog dialog = new CredentialVariablesDialog(d.getActiveShell(), store, wf.getName());
            if (dialog.open() == Window.OK) {
                for (String name : store.listNames()) {
                    store.remove(name);
                }
                List<Credentials> credentials = dialog.getCredentials();
                for (Credentials cred : credentials) {
                    store.add(cred);
                }
            }
        }
    });
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) CredentialsStore(org.knime.core.node.workflow.CredentialsStore) CredentialVariablesDialog(org.knime.workbench.ui.masterkey.CredentialVariablesDialog) List(java.util.List) Credentials(org.knime.core.node.workflow.Credentials) Display(org.eclipse.swt.widgets.Display)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)99 NodeID (org.knime.core.node.workflow.NodeID)38 NodeContainer (org.knime.core.node.workflow.NodeContainer)22 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)14 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)14 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 MessageBox (org.eclipse.swt.widgets.MessageBox)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 List (java.util.List)8 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)8 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)8