Search in sources :

Example 1 with Annotation

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;
}
Also used : AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) Composite(org.eclipse.swt.widgets.Composite) AnnotationData(org.knime.core.node.workflow.AnnotationData) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Annotation(org.knime.core.node.workflow.Annotation) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Example 2 with Annotation

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();
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation)

Example 3 with Annotation

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();
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodeAnnotationFigure(org.knime.workbench.editor2.figures.NodeAnnotationFigure) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation)

Example 4 with Annotation

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();
}
Also used : NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation) Font(org.eclipse.swt.graphics.Font)

Example 5 with Annotation

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;
}
Also used : EditPart(org.eclipse.gef.EditPart) NodeID(org.knime.core.node.workflow.NodeID) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation)

Aggregations

Annotation (org.knime.core.node.workflow.Annotation)14 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)9 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)7 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)3 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)3 NodeAnnotationFigure (org.knime.workbench.editor2.figures.NodeAnnotationFigure)3 EditPart (org.eclipse.gef.EditPart)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 Font (org.eclipse.swt.graphics.Font)2 NodeID (org.knime.core.node.workflow.NodeID)2 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)2 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 Composite (org.eclipse.swt.widgets.Composite)1 CellEditorActionHandler (org.eclipse.ui.part.CellEditorActionHandler)1 AnnotationData (org.knime.core.node.workflow.AnnotationData)1 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)1