Eclipse Gef Tutorial (Must Watch)
@Override protected void initializeGraphicalViewer() diagram = new Diagram(); diagram.addChild(new RectangleNode()); getGraphicalViewer().setContents(diagram);
Without edit policies, your editor is just a static drawing. Policies enable moving, resizing, and deleting.
@Override protected PaletteRoot getPaletteRoot() // return palette with creation tools (optional) return null; // for minimal eclipse gef tutorial
Unlike standard UI toolkits like SWT or Swing, which are widget-based, GEF is designed for . This means it handles complex interactions like dragging and dropping objects, connecting nodes with lines, resizing elements, and managing a palette of tools.
We will focus primarily on GEF (Classic/MVC) , as it remains the industry standard for creating full-featured editing tools within the Eclipse IDE. This means it handles complex interactions like dragging
Connections will be added later using PolylineConnection .
@Override protected List<Shape> getModelChildren() return ((Diagram)getModel()).getChildren(); @Override protected List<
– Base class for all shapes:
In ShapeEditPart :
@Override protected PaletteRoot getPaletteRoot() PaletteRoot root = new PaletteRoot(); PaletteDrawer drawer = new PaletteDrawer("Shapes"); drawer.add(new CreationToolEntry("Rectangle", new RectangleNodeCreationFactory(), null, null)); drawer.add(new SelectionToolEntry()); root.add(drawer); return root;
