From 217114e96b65846db8cf7a1e15bca8eadd290770 Mon Sep 17 00:00:00 2001
From: Daniel Ratiu <ratiu@fortiss.org>
Date: Tue, 4 Dec 2012 20:15:49 +0000
Subject: [PATCH] disabling the graphical editor and the property sections in
 the case of references to library elements refs 694

---
 .../base/ui/editor/DiagramEditorBase.java     |  7 ++-
 .../extension/base/PropertySectionBase.java   | 42 +++++++++++-----
 .../kernel/internal/LibraryService.java       | 49 +++++++++++++++++++
 .../kernel/service/ILibraryService.java       | 43 ++++++++++++++++
 4 files changed, 128 insertions(+), 13 deletions(-)
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/LibraryService.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ILibraryService.java

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java
index f895b080f..f7d0fadcf 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java
@@ -86,6 +86,7 @@ import org.fortiss.tooling.base.ui.editpart.ConnectorEditPartBase;
 import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase;
 import org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart;
 import org.fortiss.tooling.base.ui.layout.IDiagramLayoutConfiguration;
+import org.fortiss.tooling.kernel.service.ILibraryService;
 import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
 import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
 import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
@@ -100,7 +101,7 @@ import org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 1CAE889ED373A9B30794E5A4082AE081
+ * @ConQAT.Rating YELLOW Hash: ED4D836D8777F3C81641AFB476504921
  */
 public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> implements
 		IPostSelectionProvider, ContextMenuContextProvider {
@@ -206,6 +207,10 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> imple
 						return getHost().getRoot().getContents().getTargetEditPart(request);
 					}
 				});
+
+		if(ILibraryService.INSTANCE.isShadowElement(editedObject)) {
+			((ScalableRootEditPart)viewer.getRootEditPart()).deactivate();
+		}
 	}
 
 	/**
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java
index 7ed063857..03005c84b 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java
@@ -17,14 +17,20 @@ $Id$
 +--------------------------------------------------------------------------*/
 package org.fortiss.tooling.kernel.ui.extension.base;
 
+import static org.eclipse.core.databinding.conversion.NumberToStringConverter.fromDouble;
+import static org.eclipse.core.databinding.conversion.NumberToStringConverter.fromInteger;
+import static org.eclipse.core.databinding.conversion.StringToNumberConverter.toDouble;
+import static org.eclipse.core.databinding.conversion.StringToNumberConverter.toInteger;
+import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY;
+import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
+
 import org.conqat.ide.commons.ui.databinding.validate.NumberPositiveValidator;
 import org.conqat.ide.commons.ui.databinding.validate.TextToDoubleValidator;
 import org.conqat.ide.commons.ui.databinding.validate.TextToIntegerValidator;
-import org.eclipse.core.databinding.conversion.NumberToStringConverter;
-import org.eclipse.core.databinding.conversion.StringToNumberConverter;
 import org.eclipse.core.databinding.observable.value.IObservableValue;
 import org.eclipse.core.databinding.validation.IValidator;
 import org.eclipse.emf.databinding.EMFDataBindingContext;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.gef.EditPart;
 import org.eclipse.jface.fieldassist.ControlDecoration;
 import org.eclipse.jface.layout.GridDataFactory;
