Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Changing Palette ToolGroups dynamically in GMF editor
Changing Palette ToolGroups dynamically in GMF editor [message #1065579] Wed, 26 June 2013 10:47 Go to next message
Eclipse UserFriend
I am pretty sure this question has come up before, but I have looked through the forum messages and couldn't find a solution.

I have to change the toolgroup displayed on a palette based on the diagram that the user wishes to create at runtime. For example, when a user drags and drops a diagram 'Event' the palette should display only those icons related to 'Event' and nothing else. Going through the forum I found some relevant messages but some of the link lead nowhere.

Would like some help with this.

Thanks

Re: Changing Palette ToolGroups dynamically in GMF editor [message #1066377 is a reply to message #1065579] Tue, 02 July 2013 07:42 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

you can call the following code on an IGraphicalEditpart

final PaletteViewer palette = ((EditDomain)target.getDiagramEditDomain()).getPaletteViewer();
palette.getPaletteRoot().add(aDrawer);


This code will retrieve the palette and then add a drawer to it. You can of course also iterate over the tools and set them to visible/invisible e.g. For putting your behaviour into the drag/drop operation you might take a look if you can install a suitable GEF Edit Policy into your edit part. This can also be done by a customized template ones you have this working as you wish.

Ralph
Re: Changing Palette ToolGroups dynamically in GMF editor [message #1066673 is a reply to message #1065579] Wed, 03 July 2013 12:33 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Ralph,

I got the desired piece working as a test, however, I have yet to figure out a way of integrating this seamlessly into the editor, without breaking existing functionality. Here's what I did based on your suggestion:
I created a XXXDragAndDropEditPolicy that extends DragDropEditPolicy.
For my *test* I overrode the getCommand method with this:

get EditPart via getHost().
editPart.getModel() to get View to check if it's a shortcut (If it is, no change in Palette).
get XXXDiagramEditor via PlatformUI->WorkBench->activePage->activeEditor
getEditDomain from Editor
Get PaletteViewer(palette) using suggested method. Depending on the editPart, I set the matching toolgroup in the palette to visible and all others not visible. Only the main toolgroup was visible at the creation of the diagram.

The code looks something like:
final PaletteViewer palette = domain.getPaletteViewer()
List entries = palette.getPaletteRoot().getChildren()
for(Object entry:entries){
if (isShortcut(view)) continue;//No change for shortcuts
entry instanceof PaletteDrawer
PaletteDrawer paletteEntry = (PaletteDrawer)entry

if (isXXX(editPart) && paletteEntry.getId().equals("xxxxxx"))
paletteEntry.setVisible(true);
else
paletteEntry.setVisible(false);
........

palette.getPaletteRoot().setChildren(entries);

........


This works fine when I bring the cursor on an element in the diagram. The part that is yet to work is when the diagram file is opened, the palette shows the main toolgroup regardless of what is already on the palette.

Again, thanks for your help!

V






Re: Changing Palette ToolGroups dynamically in GMF editor [message #1067548 is a reply to message #1066673] Tue, 09 July 2013 06:00 Go to previous message
Eclipse UserFriend
Hi,

first you should place your custom code into templates. This ensures that you keep you changes even after regenerating your code. http://www.bonitasoft.org/blog/eclipse/customize-your-gmf-editor-by-customizing-templates/. This should help you with it. There is also a command called something like targetDef.procedd if you only want to change the template for some of your generated edit parts. I use this very often.

For setting up your palette you could take a look on the generated xxxDiagramEditor that is generated.

Ralph
Previous Topic:combined GMF Editors
Next Topic:GMF/TENEO/Common Navigator Framework
Goto Forum:
  


Current Time: Sat Jul 12 15:38:24 EDT 2025

Powered by FUDForum. Page generated in 0.04004 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top