diff options
author | tarendt | 2013-04-24 12:27:44 +0000 |
---|---|---|
committer | tarendt | 2013-04-24 12:27:44 +0000 |
commit | fc0a54c7343a967a39da67e00586ea333d962e39 (patch) | |
tree | 0967085076d4cc0821841b2eac9a0d68141d1ab6 /org.eclipse.emf.refactor.metrics.papyrus | |
parent | 337d65a2d191d41cbcc30aa065ea7d3f7471f24a (diff) | |
download | org.eclipse.emf.refactor.metrics-fc0a54c7343a967a39da67e00586ea333d962e39.tar.gz org.eclipse.emf.refactor.metrics-fc0a54c7343a967a39da67e00586ea333d962e39.tar.xz org.eclipse.emf.refactor.metrics-fc0a54c7343a967a39da67e00586ea333d962e39.zip |
highlighting for Papyrus added
Diffstat (limited to 'org.eclipse.emf.refactor.metrics.papyrus')
16 files changed, 340 insertions, 0 deletions
diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/PapyrusStartup.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/PapyrusStartup.class Binary files differnew file mode 100644 index 0000000..76e03c5 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/PapyrusStartup.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/managers/HighlightManager.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/managers/HighlightManager.class Binary files differnew file mode 100644 index 0000000..873e73e --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/managers/HighlightManager.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorationFigure.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorationFigure.class Binary files differnew file mode 100644 index 0000000..64bb262 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorationFigure.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$1.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$1.class Binary files differnew file mode 100644 index 0000000..5d940f6 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$1.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$2.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$2.class Binary files differnew file mode 100644 index 0000000..e576842 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$2.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$Style.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$Style.class Binary files differnew file mode 100644 index 0000000..ba6c01d --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator$Style.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator.class Binary files differnew file mode 100644 index 0000000..1950dee --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecoratorProvider.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecoratorProvider.class Binary files differnew file mode 100644 index 0000000..d9f97ea --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecoratorProvider.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusHighlighting.class b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusHighlighting.class Binary files differnew file mode 100644 index 0000000..b53a28d --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/bin/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusHighlighting.class diff --git a/org.eclipse.emf.refactor.metrics.papyrus/plugin.xml b/org.eclipse.emf.refactor.metrics.papyrus/plugin.xml index abc72c5..51be4ef 100644 --- a/org.eclipse.emf.refactor.metrics.papyrus/plugin.xml +++ b/org.eclipse.emf.refactor.metrics.papyrus/plugin.xml @@ -1,6 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> + + <extension + point="org.eclipse.ui.startup"> + <startup + class="org.eclipse.emf.refactor.metrics.papyrus.PapyrusStartup"> + </startup> + </extension> + <extension id="org.eclipse.emf.refactor.papyrus.menu" point="org.eclipse.ui.menus"> @@ -131,4 +139,21 @@ commandId="org.eclipse.emf.refactor.metrics.papyrus.generateNewMetricCompositeCommand"> </handler> </extension> + + <extension + point="org.eclipse.gmf.runtime.diagram.ui.decoratorProviders"> + <decoratorProvider + class="org.eclipse.emf.refactor.metrics.papyrus.ui.PapyrusDecoratorProvider"> + <Priority + name="Lowest"> + </Priority> + <object + class="org.eclipse.gmf.runtime.notation.View(org.eclipse.gmf.runtime.notation)" + id="NODE"> + </object> + <context + decoratorTargets="NODE"> + </context> + </decoratorProvider> + </extension> </plugin> diff --git a/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/PapyrusStartup.java b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/PapyrusStartup.java new file mode 100644 index 0000000..ab2b1f4 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/PapyrusStartup.java @@ -0,0 +1,15 @@ +package org.eclipse.emf.refactor.metrics.papyrus; + +import org.eclipse.emf.refactor.metrics.papyrus.ui.PapyrusHighlighting; +import org.eclipse.emf.refactor.metrics.runtime.managers.RuntimeManager; +import org.eclipse.ui.IStartup; + +public class PapyrusStartup implements IStartup { + + @Override + public void earlyStartup() { + RuntimeManager.getInstance(new PapyrusHighlighting()); + System.out.println("Started"); + } + +} diff --git a/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/managers/HighlightManager.java b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/managers/HighlightManager.java new file mode 100644 index 0000000..cc43d67 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/managers/HighlightManager.java @@ -0,0 +1,84 @@ +package org.eclipse.emf.refactor.metrics.papyrus.managers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.refactor.metrics.runtime.core.Result; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy.DecoratorTarget; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; + + +public class HighlightManager { + + private static HighlightManager instance = null; + private List<EObject> selected; + private List<IDecorator> decorators = null; + private Map<EObject, IDecoratorTarget> decoratorTargets = null; + + private HighlightManager() { + selected = new ArrayList<EObject>(); + decoratorTargets = new HashMap<EObject, IDecoratorTarget>(); + decorators = new ArrayList<IDecorator>(); + } + + public static HighlightManager getInstance() { + if(instance == null) { + instance = new HighlightManager(); + } + return instance; + } + + public void highlight(Object selection) { + // clear former selected eObjects + selected.clear(); + // set selected eObjects from selection + if (selection instanceof Result) { + selected.addAll(((Result) selection).getContext()); + } + // refresh each corresponding decorator + for (IDecorator decorator : decorators) { + decorator.refresh(); + } + } + + public void registerDecorator(IDecorator decorator, DecoratorTarget decoratorTarget) { + View view = (View) decoratorTarget.getAdapter(View.class); + if(decoratorTargets.containsKey(view.getElement())){ + View parent = view; + boolean topMost = false; + if(!(parent instanceof Diagram)){ + while(!((parent = (View) parent.eContainer()) instanceof Diagram)){ + if(parent == decoratorTargets.get(view.getElement()).getAdapter(View.class)){ + topMost = true; + } + } + if(!topMost){ + decoratorTargets.put(view.getElement(), decoratorTarget); + } + } + } else { + decoratorTargets.put(view.getElement(), decoratorTarget); + } + + decorators.add(decorator); + } + + public void unregisterDecorator(IDecorator decorator) { + decorators.remove(decorator); + } + + public IDecoratorTarget getPrefferedDecoratorTarget(EObject element) { + return decoratorTargets.get(element); + } + + public List<EObject> getSelected() { + return selected; + } + +} diff --git a/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorationFigure.java b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorationFigure.java new file mode 100644 index 0000000..99aee93 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorationFigure.java @@ -0,0 +1,25 @@ +package org.eclipse.emf.refactor.metrics.papyrus.ui; + +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.swt.graphics.Color; + +public class PapyrusDecorationFigure extends Figure { + + private static final Color NICE_RED = new Color(null, 232, 72, 72); + + public PapyrusDecorationFigure(){ + setLayoutManager(new ToolbarLayout()); + setOpaque(false); + } + + @Override + public void paint(Graphics graphics) { + graphics.setForegroundColor(NICE_RED); + graphics.setLineWidth(4); + graphics.drawRectangle(getClientArea()); + super.paint(graphics); + } + +} diff --git a/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator.java b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator.java new file mode 100644 index 0000000..0735eb9 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecorator.java @@ -0,0 +1,155 @@ +package org.eclipse.emf.refactor.metrics.papyrus.ui; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LayoutListener; +import org.eclipse.draw2d.PolylineConnection; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.refactor.metrics.papyrus.managers.HighlightManager; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; +import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.swt.graphics.Color; +//import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; + +public class PapyrusDecorator extends AbstractDecorator { + + private HighlightManager manager = HighlightManager.getInstance(); + + private Map<PolylineConnection, Style> decoratedLines = null; + + private LayoutListener layoutListener = new LayoutListener() { + @Override + public void setConstraint(IFigure child, Object constraint) {} + + @Override + public void remove(IFigure child) {} + + @Override + public void postLayout(IFigure container) { + refresh(); + } + + @Override + public boolean layout(IFigure container) { return false; } + + @Override + public void invalidate(IFigure container) {}}; + + private NotificationListener notificationListener = new NotificationListener() { + public void notifyChanged(Notification notification) { + refresh(); + }}; + + + public PapyrusDecorator(IDecoratorTarget decoratorTarget) { + super(decoratorTarget); + decoratedLines = new HashMap<PolylineConnection, Style>(); + } + + @Override + public void activate() { + IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); + assert gep != null; + DiagramEventBroker.getInstance(gep.getEditingDomain()).addNotificationListener(gep.getNotationView(), + NotationPackage.eINSTANCE.getDescriptionStyle_Description(), notificationListener); + + GraphicalEditPart editPart = (GraphicalEditPart) getDecoratorTarget().getAdapter(GraphicalEditPart.class); + editPart.getFigure().addLayoutListener(layoutListener); + + manager.registerDecorator(this, getDecoratorTarget()); + } + + @Override + public void deactivate() { + removeDecoration(); + + IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); + assert gep != null; + DiagramEventBroker.getInstance(gep.getEditingDomain()).removeNotificationListener(gep.getNotationView(), + NotationPackage.eINSTANCE.getDescriptionStyle_Description(), notificationListener); + + GraphicalEditPart editPart = (GraphicalEditPart) getDecoratorTarget().getAdapter(GraphicalEditPart.class); + editPart.getFigure().removeLayoutListener(layoutListener); + + manager.unregisterDecorator(this); + } + + @Override + protected void removeDecoration() { + super.removeDecoration(); + for (PolylineConnection connection : decoratedLines.keySet()){ + connection.setForegroundColor(decoratedLines.get(connection).color); + connection.setLineWidth(decoratedLines.get(connection).lineWidth); + } + } + + @Override + public void refresh() { + System.out.println("Start REFRESH"); + removeDecoration(); + IGraphicalEditPart editPart = (IGraphicalEditPart) getDecoratorTarget().getAdapter(EditPart.class); + + View view = (View) getDecoratorTarget().getAdapter(View.class); + + if (manager.getPrefferedDecoratorTarget(view.getElement()) == getDecoratorTarget()){ + if(selectionContains(view.getElement())) { + int x = editPart.getFigure().getBounds().x; + int y = editPart.getFigure().getBounds().y; + FigureCanvas canvas = (FigureCanvas) editPart.getViewer().getControl(); + canvas.scrollSmoothTo(x, y); + if (view instanceof Node) { + IFigure figure = editPart.getFigure(); + IFigure decoration = new PapyrusDecorationFigure(); + decoration.setSize(figure.getSize()); + setDecoration(getDecoratorTarget().addShapeDecoration(decoration, IDecoratorTarget.Direction.CENTER, 0, false)); + } + if (view instanceof Edge) { + PolylineConnection connection = (PolylineConnection) editPart.getFigure(); + decoratedLines.put(connection, new Style(connection.getForegroundColor(), connection.getLineWidth())); + connection.setForegroundColor(ColorConstants.red); + connection.setLineWidth(2); + } + } + } + System.out.println("End REFRESH"); + } + + private boolean selectionContains(EObject element){ + boolean contained = false; + if (element != null) { + for(EObject selected : manager.getSelected()){ + String fragmentA = EcoreUtil.getURI(selected).fragment(); + String fragmentB = EcoreUtil.getURI(element).fragment(); + contained |= fragmentA.equals(fragmentB); + } + } + return contained; + } + + private static class Style { + + public Color color = null; + public int lineWidth = 0; + + public Style(Color c, int lw){ + color = c; + lineWidth = lw; + } + } + +} diff --git a/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecoratorProvider.java b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecoratorProvider.java new file mode 100644 index 0000000..3948899 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusDecoratorProvider.java @@ -0,0 +1,23 @@ +package org.eclipse.emf.refactor.metrics.papyrus.ui; + +import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; +import org.eclipse.gmf.runtime.common.core.service.IOperation; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; + +public class PapyrusDecoratorProvider extends AbstractProvider implements IDecoratorProvider { + + public static final String PAPYRUS_DECORATOR_KEY = "papyrus_decorator"; + + @Override + public boolean provides(IOperation operation) { + return (operation instanceof CreateDecoratorsOperation); + } + + @Override + public void createDecorators(IDecoratorTarget decoratorTarget) { + decoratorTarget.installDecorator(PAPYRUS_DECORATOR_KEY, new PapyrusDecorator(decoratorTarget)); + } + +} diff --git a/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusHighlighting.java b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusHighlighting.java new file mode 100644 index 0000000..9902901 --- /dev/null +++ b/org.eclipse.emf.refactor.metrics.papyrus/src/org/eclipse/emf/refactor/metrics/papyrus/ui/PapyrusHighlighting.java @@ -0,0 +1,13 @@ +package org.eclipse.emf.refactor.metrics.papyrus.ui; + +import org.eclipse.emf.refactor.metrics.interfaces.IHighlighting; +import org.eclipse.emf.refactor.metrics.papyrus.managers.HighlightManager; + +public class PapyrusHighlighting implements IHighlighting { + + @Override + public void highlight(Object selection) { + HighlightManager.getInstance().highlight(selection); + } + +} |