Search in sources :

Example 1 with WorkflowPersistor

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

the class NewWorkflowContainerEditPolicy method getCreateCommand.

/**
 * {@inheritDoc}
 */
@Override
protected Command getCreateCommand(final CreateRequest request) {
    // point where the command occurred
    // The node/description should be initially located here
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    WorkflowRootEditPart workflowPart = (WorkflowRootEditPart) this.getHost();
    if (!Wrapper.wraps(workflowPart.getWorkflowManager(), WorkflowManager.class)) {
        // adding new nodes not supported yet by UI-interfaces and implemenations
        LOGGER.error("Adding new nodes not supported by '" + workflowPart.getWorkflowManager().getClass().getSimpleName() + "'.");
        return null;
    }
    WorkflowManager manager = Wrapper.unwrapWFM(workflowPart.getWorkflowManager());
    if (request instanceof CreateDropRequest) {
        Object obj = request.getNewObject();
        CreateDropRequest cdr = (CreateDropRequest) request;
        if (obj instanceof NodeFactory) {
            return handleNodeDrop(manager, (NodeFactory<? extends NodeModel>) obj, cdr);
        } else if (obj instanceof AbstractExplorerFileStore) {
            AbstractExplorerFileStore fs = (AbstractExplorerFileStore) obj;
            if (AbstractExplorerFileStore.isWorkflowTemplate(fs)) {
                return handleMetaNodeTemplateDrop(manager, cdr, fs);
            }
        } else if (obj instanceof WorkflowPersistor) {
            return handleMetaNodeDrop(manager, (WorkflowPersistor) obj, cdr);
        } else if (obj instanceof ReaderNodeSettings) {
            ReaderNodeSettings settings = (ReaderNodeSettings) obj;
            return new DropNodeCommand(manager, settings.getFactory(), new NodeCreationContext(settings.getUrl()), request.getLocation(), snapToGrid);
        } else {
            LOGGER.error("Illegal drop object: " + obj);
        }
    }
    return null;
}
Also used : CreateDropRequest(org.knime.workbench.editor2.CreateDropRequest) DropNodeCommand(org.knime.workbench.editor2.commands.DropNodeCommand) ReaderNodeSettings(org.knime.workbench.editor2.ReaderNodeSettings) NodeFactory(org.knime.core.node.NodeFactory) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) NodeCreationContext(org.knime.core.node.NodeCreationContext)

Example 2 with WorkflowPersistor

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

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

the class UpdateMetaNodeTemplateRunnable method run.

/**
 * {@inheritDoc}
 */
@Override
public void run(final IProgressMonitor pm) throws InterruptedException {
    m_newIDs = new ArrayList<NodeID>();
    m_undoPersistors = new ArrayList<WorkflowPersistor>();
    // create progress monitor
    ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Updating node links...");
    final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
    progressMonitor.addProgressListener(progressHandler);
    final Display d = Display.getDefault();
    ExecutionMonitor exec = new ExecutionMonitor(progressMonitor);
    IStatus[] stats = new IStatus[m_ids.length];
    for (int i = 0; i < m_ids.length; i++) {
        NodeID id = m_ids[i];
        NodeContainerTemplate tnc = (NodeContainerTemplate) m_parentWFM.findNodeContainer(id);
        LOGGER.debug("Updating " + tnc.getNameWithID() + " from " + tnc.getTemplateInformation().getSourceURI());
        ExecutionMonitor subExec = exec.createSubProgress(1.0 / m_ids.length);
        String progMsg = "Node Link \"" + tnc.getNameWithID() + "\"";
        exec.setMessage(progMsg);
        GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, progMsg, null, null, null, true);
        NodeContainerTemplateLinkUpdateResult updateMetaNodeLinkResult;
        try {
            updateMetaNodeLinkResult = tnc.getParent().updateMetaNodeLink(id, subExec, loadHelper);
        } catch (CanceledExecutionException e) {
            String message = "Node update canceled";
            LOGGER.warn(message, e);
            throw new InterruptedException(message);
        }
        WorkflowPersistor p = updateMetaNodeLinkResult.getUndoPersistor();
        if (p != null) {
            // no error
            m_newIDs.add(updateMetaNodeLinkResult.getNCTemplate().getID());
            m_undoPersistors.add(p);
        }
        // metanodes don't have data
        // data load errors are unexpected but OK
        IStatus status = createStatus(updateMetaNodeLinkResult, true);
        subExec.setProgress(1.0);
        switch(status.getSeverity()) {
            case IStatus.OK:
                break;
            case IStatus.WARNING:
                logPreseveLineBreaks("Warnings during load: " + updateMetaNodeLinkResult.getFilteredError("", LoadResultEntryType.Warning), false);
                break;
            default:
                logPreseveLineBreaks("Errors during load: " + updateMetaNodeLinkResult.getFilteredError("", LoadResultEntryType.Warning), true);
        }
        stats[i] = status;
    }
    pm.done();
    final IStatus status = createMultiStatus("Update node links", stats);
    final String message;
    switch(status.getSeverity()) {
        case IStatus.OK:
            message = "No problems during node link update.";
            break;
        case IStatus.WARNING:
            message = "Warnings during node link update";
            break;
        default:
            message = "Errors during node link update";
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            // will not open if status is OK.
            ErrorDialog.openError(Display.getDefault().getActiveShell(), "Update Node Links", message, status);
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) NodeContainerTemplateLinkUpdateResult(org.knime.core.node.workflow.WorkflowPersistor.NodeContainerTemplateLinkUpdateResult) NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeID(org.knime.core.node.workflow.NodeID) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Display(org.eclipse.swt.widgets.Display)

