Search in sources :

Example 1 with CreateDropRequest

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

the class NewWorkflowContainerEditPolicy method handleNodeDrop.

/**
 * @param manager the workflow manager
 * @param factory the ndoe factory
 * @param request the drop request
 */
private Command handleNodeDrop(final WorkflowManager manager, final NodeFactory<? extends NodeModel> factory, final CreateDropRequest request) {
    RequestType requestType = request.getRequestType();
    Point location = request.getLocation();
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    if (requestType.equals(RequestType.CREATE)) {
        // create a new node
        return new CreateNodeCommand(manager, factory, location, snapToGrid);
    } else {
        AbstractEditPart editPart = request.getEditPart();
        if (requestType.equals(RequestType.INSERT)) {
            // insert new node into connection
            InsertNodeCommand insertCommand = new InsertNodeCommand(manager, factory, location, snapToGrid, (ConnectionContainerEditPart) editPart);
            if (request.createSpace()) {
                CreateSpaceAction csa = new CreateSpaceAction((WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(), request.getDirection(), request.getDistance());
                return insertCommand.chain(csa.createCompoundCommand(csa.selectedParts()));
            } else {
                return insertCommand;
            }
        } else if (requestType.equals(RequestType.REPLACE)) {
            // replace node with a node
            return new ReplaceNodeCommand(manager, factory, location, snapToGrid, (NodeContainerEditPart) editPart);
        } else {
            return null;
        }
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) ReplaceNodeCommand(org.knime.workbench.editor2.commands.ReplaceNodeCommand) Point(org.eclipse.draw2d.geometry.Point) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) InsertNodeCommand(org.knime.workbench.editor2.commands.InsertNodeCommand) CreateSpaceAction(org.knime.workbench.editor2.actions.CreateSpaceAction) RequestType(org.knime.workbench.editor2.CreateDropRequest.RequestType)

Example 2 with CreateDropRequest

use of org.knime.workbench.editor2.CreateDropRequest 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 3 with CreateDropRequest

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

the class NewWorkflowContainerEditPolicy method handleMetaNodeTemplateDrop.

/**
 * @param manager the workflow manager
 * @param request the drop request
 * @param filestore the location of the metanode template
 */
private Command handleMetaNodeTemplateDrop(final WorkflowManager manager, final CreateDropRequest request, final AbstractExplorerFileStore filestore) {
    RequestType requestType = request.getRequestType();
    Point location = request.getLocation();
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    if (requestType.equals(RequestType.CREATE)) {
        // create metanode from template
        return new CreateMetaNodeTemplateCommand(manager, filestore, location, snapToGrid);
    } else {
        AbstractEditPart editPart = request.getEditPart();
        if (requestType.equals(RequestType.INSERT)) {
            // insert metanode from template into connection
            InsertMetaNodeTempalteCommand insertCommand = new InsertMetaNodeTempalteCommand(manager, filestore, location, snapToGrid, (ConnectionContainerEditPart) editPart);
            if (request.createSpace()) {
                CreateSpaceAction csa = new CreateSpaceAction((WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(), request.getDirection(), request.getDistance());
                return insertCommand.chain(csa.createCompoundCommand(csa.selectedParts()));
            } else {
                return insertCommand;
            }
        } else if (requestType.equals(RequestType.REPLACE)) {
            // replace node with metanode from template
            return new ReplaceMetaNodeTemplateCommand(manager, filestore, location, snapToGrid, (NodeContainerEditPart) editPart);
        } else {
            return null;
        }
    }
}
Also used : ReplaceMetaNodeTemplateCommand(org.knime.workbench.editor2.commands.ReplaceMetaNodeTemplateCommand) CreateMetaNodeTemplateCommand(org.knime.workbench.editor2.commands.CreateMetaNodeTemplateCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) Point(org.eclipse.draw2d.geometry.Point) InsertMetaNodeTempalteCommand(org.knime.workbench.editor2.commands.InsertMetaNodeTempalteCommand) CreateSpaceAction(org.knime.workbench.editor2.actions.CreateSpaceAction) RequestType(org.knime.workbench.editor2.CreateDropRequest.RequestType)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)2 AbstractEditPart (org.eclipse.gef.editparts.AbstractEditPart)2 RequestType (org.knime.workbench.editor2.CreateDropRequest.RequestType)2 CreateSpaceAction (org.knime.workbench.editor2.actions.CreateSpaceAction)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 NodeCreationContext (org.knime.core.node.NodeCreationContext)1 NodeFactory (org.knime.core.node.NodeFactory)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 WorkflowPersistor (org.knime.core.node.workflow.WorkflowPersistor)1 CreateDropRequest (org.knime.workbench.editor2.CreateDropRequest)1 ReaderNodeSettings (org.knime.workbench.editor2.ReaderNodeSettings)1 CreateMetaNodeTemplateCommand (org.knime.workbench.editor2.commands.CreateMetaNodeTemplateCommand)1 CreateNodeCommand (org.knime.workbench.editor2.commands.CreateNodeCommand)1 DropNodeCommand (org.knime.workbench.editor2.commands.DropNodeCommand)1 InsertMetaNodeTempalteCommand (org.knime.workbench.editor2.commands.InsertMetaNodeTempalteCommand)1 InsertNodeCommand (org.knime.workbench.editor2.commands.InsertNodeCommand)1 ReplaceMetaNodeTemplateCommand (org.knime.workbench.editor2.commands.ReplaceMetaNodeTemplateCommand)1 ReplaceNodeCommand (org.knime.workbench.editor2.commands.ReplaceNodeCommand)1 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)1 AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)1