use of org.eclipse.gef.EditPart in project knime-core by knime.
the class NodeContainerEditPart method deactivate.
/**
* {@inheritDoc}
*/
@Override
public void deactivate() {
NodeContainerUI nc = getNodeContainer();
IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
store.removePropertyChangeListener(this);
nc.removeNodeStateChangeListener(this);
nc.removeNodeMessageListener(this);
nc.removeNodeProgressListener(this);
nc.removeUIInformationListener(this);
nc.removeNodePropertyChangedListener(this);
removeEditPartListener(this);
for (Object o : getChildren()) {
EditPart editPart = (EditPart) o;
editPart.deactivate();
}
EditPolicyIterator editPolicyIterator = getEditPolicyIterator();
while (editPolicyIterator.hasNext()) {
editPolicyIterator.next().deactivate();
}
super.deactivate();
}
use of org.eclipse.gef.EditPart in project knime-core by knime.
the class SnapIconToGrid method snapRectangle.
/**
* {@inheritDoc}
*/
@Override
public int snapRectangle(final Request request, final int snapLocations, final PrecisionRectangle rect, final PrecisionRectangle result) {
PrecisionRectangle r = rect;
if (request instanceof ChangeBoundsRequest) {
EditPart refPart = getReferencePart(((ChangeBoundsRequest) request).getEditParts(), ((ChangeBoundsRequest) request).getLocation(), ((ChangeBoundsRequest) request).getMoveDelta());
if (refPart instanceof NodeContainerEditPart) {
// adjust the rectangle to snap the center of the icon of the node
NodeContainerEditPart contPart = (NodeContainerEditPart) refPart;
NodeContainerFigure fig = (NodeContainerFigure) contPart.getFigure();
Point iconOffset = getIconOffset(fig);
r = rect.getPreciseCopy();
r.translate(iconOffset);
} else if (refPart instanceof NodeAnnotationEditPart) {
// the rect is the annotation outline - adjust it to snap the center of the corresponding node icon
NodeAnnotationEditPart annoPart = (NodeAnnotationEditPart) refPart;
WorkflowRootEditPart parent = (WorkflowRootEditPart) annoPart.getParent();
IFigure annoFig = annoPart.getFigure();
NodeAnnotation anno = (NodeAnnotation) annoPart.getModel();
NodeContainerEditPart nodePart = (NodeContainerEditPart) m_container.getViewer().getEditPartRegistry().get(parent.getWorkflowManager().getNodeContainer(anno.getNodeID()));
NodeContainerFigure nodeFig = (NodeContainerFigure) nodePart.getFigure();
Point iconOffset = getIconOffset(nodeFig);
int xOff = nodeFig.getBounds().x - annoFig.getBounds().x;
xOff += iconOffset.x;
int yOff = iconOffset.y - nodeFig.getBounds().height;
r = rect.getPreciseCopy();
r.translate(new Point(xOff, yOff));
}
}
return super.snapRectangle(request, snapLocations, r, result);
}
use of org.eclipse.gef.EditPart 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.eclipse.gef.EditPart in project knime-core by knime.
the class AnnotationEditPart method performEdit.
/**
* Opens the editor to directoy edit the annotation in place.
*/
public void performEdit() {
final EditPart parent = getParent();
if (parent instanceof WorkflowRootEditPart) {
WorkflowRootEditPart wkfRootEdit = (WorkflowRootEditPart) parent;
if (wkfRootEdit.getWorkflowManager().isWriteProtected()) {
return;
}
}
if (m_directEditManager == null) {
m_directEditManager = new AnnotationEditManager(this, new StyledTextEditorLocator((NodeAnnotationFigure) getFigure()));
}
m_directEditManager.show();
}
use of org.eclipse.gef.EditPart in project knime-core by knime.
the class WorkflowRootEditPart method createChild.
/**
* {@inheritDoc}
*/
@Override
protected EditPart createChild(final Object model) {
final EditPart part = super.createChild(model);
LOGGER.debug("part: " + part);
if (part instanceof NodeContainerEditPart) {
getViewer().deselect(this);
NodeID id = ((NodeContainerEditPart) part).getNodeContainer().getID();
if (m_futureSelection.isEmpty()) {
// select only this element
getViewer().deselectAll();
getViewer().select(part);
} else if (m_futureSelection.contains(id)) {
// append this element to the current selection
getViewer().appendSelection(part);
m_futureSelection.remove(id);
// reveal the editpart after it has been created completely
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
getViewer().reveal(part);
}
});
}
}
if (model instanceof Annotation) {
// newly created annotations are only selected if done explicitly
getViewer().deselect(this);
if (m_annotationSelection.contains(model)) {
getViewer().appendSelection(part);
m_annotationSelection.remove(model);
// reveal the editpart after it has been created completely
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
getViewer().reveal(part);
}
});
}
}
// connections are selected in workflowChanged
return part;
}
Aggregations