Asher
Asher

Reputation: 821

Extending GMF Editors for Customization

I need to customize the generated code for an editor I created using GMF. For example, I need to add a pop up box on selection of a node in the editor, I need to add text too the blank space used as the canvas for the editor. I understand that these edits need to be done by hand. Could someone please tell me how to do the above mentioned things? Or possibly point me towards resources for extending the GMF editors and customizing them?

Upvotes: 0

Views: 405

Answers (2)

aboyko
aboyko

Reputation: 1572

I'm surprised that the popup bar is not showing up for you by default for the GMF generated editor. Perhaps it's just disabled. Put a breakpoint in org.eclipse.gmf.runtime.diagram.ui.editpolicies.DiagramAssistantEditPolicy#shouldShowDiagramAssistant(). First of all check if you ever stop there and if you do check why false is returned, check if #isPreferenceOn() returns false in particular. If the preference setting is off then fixing the popup bar would just be a matter of setting a preference.

I'd advice to start reading up on GEF. GEF is Eclipse's Graphical Editing Framework. GMF is based on GEF. GEF architecture is Model - View - Controller. View maps in Java implements IFigure. Controller implements EditPart interface Model is left open in GEF. GMF expects EMF model (EMF is Eclipse Modeling Framework) and adds on top of the runtime tooling component to generate code.

I'd advice you to start reading articles on GEF, some of these articles would be about GEF editors with EMF models (which is really GMF). Link to the articles: https://www.eclipse.org/gef/reference/articles.html

For the staff that you wanted you'd need to modify the Controllers from the GEF's MVC architecture. Look for classes ending with EditPart. EditPolicies are artifacts responsible for editing capabilities over the shapes on a diagram. EditPolicies are installed on editparts.

Hope this helps.

Upvotes: 0

aboyko
aboyko

Reputation: 1572

There are a few options for providing a popup on selection or hover. Not sure what you meant by text on a blank space... perhaps you can clarify that. The easiest way to enable a pop up bar would be installing a org.eclipse.gmf.runtime.diagram.ui.editpolicies.PopupbarEditPolicy on youe editparts for which you'd like the popup bar to appear. This edit policy shows a popup bar when your mouse cursor enters a figure and the mouse remains idle inside a figure for a second or something like that. Think it would show up when a shape is selected. Please play around with GMF runtime Logic example diagram editor to get an idea of what I'm talking about. You could tailor this edit policy to you liking and then install on applicable editparts via the #createDefaultEditPolicies() method. The following is the example:

installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new PopupBarEditPolicy());

See org.eclipse.gmf.runtime.emf.ui.modelingAssistantProviders to contribute actions to the popup bar. (Example is org.eclipse.gmf.examples.runtime.diagram.logic/plugin.xml)

If this is too complicated then try subclassing the ShapeResizableEditPolicy and override showSelection() and hideSelection() methods to add your popup strictly for selection. Complications are that it might some other subclass of SelectionEditPolicy you'd need to override depending on what is installed under EditPolicy.PRIMARY_DRAG_ROLE and also be careful about the figure layer where you add the popup figure.

In addition you could add a SelectionListener to a GraphicalViewer and then try add/remove a popup figure based on what's selected, but I wouldn't recommend this solution.

Hope this helps.

Upvotes: 1

Related Questions