Example 4 with WorkflowPersistor

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

the class CopyAction method runInSWT.

/**
 * {@inheritDoc}
 */
@Override
public void runInSWT() {
    m_nodeParts = getSelectedParts(NodeContainerEditPart.class);
    m_annotationParts = getSelectedParts(AnnotationEditPart.class);
    NodeID[] ids = new NodeID[m_nodeParts.length];
    for (int i = 0; i < m_nodeParts.length; i++) {
        NodeContainerEditPart nodeEP = m_nodeParts[i];
        ids[i] = nodeEP.getNodeContainer().getID();
    }
    WorkflowAnnotation[] annotations = AnnotationEditPart.extractWorkflowAnnotations(m_annotationParts);
    WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
    content.setNodeIDs(ids);
    content.setAnnotation(annotations);
    WorkflowPersistor copyPersistor = getManager().copy(false, content.build());
    // the information about the nodes is stored in the config XML format
    // also used to store workflow information in the kflow files
    getEditor().setClipboardContent(new ClipboardObject(copyPersistor));
    // 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 : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) ClipboardObject(org.knime.workbench.editor2.ClipboardObject) NodeID(org.knime.core.node.workflow.NodeID) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 5 with WorkflowPersistor

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

the class UpdateMetaNodeLinkCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    LOGGER.debug("Undo: Reverting metanode links (" + m_newIDs.size() + " metanode(s))");
    WorkflowManager hostWFM = getHostWFM();
    for (int i = 0; i < m_newIDs.size(); i++) {
        NodeID id = m_newIDs.get(i);
        WorkflowPersistor p = m_undoPersistors.get(i);
        NodeContainerTemplate nodeToBeDeleted = (NodeContainerTemplate) hostWFM.findNodeContainer(id);
        WorkflowManager parent = nodeToBeDeleted.getParent();
        parent.removeNode(nodeToBeDeleted.getID());
        parent.paste(p);
    }
}
Also used : NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor)

Aggregations

WorkflowPersistor (org.knime.core.node.workflow.WorkflowPersistor)5 NodeID (org.knime.core.node.workflow.NodeID)4 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)3 NodeContainerTemplate (org.knime.core.node.workflow.NodeContainerTemplate)2 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IStatus (org.eclipse.core.runtime.IStatus)1 EditPartViewer (org.eclipse.gef.EditPartViewer)1 Display (org.eclipse.swt.widgets.Display)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 NodeCreationContext (org.knime.core.node.NodeCreationContext)1 NodeFactory (org.knime.core.node.NodeFactory)1 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)1 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)1 NodeContainer (org.knime.core.node.workflow.NodeContainer)1 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)1 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)1