• Non ci sono risultati.

AOT AOT

N/A
N/A
Protected

Academic year: 2022

Condividi "AOT AOT"

Copied!
48
0
0

Testo completo

(1)

Agent and Object Technology Lab

Dipartimento di Ingegneria dell’Informazione Università degli Studi di Parma

AOT AOT

LAB LAB

Graphical Editing Framework Graphical Editing Framework Graphical Editing Framework Graphical Editing Framework

(GEF) (GEF) (GEF) (GEF) (GEF) (GEF) (GEF) (GEF)

Alessandro Negri negri@ce.unipr.it

http://www.ce.unipr.it/people/negri/

(2)

AOT AOT

LAB

LAB

OverviewOverviewOverviewOverview

 Interaction Layer

 Model-to-View mapping

 Workbench Integration

 Rendering

 Layout

 Scaling

 Native (SWT) Layer

(3)

AOT AOT

LAB

LAB

GEF Components & DependenciesGEF Components & DependenciesGEF Components & DependenciesGEF Components & Dependencies

ui.views*

RCP

SWT

GEF

Draw2D

<<requires>>

RCP

Platform Runtime

*Optional

GEF

(4)

AOT AOT

LAB

LAB

GEF OverviewGEF OverviewGEF OverviewGEF Overview

 Consists of 2 Eclipse Plug-ins

 Draw2D: Layout and rendering toolkit for displaying graphics

 GEF: Framework using the old Smalltalk MVC Principles (Model, Figure and EditPart)

 General Working Mechanism:

 Input events are translated into Requests

 Input events are translated into Requests

 EditParts hand over Requests to EditPolicies

 EditPolicies translate Requests into GEF Commands (when they know of the particular Request)

 Commands get executed and change the model

 Model is observed by EditPart: upon a change the EditPart refreshes the Figure

(5)

AOT AOT

LAB

LAB

GEF FeaturesGEF FeaturesGEF FeaturesGEF Features

 Move, resize, create, bend, connect

 Delete, undo, redo, direct-edit

 Overview & zoom

 Palette and workbench view

 Palette customization

 Palette customization

 Rulers & guides

 Snap-To-Grid or “geometry”

 Accessibility

 Shortest-path routing algorithm

(6)

AOT AOT

LAB

LAB

A Minimal GEF EditorA Minimal GEF EditorA Minimal GEF EditorA Minimal GEF Editor

 Creation of Eclipse plug-in with Editor

 Add the GraphicalViewer: ScrollingGraphicalViewer

 Special kind of EditPartViewer

 EditPartViewers are adapters for SWT controls that manage the EditParts

 They are populated by setting their contents

 Add the RootEditPart: ScalableFreeFormRootEditPart

 Brigdes gap between EditPartViewer and its contents

 Can provide servies such as zooming and freeform figures

 Define the model to be used: Graph

 Initially a simplistic subclass of Object

 Will be a container for Nodes later

 Create the view and the controller: GraphEditPart

 Define the GraphEditPartFactory

 Only Graph objects will be considered initially

(7)

AOT AOT

LAB

LAB

Draw2d OverviewDraw2d OverviewDraw2d OverviewDraw2d Overview

 Lightweight Toolkit built with SWT

 Figures: graphical data structure

 Similarities to other frameworks (Swing,

Hotdraw)

Rendering

Hotdraw)

 Not a widget toolkit (Swing)

 Built to support GEF function

Rendering Layout Scaling

(8)

AOT AOT

LAB

LAB

Meet the PlayersMeet the PlayersMeet the PlayersMeet the Players

 Canvas – the native SWT control that hosts a “drawing”

 Figure – the fundamental building block

 It’s what you see

 can contain other children figures

 LayoutManager – encapsulates the placement of children

 Connection – a special type of figure based on a polyline

 ConnectionRouter – determines a connection’s line, or route

 ConnectionAnchor – provides the endpoints to a connection

 Border – a decoration that can be set on a figure

(9)

AOT AOT

LAB LAB

Draw2d

Meet the Coach: Lightweight Meet the Coach: Lightweight Meet the Coach: Lightweight Meet the Coach: Lightweight

System System System System

SWT

Canvas

Lightweight

System ManagerUpdate

figure

figure figure

contents

FigureCanvas

System

SWT Events:

 Paint

 Mouse

 Key

 Focus

Event Dispatcher

