From c87dc9a3cb6d49b118beb6993e00c6eb02d54b5c Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Fri, 8 Sep 2017 11:20:56 +0000
Subject: [PATCH] Introduce "ModelEditorNotAvailableBinding"   - It can be used
 to specify that for a particular model element no editor is available.   -
 This avoids that ModelEditorBindingService further walks up the model
 hierarchy to look for an editor that is registered for one of the ancestors.
 Currently, this had the the effect that for a model element without explicit
 editor, the project configuration editor (that is registered for the root
 element "FileProject") has been opened

Use the the new ModelEditorNotAvailableBinding mechanism for the following model elements
  - SystemSchedule
  - AllocationTableCollection
  - SafetyArgumentationPackage
refs 3048
---
 .../ModelEditorNotAvailableBinding.java       | 35 +++++++++++++++++++
 .../internal/ModelEditorBindingService.java   | 15 ++++++--
 2 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100644 org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/ModelEditorNotAvailableBinding.java

diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/ModelEditorNotAvailableBinding.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/ModelEditorNotAvailableBinding.java
new file mode 100644
index 000000000..72789c102
--- /dev/null
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/ModelEditorNotAvailableBinding.java
@@ -0,0 +1,35 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2017 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.kernel.ui.extension;
+
+import org.eclipse.emf.ecore.EObject;
+import org.fortiss.tooling.kernel.ui.extension.base.ModelEditorBindingBase;
+
+/**
+ * A special model editor binding that can be used to indicate that for some model element type no
+ * editor is available.
+ * 
+ * @author barner
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating YELLOW Hash: 7832967A672B8DA3E9DA3EC5F619AF2E
+ */
+public final class ModelEditorNotAvailableBinding extends ModelEditorBindingBase<EObject> {
+	// Nothing to do: The type ModelEditorNotAvailableBinding is used in ModelEditorBindingService
+	// to make a case distinction for model elements without dedicated editors.
+}
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java
index 7822444f4..9b505788a 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java
@@ -51,6 +51,7 @@ import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase;
 import org.fortiss.tooling.kernel.ui.extension.IModelEditor;
 import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding;
 import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
+import org.fortiss.tooling.kernel.ui.extension.ModelEditorNotAvailableBinding;
 import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor;
 import org.fortiss.tooling.kernel.ui.internal.editor.ModelElementEditorInput;
 import org.fortiss.tooling.kernel.ui.internal.introspection.items.ModelEditorBindingServiceIntrospectionDetailsItem;
@@ -65,7 +66,7 @@ import org.fortiss.tooling.kernel.utils.KernelModelElementUtils;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: E0A5099E95B68D133185FE1231BD04D5
+ * @ConQAT.Rating YELLOW Hash: 4C9FA5C29DE00AF287B1AA1F131BB2A5
  */
 public class ModelEditorBindingService extends
 		EObjectAwareServiceBase<IModelEditorBinding<EObject>> implements
@@ -122,6 +123,7 @@ public class ModelEditorBindingService extends
 	/** {@inheritDoc} */
 	@Override
 	public void openInEditor(EObject element) {
+		// TODO (SB,13): Where does the "2" come from? See #3048
 		openInEditor(element, 2);
 	}
 
@@ -145,7 +147,16 @@ public class ModelEditorBindingService extends
 			}
 			return;
 		}
-		if(getBindings(element).isEmpty()) {
+
+		List<IModelEditorBinding<EObject>> bindings = getBindings(element);
+		int numBindings = bindings.size();
+		// There is exactly one binding that indicates that no editor should be displayed.
+		if(numBindings == 1 && bindings.get(0) instanceof ModelEditorNotAvailableBinding) {
+			return;
+		}
+
+		// Recurse if there is an editor for one the model element's ancestors.
+		if(numBindings == 0) {
 			if(depth > 0 && element.eContainer() != null) {
 				openInEditor(element.eContainer(), depth - 1);
 			}
-- 
GitLab