org.eclipse.graphiti.ui.editor
Class DiagramEditorInput

java.lang.Object
  extended by org.eclipse.graphiti.ui.editor.DiagramEditorInput

public class DiagramEditorInput
extends java.lang.Object

The Class DiagramEditorInput. The editor input for DiagramEditor diagram editors. Basically a TransactionalEditingDomain with an already existing ResourceSet is hosted to resolve an EObject from an URI String. Some helper methods are added.

Note that neither the URI nor the EObject is held by an instance of this object. Only the 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 disposeEditingDomain is set to true in one of the appropriate constructors.

See Also:
IEditorInput}, IPersistableElement}, DiagramEditorFactory}, DiagramEditor}

Field Summary
private  boolean disposeEditingDomain
          Controls if this instance is responsible for disposing its TransactionalEditingDomain member or not.
protected  TransactionalEditingDomain editingDomain
          The editor's TransactionalEditingDomain set by setEditorEditingDomain(TransactionalEditingDomain).
static java.lang.String KEY_OBJECT_NAME
          The memento key for the stored object name
static java.lang.String KEY_PROVIDER_ID
          The memento key for the ID of the diagram type provider.
static java.lang.String KEY_URI
          The memento key for the stored URI string
private  java.lang.String name
          The cached input name (e.g.
private  URI normalizedUri
          The stored URI in normalized form.
private  java.lang.String providerId
          The ID of the diagram type provider.
private  java.lang.String tooltip
          The cached input tooltip
private  java.lang.String uriName
          The stored URI string
 
Constructor Summary
DiagramEditorInput(java.lang.String diagramUriString, TransactionalEditingDomain domain, java.lang.String providerId)
          Creates a new DiagramEditorInput out of a URI string and a transactional editing domain.
DiagramEditorInput(java.lang.String diagramUriString, TransactionalEditingDomain domain, java.lang.String providerId, boolean disposeEditingDomain)
          Creates a new DiagramEditorInput out of a URI string and a transactional editing domain.
DiagramEditorInput(URI diagramUri, TransactionalEditingDomain domain, java.lang.String providerId)
          Creates a new DiagramEditorInput out of a URI string and a transactional editing domain.
DiagramEditorInput(URI diagramUri, TransactionalEditingDomain domain, java.lang.String providerId, boolean disposeEditingDomain)
          Creates a new DiagramEditorInput out of a URI string and a transactional editing domain.
 
Method Summary
static DiagramEditorInput createEditorInput(Diagram diagram, TransactionalEditingDomain domain, java.lang.String providerId, boolean disposeEditingDomain)
          Creates a new DiagramEditorInput with a self created TransactionalEditingDomain editing domain, which must be disposed later on.
private  URI createNormalizedUri()
           
 void dispose()
           
 boolean equals(java.lang.Object obj)
          Checks if this instance of the input represents the same object as the given instance.
 boolean exists()
          Checks if the diagram this input represents exist.
 java.lang.Object getAdapter(java.lang.Class adapter)
          Returns the concrete model element represented by the stored URI, if the requested adapter is either the same class or super class.
 Diagram getDiagram()
          Returns the diagram instance of this input
private  TransactionalEditingDomain getEditingDomain()
           
 EObject getEObject()
          Returns the model object the editor input is working on.
private  EObject getEObject(java.lang.Class<EObject> adapter)
          This method returns an instance which is either of the same Class object a sub class or sub interface of the class defined by adapter - null otherwise.
 java.lang.String getFactoryId()
          Returns the factory ID for creating DiagramEditorInputs from mementos.
 ImageDescriptor getImageDescriptor()
           
protected  java.lang.String getLiveName()
          Returns a name for the input from the Diagram, when possible.
protected  java.lang.String getLiveToolTipText()
          Returns a tooltip for the input from the Diagram object, when possible.
 java.lang.String getName()
           
 IPersistableElement getPersistable()
           
 java.lang.String getProviderId()
          Returns the diagram type provider id.
 java.lang.String getToolTipText()
           
private  URI getUri()
           
 java.lang.String getUriString()
           
 int hashCode()
           
protected  boolean hasName()
          Checks if a name is set for this instance
 void saveState(IMemento memento)
          Saves URI string, object name and provider ID to the given IMemento.
private  void setEditorEditingDomain(TransactionalEditingDomain editingDomain)
          Called from constructor to populate the editor's TransactionalEditingDomain to its input.
protected  void setName(java.lang.String name)
          Sets the name for this instance.
 void setProviderId(java.lang.String providerId)
          Sets the diagram type provider id.
 java.lang.String toString()
          Used for logging only!
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_URI

public static final java.lang.String KEY_URI
The memento key for the stored URI string

See Also:
Constant Field Values

KEY_OBJECT_NAME

public static final java.lang.String KEY_OBJECT_NAME
The memento key for the stored object name

See Also:
Constant Field Values

KEY_PROVIDER_ID

public static java.lang.String KEY_PROVIDER_ID
The memento key for the ID of the diagram type provider.


uriName

private final java.lang.String uriName
The stored URI string


normalizedUri

private URI normalizedUri
The stored URI in normalized form.


providerId

private java.lang.String providerId
The ID of the diagram type provider.


name

private java.lang.String name
The cached input name (e.g. for displaying the name in the navigation history without having to instantiate the EObject)

See Also:
getLiveName()

tooltip

private java.lang.String tooltip
The cached input tooltip

See Also:
getLiveToolTipText()

editingDomain

protected TransactionalEditingDomain editingDomain
The editor's TransactionalEditingDomain set by setEditorEditingDomain(TransactionalEditingDomain). Its ResourcSet is used to resolve uriName into live objects.

See Also:
getEditingDomain()

disposeEditingDomain

private boolean disposeEditingDomain
Controls if this instance is responsible for disposing its TransactionalEditingDomain member or not.

Constructor Detail

DiagramEditorInput

public DiagramEditorInput(java.lang.String diagramUriString,
                          TransactionalEditingDomain domain,
                          java.lang.String providerId)
Creates a new DiagramEditorInput out of a URI string and a transactional editing domain. For resolving the URI to an EObject its ResourceSet is used.
The ResourceSet of the editing domain must have been already set from outside and has to contain an instance of IWorkspaceCommandStack as the used command stack.
A diagram type provider ID is held in this class.

Parameters:
diagramUriString - A URI string as returned by URI#toString() that denotes the input's EObject
domain - A TransactionalEditingDomain which contains the ResourceSet. Note that the caller is responsible for disposing this instance of the domain when it is no longer needed!
providerId - A String which holds the diagram type id. When it is null, it is set later in DiagramEditorInternal
Throws:
java.lang.IllegalArgumentException - if uriString parameter is null
if the command stack of the passed domain is no IWorkspaceCommandStack
See Also:
URI

DiagramEditorInput

public DiagramEditorInput(java.lang.String diagramUriString,
                          TransactionalEditingDomain domain,
                          java.lang.String providerId,
                          boolean disposeEditingDomain)
Creates a new DiagramEditorInput out of a URI string and a transactional editing domain. For resolving the URI to an EObject its ResourceSet is used.
The ResourceSet of the editing domain must have been already set from outside and has to contain an instance of IWorkspaceCommandStack as the used command stack.
A diagram type provider ID is hold in this class.

Parameters:
diagramUriString - A URI string as returned by URI#toString() that denotes the input's EObject
domain - A TransactionalEditingDomain which contains the ResourceSet. Unless disposeEditingDomain is set, the caller is responsible for disposing this instance of the domain when it is no longer needed!
providerId - A String which holds the diagram type id. When it is null, it is set later in DiagramEditorInternal
disposeEditingDomain - If set to true this instance of DiagramEditorInput will on dispose care about disposing the passed TransactionalEditingDomain as well. If false is passed the caller (or rather the creator of the domain needs to care about that.
Throws:
java.lang.IllegalArgumentException - if uriString parameter is null
if the command stack of the passed domain is no IWorkspaceCommandStack
See Also:
URI

DiagramEditorInput

public DiagramEditorInput(URI diagramUri,
                          TransactionalEditingDomain domain,
                          java.lang.String providerId)
Creates a new DiagramEditorInput out of a URI string and a transactional editing domain. For resolving the URI to an EObject its ResourceSet is used.
The ResourceSet of the editing domain must have been already set from outside and has to contain an instance of IWorkspaceCommandStack as the used command stack.
A diagram type provider ID is hold in this class.Creates an input out of a URI string and a transactional editing domain. For resolving the URI to an EObject its 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.

Parameters:
diagramUri - a URI that denotes the input's EObject
domain - A TransactionalEditingDomain which contains the ResourceSet. Note that the caller is responsible for disposing this instance of the domain when it is no longer needed!
providerId - A String which holds the diagram type id. When it is null, it is set later in DiagramEditorInternal
Throws:
java.lang.IllegalArgumentException - if uri parameter is null
if the command stack of the passed domain is no IWorkspaceCommandStack
See Also:
#DiagramEditorInput(String, TransactionalEditingDomain), URI

DiagramEditorInput

public DiagramEditorInput(URI diagramUri,
                          TransactionalEditingDomain domain,
                          java.lang.String providerId,
                          boolean disposeEditingDomain)
Creates a new DiagramEditorInput out of a URI string and a transactional editing domain. For resolving the URI to an EObject its ResourceSet is used.
The ResourceSet of the editing domain must have been already set from outside and has to contain an instance of IWorkspaceCommandStack as the used command stack.
A diagram type provider ID is hold in this class.Creates an input out of a URI string and a transactional editing domain. For resolving the URI to an EObject its 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.

Parameters:
diagramUri - a URI that denotes the input's EObject
domain - A TransactionalEditingDomain which contains the ResourceSet. Unless disposeEditingDomain is set, the caller is responsible for disposing this instance of the domain when it is no longer needed!
providerId - A String which holds the diagram type id. When it is null, it is set later in DiagramEditorInternal
disposeEditingDomain - If set to true this instance of DiagramEditorInput will on dispose care about disposing the passed TransactionalEditingDomain as well. If false is passed the caller (or rather the creator of the domain needs to care about that.
Throws:
java.lang.IllegalArgumentException - if uri parameter is null
if the command stack of the passed domain is no IWorkspaceCommandStack
See Also:
#DiagramEditorInput(String, TransactionalEditingDomain), URI
Method Detail

createEditorInput

public static DiagramEditorInput createEditorInput(Diagram diagram,
                                                   TransactionalEditingDomain domain,
                                                   java.lang.String providerId,
                                                   boolean disposeEditingDomain)
Creates a new DiagramEditorInput with a self created TransactionalEditingDomain editing domain, which must be disposed later on.
The ResourceSet of the editing domain must have been already set from outside and has to contain an instance of IWorkspaceCommandStack as the used command stack.

Parameters:
diagram - A Diagram
domain - A TransactionalEditingDomain which contains the ResourceSet
providerId - A String which holds the diagram type id.
disposeEditingDomain - If set to true the created instance of DiagramEditorInput will on dispose care about disposing the passed TransactionalEditingDomain as well. If false is passed the caller (or rather the creator of the domain needs to care about that.
Returns:
A DiagramEditorInput editor input

getDiagram

public Diagram getDiagram()
Returns the diagram instance of this input

Returns:
The diagram.

getProviderId

public java.lang.String getProviderId()
Returns the diagram type provider id.

Returns:
The providerId.

setProviderId

public void setProviderId(java.lang.String providerId)
Sets the diagram type provider id.

Parameters:
providerId - The providerId to set.

getFactoryId

public java.lang.String getFactoryId()
Returns the factory ID for creating DiagramEditorInputs from mementos.

Returns:
The ID of the associated factory

dispose

public void dispose()

getImageDescriptor

public ImageDescriptor getImageDescriptor()
Returns:
Simply returns null.

getName

public java.lang.String getName()
Returns:
The cached name or the input's URI string
See Also:
getLiveName()

hasName

protected boolean hasName()
Checks if a name is set for this instance

Returns:
true in case a name is set, false in name is null.

setName

protected void setName(java.lang.String name)
Sets the name for this instance.

Parameters:
name - The name to set.

getToolTipText

public java.lang.String getToolTipText()
Returns:
The cached tooltip or the input's URI string
See Also:
getLiveToolTipText()

getLiveName

protected java.lang.String getLiveName()
Returns a name for the input from the Diagram, when possible. Otherwise it tries to get a human readable name from the EObject (retrieved via its URI) of the editor input.

Returns:
A name from Diagram or from the EObject of the editor input or null to indicate that a it can currently not be obtained.
See Also:
IEditorInput#getName(), getLiveName()

getLiveToolTipText

protected java.lang.String getLiveToolTipText()
Returns a tooltip for the input from the Diagram object, when possible. Otherwise it tries to return the object's live name and type.

Returns:
a tooltip from the Diagram or the hold object or null to indicate that a it can currently not be obtained.
See Also:
IEditorInput#getToolTipText()

getAdapter

public java.lang.Object getAdapter(java.lang.Class adapter)
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.

Parameters:
adapter - The adapter class to look up
Returns:
A object castable to the given class, or null if this object does not have an adapter for the given class

saveState

public void saveState(IMemento memento)
Saves URI string, object name and provider ID to the given IMemento.

Parameters:
memento - The memeto to store the information in

setEditorEditingDomain

private void setEditorEditingDomain(TransactionalEditingDomain editingDomain)
Called from constructor to populate the editor's TransactionalEditingDomain to its input. The resourceSet of the TransactionalEditingDomain is needed on requests to resolve the stored uriName.

Parameters:
editingDomain - the TransactionalEditingDomain to set
Throws:
java.lang.IllegalArgumentException - if editingDomain parameter is null
See Also:
getEditingDomain()

getEObject

public final EObject getEObject()
Returns the model object the editor input is working on.

Returns:
The object or null if no such object can be obtained, e.g. if the input's editor is not yet initialised.

getUriString

public final java.lang.String getUriString()
Returns:
The URI string this input and its editors operate on

exists

public boolean exists()
Checks if the diagram this input represents exist.

Note: The editor gets only restored, when true is returned.

Returns:
true if the input's state denotes a living EMF object

getPersistable

public IPersistableElement getPersistable()
Returns:
this input if it is persistable, otherwise null

getEObject

private EObject getEObject(java.lang.Class<EObject> adapter)
This method returns an instance which is either of the same Class object a sub class or sub interface of the class defined by adapter - null otherwise. The implementation also checks composite children.

Parameters:
adapter -
Returns:

getUri

private URI getUri()
Returns:
the resolved URI or null in case of failures

getEditingDomain

private TransactionalEditingDomain getEditingDomain()
Returns:
The current TransactionalEditingDomain or null

equals

public boolean equals(java.lang.Object obj)
Checks if this instance of the input represents the same object as the given instance.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare this instance with.
Returns:
true if the represented objects are the same

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Used for logging only!

Overrides:
toString in class java.lang.Object

createNormalizedUri

private URI createNormalizedUri()


Copyright (c) SAP AG 2005, 2010.