Manager figure figure

(10)

AOT AOT

LAB

LAB

Hello WorldHello WorldHello WorldHello World

Display d = new Display();

Shell shell = new Shell(d);

shell.setLayout(new FillLayout());

1 2

3 shell.setLayout(new FillLayout());

FigureCanvas canvas = new FigureCanvas(shell);

canvas.setContents(new Label("Hello World"));

shell.setText(“draw2d”);

shell.open();

while (!shell.isDisposed())

while (!d.readAndDispatch()) d.sleep();

3 4 5 6 7 8 9 10 11 12

(11)

AOT AOT

LAB LAB

 Are simple lightweight containers

 Nodes forming a Tree structure

 Properties: Font, Colors, Borders, Tooltip, etc.

 Inherit parent’s font and color (all the way up to the Canvas)

 Have a Rectangular Bounds

 Are not necessarily rectangular

Figures Figures Figures Figures

 Are not necessarily rectangular

Bounds

(x, y, width, height) Insets

(top, left, bottom, right) Client Area

(derived)

(12)

AOT AOT

LAB

LAB

Painting and Finding FiguresPainting and Finding FiguresPainting and Finding FiguresPainting and Finding Figures

 Figures form a tree

 Painting is pre-order, “LTR”

 Parents clip children

 Last painted is “on top”

 Hit-testing is the opposite

 Hit-testing is the opposite

2 3

4 5

6

(13)

AOT AOT

LAB

LAB

Painting continuedPainting continuedPainting continuedPainting continued

 Override paintFigure(), not paint()

 You don’t have to worry about maintaining the state of the Graphics object; change settings as you please

 Order of painting: parent figure, children figures, parent’s border

 Request repaint() when any property that affects the appearance is changed

appearance is changed

 Double-buffered painting (no flicker)

 Painting will be clipped to the figure’s bounds and the parent figure’s client area

 You can change child figures’ z-order to determine which one gets painted on top

 Last sibling is painted on top, in case of overlap

(14)

AOT AOT

LAB

LAB

Layout ManagersLayout ManagersLayout ManagersLayout Managers

 Responsibilities

 Position a Figure’s children: IFigure#setBounds()

 Provide the preferred sizes based on children and layout

 Only invalid figures will layout

 Hints passed during size calculations

 Hints passed during size calculations

 -1 means not confined in that direction

 AbstractHintLayout caches sizes based on hints

 Scrollbars’ visibility determined by preferred size

 Constraint ≈ SWT’s LayoutData

 Example: XYLayout uses Rectangle constraints

(15)

AOT AOT

LAB

LAB

Layout Managers in Draw2dLayout Managers in Draw2dLayout Managers in Draw2dLayout Managers in Draw2d

Top

BorderLayout FlowLayout

Left RightCenter

1 2

3 4

Bottom

ToolbarLayout XYLayout

12,8,20,10

30,20,27,14

1 2 3

(16)

AOT AOT

LAB

LAB

Coordinate SystemsCoordinate SystemsCoordinate SystemsCoordinate Systems

 By default, bounds of parent and children use same coordinates

 Relative Coordinates

 useLocalCoordinates()

 Child positioned relative to parent’s client area

 Scaling and Translation

 Scaling and Translation

 Viewport

 Zoom

 Converting coordinates

 translateToParent() – Translate to parent’s coordinate system

 translateFromParent() – Translate from parent’s coordinate system to child’s

 translateToAbsolute() & translateToRelative()

(17)

AOT AOT

LAB

LAB

Draw2d Interaction SequenceDraw2d Interaction SequenceDraw2d Interaction SequenceDraw2d Interaction Sequence

Lightweight System

Event Dispatcher

Figure

Listeners SWT

Event SWT

Event Draw2d Event Draw2d

Event Draw2d Event

(18)

AOT AOT

LAB LAB

Update Handle Event

Mark dirty

Making Changes to Figures Making Changes to Figures Making Changes to Figures Making Changes to Figures

“Handler”

Figure

Update Manager

Queue update

Mark invalid

Perform Update

validate paint

(19)

AOT AOT

LAB

LAB

