Search in sources :

Example 66 with WorkflowManager

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

the class AddAnnotationCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // adapt location to the viewport location and the zoom factor
    // this seems to be a workaround for a bug in the framework
    ZoomManager zoomManager = (ZoomManager) m_viewer.getProperty(ZoomManager.class.toString());
    // adjust the location according to the viewport position
    // seems to be a workaround for a bug in the framework
    // (should imediately deliver the correct view position and not
    // the position of the viewport)
    PrecisionPoint location = new PrecisionPoint(m_location.x, m_location.y);
    WorkflowEditor.adaptZoom(zoomManager, location, true);
    m_anno = new WorkflowAnnotation();
    AnnotationData data = new AnnotationData();
    // it is a workflow annotation
    data.setBgColor(INITIAL_FLOWANNO_COLOR);
    data.setDimension((int) location.preciseX, (int) location.preciseY, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    data.setBorderSize(AnnotationEditPart.getAnnotationDefaultBorderSizePrefValue());
    data.setBorderColor(INITAL_FLOWBORDER_COLOR);
    data.setText(INITIAL_FLOWANNO_TEXT);
    data.setStyleRanges(new AnnotationData.StyleRange[0]);
    m_anno.copyFrom(data, true);
    WorkflowManager hostWFM = getHostWFM();
    hostWFM.addWorkflowAnnotation(m_anno);
    m_viewer.deselectAll();
    // select the new ones....
    if (m_viewer.getRootEditPart().getContents() != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        ((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureAnnotationSelection(Collections.singleton(m_anno));
    }
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) AnnotationData(org.knime.core.node.workflow.AnnotationData) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 67 with WorkflowManager

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

the class CreateConnectionCommand method canExecute.

/**
 * @return <code>true</code> if the connection can be added (that is, all
 *         fields were set to valid values before and the corresponding edit
 *         parts are not locked
 * @see org.eclipse.gef.commands.Command#canExecute()
 */
@Override
public boolean canExecute() {
    if (!super.canExecute()) {
        return false;
    }
    if (m_sourceNode == null || m_targetNode == null) {
        return false;
    }
    WorkflowManager wm = getHostWFM();
    if (m_targetPortID < 0) {
        ConnectableEditPart target = getTargetNode();
        if (target instanceof NodeContainerEditPart) {
            m_targetPortID = ((NodeContainerEditPart) target).getFreeInPort(getSourceNode(), getSourcePortID());
        }
    }
    // check whether an existing connection can be removed
    ConnectionContainer conn = wm.getIncomingConnectionFor(m_targetNode.getNodeContainer().getID(), m_targetPortID);
    boolean canRemove = conn == null || wm.canRemoveConnection(conn);
    // let the workflow manager check if the connection can be created
    // or removed
    boolean canAdd = wm.canAddConnection(m_sourceNode.getNodeContainer().getID(), m_sourcePortID, m_targetNode.getNodeContainer().getID(), m_targetPortID);
    return canRemove && canAdd;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 68 with WorkflowManager

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

the class CreateConnectionCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    WorkflowManager wm = getHostWFM();
    wm.removeConnection(m_connection);
    ConnectionContainer old = m_oldConnection;
    if (old != null) {
        ConnectionContainer newConn = wm.addConnection(old.getSource(), old.getSourcePort(), old.getDest(), old.getDestPort());
        newConn.setUIInfo(old.getUIInfo());
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 69 with WorkflowManager

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

the class CreateConnectionCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // check whether it is the same connection
    ConnectionContainer conn = getHostWFM().getIncomingConnectionFor(m_targetNode.getNodeContainer().getID(), m_targetPortID);
    if (conn != null && conn.getSource().equals(m_sourceNode.getNodeContainer().getID()) && conn.getSourcePort() == m_sourcePortID && conn.getDest().equals(m_targetNode.getNodeContainer().getID()) && conn.getDestPort() == m_targetPortID) {
        // it is the very same connection -> do nothing
        return;
    }
    WorkflowManager wm = getHostWFM();
    // displayed to the user
    try {
        // if target nodeport is already connected
        if (conn != null) {
            // ask user if it should be replaced...
            if (m_confirm && m_targetNode.getNodeContainer().getNodeContainerState().isExecuted()) {
                // show confirmation message only if target node is executed
                MessageDialogWithToggle msgD = openReconnectConfirmDialog(m_confirm, "Do you want to replace existing connection? \n" + "This will reset the target node!");
                m_confirm = !msgD.getToggleState();
                if (msgD.getReturnCode() != IDialogConstants.YES_ID) {
                    return;
                }
            }
            // remove existing connection
            wm.removeConnection(conn);
            m_oldConnection = conn;
        }
        LOGGER.debug("adding connection from " + m_sourceNode.getNodeContainer().getID() + " " + m_sourcePortID + " to " + m_targetNode.getNodeContainer().getID() + " " + m_targetPortID);
        m_connection = wm.addConnection(m_sourceNode.getNodeContainer().getID(), m_sourcePortID, m_targetNode.getNodeContainer().getID(), m_targetPortID);
        NodeTimer.GLOBAL_TIMER.addConnectionCreation(unwrapNC(m_sourceNode.getNodeContainer()), unwrapNC(m_targetNode.getNodeContainer()));
        if (m_newConnectionUIInfo != null) {
            m_connection.setUIInfo(m_newConnectionUIInfo);
        }
    } catch (Exception e) {
        LOGGER.error("Connection could not be created.", e);
        m_connection = null;
        m_oldConnection = null;
        m_sourceNode = null;
        m_targetNode = null;
        m_sourcePortID = -1;
        m_targetPortID = -1;
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Connection could not be created", "The two nodes could not be connected due to " + "the following reason:\n " + e.getMessage());
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 70 with WorkflowManager

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

the class CreateMetaNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // Add node to workflow and get the container
    try {
        WorkflowManager wfm = getHostWFM();
        m_copyContent = wfm.paste(m_persistor);
        NodeID[] nodeIDs = m_copyContent.getNodeIDs();
        if (nodeIDs.length > 0) {
            NodeID first = nodeIDs[0];
            m_container = wfm.getNodeContainer(first);
            // create extra info and set it
            NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
            m_container.setUIInformation(info);
        }
    } catch (Throwable t) {
        // if fails notify the user
        String error = "Metanode cannot be created";
        LOGGER.debug(error + ": " + t.getMessage(), t);
        MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
        mb.setText(error);
        mb.setMessage("The metanode could not be created " + "due to the following reason:\n" + t.getMessage());
        mb.open();
        return;
    }
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)88 NodeID (org.knime.core.node.workflow.NodeID)31 NodeContainer (org.knime.core.node.workflow.NodeContainer)20 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)12 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)12 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)10 ArrayList (java.util.ArrayList)9 MessageBox (org.eclipse.swt.widgets.MessageBox)9 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 IOException (java.io.IOException)8 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)8 Map (java.util.Map)7 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)7 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)7 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)7 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)7 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)6