public class EditModuleCommand extends CommandWrapper
The module is required to exist before this command is executed. If the module is to be created, use a CreateModuleCommand
instance
instead.
Executing this command requires the module to be open in the DOORS client in exclusive edit. If exclusive edit cannot be obtained (i.e. another
user is currently editing the module), an exception is thrown when the command is executed. In such case the status code of the exception is
DoorsStatusCode.CANNOT_EDIT_MODULE
, so that you can identify the cause of the issue and offer to execute again later the command.
The ShareModuleCommand
command provides the capability to update sections of a formal module in share mode, which is less restrictive
than exclusive edit. However it is only applicable to modules which define editable sections. And note that editing in share mode doesn't allow to
update the structure of a module (the types and attributes).
A command to edit a module is decomposed into multiple fragments, each one modifying a different portion of the data: one to create an new object, a second one to insert a picture, a third one to move an object, etc. Combining fragments into one command has two major benefits:
When instantiating an edit command, you indicate the expected behavior at the end of a successful execution:
TerminationMode.SAVE_AND_CLOSE
: the edited module is saved and closed. This is the typical mode in which the command is usually
executedTerminationMode.SAVE
: the edited module is saved but isn't closed. Use this mode if you need to store the modifications made but
also want to execute an additional edit command on the same module.TerminationMode.LEAVE_OPEN
: the edited module is left open and modifications are not saved. Use this mode if you want to execute
an additional edit command on the same module and need to ensure all modifications are discarded if one command fails to execute properly.
Below is a snippet illustrating how to use this command (see CommandRunner
for a full snippet and EditModuleFragment
subclasses for details):
ModuleRef module = ModuleRef.qualifiedName("/MyFolder/MyModule"); EditModuleCommand command = new EditModuleCommand(module, TerminationMode.SAVE_AND_CLOSE); // create a new object CreateObjectFragment creationFragment = new CreateObjectFragment(); command.add(creationFragment); // set its heading ObjectRef createdObject = ObjectRef.created(creationFragment); String heading = "Introduction"; command.add(new SetAttributeValueFragment(createdObject, "Object Heading", heading)); // change the text of an existing object ObjectRef existingObject = ObjectRef.absoluteNumber(4); // identifies an object with its absolute number in the edited module RichText text = RichText.valueOf("<html><body><p>Some <b>formatted</b> <i>text</id></p></body></html>"); command.add(new SetAttributeValueFragment(existingObject, "Object Text", text)); myCommandRunner.run(command);
This class is not intended to be subclassed by clients but may be instantiated.
CommandRunner
,
EditModuleFragment
,
ShareModuleCommand
,
DoorsStatusCode.CANNOT_EDIT_MODULE
Modifier and Type | Class and Description |
---|---|
static class |
EditModuleCommand.TerminationMode
Determines the behavior of the
EditModuleCommand command when it successfully completes. |
Constructor and Description |
---|
EditModuleCommand(ModuleRef module,
EditModuleCommand.TerminationMode terminationMode)
Instantiates a command to edit a module and modify its content.
|
Modifier and Type | Method and Description |
---|---|
void |
add(EditModuleFragment fragment)
Adds a new fragment in the command, to create or modify a portion of the module.
|
void |
remove(EditModuleFragment fragment)
Removes a fragment previously registered to this command.
|
run
public EditModuleCommand(ModuleRef module, EditModuleCommand.TerminationMode terminationMode)
module
- the module to be edited. The module must already exist by the time the command is executed.
The command will request exclusive edit on this module.terminationMode
- determines the behavior of the command when it successfully completes.public void add(EditModuleFragment fragment)
fragment
- the fragment to execute to either create, modify or delete information in the module.public final void remove(EditModuleFragment fragment)
fragment
- the fragment to remove.