Search in sources :

Example 1 with StyledTextEditorLocator

use of org.knime.workbench.editor2.directannotationedit.StyledTextEditorLocator 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 StyledTextEditorLocator

use of org.knime.workbench.editor2.directannotationedit.StyledTextEditorLocator 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();
}
Also used : EditPart(org.eclipse.gef.EditPart) AnnotationEditManager(org.knime.workbench.editor2.directannotationedit.AnnotationEditManager) StyledTextEditorLocator(org.knime.workbench.editor2.directannotationedit.StyledTextEditorLocator)

Aggregations

Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 EditPart (org.eclipse.gef.EditPart)1 Composite (org.eclipse.swt.widgets.Composite)1 Annotation (org.knime.core.node.workflow.Annotation)1 AnnotationData (org.knime.core.node.workflow.AnnotationData)1 AnnotationEditManager (org.knime.workbench.editor2.directannotationedit.AnnotationEditManager)1 StyledTextEditorLocator (org.knime.workbench.editor2.directannotationedit.StyledTextEditorLocator)1 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)1 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)1