org.eclipse.wst.common.componentcore
Class ArtifactEdit

java.lang.Object
  extended byorg.eclipse.wst.common.componentcore.ArtifactEdit
All Implemented Interfaces:
IEditModelHandler

public class ArtifactEdit
extends java.lang.Object
implements IEditModelHandler

Provides a Facade pattern for accessing Module Content Metamodels for Web Tools Platform flexible modules.

ArtifactEdit hides the management of accessing edit models (ArtifactEditModel) correctly. Each project may have multiple (ArtifactEditModel)s depending on the number of modules contained by the project. Clients should use ArtifactEdit or an appropriate subclass when working with the content models of WTP modules.

Each ArtifactEdit facade is designed to manage the EditModel lifecycle for clients. However, while each ArtifactEdit is designed to be passed around as needed, clients must enforce the ArtifactEdit lifecycle. The most common method of acquiring a ArtifactEdit instance facade is to use #getArtifactEditForRead(WorkbenchComponent) or #getArtifactEditForWrite(WorkbenchComponent).

When clients have concluded their use of the instance, clients must call dispose() .

This class is experimental until fully documented.

Since:
1.0
See Also:
ModuleCoreNature, ArtifactEditModel

Field Summary
static java.lang.Class ADAPTER_TYPE
           
 
Constructor Summary
ArtifactEdit(org.eclipse.wst.common.componentcore.internal.ArtifactEditModel anArtifactEditModel)
           Creates an instance facade for the given ArtifactEditModel.
ArtifactEdit(ComponentHandle aHandle, boolean toAccessAsReadOnly)
           Creates an instance facade for the given WorkbenchComponent.
ArtifactEdit(ModuleCoreNature aNature, IVirtualComponent aModule, boolean toAccessAsReadOnly)
           Creates an instance facade for the given WorkbenchComponent.
 
Method Summary
 void addListener(org.eclipse.wst.common.internal.emfworkbench.integration.EditModelListener listener)
           Add a listener to track lifecylce events from the underlying EditModel.
 void deleteResource(Resource aResource)
           
 void dispose()
           Clients must call the following method when they have finished using the model, even if the ArtifactEdit instance facade was created as read-only.
static ArtifactEdit getArtifactEditForRead(ComponentHandle aHandle)
           Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent.
static ArtifactEdit getArtifactEditForRead(IVirtualComponent aModule)
           Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent.
static ArtifactEdit getArtifactEditForWrite(ComponentHandle aHandle)
           Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent.
static ArtifactEdit getArtifactEditForWrite(IVirtualComponent aModule)
           Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent.
 org.eclipse.emf.common.command.CommandStack getCommandStack()
           
 ComponentHandle getComponentHandle()
           
 EObject getContentModelRoot()
           Returns the root object for read or write access (depending on how the current ArtifactEdit was loaded).
 boolean hasEditModel(org.eclipse.wst.common.internal.emfworkbench.integration.EditModel editModel)
           This method may be removed soon.
 boolean isDirty()
           
 boolean isReadOnly()
           
static boolean isValidEditableModule(IVirtualComponent aModule)
          Note: This method is for internal use only.
 void removeListener(org.eclipse.wst.common.internal.emfworkbench.integration.EditModelListener listener)
           Remove the supplied listener
 void save(IProgressMonitor aMonitor)
           Force a save of the underlying model.
 void saveIfNecessary(IProgressMonitor aMonitor)
           Save the underlying model only if no other clients are currently using the model.
 void saveIfNecessaryWithPrompt(IProgressMonitor monitor, org.eclipse.wst.common.frameworks.internal.operations.IOperationHandler operationHandler, boolean wasDirty)
          Save only if necessary.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADAPTER_TYPE

public static final java.lang.Class ADAPTER_TYPE
Constructor Detail

ArtifactEdit

public ArtifactEdit(org.eclipse.wst.common.componentcore.internal.ArtifactEditModel anArtifactEditModel)

Creates an instance facade for the given ArtifactEditModel.

Parameters:
anArtifactEditModel -

ArtifactEdit

public ArtifactEdit(ModuleCoreNature aNature,
                    IVirtualComponent aModule,
                    boolean toAccessAsReadOnly)

Creates an instance facade for the given WorkbenchComponent.

Note: This method is for internal use only. Clients should not call this method.

Parameters:
aNature - A non-null ModuleCoreNature for an accessible project
aModule - A non-null WorkbenchComponent pointing to a module from the given ModuleCoreNature

ArtifactEdit

public ArtifactEdit(ComponentHandle aHandle,
                    boolean toAccessAsReadOnly)
             throws java.lang.IllegalArgumentException

Creates an instance facade for the given WorkbenchComponent.

Method Detail

getArtifactEditForRead

public static ArtifactEdit getArtifactEditForRead(IVirtualComponent aModule)

Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent. Instances of ArtifactEdit that are returned through this method must be dispose()ed of when no longer in use.

Use to acquire an ArtifactEdit facade for a specific WorkbenchComponent that will not be used for editing. Invocations of any save*() API on an instance returned from this method will throw exceptions.

