From abe9e8b6b21d91620b6c828d0282a40463399d14 Mon Sep 17 00:00:00 2001
From: Daniel Ratiu <ratiu@fortiss.org>
Date: Mon, 19 Nov 2012 10:42:17 +0000
Subject: [PATCH] first steps towards the library refs 694

---
 .../dialog/ElementTreeSingleSelectDialog.java | 39 +++++++++-
 .../trunk/model/base.ecore                    |  6 ++
 .../trunk/model/base.genmodel                 |  1 +
 .../trunk/plugin.xml                          |  8 ++
 .../ElementWithURIPropertySection.java        | 74 +++++++++++++++++++
 .../kernel/ui/internal/views/LibraryView.java |  1 +
 .../views/NavigatorTreeContentProvider.java   | 20 ++++-
 .../ui/internal/views/NavigatorViewPart.java  | 18 +++++
 .../kernel/ui/util/EObjectSelectionUtils.java |  8 +-
 .../trunk/model/kernel.ecore                  | 25 +++++++
 .../trunk/model/kernel.genmodel               |  7 ++
 .../extension/base/PrototypeProviderBase.java |  2 +-
 .../extension/data/LibraryPrototype.java      | 40 ++++++++++
 .../kernel/extension/data/Prototype.java      |  4 +-
 .../kernel/utils/KernelModelElementUtils.java | 28 +++++++
 15 files changed, 273 insertions(+), 8 deletions(-)
 create mode 100644 org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/properties/ElementWithURIPropertySection.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/LibraryPrototype.java

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java
index cc2b12ed7..bf3c31a76 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java
@@ -71,6 +71,12 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
 	/** The gui composite */
 	private ElementTreeSingleSelectDialogGUI gui;
 
