From 254c94e8e1cd535ce09d49b31ed01bbfd94799b0 Mon Sep 17 00:00:00 2001 From: Johannes Dicks Date: Mon, 27 Jun 2016 17:03:16 +0200 Subject: [PATCH] #791 : update priority decorators if priority changed in owning state --- .../gmf/runtime/decorators/BaseDecorator.java | 135 +++++++++--------- .../TransitionPriorityDecorationProvider.java | 37 ++++- 2 files changed, 100 insertions(+), 72 deletions(-) diff --git a/plugins/org.yakindu.base.gmf.runtime/src/org/yakindu/base/gmf/runtime/decorators/BaseDecorator.java b/plugins/org.yakindu.base.gmf.runtime/src/org/yakindu/base/gmf/runtime/decorators/BaseDecorator.java index 6df134c76d..921f4c3001 100644 --- a/plugins/org.yakindu.base.gmf.runtime/src/org/yakindu/base/gmf/runtime/decorators/BaseDecorator.java +++ b/plugins/org.yakindu.base.gmf.runtime/src/org/yakindu/base/gmf/runtime/decorators/BaseDecorator.java @@ -1,69 +1,66 @@ -/** - * Copyright (c) 2011 committers of YAKINDU and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * Contributors: - * committers of YAKINDU - initial API and implementation - * - */ -package org.yakindu.base.gmf.runtime.decorators; - -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -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; - -/** - * - * @author andreas muelder - Initial contribution and API - * - */ -public abstract class BaseDecorator extends AbstractDecorator { - - private IGraphicalEditPart gep; - - private EObject semanticElement; - - public BaseDecorator(IDecoratorTarget decoratorTarget) { - super(decoratorTarget); - gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter( - IGraphicalEditPart.class); - semanticElement = gep.resolveSemanticElement(); - - } - - private NotificationListener notificationListener = new NotificationListener() { - - public void notifyChanged(Notification notification) { - refresh(); - } - }; - - public void activate() { - DiagramEventBroker.getInstance(gep.getEditingDomain()) - .addNotificationListener(semanticElement, notificationListener); - DiagramEventBroker.getInstance(gep.getEditingDomain()) - .addNotificationListener(gep.getNotationView(), - notificationListener); - } - - public void deactivate() { - removeDecoration(); - IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget() - .getAdapter(IGraphicalEditPart.class); - assert gep != null; - - DiagramEventBroker.getInstance(gep.getEditingDomain()) - .removeNotificationListener(semanticElement, - notificationListener); - DiagramEventBroker.getInstance(gep.getEditingDomain()) - .removeNotificationListener(gep.getNotationView(), - notificationListener); - } - -} +/** + * Copyright (c) 2011 committers of YAKINDU and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * Contributors: + * committers of YAKINDU - initial API and implementation + * + */ +package org.yakindu.base.gmf.runtime.decorators; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +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; + +/** + * + * @author andreas muelder - Initial contribution and API + * + */ +public abstract class BaseDecorator extends AbstractDecorator { + + protected IGraphicalEditPart gep; + + protected EObject semanticElement; + + public BaseDecorator(IDecoratorTarget decoratorTarget) { + super(decoratorTarget); + gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter( + IGraphicalEditPart.class); + semanticElement = gep.resolveSemanticElement(); + + } + + private NotificationListener notificationListener = new NotificationListener() { + + public void notifyChanged(Notification notification) { + refresh(); + } + }; + + public void activate() { + DiagramEventBroker.getInstance(gep.getEditingDomain()) + .addNotificationListener(semanticElement, notificationListener); + DiagramEventBroker.getInstance(gep.getEditingDomain()) + .addNotificationListener(gep.getNotationView(), + notificationListener); + } + + public void deactivate() { + removeDecoration(); + + DiagramEventBroker.getInstance(gep.getEditingDomain()) + .removeNotificationListener(semanticElement, + notificationListener); + DiagramEventBroker.getInstance(gep.getEditingDomain()) + .removeNotificationListener(gep.getNotationView(), + notificationListener); + } + +} diff --git a/plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/providers/TransitionPriorityDecorationProvider.java b/plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/providers/TransitionPriorityDecorationProvider.java index c7ea9867cf..a1fb01d5a4 100644 --- a/plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/providers/TransitionPriorityDecorationProvider.java +++ b/plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/providers/TransitionPriorityDecorationProvider.java @@ -13,9 +13,12 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gef.EditDomain; import org.eclipse.gef.EditPart; import org.eclipse.gef.editparts.AbstractConnectionEditPart; +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.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator; @@ -27,6 +30,8 @@ import org.eclipse.ui.IEditorPart; import org.yakindu.base.gmf.runtime.decorators.AbstractDecoratorProvider; import org.yakindu.base.gmf.runtime.decorators.BaseDecorator; +import org.yakindu.sct.model.sgraph.SGraphPackage; +import org.yakindu.sct.model.sgraph.State; import org.yakindu.sct.model.sgraph.Transition; import org.yakindu.sct.model.sgraph.Vertex; import org.yakindu.sct.ui.editor.DiagramActivator; @@ -35,6 +40,7 @@ import org.yakindu.sct.ui.editor.editparts.TransitionEditPart; import org.yakindu.sct.ui.editor.preferences.StatechartPreferenceConstants; + /** * * @author andreas muelder - Initial contribution and API @@ -58,7 +64,7 @@ public void createDecorators(IDecoratorTarget decoratorTarget) { if (!(ed instanceof DiagramEditDomain)) { return; } - if (shouldInstall(((DiagramEditDomain) ed).getEditorPart())) { + if (shouldInstall(((DiagramEditDomain) ed).getEditorPart()) && editPart instanceof TransitionEditPart) { IDecorator decorator = createStatusDecorator(decoratorTarget); decorators.add(decorator); decoratorTarget.installDecorator(getDecoratorKey(), decorator); @@ -84,6 +90,31 @@ public PriorityDecorator(IDecoratorTarget decoratorTarget) { super(decoratorTarget); } + protected NotificationListener transitionPriorityChangeListener = new NotificationListener() { + + public void notifyChanged(Notification notification) { + if (notification.getFeatureID(State.class) == SGraphPackage.STATE__OUTGOING_TRANSITIONS) + refresh(); + } + }; + + @Override + public void activate() { + super.activate(); + //priorities will be changed via reordering the list of transitions within the owning element + Vertex owningElement = (Vertex) ((Transition) semanticElement).eContainer(); + DiagramEventBroker.getInstance(gep.getEditingDomain()).addNotificationListener( + owningElement, transitionPriorityChangeListener); + } + + @Override + public void deactivate() { + Vertex owningElement = (Vertex) ((Transition) semanticElement).eContainer(); + DiagramEventBroker.getInstance(gep.getEditingDomain()).removeNotificationListener( + owningElement, transitionPriorityChangeListener); + super.deactivate(); + } + @Override public void refresh() { removeDecoration(); @@ -120,8 +151,8 @@ public int getPriority(TransitionEditPart editPart) { Transition transition = ((Transition) editPart.resolveSemanticElement()); Vertex container = (Vertex) transition.eContainer(); int indexOf = container.getOutgoingTransitions().indexOf(transition); - //visible priorities should start with 1 - return indexOf+1; + // visible priorities should start with 1 + return indexOf + 1; } }