use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.
the class WorkflowMarqueeSelectionTool method calculateNewSelection.
private void calculateNewSelection(final Collection<GraphicalEditPart> newSelections, final Collection<GraphicalEditPart> deselections) {
Rectangle marqueeRect = getMarqueeSelectionRectangle();
for (Iterator<GraphicalEditPart> itr = getAllChildren().iterator(); itr.hasNext(); ) {
GraphicalEditPart child = itr.next();
IFigure figure = child.getFigure();
if (!child.isSelectable() || child.getTargetEditPart(MARQUEE_REQUEST) != child || !isFigureVisible(figure) || !figure.isShowing()) {
continue;
}
if (!(child instanceof NodeContainerEditPart || child instanceof ConnectionContainerEditPart || child instanceof AbstractWorkflowPortBarEditPart || child instanceof AnnotationEditPart)) {
continue;
}
Rectangle r = figure.getBounds().getCopy();
figure.translateToAbsolute(r);
boolean included = false;
if (child instanceof ConnectionEditPart && marqueeRect.intersects(r)) {
Rectangle relMarqueeRect = Rectangle.SINGLETON;
figure.translateToRelative(relMarqueeRect.setBounds(marqueeRect));
included = ((PolylineConnection) figure).getPoints().intersects(relMarqueeRect);
} else if (child instanceof AnnotationEditPart) {
// select WorkflowAnnotations only if they are fully included in the selection
if (figure instanceof WorkflowAnnotationFigure) {
included = marqueeRect.contains(r);
}
} else if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
included = marqueeRect.intersects(r);
} else {
included = marqueeRect.contains(r);
}
if (included) {
if (isToggle()) {
if (wasSelected(child)) {
deselections.add(child);
} else {
newSelections.add(child);
}
} else {
newSelections.add(child);
}
} else if (isToggle()) {
// readded if it was in the selection before
if (wasSelected(child)) {
newSelections.add(child);
} else {
deselections.add(child);
}
}
}
if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
calculateConnections(newSelections, deselections);
}
}
use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.
the class CutAction method runInSWT.
/**
* Invokes the copy action followed by the delete command.
* {@inheritDoc}
*/
@Override
public void runInSWT() {
LOGGER.debug("Clipboard cut action invoked...");
// invoke copy action
CopyAction copy = new CopyAction(getEditor());
copy.runInSWT();
NodeContainerEditPart[] nodeParts = copy.getNodeParts();
AnnotationEditPart[] annotationParts = copy.getAnnotationParts();
Collection<EditPart> coll = new ArrayList<EditPart>();
coll.addAll(Arrays.asList(nodeParts));
coll.addAll(Arrays.asList(annotationParts));
DeleteCommand delete = new DeleteCommand(coll, getEditor().getWorkflowManager().get());
// enable undo
getCommandStack().execute(delete);
getEditor().updateActions();
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.
the class NewWorkflowXYLayoutPolicy method createChangeConstraintCommand.
/**
* Creates command to move / resize <code>NodeContainer</code> components on
* the project's client area.
*
* {@inheritDoc}
*/
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
// only rectangular constraints are supported
if (!(constraint instanceof Rectangle)) {
return null;
}
Command command = null;
Rectangle rect = ((Rectangle) constraint).getCopy();
if (child.getModel() instanceof NodeContainerUI) {
NodeContainerUI container = (NodeContainerUI) child.getModel();
if (!Wrapper.wraps(container, NodeContainer.class)) {
// not supported for others than ordinary NodeContainers
return null;
}
NodeContainerEditPart nodePart = (NodeContainerEditPart) child;
command = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(container), (NodeContainerFigure) nodePart.getFigure(), rect);
} else if (child instanceof AbstractWorkflowPortBarEditPart) {
command = new ChangeWorkflowPortBarCommand((AbstractWorkflowPortBarEditPart) child, rect);
} else if (child instanceof AnnotationEditPart) {
AnnotationEditPart annoPart = (AnnotationEditPart) child;
// TODO the workflow annotation could know what its WFM is?
WorkflowRootEditPart root = (WorkflowRootEditPart) annoPart.getParent();
WorkflowManagerUI wm = root.getWorkflowManager();
if (!Wrapper.wraps(wm, WorkflowManager.class)) {
// not supported for others than an ordinary workflow manager
return null;
}
command = new ChangeAnnotationBoundsCommand(Wrapper.unwrapWFM(wm), annoPart, rect);
}
return command;
}
use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.
the class WorkflowEditor method onF2Pressed.
/**
* Opens editor for (node) annotation (given that a single node or
* annotation is selected).
*/
private void onF2Pressed() {
ISelectionProvider provider = getEditorSite().getSelectionProvider();
if (provider == null) {
return;
}
ISelection sel = provider.getSelection();
if (!(sel instanceof IStructuredSelection)) {
return;
}
Set<AnnotationEditPart> selectedAnnoParts = new HashSet<AnnotationEditPart>();
@SuppressWarnings("rawtypes") Iterator selIter = ((IStructuredSelection) sel).iterator();
while (selIter.hasNext()) {
Object next = selIter.next();
if (next instanceof AnnotationEditPart) {
selectedAnnoParts.add((AnnotationEditPart) next);
} else if (next instanceof NodeContainerEditPart) {
NodeAnnotationEditPart nodeAnnoPart = ((NodeContainerEditPart) next).getNodeAnnotationEditPart();
if (nodeAnnoPart != null) {
selectedAnnoParts.add(nodeAnnoPart);
}
} else {
// unknown type selected
return;
}
}
if (selectedAnnoParts.size() == 1) {
AnnotationEditPart next = selectedAnnoParts.iterator().next();
next.performEdit();
}
}
use of org.knime.workbench.editor2.editparts.AnnotationEditPart in project knime-core by knime.
the class AnnotationEditPolicy method getDirectEditCommand.
/**
* {@inheritDoc}
*/
@Override
protected Command getDirectEditCommand(final DirectEditRequest edit) {
StyledTextEditor ste = (StyledTextEditor) edit.getCellEditor();
AnnotationData newAnnoData = (AnnotationData) ste.getValue();
AnnotationEditPart annoPart = (AnnotationEditPart) getHost();
Annotation oldAnno = annoPart.getModel();
Rectangle oldFigBounds = annoPart.getFigure().getBounds().getCopy();
// y-coordinate is the only dimension that doesn't change
newAnnoData.setY(oldFigBounds.y);
// trim was never really verified (was always 0 on my platform),
// see also StyledTextEditorLocator#relocate
Composite compositeEditor = (Composite) ste.getControl();
org.eclipse.swt.graphics.Rectangle trim = compositeEditor.computeTrim(0, 0, 0, 0);
if (annoPart instanceof NodeAnnotationEditPart) {
// the width and height grow with the text entered
newAnnoData.setX(compositeEditor.getBounds().x);
newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
newAnnoData.setWidth(compositeEditor.getBounds().width - trim.width);
} else {
// with workflow annotations only the height grows with the text
newAnnoData.setX(oldFigBounds.x);
newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
newAnnoData.setWidth(oldFigBounds.width - trim.width);
}
if (hasAnnotationDataChanged(oldAnno, newAnnoData)) {
return new AnnotationEditCommand(annoPart, oldAnno, newAnnoData);
}
return null;
}
Aggregations