You are here: Foswiki>ProjetSEG Web>NetworkEditorConcepts (14 Feb 2005, JordanMcManus)Edit Attach
The network editor was created by copying the necessary code from this example so I won't go into any detail about the implementation (check out the code while you read this).

The first thing to understand:

EditParts, EditPolicies and Commands go together. You cannot independently understand an EditPart without understanding its EditPolicies. And since all modifications of the model are done through Commands, EditParts and EditPolicies use them to do their job.

Edit parts:

Set the model in the constructor.

Create a class for the figure related to this edit part, and return an instance of this class in the createFigure() method. This figure will be displayed in the editor.

Create a class for all the edit policies related to the edit part and install them by calling installEditPolicy(ROLE, PolicyObject) inside the createEditPolicies() method.

The active and deactivate methods need to add and remove the edit part from the adapters of their model object.

getModelObject().eAdapters().add(this); //getModelObject() could be something like getNetwork()

The notifyChanged(Notification notification) method should determine what has changed and refresh that instead of calling a potentially costly refresh(). For exemple if only a connection changes then only this connection should be refreshed.

In the network editor:

LinkEditPart extends AbstractConnectionEditPart

NetworkEditPart extends AbstractGraphicalEditPart implements Adapter

NetworkNodeEditPart extends AbstractGraphicalEditPart implements Adapter, NodeEditPart

For each of these classes check out the installed edit policies and the notifyChanged() methods (if present).

GraphicalEditPartFactory implements EditPartFactory simply constructs the appropriate edit part given a model element (haven't figured out what the context is, probably used when the constructed editpart is a child of another editpart)

Edit policies:

The most interesting policy is the XYLayoutEditPolicy. All model objects that can be moved by the user must have an edit policy (which will be installed in the edit part class). This is the policy that is used to create EditParts (since they need an x,y position to begin with). Many of the methods return Command objects.

protected Command getCreateCommand(CreateRequest request);

This methods creates a Command that has all the necessary information to create a model object and display it in the Editor.

Notice the request. In the GEF, all information that is exchanged between EditParts and EditPolicies is done via Requests. These objects carry all the (references to) information needed when a transfer of responsibility is done.

The other edit policies are quite straightforward, go through the source code and understand what each method does (many of them are 1 or 2 liners). Try to understand how the commands are used.


GEF uses the command pattern to modify the model. Commands have all the necessary information to execute, undo and redo an action. All actions must be encapsulated within a command.

-- JordanMcManus - 14 Feb 2005
Topic revision: r1 - 14 Feb 2005, JordanMcManus
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback