Jump to: navigation, search

Difference between revisions of "GEF/Troubleshooting Guide"

< GEF
(updated troubleshooting guide)
 
m (Added to Category:GEF)
Line 35: Line 35:
  
 
Since GEF is built on UI frameworks such as Draw2d, it also is not thread-safe.  EditParts should not be updated from background or "job" threads.  Use asnycExec(Runnable) or syncExec(Runnable) to perform the changes on the proper thread.
 
Since GEF is built on UI frameworks such as Draw2d, it also is not thread-safe.  EditParts should not be updated from background or "job" threads.  Use asnycExec(Runnable) or syncExec(Runnable) to perform the changes on the proper thread.
 +
 +
[[Category:GEF]]

Revision as of 18:04, 23 April 2009

Draw2D common mistakes

Using Freeform Figures

Freeform is a special concept which requires several special implementation classes to work properly. A freeform figure may extend in any direction. Because of this feature, the concept of bounds and preferred size do not apply. The following rules must be followed:

FreeformViewport. The normal Viewport may not contain a freeform figure. XYLayout must not be used as the layout for a freeform figure. Use FreeformLayout instead. Failure to do so may result in infinite loops.

A freeform layered pane must contain freeform layers.

For convenience, FreeformLayer can be used as a normal layer. This allows for specialized layers to inherit from it for use with or without freeform functionality.

Implementing Connection Anchors

When implementing your own custom connection anchors, it is important to understand the coordinate systems in Draw2d. An anchor must always deal in absolute coordinates. The anchor's figure's bounds are not absolute. When scrolling or zooming, the figure's bounds must be converted to absolute for both the anchor's location and its reference point. Here is some example code from ChopBoxAnchor:

public Point getReferencePoint() {

       Point ref = getBox().getCenter();
       getOwner().translateToAbsolute(ref);
       return ref;

}

Background Threads and Draw2d

Draw2d, just like Swing, is not thread-safe. Do not call repaint(), revalidate(), or any other method on a figure from a thread other than the Main (UI) thread. One symptom of doing this is a NullPointerException in the DeferredUpdateManager. Use asnycExec(Runnable) or syncExec(Runnable) to perform the changes on the proper thread.

GEF common mistakes

Connection and Delete

For applications with multiple levels of containers, delete can be tricky. When objects (i.e. "nodes") in a diagram are deleted, it is necessary to remove, in the very least, the connections between the items being deleted, including contained parts such as children, and any items remaining in the diagram. The recommended place to do this is in the command which deletes the object. Care must be taken in the implementation because both ends of the connection may be deleted using multiple selection. To avoid deleting the connection twice, the application should lazily determine which connections must be deleted. Do this inside the execute() of the command. On undo, the connection will get restored just once. For an example implementation, see DeleteCommand in the Logic example.

Background Threads and Updates

Since GEF is built on UI frameworks such as Draw2d, it also is not thread-safe. EditParts should not be updated from background or "job" threads. Use asnycExec(Runnable) or syncExec(Runnable) to perform the changes on the proper thread.