From 05a3fc489e28927549271b6fe9d19ec2d154770b Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Tue, 17 Jan 2012 08:53:51 +0000
Subject: [PATCH] fixed marker refresh refs 307

---
 .../ui/editpart/PositionedEditPartBase.java   |  6 ++--
 .../kernel/ui/internal/MarkerService.java     | 35 +++++++++++++++----
 .../ui/internal/views/MarkerViewPart.java     | 10 +++---
 .../kernel/ui/service/IMarkerService.java     |  5 +--
 .../extension/data/IConstraintViolation.java  | 15 +++++---
 5 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/PositionedEditPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/PositionedEditPartBase.java
index 6ad550a12..329870060 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/PositionedEditPartBase.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/PositionedEditPartBase.java
@@ -69,7 +69,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 3B050D7FB691B8F17BBADB932EFF2BF2
+ * @ConQAT.Rating YELLOW Hash: 3F8B52876DADB7B723518D32AFDAD2AD
  */
 public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
 		extends GraphicalEditPartBase<T> implements NodeEditPart {
@@ -204,10 +204,9 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
 		decorationFigure.getParent().setConstraint(decorationFigure,
 				decorationBounds);
 
+		Image icon = null;
 		ESeverity sev = IMarkerService.INSTANCE
 				.getHighestViolationSeverity(getModel());
-
-		Image icon = null;
 		switch (sev) {
 		case ERROR:
 			icon = IMarkerService.INSTANCE.getImageFor(ESeverity.ERROR,
@@ -217,6 +216,7 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement>
 			icon = IMarkerService.INSTANCE.getImageFor(ESeverity.WARNING,
 					useSmallDecorationImage()).createImage();
 			break;
+		default:
 		}
 		decorationFigure.setIcon(icon);
 	}
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java
index bd998e86d..ccae8cf20 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/MarkerService.java
@@ -31,6 +31,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.NotificationImpl;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IDecoration;
@@ -55,7 +57,7 @@ import org.fortiss.tooling.kernel.ui.service.IMarkerService;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating YELLOW Hash: BD8AB2A7EDA9DB684707242CAC441F6F
+ * @ConQAT.Rating YELLOW Hash: 242B488A1C4D7DDB614EB3E75F8D9294
  */
 public class MarkerService implements IMarkerService,
 		IPersistencyServiceListener, ILightweightLabelDecorator {
@@ -156,7 +158,7 @@ public class MarkerService implements IMarkerService,
 		ITopLevelElement top = IPersistencyService.INSTANCE
 				.getTopLevelElementFor(element);
 		if (top == null) {
-			return ESeverity.lowest();
+			return null;
 		}
 		return getCacheEntry(top).getHighestSeverity(element);
 	}
@@ -289,6 +291,26 @@ public class MarkerService implements IMarkerService,
 		/** Stores the top-level element. */
 		private ITopLevelElement topElement;
 
+		/** Notification to cause model element display refresh. */
+		private Notification refreshOnly = new NotificationImpl(
+				Notification.EVENT_TYPE_COUNT + 256, null, null);
+
+		/** Stores the display update UI job. */
+		private final UIJob refreshElementDisplay = new UIJob("Update Markers") {
+
+			@Override
+			public IStatus runInUIThread(IProgressMonitor monitor) {
+				for (EObject eo : violationsMap.keySet()) {
+					eo.eNotify(refreshOnly);
+					for (IConstraintViolation<? extends EObject> viol : violationsMap
+							.get(eo)) {
+						viol.getSource().eNotify(refreshOnly);
+					}
+				}
+				return Status.OK_STATUS;
+			}
+		};
+
 		/** Constructor. */
 		public CacheEntry(ITopLevelElement topElement) {
 			this.topElement = topElement;
@@ -296,11 +318,10 @@ public class MarkerService implements IMarkerService,
 
 		/** Returns the highest severity for the given element. */
 		public ESeverity getHighestSeverity(EObject element) {
-			ESeverity severity = highestSeverityMap.get(element);
-			if (severity == null) {
-				severity = ESeverity.lowest();
+			if (!highestSeverityMap.containsKey(element)) {
+				return ESeverity.lowest();
 			}
-			return severity;
+			return highestSeverityMap.get(element);
 		}
 
 		/** Updates the cache entry. */
@@ -325,6 +346,8 @@ public class MarkerService implements IMarkerService,
 			}
 			// project severity to parent
 			computeHighestSeverity(topElement.getRootModelElement());
+			// refresh display
+			refreshElementDisplay.schedule();
 		}
 
 		/** Recursively projects highest severity from children to parents. */
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java
index 6af4ce2b2..c96b5b58f 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java
@@ -55,7 +55,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 2EC4BD8032972D2AFD4E88B3F34E5049
+ * @ConQAT.Rating YELLOW Hash: CBDF2C05D0E2D9AC3FAC9D3030ECAC05
  */
 public class MarkerViewPart extends ViewPart {
 
@@ -113,9 +113,9 @@ public class MarkerViewPart extends ViewPart {
 
 			@Override
 			public Object[] getElements(Object inputElement) {
-				List<ESeverity> result = new ArrayList<ESeverity>(5);
+				List<ESeverity> result = new ArrayList<ESeverity>();
 				for (ESeverity sev : ESeverity.values()) {
-					if (toggleState.get(sev)) {
+					if (sev != ESeverity.lowest() && toggleState.get(sev)) {
 						result.add(sev);
 					}
 				}
@@ -213,7 +213,9 @@ public class MarkerViewPart extends ViewPart {
 
 	/** Refreshes the view. Needs to be called on UI thread. */
 	public void refresh() {
-		gui.getTreeViewer().refresh();
+		if (!gui.getTreeViewer().getControl().isDisposed()) {
+			gui.getTreeViewer().refresh();
+		}
 	}
 
 	/** Creates the toggle actions. */
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IMarkerService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IMarkerService.java
index 88a135768..359cae2ca 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IMarkerService.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IMarkerService.java
@@ -35,7 +35,7 @@ import org.fortiss.tooling.kernel.ui.internal.MarkerService;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 7CA4B3A1CFB5DAA9243A2537F4C75C02
+ * @ConQAT.Rating YELLOW Hash: 2AF8DAFE162ECF932E56C8770FADF137
  */
 public interface IMarkerService {
 
@@ -50,7 +50,8 @@ public interface IMarkerService {
 			EObject element);
 
 	/**
-	 * /** Returns the highest severity for the given element.
+	 * /** Returns the highest severity for the given element or
+	 * <code>null</code> if there are no violations for this element.
 	 */
 	ESeverity getHighestViolationSeverity(EObject element);
 
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java
index 65ecad005..11d749fd3 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java
@@ -37,7 +37,7 @@ import org.fortiss.tooling.kernel.extension.base.ConstraintViolationBase;
  * @author hoelzlf
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating YELLOW Hash: 11AEB121B98133BB02808AA44C0BFFDB
+ * @ConQAT.Rating YELLOW Hash: 7C5D15AAF9D6703ABFECFDF82B5D45B8
  */
 public interface IConstraintViolation<T extends EObject> extends IAdaptable {
 
@@ -64,7 +64,10 @@ public interface IConstraintViolation<T extends EObject> extends IAdaptable {
 		/** Information severity. */
 		INFO,
 		/** Debug severity. */
-		DEBUG;
+		DEBUG,
+
+		/** The lowest None severity. */
+		NONE;
 
 		/** Translates ESeverity to int. */
 		public static int getIntSeverity(ESeverity severity) {
@@ -77,14 +80,16 @@ public interface IConstraintViolation<T extends EObject> extends IAdaptable {
 				return -1;
 			case INFO:
 				return 1;
+			case DEBUG:
+				return 5;
 			}
-			// ESeverity.DEBUG
-			return 5;
+			// ESeverity.NONE
+			return 10000;
 		}
 
 		/** Returns the lowest severity level. */
 		public static ESeverity lowest() {
-			return DEBUG;
+			return NONE;
 		}
 	}
 
-- 
GitLab