use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class WorkflowEditor method addMetaNode.
/*
* --------- methods for adding a auto-placed and auto-connected node -----
*/
/**
* {@inheritDoc}
* Listener interface method of the {@link NodeProvider}.
* Called when other instances want to add a metanode to the workflow in
* the editor. <br>
* The implementation only adds it if the editor is active. If one other
* node is selected in the editor, to which the new node will then be
* connected to.
*
* @param sourceManager wfm to copy the metanode from
* @param id the id of the metanode in the source manager
* @return if the metanode was actually added
*/
@Override
public boolean addMetaNode(final WorkflowManager sourceManager, final NodeID id) {
if (id == null || sourceManager == null) {
return false;
}
if (!isEditorActive()) {
return false;
}
NodeContainerEditPart preNode = getTheOneSelectedNode();
NodeID preID = null;
Point nodeLoc = null;
if (preNode == null) {
nodeLoc = getViewportCenterLocation();
nodeLoc = toAbsolute(nodeLoc);
} else {
nodeLoc = getLocationRightOf(preNode);
preID = preNode.getNodeContainer().getID();
}
if (getEditorSnapToGrid()) {
nodeLoc = getClosestGridLocation(nodeLoc);
}
Command newNodeCmd = new CreateNewConnectedMetaNodeCommand(getViewer(), unwrapWFM(m_manager), sourceManager, id, nodeLoc, preID);
getCommandStack().execute(newNodeCmd);
// after adding a node the editor should get the focus
setFocus();
return true;
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class WorkflowEditorDropTargetListener method dragOver.
/**
* {@inheritDoc}
*
* Marks nodes or edges if a new node should replace an old node or should be inserted on an edge.
*/
@Override
public void dragOver(final DropTargetEvent event) {
WorkflowManagerUI wfm = ((WorkflowRootEditPart) getViewer().getRootEditPart().getContents()).getWorkflowManager();
m_node = null;
m_edge = null;
m_nodeCount = 0;
m_edgeCount = 0;
// edge-/nodedist
double edgedist = Integer.MAX_VALUE;
double nodedist = Integer.MAX_VALUE;
Point dropLocation = getDropLocation(event);
EditPart ep = getViewer().findObjectAt(dropLocation.getTranslated(0, 0));
if (ep instanceof NodeContainerEditPart) {
double temp = dropLocation.getDistance(dropLocation.getTranslated(0, 0));
// choose nearest node to mouse position
if (nodedist >= temp) {
m_node = (NodeContainerEditPart) ep;
nodedist = temp;
}
m_nodeCount++;
} else if (ep instanceof ConnectionContainerEditPart) {
double temp = dropLocation.getDistance(dropLocation.getTranslated(0, 0));
// choose nearest edge to mouse-position
if (edgedist >= temp) {
m_edge = (ConnectionContainerEditPart) ep;
edgedist = temp;
}
m_edgeCount++;
}
unmark(wfm);
if (m_node != null && m_nodeCount >= m_edgeCount) {
m_markedNode = m_node;
m_markedNode.mark();
// workaround for eclipse bug 393868 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=393868)
WindowsDNDHelper.hideDragImage();
} else if (m_edge != null) {
m_edgeColor = m_edge.getFigure().getForegroundColor();
m_edgeWidth = ((ProgressPolylineConnection) m_edge.getFigure()).getLineWidth();
m_markedEdge = m_edge;
((ProgressPolylineConnection) m_markedEdge.getFigure()).setLineWidth(m_edgeWidth + 3);
m_markedEdge.getFigure().setForegroundColor(RED);
// workaround for eclipse bug 393868 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=393868)
WindowsDNDHelper.hideDragImage();
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class VerifyingCompoundCommand method execute.
/**
* Overrides the execute method of <code>CompoundCommand</code> to add a
* verification dialog with the given message.
*
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void execute() {
// before showing the confirmation dialog, mark the node part figures
for (NodeContainerEditPart nodePart : m_nodeParts) {
nodePart.mark();
}
try {
// the following code has mainly been copied from
// IDEWorkbenchWindowAdvisor#preWindowShellClose
IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
if (!store.contains(PreferenceConstants.P_CONFIRM_DELETE) || store.getBoolean(PreferenceConstants.P_CONFIRM_DELETE)) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(Display.getDefault().getActiveShell(), "Confirm ...", m_dialogDisplayText, "Do not ask again", false, null, null);
if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
return;
}
if (dialog.getToggleState()) {
store.setValue(PreferenceConstants.P_CONFIRM_DELETE, false);
KNIMEUIPlugin.getDefault().savePluginPreferences();
}
}
// in all other cases execute the commands
LOGGER.debug("Executing <" + size() + "> commands.");
super.execute();
} finally {
for (NodeContainerEditPart nodePart : m_nodeParts) {
nodePart.unmark();
}
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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;
}
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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;
}
}
}
Aggregations