+	/** The title of the dialog. */
+	private String dialogTitle = "Select";
+
+	/** The message that explains what should be selected. */
+	private String selectionMessage = "Select an element";
+
 	/**
 	 * Main constructor
 	 * 
@@ -109,13 +115,42 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
 		}
 	}
 
+	/**
+	 * Constructor.
+	 * 
+	 * @param parentShell
+	 *            the parent shell
+	 * @param dialogTitle
+	 *            the title of the dialog
+	 * @param selectionMessage
+	 *            the message explaining what is the selection about
+	 * @param roots
+	 *            the root elements
+	 * @param selected
+	 *            the pre-selected element or null
+	 * @param contentProvider
+	 *            the content provider
+	 * @param labelProvider
+	 *            the label provider
+	 * @param edit
+	 *            the editing module or null
+	 */
+	public ElementTreeSingleSelectDialog(Shell parentShell, String dialogTitle,
+			String selectionMessage, List<?> roots, Object selected,
+			ITreeContentProvider contentProvider, ILabelProvider labelProvider,
+			IDialogEditSupport edit) {
+		this(parentShell, roots, selected, contentProvider, labelProvider, edit);
+		this.dialogTitle = dialogTitle;
+		this.selectionMessage = selectionMessage;
+	}
+
 	/** {@inheritDoc} */
 	@Override
 	protected Control createDialogArea(Composite parent) {
 		setHelpAvailable(false);
 
-		setTitle("Select");
-		setMessage("Select an element");
+		setTitle(dialogTitle);
+		setMessage(selectionMessage);
 
 		// create controls
 		Composite area = (Composite)super.createDialogArea(parent);
diff --git a/org.fortiss.tooling.base/trunk/model/base.ecore b/org.fortiss.tooling.base/trunk/model/base.ecore
index c7a15f016..9e3ecdb08 100644
--- a/org.fortiss.tooling.base/trunk/model/base.ecore
+++ b/org.fortiss.tooling.base/trunk/model/base.ecore
@@ -141,6 +141,12 @@
         <details key="documentation" value="Super class of hidden model element specifications that represent annotations."/>
       </eAnnotations>
     </eClassifiers>
+    <eClassifiers xsi:type="ecore:EDataType" name="IModelElementSpecificationArray"
+        instanceClassName="org.fortiss.tooling.base.model.element.IModelElementSpecification[]">
+      <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
+        <details key="documentation" value="An array of model element specifications."/>
+      </eAnnotations>
+    </eClassifiers>
   </eSubpackages>
   <eSubpackages name="layout" nsURI="http://www.fortiss.org/tooling/base/model/layout"
       nsPrefix="org-fortiss-tooling-base-model-layout">
diff --git a/org.fortiss.tooling.base/trunk/model/base.genmodel b/org.fortiss.tooling.base/trunk/model/base.genmodel
index c4edb8b0e..0c1efdbc2 100644
--- a/org.fortiss.tooling.base/trunk/model/base.genmodel
+++ b/org.fortiss.tooling.base/trunk/model/base.genmodel
@@ -10,6 +10,7 @@
       ecorePackage="base.ecore#/">
     <nestedGenPackages prefix="Element" basePackage="org.fortiss.tooling.base.model"
         disposableProviderFactory="true" ecorePackage="base.ecore#//element">
+      <genDataTypes ecoreDataType="base.ecore#//element/IModelElementSpecificationArray"/>
       <genClasses ecoreClass="base.ecore#//element/IModelElement">
         <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference base.ecore#//element/IModelElement/specifications"/>
         <genFeatures notify="false" createChild="false" propertySortChoices="true"
diff --git a/org.fortiss.tooling.kernel.ui/trunk/plugin.xml b/org.fortiss.tooling.kernel.ui/trunk/plugin.xml
index c0ffbc07a..6929af667 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/plugin.xml
+++ b/org.fortiss.tooling.kernel.ui/trunk/plugin.xml
@@ -97,6 +97,14 @@
                   type="org.fortiss.tooling.kernel.model.INamedCommentedElement">
             </input>
          </propertySection>
+         <propertySection
+               class="org.fortiss.tooling.kernel.ui.internal.properties.ElementWithURIPropertySection"
+               id="org.fortiss.tooling.kernel.ui.internal.properties.ElementWithURIPropertySection"
+               tab="org.fortiss.tooling.kernel.ui.property.tab.general">
+            <input
+                  type="org.fortiss.tooling.kernel.model.IElementWithURI">
+            </input>
+         </propertySection>
       </propertySections>
    </extension>
    <extension
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/properties/ElementWithURIPropertySection.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/properties/ElementWithURIPropertySection.java
new file mode 100644
index 000000000..889cd5592
--- /dev/null
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/properties/ElementWithURIPropertySection.java
@@ -0,0 +1,74 @@
+/*--------------------------------------------------------------------------+
+$Id: IdLabeledPropertySection.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.ui.internal.properties;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+import org.fortiss.tooling.kernel.model.FortissToolingKernelPackage;
+import org.fortiss.tooling.kernel.model.IElementWithURI;
+import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
+import org.fortiss.tooling.kernel.ui.util.ObservableUtils;
+
+/**
+ * Property section for {@link IElementWithURI}s.
+ * 
+ * @author ratiu
+ * @author $Author: ratiu $
+ * @version $Rev: 5274 $
+ * @ConQAT.Rating GREEN Hash: E6A4B98E0681984D8DCCBFFBF99412CA
+ */
+public final class ElementWithURIPropertySection extends PropertySectionBase {
+
+	/** URI edit widget. */
+	private Text uriText;
+
+	/** Stores the current input. */
+	private IElementWithURI elementWithURI;
+
+	/** {@inheritDoc} */
+	@Override
+	public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
+		super.createControls(parent, aTabbedPropertySheetPage);
+		uriText = createFormText("URI");
+		uriText.setEnabled(false);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected void setSectionInput(Object input) {
+		if(input instanceof IElementWithURI) {
+			elementWithURI = (IElementWithURI)input;
+		}
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public void refresh() {
+		super.refresh();
+
+		IObservableValue modelObservable =
+				ObservableUtils.observeValue(elementWithURI,
+						FortissToolingKernelPackage.Literals.IELEMENT_WITH_URI__URI);
+		dbc.bindValue(SWTObservables.observeText(uriText, SWT.FocusOut), modelObservable, null,
+				null);
+	}
+}
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java
index 061f3615c..51aefacbe 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java
@@ -252,6 +252,7 @@ public class LibraryView extends ViewPart {
 			}
 
 			IEditorPart part = (IEditorPart)workbenchPart;
+			viewer.setInput(IPrototypeService.INSTANCE.getAllPrototypesByCategory());
 			switchWorkbenchEditor(part);
 		}
 	}
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorTreeContentProvider.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorTreeContentProvider.java
index 73f21a5cb..a87d9122a 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorTreeContentProvider.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorTreeContentProvider.java
@@ -24,6 +24,7 @@ import java.util.List;
 import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
 import org.eclipse.emf.ecore.EObject;
 import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
