use of org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart in project knime-core by knime.
the class WorkflowEditorDropTargetListener method getInsertLocation.
/**
* Computes the location of the new node and also determines if some node should be moved.
*
* A successor node is selected for the move action if the distance between this node and the successor is
* smaller than the {@link WorkflowEditorDropTargetListener#MINIMUM_NODE_DISTANCE} and if they overlap vertically.
*
* @return point where the new node should be inserted and sets
* {@link WorkflowEditorDropTargetListener#m_distanceToMoveTarget}
*/
private Point getInsertLocation() {
ZoomManager zoomManager = (ZoomManager) getViewer().getProperty(ZoomManager.class.toString());
double zoom = zoomManager.getZoom();
int adjustedMinimumNodeDistance = (int) (MINIMUM_NODE_DISTANCE * zoom);
double adjustedMinimumNodeDistanceBeforeInsertion = MINIMUM_NODE_DISTANCE_BEFORE_INSERTION * zoom;
Point dropLocation = getDropLocation();
Point insertLocation = dropLocation;
int[] sourceBounds = null;
int[] targetBounds = null;
int sourceAnnotationHeight = 0;
int targetAnnotationHeight = 0;
EditPart source = m_edge.getSource().getParent();
EditPart target = m_edge.getTarget().getParent();
NodeContainerEditPart nextNode = null;
if (source instanceof WorkflowInPortBarEditPart && target instanceof NodeContainerEditPart) {
// metanode start --> first node in metanode
WorkflowInPortBarEditPart sourceBar = ((WorkflowInPortBarEditPart) source);
NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
Rectangle bounds = sourceBar.getFigure().getBounds();
org.eclipse.swt.graphics.Point p = getViewer().getControl().toControl(bounds.x, bounds.y);
sourceBounds = new int[] { p.x, p.y, bounds.width, bounds.height };
targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
nextNode = targetNode;
} else if (source instanceof NodeContainerEditPart && target instanceof WorkflowOutPortBarEditPart) {
// last node in metanode --> metanode end
NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
Rectangle bounds = targetBar.getFigure().getBounds();
targetBounds = new int[] { bounds.x, bounds.y, bounds.width, bounds.height };
sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
} else if (source instanceof WorkflowInPortBarEditPart && target instanceof WorkflowOutPortBarEditPart) {
// metanode start --> metanode end
WorkflowInPortBarEditPart sourceBar = (WorkflowInPortBarEditPart) source;
WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
sourceBounds = sourceBar.getNodeContainer().getUIInformation().getBounds();
targetBounds = targetBar.getNodeContainer().getUIInformation().getBounds();
} else if (source instanceof NodeContainerEditPart && target instanceof NodeContainerEditPart) {
// node --> node
NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
nextNode = targetNode;
}
if (sourceBounds != null && targetBounds != null) {
sourceBounds = recomputeBounds(sourceBounds);
targetBounds = recomputeBounds(targetBounds);
if (0 <= targetBounds[0] - sourceBounds[0] && targetBounds[0] - sourceBounds[0] >= adjustedMinimumNodeDistanceBeforeInsertion) {
m_distanceToMoveTarget = 0;
} else {
m_distanceToMoveTarget = adjustedMinimumNodeDistance + (sourceBounds[0] + adjustedMinimumNodeDistance - targetBounds[0]);
m_distanceToMoveTarget = (int) (m_distanceToMoveTarget / zoom);
}
insertLocation = new Point(getXLocation(dropLocation.x, sourceBounds[0], zoom), getYLocation(dropLocation.y, sourceBounds[1], targetBounds[1], zoom));
if (WorkflowEditor.getActiveEditorSnapToGrid()) {
insertLocation = WorkflowEditor.getActiveEditorClosestGridLocation(insertLocation);
}
getViewer().getSelectionManager().deselectAll();
if (nextNode != null && selectSuccessor(sourceBounds[0], targetBounds[0], sourceBounds[1], sourceBounds[1] + sourceBounds[3] + sourceAnnotationHeight, targetBounds[1], targetBounds[1] + targetBounds[3] + targetAnnotationHeight, zoom)) {
selectNodes(nextNode, zoom);
}
}
return insertLocation;
}
use of org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart in project knime-core by knime.
the class WorkflowEditPartFactory method createEditPart.
/**
* Creates the referring edit parts for the following parts of the model.
* <ul>
* <li>{@link WorkflowManager}: either {@link WorkflowRootEditPart} or {@link NodeContainerEditPart} (depending on
* the currently displayed level)</li>
* <li>{@link SingleNodeContainer}: {@link NodeContainerEditPart}</li>
* <li>{@link NodeInPort}: {@link NodeInPortEditPart}</li>
* <li>{@link NodeOutPort}: {@link NodeOutPortEditPart}</li>
* <li>{@link ConnectionContainer}: {@link ConnectionContainerEditPart}</li>
* <li>{@link WorkflowInPort}: {@link WorkflowInPortEditPart}</li>
* <li>{@link WorkflowOutPort}: {@link WorkflowOutPortEditPart}</li>
* </ul>
*
* The {@link WorkflowRootEditPart} has its {@link NodeContainer}s and its {@link WorkflowInPort}s and
* {@link WorkflowOutPort}s as model children. The {@link NodeContainerEditPart} has its {@link NodePort}s as its
* children.
*
* @see WorkflowRootEditPart#getModelChildren()
* @see NodeContainerEditPart#getModelChildren()
*
* @throws IllegalArgumentException if any other object is passed
*
* {@inheritDoc}
*/
@Override
public EditPart createEditPart(final EditPart context, final Object model) {
// instantiated here
// correct type in the if statement
// model at the end of method
EditPart part = null;
if (model instanceof WorkflowManagerUI) {
// this is out "root" workflow manager
if (m_isTop) {
// all following objects of type WorkflowManager are treated as
// metanodes and displayed as NodeContainers
m_isTop = false;
part = new WorkflowRootEditPart();
} else {
// we already have a "root" workflow manager
// must be a metanode
part = new SubworkflowEditPart();
}
} else if (model instanceof NodeAnnotation) {
/* IMPORTANT: first test NodeAnnotation then Annotation (as the
* first derives from the latter! */
part = new NodeAnnotationEditPart();
} else if (model instanceof Annotation) {
/* IMPORTANT: first test NodeAnnotation then Annotation (as the
* first derives from the latter! */
/* workflow annotations hang off the workflow manager */
part = new AnnotationEditPart();
} else if (model instanceof WorkflowPortBar) {
WorkflowPortBar bar = (WorkflowPortBar) model;
if (bar.isInPortBar()) {
part = new WorkflowInPortBarEditPart();
} else {
part = new WorkflowOutPortBarEditPart();
}
} else if (model instanceof SingleNodeContainerUI) {
// SingleNodeContainer -> NodeContainerEditPart
part = new NodeContainerEditPart();
// we have to test for WorkflowInPort first because it's a
// subclass of NodeInPort (same holds for WorkflowOutPort and
// NodeOutPort)
} else if (model instanceof WorkflowInPortUI && context instanceof WorkflowInPortBarEditPart) {
// WorkflowInPort and context WorkflowRootEditPart ->
// WorkflowInPortEditPart
/*
* if the context is a WorkflowRootEditPart it indicates that the
* WorkflowInPort is a model child of the WorkflowRootEditPart, i.e.
* we look at it as a workflow in port. If the context is a
* NodeContainerEditPart the WorkflowInPort is a model child of a
* NodeContainerEditPart and we look at it as a node in port.
*/
WorkflowInPortUI inport = (WorkflowInPortUI) model;
part = new WorkflowInPortEditPart(inport.getPortType(), inport.getPortIndex());
} else if (model instanceof WorkflowOutPortUI && context instanceof WorkflowOutPortBarEditPart) {
// WorkflowOutPort and context WorkflowRootEditPart ->
// WorkflowOutPortEditPart
/*
* if the context is a WorkflowRootEditPart it indicates that the
* WorkflowOutPort is a model child of the WorkflowRootEditPart,
* i.e. we look at it as a workflow out port. If the context is a
* NodeContainerEditPart the WorkflowOutPort is a model child of a
* NodeContainerEditPart and we look at it as a node out port.
*/
// TODO: return SubWorkFlowOutPortEditPart
WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
part = new WorkflowOutPortEditPart(outport.getPortType(), outport.getPortIndex());
} else if (model instanceof WorkflowOutPortUI) {
// TODO: return SubWorkFlowOutPortEditPart
WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
part = new MetaNodeOutPortEditPart(outport.getPortType(), outport.getPortIndex());
} else if (model instanceof NodeInPortUI) {
// NodeInPort -> NodeInPortEditPart
NodePortUI port = (NodeInPortUI) model;
part = new NodeInPortEditPart(port.getPortType(), port.getPortIndex());
} else if (model instanceof NodeOutPortUI) {
// NodeOutPort -> NodeOutPortEditPart
NodePortUI port = (NodeOutPortUI) model;
part = new NodeOutPortEditPart(port.getPortType(), port.getPortIndex());
} else if (model instanceof ConnectionContainerUI) {
// ConnectionContainer -> ConnectionContainerEditPart
part = new ConnectionContainerEditPart();
} else {
throw new IllegalArgumentException("unknown model obj: " + model);
}
// associate the model with the part (= the controller)
part.setModel(model);
return part;
}
Aggregations