You are here: ProjetSEG Web>NetworkEditorConcepts (14 Feb 2005)
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:

Edit Parts?, Edit Policies? and Commands go together. You cannot independently understand an Edit Part? without understanding its Edit Policies?. And since all modifications of the model are done through Commands, Edit Parts? and Edit Policies? 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, Policy Object?) 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:

Link Edit Part? extends Abstract Connection Edit Part?

Network Edit Part? extends Abstract Graphical Edit Part? implements Adapter

Network Node Edit Part? extends Abstract Graphical Edit Part? implements Adapter, Node Edit Part?

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

Graphical Edit Part Factory? implements Edit Part Factory? 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 XYLayout Edit Policy?. 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 Edit Parts? (since they need an x,y position to begin with). Many of the methods return Command objects.

protected Command getCreateCommand(Create Request? 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 Edit Parts? and Edit Policies? 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.

Commands:

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.

-- Jordan Mc Manus? - 14 Feb 2005

Topic revision: r1 - 14 Feb 2005 - 19:00:01 - Jordan Mc Manus?
 
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