ConnectionsConnectionsConnectionsConnections

 Just Figures with special behavior

 Render a PointList managed by a ConnectionRouter

 Have a source and target ConnectionAnchor

 Define the start and end points of the connection

 Return locations using absolute coordinates

 #getLocation(referencePoint)

 Context sensitive (ChopBoxAnchor or EllipseAnchor)Context sensitive (ChopBoxAnchor or EllipseAnchor)

 Routers

 Responsible for setting all points in a connection

 May use routing constraints such as Bendpoint

 Examples: Fan, Bendpoint, Manhattan, ShortestPath

 Connection can have children too

 Arrowheads, Labels, etc.

 DelegatingLayout

 Locators place children of a connection

(20)

AOT AOT

LAB LAB

Fig 2

Midpoint

Endpoint u}

v{

Anchor Location

Labels placed using ConnectionLocators

Connections et al Connections et al Connections et al Connections et al

Fig 1

Midpoint

PolygonDecoration

Anchor Location

-1 -2 -3 -4 2

1

-1

-2

PolylineConnection

(21)

AOT AOT

LAB

LAB

The GEF plugThe GEF plugThe GEF plugThe GEF plug----inininin

 Interaction Layer

 Model-to-View mapping

 Workbench Integration

(22)

AOT AOT

LAB

LAB

What Problems does GEF Solve?What Problems does GEF Solve?What Problems does GEF Solve?What Problems does GEF Solve?

1. Display a Model graphically

2. Allow the User to interact with that model

 Process user input from Mouse & Keyboard

 Interpret that input

 Provide hooks for updating the model

 Make it undo/redo-able

3. Provide Workbench integration

 Actions and Menus

 Toolbars, Contributions

 Keybindings

 Where Can I use GEF?

 EditorParts, Views

 Anywhere in the Workbench

(23)

AOT AOT

LAB

LAB

Meet the PlayersMeet the PlayersMeet the PlayersMeet the Players

 Viewer – foundation for displaying and editing your model

 Adapter on an SWT Control

 Selection Provider

 EditPart – elements inside a viewer

 Tool – interprets user input; represents mode

 Tool – interprets user input; represents mode

 Palette – displays available tools

 CommandStack – stores Commands for undo/redo

 EditDomain – ties everything together

(24)

AOT AOT

LAB LAB

Model Element

UI Task

Comparing GEF to JFace Comparing GEF to JFaceComparing GEF to JFace Comparing GEF to JFace

Company

1) Render Element

2) Determine Structure

3) Edit the Model

JFace: JFace: JFace: JFace: JFace:

Company

JFace:LabelProvider JFace:LabelDecorator JFace:ContentProvider JFace:Filter JFace:N/A

Department

Employee

(25)

AOT AOT

LAB LAB

Model Element

UI Task

Comparing GEF to JFace Comparing GEF to JFaceComparing GEF to JFace Comparing GEF to JFace

Company

1) Render Element

2) Determine Structure

3) Edit the Model

JFace: JFace: JFace: JFace: JFace:

GEF:CompanyEditPart

Company

JFace:LabelProvider JFace:LabelDecorator JFace:ContentProvider JFace:Filter JFace:N/A

GEF:CompanyEditPart GEF:DepartmentEditPart GEF:EmployeeEditPart

Department

Employee

(26)

AOT AOT

LAB

LAB

Displaying Your Model GraphicallyDisplaying Your Model GraphicallyDisplaying Your Model GraphicallyDisplaying Your Model Graphically

 Setup: Where will the UI appear?

 EditorPart, ViewPart, or somewhere else?

 GraphicalEditorWithFlyoutPalette

 Use a GraphicalViewer

Manages the Draw2d foundation

1. Create the Viewer

2. Configure the Viewer and create its Canvas 3. Set the viewer’s contents

 Next: Mapping the Model into Figures

(27)

AOT AOT

LAB

LAB

Populating a ViewerPopulating a ViewerPopulating a ViewerPopulating a Viewer

Model

GraphicalViewer

EditParts Figures

EditPart Factory

@#!

(28)

AOT AOT

LAB LAB

Model EditParts Figures

Containment, and More Containment, and More Containment, and More Containment, and More

Containment Containment Containment

Containment ---- MVCMVCMVCMVC

Model Root (Diagram)

“Diagram”

EditPart

figure

Diagram children

… figure figure

(29)

AOT AOT

LAB

LAB

Model Model Model Model –– View View View View ---- ControllerControllerControllerController

(30)

AOT AOT

LAB

LAB

