use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart 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.ConnectionContainerEditPart 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.ConnectionContainerEditPart 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;
}
}
}
use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart in project knime-core by knime.
the class WorkflowEditorDropTargetListener method selectNodes.
/**
* Selects all nodes after this node which are around the same y coordinate and closer than
* {@link WorkflowEditorDropTargetListener#m_distanceToMoveTarget} +
* {@link WorkflowEditorDropTargetListener#MINIMUM_NODE_DISTANCE}
*
* All selected elements will be moved by the move action.
*
* @param node from which on the selection starts
*/
private void selectNodes(final NodeContainerEditPart node, final double zoom) {
getViewer().getSelectionManager().appendSelection(node);
for (ConnectionContainerEditPart c : node.getOutgoingConnections()) {
EditPart source = c.getSource().getParent();
EditPart target = c.getTarget().getParent();
if (source instanceof NodeContainerEditPart && target instanceof NodeContainerEditPart) {
NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
int[] sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
int[] targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
sourceBounds = recomputeBounds(sourceBounds);
targetBounds = recomputeBounds(targetBounds);
int sourceYTop = sourceBounds[1];
int sourceYBot = sourceYTop + sourceBounds[3] + sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
int targetYTop = targetBounds[1];
int targetYBot = targetYTop + targetBounds[3] + targetNode.getNodeAnnotationEditPart().getModel().getHeight();
if (selectSuccessor(sourceBounds[0], targetBounds[0], sourceYTop, sourceYBot, targetYTop, targetYBot, zoom)) {
selectNodes(targetNode, zoom);
}
}
}
}
use of org.knime.workbench.editor2.editparts.ConnectionContainerEditPart in project knime-core by knime.
the class WorkflowSelectionDragEditPartsTracker method getEmbracedConnections.
/**
* Returns the connections whose source and target is contained in the argument list.
* @param parts list of selected nodes
* @return the connections whose source and target is contained in the argument list.
*/
public static ConnectionContainerEditPart[] getEmbracedConnections(final List<EditPart> parts) {
// result list
List<ConnectionContainerEditPart> result = new ArrayList<ConnectionContainerEditPart>();
for (EditPart part : parts) {
if (part instanceof NodeContainerEditPart || part instanceof AbstractWorkflowPortBarEditPart) {
EditPart containerPart = part;
ConnectionContainerEditPart[] outPortConnectionParts = getOutportConnections(containerPart);
// selected list, the connections bendpoints must be adapted
for (ConnectionContainerEditPart connectionPart : outPortConnectionParts) {
// get the in-port-node part of the connection and check
AbstractPortEditPart inPortPart = null;
if (connectionPart.getTarget() != null && ((AbstractPortEditPart) connectionPart.getTarget()).isInPort()) {
inPortPart = (AbstractPortEditPart) connectionPart.getTarget();
} else if (connectionPart.getSource() != null) {
inPortPart = (AbstractPortEditPart) connectionPart.getSource();
}
if (inPortPart != null && isPartInList(inPortPart.getParent(), parts)) {
result.add(connectionPart);
}
}
}
}
return result.toArray(new ConnectionContainerEditPart[result.size()]);
}
Aggregations