+import org.fortiss.tooling.kernel.model.ILibrary;
 import org.fortiss.tooling.kernel.service.IPersistencyService;
 import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
 import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
@@ -41,6 +42,9 @@ public class NavigatorTreeContentProvider extends TreeContentProviderBase {
 	/** Stores whether the expert view is active. **/
 	private boolean expertViewActive = false;
 
+	/** Stores whether the library view is active. **/
+	private boolean libraryViewActive = false;
+
 	/** {@inheritDoc} */
 	@Override
 	public Object[] getElements(Object inputElement) {
@@ -48,7 +52,13 @@ public class NavigatorTreeContentProvider extends TreeContentProviderBase {
 		List<EObject> result = new LinkedList<EObject>();
 
 		for(ITopLevelElement context : IPersistencyService.INSTANCE.getTopLevelElements()) {
-			result.add(context.getRootModelElement());
+			EObject root = context.getRootModelElement();
+			if(libraryViewActive && root instanceof ILibrary) {
+				result.add(root);
+			}
+			if(!libraryViewActive && !(root instanceof ILibrary)) {
+				result.add(root);
+			}
 		}
 		return result.toArray();
 	}
@@ -108,6 +118,14 @@ public class NavigatorTreeContentProvider extends TreeContentProviderBase {
 		expertViewActive = !expertViewActive;
 	}
 
+	/**
+	 * Change to the library view. When library view is active then libraries are
+	 * displayed in the tree.
+	 */
+	public void toggleLibraryView() {
+		libraryViewActive = !libraryViewActive;
+	}
+
 	/** Returns whether expert view is active. */
 	public boolean isExpertViewActive() {
 		return expertViewActive;
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java
index a2e1b245a..a8c030e0e 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java
@@ -93,6 +93,9 @@ public final class NavigatorViewPart extends ViewPart implements ISelectionListe
 	/** Toggle expert view filter action. */
 	private Action toggleExpertViewAction = null;
 
+	/** Change to library/non-library view action. */
+	private Action toggleLibraryViewAction = null;
+
 	/** Dialog setting ID for the link with editor action flag. */
 	private static final String LINK_WITH_EDITOR_FLAG = "navigatorSettingLinkWithEditor";
 
@@ -181,6 +184,19 @@ public final class NavigatorViewPart extends ViewPart implements ISelectionListe
 		linkWithEditorAction.setToolTipText("Link with editor");
 		linkWithEditorAction.setChecked(settings.getBoolean(LINK_WITH_EDITOR_FLAG));
 
+		toggleLibraryViewAction = new Action("Toggle library view", SWT.TOGGLE) {
+
+			@Override
+			public void run() {
+				((NavigatorTreeContentProvider)viewer.getContentProvider()).toggleLibraryView();
+				viewer.refresh();
+			}
+		};
+
+		toggleLibraryViewAction.setImageDescriptor(ToolingKernelUIActivator
+				.getImageDescriptor("icons/library.png"));
+		toggleLibraryViewAction.setToolTipText("Toggle library view");
+
 		toggleExpertViewAction = new Action("Toggle expert view", SWT.TOGGLE) {
 
 			@Override
@@ -198,8 +214,10 @@ public final class NavigatorViewPart extends ViewPart implements ISelectionListe
 		Separator additionsSeperator = new Separator("additions");
 		additionsSeperator.setVisible(true);
 		toolBarManager.add(additionsSeperator);
+
 		toolBarManager.insertAfter("additions", toggleExpertViewAction);
 		toolBarManager.insertAfter("additions", linkWithEditorAction);
+		toolBarManager.insertAfter("additions", toggleLibraryViewAction);
 	}
 
 	/** Creates the context menu. */
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java
index 2d30e7c1f..d7c2e770c 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java
@@ -26,6 +26,7 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 
 /**
@@ -85,7 +86,8 @@ public final class EObjectSelectionUtils {
 	 * @return the current selection
 	 */
 	public static ISelection getCurrentSelection() {
-		return getSelectionService().getSelection();
+		ISelectionService selectionService = getSelectionService();
+		return selectionService == null ? null : selectionService.getSelection();
 	}
 
 	/**
@@ -94,7 +96,9 @@ public final class EObjectSelectionUtils {
 	 * @return the platform selection service
 	 */
 	public static ISelectionService getSelectionService() {
-		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+		IWorkbenchWindow activeWorkbenchWindow =
+				PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+		return activeWorkbenchWindow == null ? null : activeWorkbenchWindow.getSelectionService();
 	}
 
 	/**
diff --git a/org.fortiss.tooling.kernel/trunk/model/kernel.ecore b/org.fortiss.tooling.kernel/trunk/model/kernel.ecore
index a84e422af..5ffb5b46b 100644
--- a/org.fortiss.tooling.kernel/trunk/model/kernel.ecore
+++ b/org.fortiss.tooling.kernel/trunk/model/kernel.ecore
@@ -52,4 +52,29 @@
       </eAnnotations>
     </eStructuralFeatures>
   </eClassifiers>
+  <eClassifiers xsi:type="ecore:EClass" name="ILibraryElement" abstract="true" interface="true"
+      eSuperTypes="#//INamedCommentedElement #//IElementWithURI">
+    <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
+      <details key="documentation" value="ILibraryElement is the super class of all elements contained in a library."/>
+    </eAnnotations>
+  </eClassifiers>
+  <eClassifiers xsi:type="ecore:EClass" name="ILibraryElementReference" abstract="true"
+      interface="true" eSuperTypes="#//INamedCommentedElement #//IElementWithURI">
+    <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
+      <details key="documentation" value="ILibraryElementReference is the super class of all references to elements contained in a library."/>
+    </eAnnotations>
+  </eClassifiers>
+  <eClassifiers xsi:type="ecore:EClass" name="ILibraryRootElement" eSuperTypes="#//INamedCommentedElement #//IElementWithURI"/>
+  <eClassifiers xsi:type="ecore:EClass" name="ILibrary" abstract="true" interface="true"
+      eSuperTypes="#//INamedCommentedElement">
+    <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
+      <details key="documentation" value="ILibrary is the super class of all libraries."/>
+    </eAnnotations>
+  </eClassifiers>
+  <eClassifiers xsi:type="ecore:EClass" name="IElementWithURI" abstract="true" interface="true">
+    <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
+      <details key="documentation" value="ILibraryElement is the super class of all elements contained in a library."/>
+    </eAnnotations>
+    <eStructuralFeatures xsi:type="ecore:EAttribute" name="uri" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+  </eClassifiers>
 </ecore:EPackage>
diff --git a/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel b/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel
index 2d1c3b6c7..7f1aec633 100644
--- a/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel
+++ b/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel
@@ -24,5 +24,12 @@
     <genClasses image="false" ecoreClass="kernel.ecore#//IIdLabeledReference">
       <genFeatures createChild="false" ecoreFeature="ecore:EAttribute kernel.ecore#//IIdLabeledReference/idReference"/>
     </genClasses>
+    <genClasses image="false" ecoreClass="kernel.ecore#//ILibraryElement"/>
+    <genClasses image="false" ecoreClass="kernel.ecore#//ILibraryElementReference"/>
+    <genClasses ecoreClass="kernel.ecore#//ILibraryRootElement"/>
+    <genClasses image="false" ecoreClass="kernel.ecore#//ILibrary"/>
+    <genClasses image="false" ecoreClass="kernel.ecore#//IElementWithURI">
+      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute kernel.ecore#//IElementWithURI/uri"/>
+    </genClasses>
   </genPackages>
 </genmodel:GenModel>
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/PrototypeProviderBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/PrototypeProviderBase.java
index 3600b2618..c64f5cbeb 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/PrototypeProviderBase.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/PrototypeProviderBase.java
@@ -43,7 +43,7 @@ import org.fortiss.tooling.kernel.extension.data.Prototype;
 public abstract class PrototypeProviderBase implements IPrototypeProvider {
 
 	/** Stores the registered prototypes. */
-	private final List<Prototype> prototypes = new ArrayList<Prototype>();
+	protected final List<Prototype> prototypes = new ArrayList<Prototype>();
 
 	/** Stores the optional category affiliation for the prototype. */
 	private final HashMap<Class<? extends EObject>, String> map =
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/LibraryPrototype.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/LibraryPrototype.java
new file mode 100644
index 000000000..7a2499606
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/LibraryPrototype.java
@@ -0,0 +1,40 @@
+/*--------------------------------------------------------------------------+
+$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.extension.data;
+
+import org.fortiss.tooling.kernel.model.ILibraryElementReference;
+
+/**
+ * A prototype for the library element.
+ * 
+ * @author ratiu
+ * @author $Author: hoelzl $
+ * @version $Rev: 18709 $
+ * @ConQAT.Rating RED Hash:
+ */
+public abstract class LibraryPrototype extends Prototype {
+
+	/** Constructor. */
+	public LibraryPrototype(String name, ILibraryElementReference libraryElementReference) {
+		super(name, libraryElementReference, false);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public abstract ILibraryElementReference getPrototypeCopy();
+}
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/Prototype.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/Prototype.java
index f1917e6f2..2dff101cf 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/Prototype.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/Prototype.java
@@ -28,13 +28,13 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
  * @version $Rev$
  * @ConQAT.Rating GREEN Hash: D5F7FE80539882533974AD12EEE0E643
  */
-public final class Prototype {
+public class Prototype {
 
 	/** The generic prototype name. */
 	private final String name;
 
 	/** The pre-configured {@link EObject}. */
-	private final EObject prototype;
+	protected final EObject prototype;
 
 	/** Flag for primary class prototypes. */
 	private final boolean isPrimary;
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java
index 3eca7d201..2e72bd5f2 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import org.eclipse.emf.ecore.EObject;
 import org.fortiss.tooling.kernel.model.IIdLabeled;
 import org.fortiss.tooling.kernel.model.IIdLabeledReference;
+import org.fortiss.tooling.kernel.model.ILibraryElementReference;
 import org.fortiss.tooling.kernel.model.INamedElement;
 import org.fortiss.tooling.kernel.model.IProjectRootElement;
 import org.fortiss.tooling.kernel.service.IPersistencyService;
@@ -203,4 +204,31 @@ public final class KernelModelElementUtils {
 
 		return qualifiedName;
 	}
+
+	/**
+	 * Returns true if the parameter is a child of a {@link ILibraryElementReference}.
+	 * 
+	 * @param eObject
+	 *            an object from the model.
+	 * 
+	 * @return true if the element is under a library reference
+	 */
+	public static boolean isChildOfLibraryReference(EObject eObject) {
+		if(eObject != null) {
+			int count = 0;
+			for(EObject parent = eObject.eContainer(); parent != null; parent = parent.eContainer()) {
+				if(parent instanceof ILibraryElementReference) {
+					return true;
+				}
+				if(++count > 100000) {
+					return isChildOfLibraryReference(parent);
+				}
+				if(parent == eObject) {
+					throw new IllegalStateException(
+							"There is a cycle in the containment hierarchy of " + eObject);
+				}
+			}
+		}
+		return false;
+	}
 }
-- 
GitLab