use of org.knime.core.node.workflow.Annotation 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;
}
use of org.knime.core.node.workflow.Annotation in project knime-core by knime.
the class AnnotationEditPart method deactivate.
/**
* {@inheritDoc}
*/
@Override
public void deactivate() {
IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
store.removePropertyChangeListener(this);
Annotation anno = getModel();
anno.removeUIInformationListener(this);
super.deactivate();
}
use of org.knime.core.node.workflow.Annotation in project knime-core by knime.
the class AnnotationEditPart method nodeUIInformationChanged.
/**
* {@inheritDoc}
*/
@Override
public void nodeUIInformationChanged(final NodeUIInformationEvent evt) {
Annotation anno = getModel();
NodeAnnotationFigure annoFig = (NodeAnnotationFigure) getFigure();
annoFig.newContent(anno);
WorkflowRootEditPart parent = (WorkflowRootEditPart) getParent();
parent.setLayoutConstraint(this, getFigure(), new Rectangle(anno.getX(), anno.getY(), anno.getWidth(), anno.getHeight()));
refreshVisuals();
parent.refresh();
}
use of org.knime.core.node.workflow.Annotation in project knime-core by knime.
the class StyledTextEditor method doSetValue.
/**
* {@inheritDoc}
*/
@Override
protected void doSetValue(final Object value) {
assert value instanceof Annotation : "Wrong value object!";
Annotation wa = (Annotation) value;
int alignment;
switch(wa.getAlignment()) {
case CENTER:
alignment = SWT.CENTER;
break;
case RIGHT:
alignment = SWT.RIGHT;
break;
default:
alignment = SWT.LEFT;
}
checkSelectionOfAlignmentMenuItems(alignment);
m_selectAllUponFocusGain = false;
String text;
if (wa instanceof NodeAnnotation) {
if (AnnotationEditPart.isDefaultNodeAnnotation(wa)) {
text = AnnotationEditPart.getAnnotationText(wa);
m_selectAllUponFocusGain = true;
} else {
text = wa.getText();
}
} else {
text = wa.getText();
m_selectAllUponFocusGain = AddAnnotationCommand.INITIAL_FLOWANNO_TEXT.equals(text);
int annotationBorderSize = wa.getBorderSize();
// set margins as borders
m_styledText.setMarginColor(AnnotationEditPart.RGBintToColor(wa.getBorderColor()));
if (annotationBorderSize > 0) {
m_styledText.setMargins(annotationBorderSize, annotationBorderSize, annotationBorderSize, annotationBorderSize);
}
// for workflow annotations set the default font to the size stored in the annotation
Font defFont;
int defFontSize = wa.getDefaultFontSize();
if (defFontSize < 0) {
// uses the size from the pref page
defFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont();
} else {
defFont = AnnotationEditPart.getWorkflowAnnotationDefaultFont(defFontSize);
}
setDefaultFont(defFont);
}
m_styledText.setAlignment(alignment);
m_styledText.setText(text);
m_styledText.setStyleRanges(AnnotationEditPart.toSWTStyleRanges(wa.getData(), m_styledText.getFont()));
setBackgroundColor(AnnotationEditPart.RGBintToColor(wa.getBgColor()));
syncShadowWithEditor();
}
use of org.knime.core.node.workflow.Annotation 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