Browse Source

Release and Lock Editor executed in sync display thread

Andreas Muelder 9 years ago
parent
commit
7cb461a9d8

+ 34 - 1
plugins/org.yakindu.base.gmf.runtime/src/org/yakindu/base/gmf/runtime/highlighting/HighlightingSupportAdapter.java

@@ -11,6 +11,7 @@
 package org.yakindu.base.gmf.runtime.highlighting;
 
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -124,7 +125,17 @@ public class HighlightingSupportAdapter implements IHighlightingSupport {
 		if (locked) {
 			throw new IllegalStateException("Editor already locked!");
 		}
+		List<Action> singletonList = new ArrayList<>();
+		singletonList.add(new Action() {
+			@Override
+			public void execute(IHighlightingSupport hs) {
+				lockEditorInternal();
+			}
+		});
+		executeSync(singletonList);
+	}
 
+	private void lockEditorInternal() {
 		setSanityCheckEnablementState(false);
 		for (Object editPart : diagramWorkbenchPart.getDiagramGraphicalViewer().getEditPartRegistry().values()) {
 			if (editPart instanceof IGraphicalEditPart) {
@@ -151,7 +162,17 @@ public class HighlightingSupportAdapter implements IHighlightingSupport {
 		if (!locked) {
 			throw new IllegalStateException("Editor not locked!");
 		}
+		List<Action> singletonList = new ArrayList<>();
+		singletonList.add(new Action() {
+			@Override
+			public void execute(IHighlightingSupport hs) {
+				releaseInternal();
+			}
+		});
+		executeSync(singletonList);
+	}
 
+	protected void releaseInternal() {
 		// restore all elements still being highlighted
 		for (ColorMemento figureState : figureStates.values()) {
 			figureState.restore();
@@ -201,7 +222,7 @@ public class HighlightingSupportAdapter implements IHighlightingSupport {
 		return locked;
 	}
 
-	public void execute(final List<Action> actions) {
+	public void executeAsync(final List<Action> actions) {
 		if (actions != null) {
 
 			Display.getDefault().asyncExec(new Runnable() {
@@ -213,4 +234,16 @@ public class HighlightingSupportAdapter implements IHighlightingSupport {
 			});
 		}
 	}
+	public void executeSync(final List<Action> actions) {
+		if (actions != null) {
+
+			Display.getDefault().syncExec(new Runnable() {
+				public void run() {
+					for (Action a : actions) {
+						a.execute(HighlightingSupportAdapter.this);
+					}
+				}
+			});
+		}
+	}
 }

+ 2 - 2
plugins/org.yakindu.base.gmf.runtime/src/org/yakindu/base/gmf/runtime/highlighting/IHighlightingSupport.java

@@ -32,7 +32,7 @@ public interface IHighlightingSupport {
 
 	void flash(List<? extends EObject> semanticElemesnt, HighlightingParameters parameters, int highlightTime);
 
-	void execute(List<Action> actions);
+	void executeAsync(List<Action> actions);
 
 	public static interface Action {
 		public void execute(IHighlightingSupport hs);
@@ -97,7 +97,7 @@ public interface IHighlightingSupport {
 		}
 
 		@Override
-		public void execute(List<Action> actions) {
+		public void executeAsync(List<Action> actions) {
 		}
 
 		@Override

+ 1 - 1
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/DefaultDynamicNotationHandler.java

@@ -48,7 +48,7 @@ public class DefaultDynamicNotationHandler extends AbstractDynamicNotationHandle
 		actions.add(new IHighlightingSupport.Flash(context.getExecutedElements(), HighlightingParameters.DEFAULT,
 				FLASHTIME));
 		actions.add(new IHighlightingSupport.Highlight(context.getExecutedElements(), SUSPENDED_PARAMS));
-		getHighlightingSupport().execute(actions);
+		getHighlightingSupport().executeAsync(actions);
 	}
 
 	@Override

+ 2 - 2
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/ExecutionContextVisualizer.java

@@ -90,7 +90,7 @@ public class ExecutionContextVisualizer extends CrossDocumentContentAdapter {
 				}
 			}
 		}
-		getHighlightingSupport().execute(actions);
+		getHighlightingSupport().executeAsync(actions);
 	}
 
 	protected void highlight(final Notification notification, HighlightingParameters params) {
@@ -103,7 +103,7 @@ public class ExecutionContextVisualizer extends CrossDocumentContentAdapter {
 			List<EObject> objects = toList(notification.getOldValue());
 			actions.add(new IHighlightingSupport.Highlight(objects, null));
 		}
-		getHighlightingSupport().execute(actions);
+		getHighlightingSupport().executeAsync(actions);
 	}
 
 	@SuppressWarnings("unchecked")

+ 0 - 1
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ExecutionContextContentProvider.java

@@ -41,7 +41,6 @@ public class ExecutionContextContentProvider implements ITreeContentProvider, IP
 					Thread.sleep(UPDATE_INTERVAL);
 					Display.getDefault().asyncExec(new Runnable() {
 						public void run() {
-							System.out.println("running update threade");
 							if (viewer != null && !viewer.getControl().isDisposed() && shouldUpdate)
 								viewer.refresh();
 						}