AbstractGraphicalEditPartAbstractGraphicalEditPartAbstractGraphicalEditPartAbstractGraphicalEditPartExtending Extending Extending Extending 1. createFigure()

 Just builds the figure

2. refreshVisuals()

 Reflect the model’s state in the view

3. getModelChildren() 3. getModelChildren()

 Determines children structure

 Looking ahead:

 Changing the model

 Responding to model changes

(31)

AOT AOT

LAB

LAB

Connection EditPartsConnection EditPartsConnection EditPartsConnection EditParts

 Similarities to children parts:

 Return a list of model objects:

getModelSource/TargetConnections()

 Factory can create the Connection Parts

 Differences:

 Differences:

 An anchor must be set for the source and target

 Target may come before Source

 Figure gets added to the Connection Layer

 NodeEditPart Interface

 Connection must have a direction

(32)

AOT AOT

LAB

LAB

More about EditPartsMore about EditPartsMore about EditPartsMore about EditParts

 Deciding on Model  EditPart mapping

 Unit of “interaction”

 Selection is comprised of EditParts

 Can it be deleted?

 Graphical vs. Tree Viewers

 Graphical vs. Tree Viewers

 The Root EditPart

(33)

AOT AOT

LAB

LAB

Editing: Putting the “E” in GEF: Putting the “E” in GEF: Putting the “E” in GEF: Putting the “E” in GEF

Model

GraphicalViewer

EditParts Figures

@#!

(34)

AOT AOT

LAB

LAB

Editing and ToolsEditing and ToolsEditing and ToolsEditing and Tools

SWT Events

Tool

Requests

EditPart

EditPart EditPolicyEditPolicyEditPolicy

Requests

Commands

Requests

Commands

Stack

Commands

?

 showFeedback()

 eraseFeedback()

 getCommand()

(35)

AOT AOT

LAB

LAB

EditParts and EditPoliciesEditParts and EditPoliciesEditParts and EditPoliciesEditParts and EditPolicies

 EditPolicies are installed and maintained by their host part

 EditPart responsibility is keep view up-to-date

 EditPolicies offload the editing tasks

 Avoid limitations of single inheritance

 Separate unrelated editing tasks

 Separate unrelated editing tasks

 Allows editing behavior to be dynamic

 Keyed using Strings (“Roles”)

 May contribute to feedback, commands, targeting, etc.

 Tip: UnexecutableCommand vs. null

 Examples: BendpointEditPolicy, SelectionEditPolicy, etc.

 Pattern used: “Pool of Responsibility”

(36)

AOT AOT

LAB

LAB

Responding to Model changesResponding to Model changesResponding to Model changesResponding to Model changes

 Extend activate() to hook listeners

 Extend deactivate() to unhook listeners

 Depending on the type of change

 Add, remove, or reorder Children

 Update Connections

 Update Connections

 Update the view

(37)

AOT AOT

LAB

LAB

Building a GEF ApplicationBuilding a GEF ApplicationBuilding a GEF ApplicationBuilding a GEF Application

Step 1:

Model

Step 2:

View

Edit Policies

Property Step 3:

Controller

Step 4:

“Editor”

Property Sheet

Palette and Tools Add Editing

Behavior

(38)

AOT AOT

LAB

LAB

The Big PictureThe Big PictureThe Big PictureThe Big Picture

Model EditPartViewer

1. acts on

EditPartViewer EditPartViewer

EditDomain

6.

modifies Palette

Tool1 Tool2 Tool3 Active

Tool

2. events

5. execute 3. request 4. command

CommandStack

Command Command Command Command

(39)

AOT AOT

LAB

LAB

GEF GEF GEF GEF –– Conventions and Patterns Conventions and PatternsConventions and PatternsConventions and Patterns

 Tools to interpret mouse and keyboard

 Requests to encapsulate interactions

 Tip: performRequest() for REQ_DIRECT_EDITING and REQ_OPEN

 Absolute coordinates

 Edit Policies for separation of concerns

 Command pattern for undo/redo

 Use of IAdaptable

(40)

AOT AOT

LAB

LAB

PalettePalettePalettePalette

 PaletteViewer: Just another GraphicalViewer

 Tip: #saveState(IMemento)

 Palette Model

 Templates vs. Tools

 Drawers, Groups and Stacks

 Permissions

 Permissions

 PaletteViewerProvider

 Add drag source listener for DND

 Fly-out Palette and PaletteView

 GraphicalEditorWithFlyoutPalette

 PalettePage

 FlyoutPreferences

