Beruflich Dokumente
Kultur Dokumente
Written by Martin Bouladour (s081034) Olga Dmitricenko (s061242) Mohamed Gasmi (s081195) DTU - IMM -2008
2/16
3/16
4/16
An EditingDomain can manage one or more model. The models are maintained in the form of a ResourceSet object where each resource represents a document in which a model is stored. Among other things, it provides methods to browse the model (getChildren(), getParent(), treeIterator()) and to create commands (createCommand(), createOverrideCommand()). The CommandStack can be accessed via the getCommandStack() method. A command stack is an undoable stack of commands. The CommandStack execute() method is used to execute a command within a stack. Commands are used to modify a model. AddCommand, RemoveCommand and MoveCommand are examples of generic commands. A command can be tested for executability, it can be executed, it can be tested for undoability, it can be undone, and can then be redone. A command also provides access to a result collection, an affected-objects collection, a label, and a description. Though the model can be directly accessed and modified, using commands to do so is much more better. Actually every modification must be done using commands. In this way, the EMF.edit framework provides all its functionalities (such as undo commands, etc.).
5/16
In our actual instance, there is a company that contains several departments. If we want to remove one department, we could simply write the following code:
Department d = ... Company c = ... c.getDepartments().remove(d);
In that way, the department is indeed removed from the company, and nothing else. Now, let's do it using the EMF.edit remove command, the editing domain and its command stack:
Department d = ... Company c = ... EditingDomain ed = ... RemoveCommand cmd = new RemoveCommand(ed, c, CompanyPackage.eINSTANCE.getCompany_Departments(), d); ed.getCommandStack().execute(cmd);
Here, the department is also removed from the company. However, deleting a department this way has one big advantage: The deletion can be undone using the ed.getCommandStack().undo() method. Moreover, using commands and a command stack allows the stack to be checked to find out if a model is dirty or not, and commands validity can be tested before being executed (using the canExcecute() method of the Command interface).
6/16
To use this method, we need to create a CommandParameter object first, set command parameters into it, and then call the create method passing it the command class we want (for instance RemoveCommand.class) and the parameters. To simplify the command creation, every command class contains a static convenience create() method. See:
Department d = ... EditingDomain ed = ... Command cmd = RemoveCommand.create(ed, d); ed.getCommandStack().execute(cmd);
This is just a small syntactic change (RemoveCommand.create() instead of new RemoveCommand), but there are fundamental differences. We only passed one argument (that is, the object being removed), aside from the editing domain, instead of the three arguments previously. Notice how this piece of code can now be used to remove any kind of object. By delegating the creation of the command to the editing domain, we're letting it fill in the missing arguments.
7/16
A box can contain things or other boxes, recursively. The root object of this model is a box. In the generated editor, we can draw something like that:
Then, if we want to remove a box, the box and all the objects that it contains will be removed. It's the behaviour of the existing remove command of the framework.
Now, say we want to change this behaviour. When a bow is deleted, then all the objects it contains will be move in the parent box.
To do so, we have to replace the remove command of a box with a new command. This command will extends the CompoundCommand class. A compound command is a command that is composed of other commands. If the object to remove is a Box, this new command will first move the objects
8/16
// constructor that initializes the four instance variables: public void execute() { Iterator<emf3.Object> it = this.collection.iterator(); emf3.Object objectToRemove; // for each object to remove while (it.hasNext()) { objectToRemove = (emf3.Object)it.next(); if (objectToRemove instanceof Box) { // if the object is a Box, // then move its children to the parent Box Collection<emf3.Object> children = (Collection<emf3.Object>) this.domain.getChildren(objectToRemove); this.appendAndExecute( new RemoveCommand(this.domain, objectToRemove, objectToRemove.eContainingFeature(), children)); this.appendAndExecute( AddCommand.create(this.domain, this.owner, this.owner.eContainingFeature(), children)); } // remove the object this.appendAndExecute( new RemoveCommand(this.domain, this.owner, this.feature, objectToRemove)); } } }
One nave way to move the object is to directly modify the model (i.e. removing the objects from the contents collection of the box to be deleted, and then adding then to the contents collection of the parent box). However, doing so won't allow the user to undo that change (by doing undo, the removed box will be retrieved, but the children objects won't be moved back into it). That's why the EMF.edit commands has to be used. Once the command is created, the createRemoveCommand() method of the ObjectItemProvider class must be overridden too, so that the command returned is the our RemoveObjectCommand.
public class ObjectItemProvider implements ... { ... protected Command createRemoveCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.util.Collection<?> collection) { return new RemoveObjectCommand(domain, owner, feature, (Collection<emf3.Object>)collection); } }
Now, when a box is removed, then all its contained objects are moved in the parent box.
9/16
Isolation of concurrent threads to prevent data corruption; Validation of changes on commit, rolling back (undoing those changes) automatically when data integrity is violated; Automatic execution of triggers on commit, to proactively maintain data integrity.
10/16
11/16
12/16
13/16
A: All the files of the example (Component Definition File / Diagrams / Dashboard ) B: The Dashboard view C: The plug-in tools D: The simulator manager
14/16
A: Create a new instance of simulation B: Start / Pause / Stop / One Step (simulation options) C: To choose a sensor (rainSensor / switch) D: To change the state of the sensor E: Set the simulation speed Step 6: (Start the simulation) This is the simulation of the wire for a simulation speed (1 Step / Sec) and for a light rain.
15/16
16/16