Java Reference
In-Depth Information
EditPart
Factory
Graphical Viewer
Model
EditParts
Figures
Figure 9-9
GEF EditPartFactory
Following is code from the GEF Logic Diagram example's LogicEditor class,
showing how its
GraphicalViewer
is set up. Note that I have removed config-
uration code for elements not discussed (such as zoom and action configuration).
protected void
configureGraphicalViewer() {
super
.configureGraphicalViewer();
ScrollingGraphicalViewer viewer =
(ScrollingGraphicalViewer)getGraphicalViewer();
ScalableFreeformRootEditPart root =
new
ScalableFreeformRootEditPart();
viewer.setRootEditPart(root);
viewer.setEditPartFactory(
new
GraphicalPartFactory());
}
The contents are set in the LogicEditor's
setContents()
method:
getGraphicalViewer().setContents(getLogicDiagram());
Looking at the logic diagram's implementation of
EditPartFactory
, you
can get a feel for how
EditPart
s are created for corresponding model objects.
public class
GraphicalPartFactory
implements
EditPartFactory {
public
EditPart createEditPart(EditPart context, Object model) {
EditPart child =
null
;
if
(model
instanceof
LogicFlowContainer)
child =
new
LogicFlowContainerEditPart();
else if
(model
instanceof
Wire)
Search WWH ::
Custom Search