The following method may return null.

Note: This method is for internal use only. Clients should not call this method.

Parameters:
aModule - A valid WorkbenchComponent with a handle that resolves to an accessible project in the workspace
Returns:
An instance of ArtifactEdit that may only be used to read the underlying content model

getArtifactEditForWrite

public static ArtifactEdit getArtifactEditForWrite(IVirtualComponent aModule)

Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent. Instances of ArtifactEdit that are returned through this method must be dispose()ed of when no longer in use.

Use to acquire an ArtifactEdit facade for a specific WorkbenchComponent that will be used for editing.

The following method may return null.

Note: This method is for internal use only. Clients should not call this method.

Parameters:
aModule - A valid WorkbenchComponent with a handle that resolves to an accessible project in the workspace
Returns:
An instance of ArtifactEdit that may be used to modify and persist changes to the underlying content model

getArtifactEditForRead

public static ArtifactEdit getArtifactEditForRead(ComponentHandle aHandle)

Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent. Instances of ArtifactEdit that are returned through this method must be dispose()ed of when no longer in use.

Use to acquire an ArtifactEdit facade for a specific WorkbenchComponent that will not be used for editing. Invocations of any save*() API on an instance returned from this method will throw exceptions.

The following method may return null.

Returns:
An instance of ArtifactEdit that may only be used to read the underlying content model

getArtifactEditForWrite

public static ArtifactEdit getArtifactEditForWrite(ComponentHandle aHandle)

Returns an instance facade to manage the underlying edit model for the given WorkbenchComponent. Instances of ArtifactEdit that are returned through this method must be dispose()ed of when no longer in use.

Use to acquire an ArtifactEdit facade for a specific WorkbenchComponent that will be used for editing.

The following method may return null.

Returns:
An instance of ArtifactEdit that may be used to modify and persist changes to the underlying content model

isValidEditableModule

public static boolean isValidEditableModule(IVirtualComponent aModule)

Note: This method is for internal use only. Clients should not call this method.

Returns:
True if the supplied module has a moduleTypeId which has a defined IEditModelFactory and is contained by an accessible project

save

public void save(IProgressMonitor aMonitor)

Force a save of the underlying model. The following method should be used with care. Unless required, use saveIfNecessary(IProgressMonitor)  instead.

Specified by:
save in interface IEditModelHandler
Parameters:
aMonitor - A valid progress monitor or null
Throws:
java.lang.IllegalStateException - If the ModuleCore object was created as read-only
See Also:
org.eclipse.wst.common.componentcore.IEditModelHandler#save()

saveIfNecessary

public void saveIfNecessary(IProgressMonitor aMonitor)

Save the underlying model only if no other clients are currently using the model. If the model is not shared, it will be saved. If it is shared, the save will be deferred.

Specified by:
saveIfNecessary in interface IEditModelHandler
Parameters:
aMonitor - A valid progress monitor or null
Throws:
java.lang.IllegalStateException - If the ModuleCore object was created as read-only
See Also:
org.eclipse.wst.common.componentcore.IEditModelHandler#saveIfNecessary()

saveIfNecessaryWithPrompt

public void saveIfNecessaryWithPrompt(IProgressMonitor monitor,
                                      org.eclipse.wst.common.frameworks.internal.operations.IOperationHandler operationHandler,
                                      boolean wasDirty)
Save only if necessary. If typically a save would not occur because this edit model is shared, the user will be prompted using the


dispose

public void dispose()

Clients must call the following method when they have finished using the model, even if the ArtifactEdit instance facade was created as read-only.

Specified by:
dispose in interface IEditModelHandler
See Also:
IEditModelHandler.dispose()

getContentModelRoot

public EObject getContentModelRoot()

Returns the root object for read or write access (depending on how the current ArtifactEdit was loaded).

Returns:
The root object of the underlying model

addListener

public void addListener(org.eclipse.wst.common.internal.emfworkbench.integration.EditModelListener listener)

Add a listener to track lifecylce events from the underlying EditModel.

Parameters:
listener - A non-null EditModelListener

removeListener

public void removeListener(org.eclipse.wst.common.internal.emfworkbench.integration.EditModelListener listener)

Remove the supplied listener

Parameters:
listener - A non-null EditModelListener

hasEditModel

public boolean hasEditModel(org.eclipse.wst.common.internal.emfworkbench.integration.EditModel editModel)

This method may be removed soon. Avoid adding dependencies to it.

This method is considered internal and not published as API.

Parameters:
editModel -
Returns:

getComponentHandle

public ComponentHandle getComponentHandle()
Returns:
ComponentHandle - returns the handle of the underlying workbench component.

getCommandStack

public org.eclipse.emf.common.command.CommandStack getCommandStack()
Returns:
The EMF command stack managed by the underlying editmodel

deleteResource

public void deleteResource(Resource aResource)

isDirty

public boolean isDirty()
Returns:
The isDirty flag based the underlying editmodel's list of resources.

isReadOnly

public boolean isReadOnly()