Unification of DiagranEditorInput and DiagramEditorInputDisposingTED
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorFactory.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorFactory.java
index 1d2e46c..ecfd0ee 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorFactory.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorFactory.java
@@ -24,7 +24,6 @@
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.graphiti.internal.util.T;
 import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.ui.internal.editor.DiagramEditorInputDisposingTED;
 import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorMatchingStrategy;
@@ -66,7 +65,7 @@
 			if (diagramFileUri != null) {
 				// the file has to contain one base node which has to be a diagram
 				diagramFileUri = diagramFileUri.appendFragment("/"); //$NON-NLS-1$
-				return new DiagramEditorInputDisposingTED(diagramFileUri, domain, null);
+				return new DiagramEditorInput(diagramFileUri, domain, null, true);
 			}
 		}
 
@@ -138,7 +137,7 @@
 		//			return null;
 
 		final TransactionalEditingDomain domain = GraphitiUiInternal.getEmfService().createResourceSetAndEditingDomain();
-		return new DiagramEditorInputDisposingTED(diagramUriString, domain, providerID);
+		return new DiagramEditorInput(diagramUriString, domain, providerID, true);
 	}
 
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorInput.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorInput.java
index da04be3..4daf579 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorInput.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditorInput.java
@@ -15,8 +15,6 @@
  *******************************************************************************/
 package org.eclipse.graphiti.ui.editor;
 
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.common.util.WrappedException;
 import org.eclipse.emf.ecore.EObject;
@@ -26,7 +24,6 @@
 import org.eclipse.graphiti.mm.pictograms.Diagram;
 import org.eclipse.graphiti.ui.internal.T;
 import org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal;
-import org.eclipse.graphiti.ui.internal.editor.DiagramEditorInputDisposingTED;
 import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