@@ -40,7 +46,8 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
-import org.fortiss.tooling.kernel.ui.util.DataBindingUtils;
+import org.fortiss.tooling.kernel.model.ILibraryElementReference;
+import org.fortiss.tooling.kernel.service.ILibraryService;
 
 /**
  * Base class for property sections, dealing with setting the input and
@@ -49,7 +56,7 @@ import org.fortiss.tooling.kernel.ui.util.DataBindingUtils;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 532E5AECE5CF1BAB9CC2A690D10FAC34
+ * @ConQAT.Rating YELLOW Hash: F463D51EE5F523EE8929648DB7D105C7
  */
 public abstract class PropertySectionBase extends AbstractPropertySection {
 
@@ -91,9 +98,24 @@ public abstract class PropertySectionBase extends AbstractPropertySection {
 		if(object instanceof EditPart) {
 			object = ((EditPart)object).getModel();
 		}
+
+		disableControlsForLibraryReferences(object);
 		setSectionInput(object);
 	}
 
+	/** Disables the graphical controls in the case we are in an {@link ILibraryElementReference}. */
+	private void disableControlsForLibraryReferences(Object object) {
+		if(object instanceof EObject) {
+			EObject eobj = (EObject)object;
+
+			if(ILibraryService.INSTANCE.isShadowElement(eobj)) {
+				for(Control c : composite.getChildren()) {
+					c.setEnabled(false);
+				}
+			}
+		}
+	}
+
 	/** This is used to set the single section input. The parameter may be null! */
 	protected abstract void setSectionInput(Object input);
 
@@ -103,8 +125,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection {
 	 */
 	protected Text createDecoratedText(String labelText) {
 		Text text = createFormText(labelText);
-		text.setData(DataBindingUtils.DECORATION_KEY, new ControlDecoration(text, SWT.LEFT |
-				SWT.TOP));
+		text.setData(DECORATION_KEY, new ControlDecoration(text, SWT.LEFT | SWT.TOP));
 		return text;
 	}
 
@@ -153,8 +174,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection {
 	/** Binds a double value. */
 	protected void bindDoubleValue(Control text, IObservableValue observedValue,
 			IValidator numberValidator) {
-		DataBindingUtils.performComplexTextBinding(dbc, text, observedValue,
-				NumberToStringConverter.fromDouble(false), StringToNumberConverter.toDouble(false),
+		performComplexTextBinding(dbc, text, observedValue, fromDouble(false), toDouble(false),
 				TextToDoubleValidator.INSTANCE, numberValidator);
 	}
 
@@ -166,9 +186,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection {
 	/** Binds a integer value. */
 	protected void bindIntegerValue(Control text, IObservableValue observedValue,
 			IValidator numberValidator) {
-		DataBindingUtils.performComplexTextBinding(dbc, text, observedValue,
-				NumberToStringConverter.fromInteger(false),
-				StringToNumberConverter.toInteger(false), TextToIntegerValidator.INSTANCE,
-				numberValidator);
+		performComplexTextBinding(dbc, text, observedValue, fromInteger(false), toInteger(false),
+				TextToIntegerValidator.INSTANCE, numberValidator);
 	}
 }
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/LibraryService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/LibraryService.java
new file mode 100644
index 000000000..e32071620
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/LibraryService.java
@@ -0,0 +1,49 @@
+/*--------------------------------------------------------------------------+
+$Id: PersistencyService.java 5274 2012-08-02 07:54:11Z mou $
+|                                                                          |
+| Copyright 2011 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.internal;
+
+import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
+
+import org.eclipse.emf.ecore.EObject;
+import org.fortiss.tooling.kernel.model.ILibraryElementReference;
+import org.fortiss.tooling.kernel.service.ILibraryService;
+
+/**
+ * This class implements the {@link ILibraryService} interface.
+ * 
+ * @author ratiu
+ * @author $Author: ratiu $
+ * @version $Rev: 5274 $
+ * @ConQAT.Rating YELLOW Hash: 4117552CB9BEEB37BBA33FF9982D5337
+ */
+public class LibraryService implements ILibraryService {
+
+	/** {@inheritDoc} */
+	@Override
+	public boolean isShadowElement(EObject eobj) {
+		ILibraryElementReference parent = getParentElement(eobj, ILibraryElementReference.class);
+
+		// with "eobj.eContainer() != parent" we assume that the model elements are not directly
+		// contained in the reference
+		if(parent != null && parent != eobj && eobj.eContainer() != parent) {
+			return true;
+		}
+
+		return false;
+	}
+}
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ILibraryService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ILibraryService.java
new file mode 100644
index 000000000..39092f4b1
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ILibraryService.java
@@ -0,0 +1,43 @@
+/*--------------------------------------------------------------------------+
+$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+|                                                                          |
+| Copyright 2012 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.service;
+
+import org.eclipse.emf.ecore.EObject;
+import org.fortiss.tooling.kernel.internal.LibraryService;
+import org.fortiss.tooling.kernel.model.ILibraryElementReference;
+
+/**
+ * The library service provides high level access to the library.
+ * 
+ * @author ratiu
+ * @author $Author: hoelzl $
+ * @version $Rev: 18709 $
+ * @ConQAT.Rating YELLOW Hash: 5341C5373D0AC230E766D56C82E331C4
+ */
+public interface ILibraryService {
+
+	/** Returns the singleton instance of the service. */
+	public static final ILibraryService INSTANCE = new LibraryService();
+
+	/**
+	 * Returns true if the parameter is a shadow of a library element.
+	 * A shadow is a temporary copy of an element, contained inside an
+	 * {@link ILibraryElementReference}.
+	 */
+	public boolean isShadowElement(EObject anObject);
+}
-- 
GitLab