Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Fixes #1972. Removed crossing of pin icon on macOS for inlined defini…
Browse files Browse the repository at this point in the history
…tion section (#1995)
  • Loading branch information
Robert Rudi authored and tkutz committed Mar 22, 2018
1 parent 279c5cf commit 38a8486
Showing 1 changed file with 51 additions and 33 deletions.
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
Expand All @@ -42,7 +41,6 @@
import org.yakindu.base.gmf.runtime.decorators.InteractiveDecorator;
import org.yakindu.base.xtext.utils.jface.viewers.util.ActiveEditorTracker;
import org.yakindu.sct.model.sgraph.SpecificationElement;
import org.yakindu.sct.ui.editor.DiagramActivator;
import org.yakindu.sct.ui.editor.StatechartImages;
import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
import org.yakindu.sct.ui.editor.editparts.StatechartTextEditPart;
Expand All @@ -66,14 +64,30 @@ public void createDecorators(IDecoratorTarget decoratorTarget) {

public static class DefinitionSectionDecorator extends InteractiveDecorator {

private static final Insets HIGHLIGHTING_BORDER_INSETS = new Insets(1, 1, 1, 1);
private static final LineBorder decorationLineBorder = new LineBorder(ColorConstants.lightGray);
private static final MarginBorder marginBorder = new MarginBorder(1, 0, 1, 0);
private static final Insets decorationExpandInsets = new Insets(0, 0, 0, 3);
private static final String TOOLTIP_TEXT = "Pin statechart definition section";
protected static final IPreferenceStore preferenceStore = DiagramActivator.getDefault().getPreferenceStore();
private static Cursor handCursor;
private static final int SHIFT_DY = 1;
private static final int SHIFT_DX = -2;
private DecorationMouseMotionListener decorationMouseMotionListener;

public DefinitionSectionDecorator(IDecoratorTarget decoratorTarget) {
super(decoratorTarget);
}

@Override
protected void disposeDecoration() {
if (handCursor != null)
handCursor.dispose();
if (getDecoration() != null && decorationMouseMotionListener != null) {
getDecoration().removeMouseMotionListener(decorationMouseMotionListener);
decorationMouseMotionListener = null;
}
super.disposeDecoration();
}

@Override
protected Direction getDecoratorPosition() {
return IDecoratorTarget.Direction.NORTH_WEST;
Expand All @@ -93,44 +107,23 @@ protected boolean shouldDecorate(EObject element) {
DiagramPartitioningUtil.INLINE_DEFINITION_SECTION_STYLE);
return style == null ? true : style.isBooleanValue();
}

return false;
}

@Override
protected Decoration createDecoration(EObject semanticElement) {
Decoration decoration = super.createDecoration(semanticElement);
installIconHighlighting(decoration, semanticElement);
if (decoration != null && semanticElement != null)
installIconHighlighting(decoration, semanticElement);
return decoration;
}

protected void installIconHighlighting(Decoration decoration, final EObject semanticElement) {
decoration.getBounds().expand(HIGHLIGHTING_BORDER_INSETS);
decoration.addMouseMotionListener(new MouseMotionListener() {

@Override
public void mouseDragged(org.eclipse.draw2d.MouseEvent me) {
}

@Override
public void mouseEntered(org.eclipse.draw2d.MouseEvent me) {
decoration.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_HAND));
decoration.setBorder(new LineBorder(ColorConstants.lightGray));
}

@Override
public void mouseExited(org.eclipse.draw2d.MouseEvent me) {
decoration.setBorder(new MarginBorder(HIGHLIGHTING_BORDER_INSETS));
}

@Override
public void mouseHover(org.eclipse.draw2d.MouseEvent me) {
}

@Override
public void mouseMoved(org.eclipse.draw2d.MouseEvent me) {
}
});
decoration.getBounds().translate(SHIFT_DX, SHIFT_DY);
decoration.getBounds().expand(decorationExpandInsets);
if (decorationMouseMotionListener == null)
decorationMouseMotionListener = new DecorationMouseMotionListener(decoration);
decoration.addMouseMotionListener(decorationMouseMotionListener);
}

@Override
Expand Down Expand Up @@ -186,6 +179,31 @@ protected IFigure getToolTipFigure(EObject element) {
return new Label(TOOLTIP_TEXT);
}

protected class DecorationMouseMotionListener implements MouseMotionListener {
private final Decoration decoration;
protected DecorationMouseMotionListener(Decoration decoration) {
this.decoration = decoration;
}
@Override
public void mouseEntered(org.eclipse.draw2d.MouseEvent me) {
if (handCursor == null || handCursor.isDisposed())
handCursor = new Cursor(Display.getDefault(), SWT.CURSOR_HAND);
decoration.setCursor(handCursor);
decoration.setBorder(decorationLineBorder);
}
@Override
public void mouseExited(org.eclipse.draw2d.MouseEvent me) {
decoration.setBorder(marginBorder);
}
@Override
public void mouseDragged(org.eclipse.draw2d.MouseEvent me) {
}
@Override
public void mouseHover(org.eclipse.draw2d.MouseEvent me) {
}
@Override
public void mouseMoved(org.eclipse.draw2d.MouseEvent me) {
}
}
}

}

0 comments on commit 38a8486

Please sign in to comment.