Copy & Paste support for MOSKitt Graphical Editors

16
Copy & Paste support for MOSKitt Graphical Editors Mario Cervera Úbeda ([email protected]) Integranova S.A http://www.moskitt.org

Transcript of Copy & Paste support for MOSKitt Graphical Editors

Copy & Paste support for MOSKitt Graphical Editors

Mario Cervera Úbeda([email protected])

Integranova S.A

http://www.moskitt.org

Copy & Paste support for MOSKitt Graphical Editors Goal:

− This presentation explains a possible solution to the problem of how to give copy & paste support to a GMF generated application.

Result:− The resulting application will be able to execute copy & paste actions on its diagrams.

Dependencies:− GMF runtime and EMF common and edit plug-ins.

Tasks:− Define a feature resolver in every edit part intended to be container of other

elements.

− Define your own Action Handler and Action Handler Provider.

− Replace the Action Handler Provider belonging to GMF by the provider just created. This is done in the extension point org.eclipse.gmf.runtime.common.ui.services.action.globalActionHandlerProviders.

Features of the GMF copy & paste support

GMF supports copy & paste functionality but it has two main features to be taken into account:

− EMF models must have UUIDs (Universally Unique Identifiers).

− It only allows copy & paste of elements contained in the canvas, that is, you can't copy elements containted in compartments and therefore you can't paste on compartments either.

Our solution: Overview

Defining the feature resolver (1/2)

The feature resolver tries to solve the problem of how to know the feature of a container that will contain a given object. We will define an interface with one single method that will return the feature for a given class. All edit parts intended to be containers will have to define its resolver and give its own implementation to this method.

Defining the feature resolver (2/2)

Once all the edit parts that will contain elements have their own feature resolver, the method getAdapter will be overriden so that the class ClipboardActionHandler can obtain it and get the feature when executing paste actions.

Defining your own Action Handler and Action Handler Provider (1/5) Action Handler Provider

− Creates the instance of the Action Handler

Defining your own Action Handler and Action Handler Provider (2/5) Action Handler

− It overrides the methods: canCopy, canCut, CanPaste, getCommand, getCopyCommand and getCutCommand.

Defining your own Action Handler and Action Handler Provider (3/5)

Defining your own Action Handler and Action Handler Provider (4/5) Action Handler

− The methods getCopyCommand and getCutCommand return a GMF command so a command wrapper will be necessary.

Defining your own Action Handler and Action Handler Provider (5/5) Action Handler

− The methods that execute the paste action must know which feature will contain the pasted object. This is implemented in the method getFeature (this method needs the resolver explained in the previous section).

Modifying the extension point (1/2)

GlobalActionHandlerProviders− The extension point where the cut, copy and paste actions are contributed

will have to be modified. This extension point is org.eclipse.gmf.runtime.common.ui.services.action.globalActionHandlerProviders

Modifying the extension point (2/2)

GlobalActionHandlerProviders− The GMF Action Handler Provider will be replaced by the one created

Result

[Result screenshots]

Documentation

GMF Documentation− http://wiki.eclipse.org/index.php/GMF_Documentation

Other:− http://help.eclipse.org/help32/index.jsp?

topic=/org.eclipse.gmf.doc/tutorials/msl/clipboardTutorial.html

− http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.gmf.doc/reference/extension-points/org_eclipse_gmf_runtime_common_ui_services_action_globalActionHandlerProviders.html

Copy & Paste support for MOSKitt Graphical Editors

Mario Cervera Úbeda([email protected])

Integranova S.A

http://www.moskitt.org