(41)

AOT AOT

LAB

LAB

Properties ViewProperties ViewProperties ViewProperties View

 Implement IPropertySource on

 The EditPart

 The Model

Or make the model IAdaptable

 A Custom adapter for combining multiple sources

 A Custom adapter for combining multiple sources

 GEF provides undo/redo support via commands

 UndoablePropertySheetEntry

 Auto-Wraps IPropertySource changes in a Command

(42)

AOT AOT

LAB

LAB

Outline ViewOutline ViewOutline ViewOutline View

 Use the provided TreeViewer class

 Extend AbstractTreeEditPart

 Use SelectionSynchronizer with multiple viewers

 Editor actions can be reused in the outline

 Use ScrollableThumbnail as an Overview

 Use ScrollableThumbnail as an Overview

(43)

AOT AOT

LAB

LAB

ActionsActionsActionsActions

 Editor’s ActionRegistry

 Actions updated as needed

Editor does the listening, not the actions

 It’s just a Map

 ActionBarContributor

 ActionBarContributor

 One for all editor instances

 Declared in plugin.xml

 Use RetargetActions

(44)

AOT AOT

LAB

LAB

AccessibilityAccessibilityAccessibilityAccessibility

 Eclipse is accessible

 GEF is accessible

 IAdaptable#getAdapter(Class)

 AccessibleEditPart

Magnifier and Screen reader API

 Focus indication (Selection Edit Policies)

 Default keyboard handlers

 Accessible Tools

 AccessibleAnchorProvider

 AccessibleHandleProvider

(45)

AOT AOT

LAB

LAB

AutoAuto----ScrollingAutoAuto ScrollingScrollingScrolling

 During drag operations, including native DND

 Search from target part upwards

 AutoExposeHelper

 #detect(Point)

 #step(Point)

 Not just for scrolling

 Expanding

 Page-flipping

 Related: ExposeHelper

(46)

AOT AOT

LAB

LAB

ZoomingZoomingZoomingZooming

 ZoomManager

 Use a Scalable RootEditPart

 Tip: available as a property on the viewer

 Action Contributions

 Zoom-In & Zoom-Out Actions

 Zoom-In & Zoom-Out Actions

 ZoomComboContributionItem

 Ctrl + MouseWheel (in 3.1)

 MouseWheelZoomHandler

(47)

AOT AOT

LAB

LAB

The Future: GMFThe Future: GMFThe Future: GMFThe Future: GMF

http://www.eclipse.org/gmf/

 The Eclipse Graphical Modeling Framework (GMF) provides a generative component and runtime

infrastructure for developing graphical editors based on EMF and GEF

 The project aims to provide these components, in

addition to exemplary tools for select domain models which illustrate its capabilities

(48)

Agent and Object Technology Lab

Dipartimento di Ingegneria dell’Informazione Università degli Studi di Parma

AOT AOT

LAB LAB

Graphical Editing Framework Graphical Editing Framework Graphical Editing Framework Graphical Editing Framework

(GEF) (GEF) (GEF) (GEF)

Alessandro Negri negri@ce.unipr.it

http://www.ce.unipr.it/people/negri/

(GEF)

(GEF) (GEF)

(GEF)

Riferimenti

Documenti correlati

Š Questo è solo possibile se oltre alla memoria primaria viene utilizzata dal sistema operativo anche la memoria secondaria del calcolatore..

Quando viene invocato wait, il thread rilascia il lock e sospende la sua esecuzione. In seguito, un altro thread acquisirà lo stesso

Š Infrared transmission uses low frequency light waves to carry data through the air. Š Its

Quando un server invia una risposta, può inviare anche informazione di stato da memorizzare sul client.  Specificato del range di url per cui lo stato

Š International Standardization Organization (ISO) is responsible for a wide range of standards including networking standards.. AOT LAB

Š FIPA ACL is an “outer language” that defines a set of performatives (communicative acts) used for exchanges of knowledge. Š But knowledge can be expressed in different

 L’ereditarità tra le classi Java è singola: solo una classe base (diretta) per ogni classe derivata..  Tutte le classi sono derivate (implicitamente)

Les pré-inscriptions se font à partir du 6 e mois de grossesse, sauf dans certains arrondis- sements où elles peuvent être enregistrées avant. Elles doivent être confirmées dans