@@ -34,41 +31,53 @@
 import org.eclipse.ui.IPersistableElement;
 
 /**
- * The model based editor input for {@link DiagramEditorInternal} diagram editors.
- * Basically a {@linkTransactionalEditingDomain} with an already existing
- * {@linkResourceSet} is hosted to resolve an {@link EObject} from an
+ * The model based editor input for {@link DiagramEditor} diagram editors.
+ * Basically a {@link TransactionalEditingDomain} with an already existing
+ * {@link ResourceSet} is hosted to resolve an {@link EObject} from an
  * {@link URI} or {@link URI} String. Some helper methods are added.
+ * <p>
+ * Note that neither the {@link URI} nor the {@link EObject} is held by an
+ * instance of this object. Only the {@link TransactionalEditingDomain} (needs
+ * to be passed to the constructor) is held and the creator of the domain is
+ * also responsible for disposing it, unless the flag
+ * <code>disposeEditingDomain</code> is set to <code>true</code> in one of the
+ * appropriate constructors.
  * 
  * @see {@link IEditorInput}
  * @see {@link IPersistableElement}
- * @see {@link DiagramEditorInputDisposingTED}
  * @see {@link DiagramEditorFactory}
- * @see {@link DiagramEditorInternal}
+ * @see {@link DiagramEditor}
  */
 public class DiagramEditorInput implements IEditorInput, IPersistableElement {
 
 	/**
+	 * The memento key for the stored {@link URI} string
+	 */
+	public static final String KEY_URI = "org.eclipse.graphiti.uri"; //$NON-NLS-1$
+
+	/**
+	 * The memento key for the stored object name
+	 */
+	public static final String KEY_OBJECT_NAME = "org.eclipse.graphiti.objectName"; //$NON-NLS-1$
+
+	/**
+	 * The memento key for the ID of the diagram type provider.
+	 */
+	public static String KEY_PROVIDER_ID = "org.eclipse.graphiti.providerId"; //$NON-NLS-1$
+
+	/**
 	 * The stored {@link URI} string
 	 */
 	private final String uriName;
 
 	/**
-	 * The key for the stored {@link URI} string
+	 * The ID of the diagram type provider.
 	 */
-	public static final String KEY_URI = "org.eclipse.graphiti.uri"; //$NON-NLS-1$
+	private String providerId;
 
 	/**
-	 * The key for the stored object name
-	 */
-	public static final String KEY_OBJECT_NAME = "org.eclipse.graphiti.objectName"; //$NON-NLS-1$
-
-	/**
-	 * The key for the ID of the diagram type provider.
-	 */
-	public static String KEY_PROVIDER_ID = "org.eclipse.graphiti.providerId"; //$NON-NLS-1$
-
-	/**
-	 * The cached input name
+	 * The cached input name (e.g. for displaying the name in the navigation
+	 * history without having to instantiate the {@link EObject})
 	 * 
 	 * @see #getLiveName()
 	 */
@@ -89,11 +98,12 @@
 	 * @see #getEditingDomain()
 	 */
 	protected TransactionalEditingDomain editingDomain;
-	/**
-	 * The ID of the diagram type provider.
-	 */
-	private String providerId;
 
+	/**
+	 * Used to control if this instance is responsible for disposing its
+	 * {@link TransactionalEditingDomain} member or not.
+	 */
+	private boolean disposeEditingDomain;
 
 	/**
 	 * Creates an input out of a {@link URI} string and a transactional editing
@@ -107,21 +117,56 @@
 	 *            that denotes the input's {@link EObject}
 	 * @param domain
 	 *            A {@link TransactionalEditingDomain} which contains the
-	 *            {@link ResourceSet}
-	 * @param providerID2
+	 *            {@link ResourceSet}. Note that the caller is responsible for
+	 *            disposing this instance of the domain when it is no longer
+	 *            needed!
+	 * @param providerId
 	 *            A {@link String} which holds the diagram type id. When it is
 	 *            null, it is set later in {@link DiagramEditorInternal}
 	 * @throws IllegalArgumentException
 	 *             if <code>uriString</code> parameter is null
 	 * @see URI
 	 */
-	public DiagramEditorInput(String diagramUriString, TransactionalEditingDomain domain, String providerID2) {
+	public DiagramEditorInput(String diagramUriString, TransactionalEditingDomain domain, String providerId) {
+		this(diagramUriString, domain, providerId, false);
+	}
+
+	/**
+	 * Creates an input out of a {@link URI} string and a transactional editing
+	 * domain. For resolving the {@link URI} to an {@link EObject} its
+	 * {@link ResourceSet} is used. The ResourceSet of the editing domain must
+	 * have been already set from outside. A diagram type provider ID is hold in
+	 * this class.
+	 * 
+	 * @param diagramUriString
+	 *            A {@link URI} string as returned by {@link URI#toString()}
+	 *            that denotes the input's {@link EObject}
+	 * @param domain
+	 *            A {@link TransactionalEditingDomain} which contains the
+	 *            {@link ResourceSet}. Unless <code>disposeEditingDomain</code>
+	 *            is set, the caller is responsible for disposing this instance
+	 *            of the domain when it is no longer needed!
+	 * @param providerId
+	 *            A {@link String} which holds the diagram type id. When it is
+	 *            null, it is set later in {@link DiagramEditorInternal}
+	 * @param disposeEditingDomain
+	 *            If set to <code>true</code> this instance of
+	 *            {@link DiagramEditorInput} will on dispose care about
+	 *            disposing the passed {@link TransactionalEditingDomain} as
+	 *            well. If <code>false</code> is passed the caller (or rather
+	 *            the creator of the domain needs to care about that.
+	 * @throws IllegalArgumentException
+	 *             if <code>uriString</code> parameter is null
+	 * @see URI
+	 */
+	public DiagramEditorInput(String diagramUriString, TransactionalEditingDomain domain, String providerId, boolean disposeEditingDomain) {
 		if (diagramUriString == null) {
 			throw new IllegalStateException("diagramUriString must not be null"); //$NON-NLS-1$
 		}
 		this.uriName = diagramUriString;
 		setEditorEditingDomain(domain);
-		setProviderId(providerID2);
+		this.disposeEditingDomain = disposeEditingDomain;
+		setProviderId(providerId);
 	}
 
 	/**
@@ -139,8 +184,10 @@
 	 *            a {@link URI} that denotes the input's {@link EObject}
 	 * @param domain
 	 *            A {@link TransactionalEditingDomain} which contains the
-	 *            {@link ResourceSet}
-	 * @param providerID2
+	 *            {@link ResourceSet}. Note that the caller is responsible for
+	 *            disposing this instance of the domain when it is no longer
+	 *            needed!
+	 * @param providerId
 	 *            A {@link String} which holds the diagram type id. When it is
 	 *            null, it is set later in {@link DiagramEditorInternal}
 	 * @throws IllegalArgumentException
@@ -148,20 +195,56 @@
 	 * @see #DiagramEditorInputBase(String, TransactionalEditingDomain)
 	 * @see URI
 	 */
-	public DiagramEditorInput(URI diagramUri, TransactionalEditingDomain domain, String providerID2) {
+	public DiagramEditorInput(URI diagramUri, TransactionalEditingDomain domain, String providerId) {
+		this(diagramUri, domain, providerId, false);
+	}
+
+	/**
+	 * Creates an input out of a {@link URI} string and a transactional editing
+	 * domain. For resolving the {@link URI} to an {@link EObject} its
+	 * {@link ResourceSet} is used. The ResourceSet of the editing domain must
+	 * have been already set from outside. A diagram type provider ID is hold in
+	 * this class.Creates an input out of a {@link URI} string and a
+	 * transactional editing domain. For resolving the {@link URI} to an
+	 * {@link EObject} its {@link ResourceSet} is used. The ResourceSet of the
+	 * editing domain must have been already set from outside. A diagram type
+	 * provider ID is hold in this class.
+	 * 
+	 * @param diagramUri
+	 *            a {@link URI} that denotes the input's {@link EObject}
+	 * @param domain
+	 *            A {@link TransactionalEditingDomain} which contains the
+	 *            {@link ResourceSet}. Unless <code>disposeEditingDomain</code>
+	 *            is set, the caller is responsible for disposing this instance
+	 *            of the domain when it is no longer needed!
+	 * @param providerId
+	 *            A {@link String} which holds the diagram type id. When it is
+	 *            null, it is set later in {@link DiagramEditorInternal}
+	 * @param disposeEditingDomain
+	 *            If set to <code>true</code> this instance of
+	 *            {@link DiagramEditorInput} will on dispose care about
+	 *            disposing the passed {@link TransactionalEditingDomain} as
+	 *            well. If <code>false</code> is passed the caller (or rather
+	 *            the creator of the domain needs to care about that.
+	 * @throws IllegalArgumentException
+	 *             , if <code>uri</code> parameter is null
+	 * @see #DiagramEditorInputBase(String, TransactionalEditingDomain)
+	 * @see URI
+	 */
+	public DiagramEditorInput(URI diagramUri, TransactionalEditingDomain domain, String providerId, boolean disposeEditingDomain) {
 		if (diagramUri == null) {
 			throw new IllegalStateException("diagramUri must not be null"); //$NON-NLS-1$
 		}
 		this.uriName = diagramUri.toString();
 		setEditorEditingDomain(domain);
-		setProviderId(providerID2);
+		this.disposeEditingDomain = disposeEditingDomain;
+		setProviderId(providerId);
 	}
 
 	/**
-	 * Creates an editor input {@link DiagramEditorInput} or a
-	 * {@link DiagramEditorInputDisposingTED} with a self created {@link}
-	 * TransactionalEditingDomain editing domain, which must be disposed later
-	 * on.
+	 * Creates an editor input {@link DiagramEditorInput} with a self created
+	 * {@link} TransactionalEditingDomain editing domain, which must be disposed
+	 * later on.
 	 * 
 	 * @param diagram
 	 *            A {@link Diagram}
@@ -171,9 +254,11 @@
 	 * @param providerId
 	 *            A {@link String} which holds the diagram type id.
 	 * @param disposeEditingDomain
-	 *            A {@link Boolean}, when true a
-	 *            {@link DiagramEditorInputDisposingTED} is created, otherwise a
-	 *            {@link DiagramEditorInput}
+	 *            If set to <code>true</code> the created instance of
+	 *            {@link DiagramEditorInput} will on dispose care about
+	 *            disposing the passed {@link TransactionalEditingDomain} as
+	 *            well. If <code>false</code> is passed the caller (or rather
+	 *            the creator of the domain needs to care about that.
 	 * @return A {@link DiagramEditorInput} editor input
 	 */
 	public static DiagramEditorInput createEditorInput(Diagram diagram, TransactionalEditingDomain domain, String providerId,
@@ -186,7 +271,7 @@
 		final URI fragmentUri = resource.getURI().appendFragment(fragment);
 		DiagramEditorInput diagramEditorInput;
 		if (disposeEditingDomain) {
-			diagramEditorInput = new DiagramEditorInputDisposingTED(fragmentUri, domain, providerId);
+			diagramEditorInput = new DiagramEditorInput(fragmentUri, domain, providerId, true);
 		} else {
 			diagramEditorInput = new DiagramEditorInput(fragmentUri, domain, providerId);
 		}
@@ -194,18 +279,18 @@
 	}
 
 	/**
-	 * Gets the diagram.
+	 * Returns the diagram instance of this input
 	 * 
-	 * @return Returns the diagram.
+	 * @return The diagram.
 	 */
 	public Diagram getDiagram() {
 		return (Diagram) getAdapter(Diagram.class);
 	}
 
 	/**
-	 * Gets the diagram type provider id.
+	 * Returns the diagram type provider id.
 	 * 
-	 * @return Returns the providerId.
+	 * @return The providerId.
 	 */
 	public String getProviderId() {
 		return this.providerId;
@@ -221,17 +306,25 @@
 		this.providerId = providerId;
 	}
 
+	/**
+	 * Returns the factory ID for creating {@link DiagramEditorInput}s from
+	 * mementos.
+	 * 
+	 * @return The ID of the associated factory
+	 */
 	public String getFactoryId() {
 		return DiagramEditorFactory.class.getName();
 	}
 
 	public void dispose() {
-		// do nothing
-
+		if (this.disposeEditingDomain && this.editingDomain != null) {
+			this.editingDomain.dispose();
+			this.editingDomain = null;
+		}
 	}
 
 	/**
-	 * @return <code>null</code>
+	 * @return Simply returns <code>null</code>.
 	 */
 	public ImageDescriptor getImageDescriptor() {
 		return null;
@@ -248,10 +341,22 @@
 		return this.uriName;
 	}
 
+	/**
+	 * Checks if a name is set for this instance
+	 * 
+	 * @return <code>true</code> in case a name is set, <code>false</code> in
+	 *         name is <code>null</code>.
+	 */
 	protected boolean hasName() {
 		return this.mame != null;
 	}
 
+	/**
+	 * Sets the name for this instance.
+	 * 
+	 * @param name
+	 *            The name to set.
+	 */
 	protected void setName(String name) {
 		this.mame = name;
 	}
@@ -269,8 +374,8 @@
 
 	/**
 	 * Returns a name for the input from the {@link Diagram}, when possible.
-	 * Otherwise it tries to get a human readable name from the hold EObject of
-	 * the editor input.
+	 * Otherwise it tries to get a human readable name from the EObject
+	 * (retrieved via its URI) of the editor input.
 	 * 
 	 * @return A name from Diagram or from the EObject of the editor input or
 	 *         <code>null</code> to indicate that a it can currently not be
@@ -321,22 +426,18 @@
 	}
 
 	/**
-	 * Returns the concrete model element represented by the given URI, if the
+	 * Returns the concrete model element represented by the stored URI, if the
 	 * requested adapter is either the same class or super class. In addition
 	 * the method examines all composition parents and checks whether or not
 	 * they are of the requested class or a sub class.
 	 * <ul>
-	 * <li>get model element for uri</li>
+	 * <li>get model element for {@link URI}</li>
 	 * <li>if adapter == modelElement.class return modelElement</li>
 	 * <li>if adapter == modelElement.superclass return modelElement</li>
 	 * <li>if adapter == modelElement.compositionParent.class return
 	 * modelElement</li>
-	 * <li>if adapter == modelElement.anyCompositionParent.class return
-	 * modelElement</li>
 	 * <li>if adapter == ResourceSet return resourceSet</li>
 	 * <li>if adapter == TransactionalEditingDomain return editingDomain</li>
-	 * <li>if adapter == IFile returns the file (aka. Resource) in which the
-	 * root element of this editor is contained</li>
 	 * </ul>
 	 * 
 	 * @param adapter
@@ -359,7 +460,6 @@
 			} catch (final Exception e) {
 				// Not able to adapt to eObject, object has been deleted, file was deleted...
 				// adapt must deliver null
-				//TODO IStatus status = new Status(IStatus.WARNING, 0, e.getMessage(), e, EmfFwkUIPlugin.PLUGIN_ID);
 				T.racer().debug(e.getMessage());
 				return null;
 			}
@@ -373,10 +473,13 @@
 	}
 
 	/**
-	 * Saves {@link URI} string and object name
+	 * Saves {@link URI} string, object name and provider ID to the given
+	 * {@link IMemento}.
+	 * 
+	 * @param memento
+	 *            The memeto to store the information in
 	 */
 	public void saveState(IMemento memento) {
-		//TODO
 		// Do not store anything for deleted objects
 		boolean exists = exists();
 		if (!exists) {
@@ -395,7 +498,7 @@
 	 * {@link #uriName}.
 	 * 
 	 * @param editingDomain
-	 *            the current transactional editing domain
+	 *            the {@link TransactionalEditingDomain} to set
 	 * @throws IllegalArgumentException
 	 *             if <code>editingDomain</code> parameter is null
 	 * @see #getEditingDomain()
@@ -439,10 +542,12 @@
 	}
 
 	/**
+	 * Checks if the diagram this input represents exist.
+	 * <p>
+	 * Note: The editor gets only restored, when <code>true</code> is returned.
+	 * 
 	 * @return <code>true</code> if the input's state denotes a living EMF
 	 *         object <br>
-	 *         Note: The editor gets only restored, when <code>true</code> is
-	 *         returned.
 	 */
 	public boolean exists() {
 		if (this.uriName == null) {
@@ -471,7 +576,6 @@
 		try {
 			obj = getEObject();
 		} catch (WrappedException e) {
-			// JL-EXC$
 			// Ignore (object may not exists, even resource may be gone
 		}
 		if (obj != null) {
@@ -512,12 +616,7 @@
 				modelElement.eResource().setTrackingModification(true);
 
 				// Climb up the chain of composition. Also uses a counter to
-				// prevent infinite loops
-				// in case refImmediateComposite does not return null
-				// TODO ModelEditorInput must not adapt to composite
-				// children
-				// as this is completely unpredictable - e.g. the first
-				// element in an unordered collection might be returned
+				// prevent infinite loops in case refImmediateComposite does not return null
 				int i = 0;
 				EObject o = modelElement;
 				do {
@@ -551,6 +650,14 @@
 		return this.editingDomain;
 	}
 
+	/**
+	 * Checks if this instance of the input represents the same object as the
+	 * given instance.
+	 * 
+	 * @param obj
+	 *            The object to compare this instance with.
+	 * @return <code>true</code> if the represented objects are the same
+	 */
 	@Override
 	public boolean equals(Object obj) {
 		if (this == obj) {
@@ -573,6 +680,9 @@
 		return true;
 	}
 
+	/**
+	 * Calculates the hash code for this input
+	 */
 	@Override
 	public int hashCode() {
 		final int PRIME = 31;
@@ -581,6 +691,9 @@
 		return result;
 	}
 
+	/**
+	 * Used for logging only!
+	 */
 	@Override
 	public String toString() {
 		final String s = super.toString() + " uriName: " + this.uriName + " on TransactionalEditingDomain " //$NON-NLS-1$ 
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInputDisposingTED.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInputDisposingTED.java
deleted file mode 100644
index 69bf3d9..0000000
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInputDisposingTED.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * <copyright>
- *
- * Copyright (c) 2005, 2010 SAP AG.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    SAP AG - initial API, implementation and documentation
- *
- * </copyright>
- *
- *******************************************************************************/
-package org.eclipse.graphiti.ui.internal.editor;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
-
-public class DiagramEditorInputDisposingTED extends DiagramEditorInput {
-
-	public DiagramEditorInputDisposingTED(String diagramUriString, TransactionalEditingDomain domain, String providerID2) {
-		super(diagramUriString, domain, providerID2);
-	}
-
-	public DiagramEditorInputDisposingTED(URI diagramUri, TransactionalEditingDomain domain, String providerID2) {
-		super(diagramUri, domain, providerID2);
-	}
-
-	@Override
-	public void dispose() {
-		if (this.editingDomain != null) {
-			this.editingDomain.dispose();
-			this.editingDomain = null;
-		}
-		super.dispose();
-	}
-}