summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayant Gupta2013-07-17 18:30:15 -0400
committerJayant Gupta2013-09-03 13:02:08 -0400
commit29d00871da4c6d2e18af6a81d2822f78ba7279b1 (patch)
treed206e1bb1438b35063745580f716fbd495ce22aa
parent9bdd3272bca69ef62dc16729b4df3990f8e533e8 (diff)
downloadorg.eclipse.etrice-29d00871da4c6d2e18af6a81d2822f78ba7279b1.zip
org.eclipse.etrice-29d00871da4c6d2e18af6a81d2822f78ba7279b1.tar.gz
org.eclipse.etrice-29d00871da4c6d2e18af6a81d2822f78ba7279b1.tar.xz
Renders error, warning and info markers in eTrice State chart Editor.
1. Generates markers during the editing of the State chart diagrams. 2. Generates by validating the underlying Room Model on each change. 3. Renders over States,TrPoints,Transitions,ChoicePoints & StateGraph. 4. Combines multiple messages(of same type) into a single tool tip. 5. Master switched to Kepler. Change-Id: I99428f8451729d2efe3db0d7576cdc371aa744eb Signed-off-by: Jayant Gupta <gsocjayant@gmail.com>
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java18
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DecoratorUtil.java145
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DiagnosingModelObserver.java146
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ChoicePointSupport.java49
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java48
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java78
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java47
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java46
8 files changed, 525 insertions, 52 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
index 7de6bbe..28259a3 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
@@ -21,11 +21,13 @@ import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.behavior.Activator;
+import org.eclipse.etrice.ui.behavior.markers.DiagnosingModelObserver;
import org.eclipse.etrice.ui.behavior.support.ContextSwitcher;
import org.eclipse.etrice.ui.behavior.support.SupportUtil;
import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
@@ -42,11 +44,16 @@ import org.eclipse.swt.graphics.Image;
public class BehaviorEditor extends RoomDiagramEditor {
public static final String BEHAVIOR_EDITOR_ID = "org.eclipse.etrice.ui.behavior.editor.BehaviorEditor";
+ private DiagnosingModelObserver diagnosingModelObserver;
public BehaviorEditor() {
super();
}
+ public DiagnosingModelObserver getDiagnosingModelObserver() {
+ return diagnosingModelObserver;
+ }
+
@Override
public Image getDefaultImage() {
return Activator.getImage("icons/Behavior.gif");
@@ -54,6 +61,10 @@ public class BehaviorEditor extends RoomDiagramEditor {
@Override
public void initializeGraphicalViewer() {
+ // Start observing the Room Model for rendering Markers
+ diagnosingModelObserver = new DiagnosingModelObserver();
+ diagnosingModelObserver.observeRoomModel((RoomModel)getActorClass().eResource().getContents().get(0));
+
super.initializeGraphicalViewer();
Command cmd = new RecordingCommand(getEditingDomain()) {
@@ -66,6 +77,13 @@ public class BehaviorEditor extends RoomDiagramEditor {
getEditingDomain().getCommandStack().flush();
}
+ @Override
+ public void dispose() {
+ // Stop observing the Room Model
+ diagnosingModelObserver.removeObserver();
+ super.dispose();
+ }
+
public boolean showStateGraph(StateGraph sg) {
URI boUri = EcoreUtil.getURI(sg);
final StateGraph mySG = (StateGraph) getEditingDomain().getResourceSet().getEObject(boUri, true);
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DecoratorUtil.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DecoratorUtil.java
new file mode 100644
index 0000000..fc5c7ce
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DecoratorUtil.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.markers;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.platform.IPlatformImageConstants;
+import org.eclipse.graphiti.tb.IDecorator;
+import org.eclipse.graphiti.tb.ImageDecorator;
+
+/**
+ * A Utility Class for rendering error, warning and info markers in Behavior
+ * Graphical Editor.
+ *
+ * @author jayant
+ */
+public class DecoratorUtil {
+
+ /**
+ * Private Constructor to prevent instanstiation.
+ */
+ private DecoratorUtil() {
+ }
+
+ /**
+ * Converts the list of {@link Diagnostic}s (associated with a
+ * {@link PictogramElement}) to a list of {@link IDecorator}s to be rendered
+ * over the element.
+ *
+ * @param diagnostics
+ * @return A list of IDecorators
+ */
+ public static ArrayList<IDecorator> getMarkersFromDiagnostics(
+ ArrayList<Diagnostic> diagnostics) {
+
+ if (diagnostics == null)
+ return new ArrayList<IDecorator>();
+
+ // Classify each Diagnostic as Error, Warning or Info.
+ HashMap<Integer, Set<String>> severityMessageMap = new HashMap<Integer, Set<String>>();
+ for (Diagnostic diagnostic : diagnostics) {
+
+ switch (diagnostic.getSeverity()) {
+ case Diagnostic.ERROR:
+ addMessage(severityMessageMap, Diagnostic.ERROR,
+ diagnostic.getMessage());
+ break;
+
+ case Diagnostic.WARNING:
+ addMessage(severityMessageMap, Diagnostic.WARNING,
+ diagnostic.getMessage());
+ break;
+
+ case Diagnostic.INFO:
+ addMessage(severityMessageMap, Diagnostic.INFO,
+ diagnostic.getMessage());
+ break;
+ }
+ }
+
+ ArrayList<IDecorator> decorators = new ArrayList<IDecorator>();
+ // Form a combined marker for all Errors
+ if (severityMessageMap.containsKey(Diagnostic.ERROR)) {
+ IDecorator decorator = new ImageDecorator(
+ IPlatformImageConstants.IMG_ECLIPSE_ERROR_TSK);
+ decorator.setMessage(convertSetToString(severityMessageMap
+ .get(Diagnostic.ERROR)));
+ decorators.add(decorator);
+ }
+
+ // Form a combined marker for all Warnings
+ if (severityMessageMap.containsKey(Diagnostic.WARNING)) {
+ IDecorator decorator = new ImageDecorator(
+ IPlatformImageConstants.IMG_ECLIPSE_WARNING_TSK);
+ decorator.setMessage(convertSetToString(severityMessageMap
+ .get(Diagnostic.WARNING)));
+ decorators.add(decorator);
+ }
+
+ // Form a combined marker for all Infos
+ if (severityMessageMap.containsKey(Diagnostic.INFO)) {
+ IDecorator decorator = new ImageDecorator(
+ IPlatformImageConstants.IMG_ECLIPSE_INFORMATION_TSK);
+ decorator.setMessage(convertSetToString(severityMessageMap
+ .get(Diagnostic.INFO)));
+ decorators.add(decorator);
+ }
+
+ return decorators;
+ }
+
+ /**
+ * Adds message to the set of messages associated with the given key in the
+ * map.
+ *
+ * @param map
+ * @param key
+ * @param message
+ *
+ * @author jayant
+ */
+ private static void addMessage(HashMap<Integer, Set<String>> map, int key,
+ String message) {
+ if (!map.containsKey(key)) {
+ map.put(key, new HashSet<String>());
+ }
+ map.get(key).add(message);
+ }
+
+ /**
+ * Form a single message for all messages of the set.
+ *
+ * @param stringSet
+ * @return a single combined message string for all the messages in the set
+ *
+ * @author jayant
+ */
+ private static String convertSetToString(Set<String> stringSet) {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (String string : stringSet) {
+ stringBuilder.append("- ").append(string).append("\n");
+ }
+ stringBuilder.deleteCharAt(stringBuilder.length() - 1);
+
+ if (stringSet.size() == 1)
+ return stringBuilder.substring(2);
+ else
+ return stringBuilder.toString();
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DiagnosingModelObserver.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DiagnosingModelObserver.java
new file mode 100644
index 0000000..236e258
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DiagnosingModelObserver.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.markers;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.StateGraph;
+import org.eclipse.etrice.core.room.Trigger;
+import org.eclipse.xtext.validation.FeatureBasedDiagnostic;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+
+/**
+ * An {@link EContentAdapter} which validates the {@link RoomModel} on each
+ * change notification and stores the results of validation in a {@link HashMap}
+ * of model elements and associated {@link Diagnostic}s.
+ *
+ * @author jayant
+ */
+public class DiagnosingModelObserver extends EContentAdapter {
+
+ /**
+ * A {@link HashMap} for storing {@link Diagnostic}s keyed on the model
+ * elements they belong to.
+ */
+ private HashMap<EObject, ArrayList<Diagnostic>> elementDiagnosticMap;
+
+ /**
+ * The {@link RoomModel} being observed.
+ */
+ private RoomModel roomModel;
+
+ public DiagnosingModelObserver() {
+ elementDiagnosticMap = new HashMap<EObject, ArrayList<Diagnostic>>();
+ }
+
+ /**
+ * Starts listening to changes of the given {@link RoomModel}.
+ *
+ * @param roomModel
+ * @author jayant
+ */
+ public void observeRoomModel(RoomModel roomModel) {
+ // Start observing the room model
+ this.roomModel = roomModel;
+ setTarget(roomModel);
+
+ // Validate and Populate HashMap for rendering markers initially.
+ updateElementDiagonosticMap();
+ }
+
+ /**
+ * Stops observing the {@link RoomModel}.
+ *
+ * @author jayant
+ */
+ public void removeObserver() {
+ unsetTarget(roomModel);
+ }
+
+ /**
+ * {@inheritDoc} Updates elementDiagnosticMap on each notification (except
+ * Adapter Removal)
+ *
+ * @author jayant
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ super.notifyChanged(notification);
+
+ // Re-Validate on each notification except Adapter Removal.
+ // This prevents the editor to hang on dispose (since all adapters are
+ // then removed).
+ if (notification.getEventType() < Notification.REMOVING_ADAPTER) {
+ updateElementDiagonosticMap();
+ }
+ }
+
+ public HashMap<EObject, ArrayList<Diagnostic>> getElementDiagonsticMap() {
+ return elementDiagnosticMap;
+ }
+
+ /**
+ * Updates the elementDiagnosticMap by re-validating the model.
+ *
+ * @author jayant
+ */
+ private void updateElementDiagonosticMap() {
+ // Clear HashMap to remove orphaned element references
+ elementDiagnosticMap.clear();
+
+ // Perform Model Validation and get the diagnostic
+ Diagnostic diagnostics = Diagnostician.INSTANCE.validate(roomModel);
+
+ // Inspect each child diagnostic
+ for (Diagnostic diagnostic : diagnostics.getChildren()) {
+
+ // for each child diagnostic, find the associated EObject
+ FeatureBasedDiagnostic featureBasedDiagnostic = (FeatureBasedDiagnostic) diagnostic;
+ EObject source = featureBasedDiagnostic.getSourceEObject();
+
+ EObject eObject = null;
+ if (source instanceof StateGraph) {
+ EStructuralFeature feature = featureBasedDiagnostic
+ .getFeature();
+ int index = featureBasedDiagnostic.getIndex();
+
+ if (!feature.isMany())
+ eObject = (EObject) source.eGet(feature);
+ else if (index != ValidationMessageAcceptor.INSIGNIFICANT_INDEX) {
+ List<?> list = (List<?>) source.eGet(feature);
+ eObject = (EObject) list.get(index);
+ }
+ } else if (source instanceof Trigger)
+ eObject = source.eContainer();
+ else
+ eObject = source;
+
+ if (eObject != null) {
+ // Add diagnostic to elementDiagnosticMap keyed on model element
+ if (elementDiagnosticMap.get(eObject) == null)
+ elementDiagnosticMap.put(eObject,
+ new ArrayList<Diagnostic>());
+ elementDiagnosticMap.get(eObject).add(diagnostic);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ChoicePointSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ChoicePointSupport.java
index 3108fd3..efec629 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ChoicePointSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ChoicePointSupport.java
@@ -12,6 +12,9 @@
package org.eclipse.etrice.ui.behavior.support;
+import java.util.ArrayList;
+
+import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.naming.RoomNameProvider;
@@ -21,6 +24,8 @@ import org.eclipse.etrice.core.room.RoomFactory;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.ui.behavior.ImageProvider;
import org.eclipse.etrice.ui.behavior.dialogs.ChoicePointPropertyDialog;
+import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil;
import org.eclipse.etrice.ui.common.support.CommonSupportUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.etrice.ui.common.support.NoResizeFeature;
@@ -73,7 +78,9 @@ import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.tb.ContextButtonEntry;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
import org.eclipse.graphiti.tb.IContextButtonPadData;
+import org.eclipse.graphiti.tb.IDecorator;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.tb.ImageDecorator;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
import org.eclipse.graphiti.util.ColorConstant;
import org.eclipse.graphiti.util.IColorConstant;
@@ -583,6 +590,48 @@ public class ChoicePointSupport {
return data;
}
+
+ /**
+ * @author jayant
+ */
+ @Override
+ public IDecorator[] getDecorators(PictogramElement pe) {
+ // Constants for positioning decorators
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+ GraphicsAlgorithm rectangle = invisible
+ .getGraphicsAlgorithmChildren().get(0);
+ int xOrigin = rectangle.getX();
+ int yOrigin = rectangle.getY();
+ int xGap = 10, yGap = 0;
+
+ // Get the linked Business Object
+ EObject bo = Graphiti.getLinkService()
+ .getBusinessObjectForLinkedPictogramElement(pe);
+
+ // Get Diagnostics associated with the business object
+ ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider()
+ .getDiagramBehavior().getDiagramContainer())
+ .getDiagnosingModelObserver().getElementDiagonsticMap()
+ .get(bo);
+
+ // Form Decorators based on Diagnostics
+ ArrayList<IDecorator> decorators = DecoratorUtil
+ .getMarkersFromDiagnostics(diagnostics);
+
+ if (decorators.isEmpty())
+ return super.getDecorators(pe);
+ else {
+ int i = 0;
+ for (IDecorator decorator : decorators) {
+ ((ImageDecorator) decorator).setX(xOrigin + xGap * i);
+ ((ImageDecorator) decorator).setY(yOrigin + yGap * i);
+ i++;
+ }
+
+ return (IDecorator[]) decorators
+ .toArray(new IDecorator[decorators.size()]);
+ }
+ }
}
private FeatureProvider pfp;
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
index d2a2f1b..93971f3 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
@@ -12,8 +12,10 @@
package org.eclipse.etrice.ui.behavior.support;
+import java.util.ArrayList;
import java.util.List;
+import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.naming.RoomNameProvider;
@@ -23,6 +25,8 @@ import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.Transition;
import org.eclipse.etrice.ui.behavior.commands.StateGraphContext;
+import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
@@ -63,7 +67,9 @@ import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IDecorator;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.tb.ImageDecorator;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
import org.eclipse.graphiti.util.ColorConstant;
import org.eclipse.graphiti.util.IColorConstant;
@@ -588,6 +594,48 @@ public class StateGraphSupport {
public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
return new FeatureProvider.GoUpFeature(getDiagramTypeProvider().getFeatureProvider());
}
+
+ /**
+ * @author jayant
+ */
+ @Override
+ public IDecorator[] getDecorators(PictogramElement pe) {
+ // Constants for positioning decorators
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+ GraphicsAlgorithm rectangle = invisible
+ .getGraphicsAlgorithmChildren().get(0);
+ int xOrigin = rectangle.getX();
+ int yOrigin = rectangle.getY();
+ int xGap = 10, yGap = 0;
+
+ // Get the linked Business Object
+ EObject bo = Graphiti.getLinkService()
+ .getBusinessObjectForLinkedPictogramElement(pe);
+
+ // Get Diagnostics associated with the business object
+ ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider()
+ .getDiagramBehavior().getDiagramContainer())
+ .getDiagnosingModelObserver().getElementDiagonsticMap()
+ .get(bo);
+
+ // Form Decorators based on Diagnostics
+ ArrayList<IDecorator> decorators = DecoratorUtil
+ .getMarkersFromDiagnostics(diagnostics);
+
+ if (decorators.isEmpty())
+ return super.getDecorators(pe);
+ else {
+ int i = 0;
+ for (IDecorator decorator : decorators) {
+ ((ImageDecorator) decorator).setX(xOrigin + xGap * i);
+ ((ImageDecorator) decorator).setY(yOrigin + yGap * i);
+ i++;
+ }
+
+ return (IDecorator[]) decorators
+ .toArray(new IDecorator[decorators.size()]);
+ }
+ }
}
private FeatureProvider afp;
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
index e78d3dc..28831b8 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
@@ -13,12 +13,9 @@
package org.eclipse.etrice.ui.behavior.support;
import java.util.ArrayList;
-import java.util.List;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.etrice.core.room.ActorClass;
@@ -31,6 +28,8 @@ import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.behavior.ImageProvider;
import org.eclipse.etrice.ui.behavior.dialogs.StatePropertyDialog;
+import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil;
import org.eclipse.etrice.ui.common.support.CommonSupportUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.graphiti.datatypes.IDimension;
@@ -84,7 +83,6 @@ import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
-import org.eclipse.graphiti.platform.IPlatformImageConstants;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
@@ -1086,65 +1084,41 @@ public class StateSupport {
*/
@Override
public IDecorator[] getDecorators(PictogramElement pe) {
- //Some constants for decorator
+ // Constants for positioning decorators
GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
- GraphicsAlgorithm rectangle = invisible.getGraphicsAlgorithmChildren().get(0);
+ GraphicsAlgorithm rectangle = invisible
+ .getGraphicsAlgorithmChildren().get(0);
int xOrigin = rectangle.getX();
int yOrigin = rectangle.getY();
- ArrayList<IDecorator> decorators = new ArrayList<IDecorator>();
+ int xGap = 10, yGap = 0;
- //Get the linked Business Object
+ // Get the linked Business Object
EObject bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(pe);
- //Validate the compete ROOM Model and Get Diagnostics
- EObject myModel = bo.eResource().getContents().get(0);
- Diagnostic diagnostics = Diagnostician.INSTANCE.validate(myModel);
+ // Get Diagnostics associated with the business object
+ ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider()
+ .getDiagramBehavior().getDiagramContainer())
+ .getDiagnosingModelObserver().getElementDiagonsticMap()
+ .get(bo);
- //Inspect each child diagnostic
- for (Diagnostic diagnostic : diagnostics.getChildren()) {
-
- //for each child diagnostic, find the associated EObject
- FeatureBasedDiagnostic featureBasedDiagnostic = (FeatureBasedDiagnostic)diagnostic;
- EObject source = featureBasedDiagnostic.getSourceEObject();
- EStructuralFeature feature = featureBasedDiagnostic.getFeature();
- int index = featureBasedDiagnostic.getIndex();
- EObject eObject = null;
- if (!feature.isMany())
- eObject = (EObject) source.eGet(feature);
- else {
- List<?> list = (List<?>) source.eGet(feature);
- eObject = (EObject) list.get(index);
- }
-
- //compare the diagnostic EObject with the Business object linked with the pictogram element
- //if they are equal, add entry to IDecorator[]
- if (eObject.equals(bo)){
- ImageDecorator imageRenderingDecorator = null;
- switch (diagnostic.getSeverity()) {
- case Diagnostic.ERROR:
- imageRenderingDecorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR_TSK);
- break;
- case Diagnostic.WARNING:
- imageRenderingDecorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_WARNING_TSK);
- break;
- case Diagnostic.INFO:
- imageRenderingDecorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_INFORMATION_TSK);
- break;
- }
- if (imageRenderingDecorator != null){
- imageRenderingDecorator.setMessage(diagnostic.getMessage());
- imageRenderingDecorator.setX(xOrigin);
- imageRenderingDecorator.setY(yOrigin);
- decorators.add(imageRenderingDecorator);
- }
- }
- }
+ // Form Decorators based on Diagnostics
+ ArrayList<IDecorator> decorators = DecoratorUtil
+ .getMarkersFromDiagnostics(diagnostics);
if (decorators.isEmpty())
return super.getDecorators(pe);
- else
- return (IDecorator[]) decorators.toArray(new IDecorator[decorators.size()]);
+ else {
+ int i = 0;
+ for (IDecorator decorator : decorators) {
+ ((ImageDecorator) decorator).setX(xOrigin + xGap * i);
+ ((ImageDecorator) decorator).setY(yOrigin + yGap * i);
+ i++;
+ }
+
+ return (IDecorator[]) decorators
+ .toArray(new IDecorator[decorators.size()]);
+ }
}
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
index fa0dc3f..0dbfec8 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
@@ -12,8 +12,10 @@
package org.eclipse.etrice.ui.behavior.support;
+import java.util.ArrayList;
import java.util.List;
+import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.naming.RoomNameProvider;
@@ -29,6 +31,8 @@ import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.etrice.ui.behavior.ImageProvider;
import org.eclipse.etrice.ui.behavior.dialogs.TrPointPropertyDialog;
+import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil;
import org.eclipse.etrice.ui.common.support.CommonSupportUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.etrice.ui.common.support.NoResizeFeature;
@@ -86,7 +90,9 @@ import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.tb.ContextButtonEntry;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
import org.eclipse.graphiti.tb.IContextButtonPadData;
+import org.eclipse.graphiti.tb.IDecorator;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.tb.ImageDecorator;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
import org.eclipse.graphiti.util.ColorConstant;
import org.eclipse.graphiti.util.IColorConstant;
@@ -980,6 +986,47 @@ public class TrPointSupport {
return data;
}
+
+ /**
+ * @author jayant
+ */
+ @Override
+ public IDecorator[] getDecorators(PictogramElement pe) {
+ // Constants for positioning decorators
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ GraphicsAlgorithm port = ga.getGraphicsAlgorithmChildren().get(0);
+ int xOrigin = port.getX() + 6;
+ int yOrigin = port.getY() - 6;
+ int xGap = 0, yGap = 7;
+
+ // Get the linked Business Object
+ EObject bo = Graphiti.getLinkService()
+ .getBusinessObjectForLinkedPictogramElement(pe);
+
+ // Get Diagnostics associated with the business object
+ ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider()
+ .getDiagramBehavior().getDiagramContainer())
+ .getDiagnosingModelObserver().getElementDiagonsticMap()
+ .get(bo);
+
+ // Form Decorators based on Diagnostics
+ ArrayList<IDecorator> decorators = DecoratorUtil
+ .getMarkersFromDiagnostics(diagnostics);
+
+ if (decorators.isEmpty())
+ return super.getDecorators(pe);
+ else {
+ int i = 0;
+ for (IDecorator decorator : decorators) {
+ ((ImageDecorator) decorator).setX(xOrigin + xGap * i);
+ ((ImageDecorator) decorator).setY(yOrigin + yGap * i);
+ i++;
+ }
+
+ return (IDecorator[]) decorators
+ .toArray(new IDecorator[decorators.size()]);
+ }
+ }
}
private FeatureProvider pfp;
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java
index c5eae86..1d00fbf 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java
@@ -14,6 +14,7 @@ package org.eclipse.etrice.ui.behavior.support;
import java.util.ArrayList;
+import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.naming.RoomNameProvider;
@@ -38,6 +39,8 @@ import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.etrice.ui.behavior.ImageProvider;
import org.eclipse.etrice.ui.behavior.dialogs.TransitionPropertyDialog;
+import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.graphiti.datatypes.ILocation;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
@@ -86,7 +89,9 @@ import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IDecorator;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.tb.ImageDecorator;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
import org.eclipse.graphiti.util.ColorConstant;
import org.eclipse.graphiti.util.IColorConstant;
@@ -901,6 +906,47 @@ public class TransitionSupport {
return super.getToolTip(ga);
}
+
+ /**
+ * @author jayant
+ */
+ @Override
+ public IDecorator[] getDecorators(PictogramElement pe) {
+ if (pe.isVisible()) {
+ // Constants for positioning decorators
+ int xOrigin = -20, yOrigin = 0; // Position to the left of label
+ int xGap = 0, yGap = -10;
+
+ // Get the linked Business Object
+ EObject bo = Graphiti.getLinkService()
+ .getBusinessObjectForLinkedPictogramElement(
+ (PictogramElement) pe.eContainer());
+
+ // Get Diagnostics associated with the business object
+ ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider()
+ .getDiagramBehavior().getDiagramContainer())
+ .getDiagnosingModelObserver().getElementDiagonsticMap()
+ .get(bo);
+
+ // Form Decorators based on Diagnostics
+ ArrayList<IDecorator> decorators = DecoratorUtil
+ .getMarkersFromDiagnostics(diagnostics);
+
+ if (!decorators.isEmpty()) {
+ int i = 0;
+ for (IDecorator decorator : decorators) {
+ ((ImageDecorator) decorator).setX(xOrigin + i * xGap);
+ ((ImageDecorator) decorator).setY(yOrigin + i * yGap);
+ i++;
+ }
+
+ return (IDecorator[]) decorators
+ .toArray(new IDecorator[decorators.size()]);
+ }
+ }
+
+ return super.getDecorators(pe);
+ }
}
private FeatureProvider pfp;