AOT A O T Lab LAB Università degli Studi di Parma
Transcript of AOT A O T Lab LAB Università degli Studi di Parma
![Page 1: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/1.jpg)
Agent and Object Technology LabDipartimento di Ingegneria dell’Informazione
Università degli Studi di Parma
AOTAOTLABLAB
GEF TUTORIAL
Alessandro [email protected]
http://www.ce.unipr.it/people/negri/
![Page 2: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/2.jpg)
2
AOTAOTLABLAB GEF Editor Structure
![Page 3: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/3.jpg)
3
AOTAOTLABLAB GEF MVC Interactions
![Page 4: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/4.jpg)
4
AOTAOTLABLAB A Minimal Shapes GEF Editor
Creation of Eclipse plug-in with EditorAdd the GraphicalViewer: GraphicalViewer
Special kind of EditPartViewerEditPartViewers are adapters for SWT controls that manage the EditPartsThey are populated by setting their contents
Add the RootEditPart: ScalableFreeformRootEditPartBrigdes gap between EditPartViewer and its contentsCan provide services such as zooming and freeform figures
Define the model to be used: ShapesDiagramCreate the view and the controller: ShapeEditPartDefine the ShapeEditPartFactory
![Page 5: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/5.jpg)
5
AOTAOTLABLAB Today’s Activity
Create your own plug-inBased on the simple Shapes example contributed by Elias Volanakis (included into GEF official examples)Skeleton provided for the plug-in
![Page 6: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/6.jpg)
6
AOTAOTLABLAB Set-up Sample Project
Unzip shapes_example.zip before launching EclipseOpen EclipseStart with a clean workspaceThen from within Eclipse
Import -> Existing Project Into WorkspaceSelect shapes_example.zip from Archived Files Option or from the previous directory
Switch to the Java™ perspective
![Page 7: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/7.jpg)
7
AOTAOTLABLAB Model
Provided!So are the CommandsModelElement implements IPropertySource and Serializable
![Page 8: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/8.jpg)
8
AOTAOTLABLAB View
Available in Draw2dBasic Shapes: RectangleFigure and Ellipse
![Page 9: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/9.jpg)
9
AOTAOTLABLAB Controller
ConnectionEditPart (AbstractConnectionEditPart)
ShapeEditPart(AbstractGraphicalEditPart)
ShapeDiagramEditPart (AbstractGraphicalEditPart)
Sha
peE
ditP
artF
acto
ry
![Page 10: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/10.jpg)
10
AOTAOTLABLAB ShapeDiagramEditPart
Listen to the model only when the EditPart is activeactivate()deactivate()propertyChange()
createFigure()FreeformLayer with FreeformLayout if you want to scroll into negative co-ordinates; Figure with XYLayout otherwise
getModelChildren()createEditPolicies()
COMPONENT_ROLE: RootComponentEditPolicy (provided by GEF) to prevent deletion of the content EditPartLAYOUT_ROLE: Subclass XYLayoutEditPolicy
• For creating, moving and resizing children• createChildEditPolicy() : default will do
![Page 11: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/11.jpg)
11
AOTAOTLABLAB ShapeEditPart
Listen to the model for changesCreate RectangleFigure or Ellipse based on the model instanceImplement NodeEditPart to support connections ChopboxAnchor or EllipseAnchor (return the same anchor in all methods)Edit Policies
COMPONENT_ROLE: Sub-class ComponentEditPolicy to provide delete supportGRAPHICAL_NODE_ROLE: Sub-class GraphicalNodeEditPolicy
getModelSourceConnections() and getModelTargetConnections()refreshVisuals()
((GraphicalEditPart)getParent()).setLayoutConstraint(…)
![Page 12: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/12.jpg)
12
AOTAOTLABLAB ConnectionEditPart
Listen to model for changesCreate figure
PolylineConnection with a target decoration and proper lineStyle
Edit PoliciesCONNECTION_ENDPOINTS_ROLE: ConnectionEndpointEditPolicy (provided by GEF) to select the connection’s endpointsCONNECTION_ROLE: Sub-class ConnectionEditPolicy to support delete
![Page 13: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/13.jpg)
13
AOTAOTLABLAB Bring It All Together - ShapesEditor
Functionality not related to GEF is providedWe’ve added TODO:Tutorial to mark missing functionality
Constructor: Provide a new DefaultEditDomainconfigureGraphicalViewer()
RootEditPartEditPartFactory
initializeGraphicalViewer()Set the viewer’s contents
PalettegetPaletteRoot() and getPalettePreferences()Delegate to ShapesEditorPaletteFactory
![Page 14: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/14.jpg)
14
AOTAOTLABLAB
Bring It All Together -ShapesEditorPaletteFactory
createPalettePreferences()ShapesPlugin#getDefault()#getPreferenceStore()
createPaletteRoot()Tools Group has PanningSelectionToolEntry, MarqueeToolEntry and ConnectionCreationToolEntryShapes Drawer has CombinedTemplateCreationEntryfor the two shapes
• The templates can be null for now (used for DND)
Tip: Do not forget to provide a default tool (usually Selection)
![Page 15: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/15.jpg)
15
AOTAOTLABLAB Test Drive
Launch the Runtime WorkbenchRun menu -> Debug… -> Click on Entire Application -> Click New
Test functionalityCreate a Simple Project and a new Shapes example using the wizardClick and drop from palette (notice drag and drop doesn’t work yet)Select, move, resize, connect partsProperties ViewSelect a shape and hit ‘.’ (the period key); then try ‘/’ (the slash key)Bring up the Palette ViewRight-click on the paletteDrag the shapes into negative region
From here, we’ll incrementally add desired features
![Page 16: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/16.jpg)
16
AOTAOTLABLAB (Native) Drag-n-Drop from Palette
Add DragSourceListener to the Palette and DropTargetListener to the graphical viewerShapesEditor
createPaletteViewerProvider() -TemplateTransferDragSourceListenerinitializeGraphicalViewer() –TemplateTransferDropTargetListener
ShapesEditorPaletteFactoryChange CombinedTemplateCreationEntries’ to return the model classes as templatesSub-class TemplateTransferDropTargetListener to provide the CreationFactory: use SimpleFactory
![Page 17: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/17.jpg)
17
AOTAOTLABLAB Context Menu
ShapesEditorContextMenuProvider#buildContextMenu()
Add Undo, Redo, Delete and Save actions from the Editor’s ActionRegistry
ShapesEditor#configureGraphicalViewer()Create and hook the context menu
![Page 18: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/18.jpg)
18
AOTAOTLABLAB Actions
ShapesEditorActionBarContributorAll ShapesEditor instances share this ContributorbuildActions() – Add RetargetActions for undo, redo, deletecontributeToToolBar() – Add undo and redo retarget actions to the toolbar
• Do not create new actions here!
Register the contributor in plugin.xml where you register your editor
contributorClass= "org.eclipse.gef.examples.shapes.ShapesEditorActionBarContributor"
![Page 19: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/19.jpg)
19
AOTAOTLABLAB Connection Routing
ShapesEditor#initializeGraphicalViewer()Get the connection layer from the RootEditPartCreate a new ShortestPathConnectionRouter and add it to the connection layerAdd the router’s layoutListener to the content EditPart’s content pane (i.e., the figure that is going to have the connections)Voila!
![Page 20: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/20.jpg)
20
AOTAOTLABLAB Outline
ShapesOutlinePage extends ContentOutlinePageSet-up as inner class in ShapesEditor since it shares a few things with itUse the GEF TreeViewerSince we’re creating a new viewer, we’ll need to define a new EditPartFactory and new EditParts
EditPartExtend AbstractTreeEditPartMuch simpler than earlier ones
• No Edit Policies needed since we’re only supporting selectionListen to the model for changesWe do not show connections in the outline, so no need to worry about thoseOverride getImage() and getText()
![Page 21: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/21.jpg)
21
AOTAOTLABLAB ShapesOutlinePage
Override createControl()Outline viewer should share EditDomain/CommandStack with the Editor’s viewerProvide the EditPartFactoryRegister the context menu for this viewerRegister viewer with the SelectionSynchronizer
• Tip: Don’t forget to remove the viewer from the SelectionSynchronizer when the outline page is disposed – override dispose()
Set the contentsOverride init()
Register Editor’s actions as GlobalActionHandlers (undo, redo, delete)pageSite.getActionBars().setGlobalActionHandler(…)
Hook with the EditorShapesEditor#getAdapter()
![Page 22: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/22.jpg)
22
AOTAOTLABLAB Other Features
Customizer for the PaletteZooming (already supported, but no means to manipulate it)GridSnap To GeometryRulers & Guides
![Page 23: AOT A O T Lab LAB Università degli Studi di Parma](https://reader031.fdocuments.in/reader031/viewer/2022012007/61d9810dffd0993fd31c8cd4/html5/thumbnails/23.jpg)
Agent and Object Technology LabDipartimento di Ingegneria dell’Informazione
Università degli Studi di Parma
AOTAOTLABLAB
GEF TUTORIAL
Alessandro [email protected]
http://www.ce.unipr.it/people/negri/