Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Filling the palette dynamically(Add buttons to the palette by loading information from a configuration file)
Filling the palette dynamically [message #556651] Thu, 02 September 2010 08:41 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
I am currently designing an editor in which you can create blocks with predefined input and output ports. So, I have a certain number of blocks which are all of the same type but the difference between them is their input and output ports.
I would like to be able to create the buttons in the palette at runtime: all the blocks information (name, ports, ...) would be loaded from a configuration file when the program starts. The reason why I would like something like that is my users would like to add their own blocks to the program and if they have to change only the configuration file, this becomes MUCH easier (I can even write a small program to edit the file). Otherwise, I will need to edit my model, regenerate the model code and recreate the full GMF code, which is obviously not an option.

The way to solve this would be to be able to add a button to the palette that "contains" some information about the button to create (typically just the type is enough, because all the information can be retrieved based on the name).
I've looked in the generated code but I can't see nowhere code related to the palette. Any slightest hint on how can achieve this would be welcome, because I have no clue how to do this (and I don't even know if this is possible).
Re: Filling the palette dynamically [message #556733 is a reply to message #556651] Thu, 02 September 2010 13:25 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Hi Cedric.

I just post this message to say that I'm very interested in the topic (sorry, I have no idea for the moment about how to implement this).
I would like my users to be able to save a subset of the diagram, to give it a name and be able to put a tool on the palete in order to create that subset. This brings me to your problem.

If anyone has experience with dynamically creation of the palette, please give us a clue.


Cheers,
Emil.



Re: Filling the palette dynamically [message #556735 is a reply to message #556651] Thu, 02 September 2010 13:15 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi, I have done something similar.

1) Using a palette provider, but this wouldn't be dynamic. (See 2)
(Note: The GMF generated code doesn't use the paletteProvider!)

You can actually create your own custom paletteProvider service.
look for extension:

org.eclipse.gmf.runtime.diagram.ui.paletterProviders

The extension point description should get you going!

2) Hooking to the generated code.

A factory is generated, you'll find it here:
xxx.part/xxx.PaletteFactory

Simply add Tool (Link, Node) entries to your palette in fillPalette()

The DiagramEditor calls this:

protected PaletteRoot createPaletteRoot(PaletteRoot existingPaletteRoot) {
PaletteRoot root = super.createPaletteRoot(existingPaletteRoot);
new xxxPaletteFactory().fillPalette(root);
return root;
}

I can imagine your app would have code here which would read your config
file and populate the palette. My approach was to generated Tool entries
from an EMF model which could be populated from the app itself. (Pretty
cool self-extending GMF editor).

Also there is a way that if you use multiple creationtool for the same
semantic object, you can act on the created object depending on the
custom Palette tool. (Of course this would assume the dynamic aspect, as
otherwise you have declared this as another element type when building
your .gmfgraph / .gmfmap / .gmftool statically)

First you would need to create a custom CreationTool which would put a
parameter in the create request.

public class CustomCreationTool extends CreationTool {
protected String node;
public CustomCreationTool(List elementTypes, String node) {
super();
this.node = node;
this.elementTypes = elementTypes;
}


protected Request createTargetRequest() {

CreateUnspecifiedTypeRequest req= new
CreateUnspecifiedTypeRequest(elementTypes, getPreferencesHint());
req.getExtendedData().put("name of tool clicked", node);
return req;
}

/**
* List of element types of which one will be created (of type
* <code>IElementType</code>).
*/
private List elementTypes;

}

Next you pick up the request in the edit helpers, by using
xxx.edit.Helpers classes. So when an object is created you could derive
which tool did it and set some features on the semantic model.

So you would override i.e. the getConfigureCommand() like below.

@Override
protected ICommand getConfigureCommand(final ConfigureRequest req) {

return new ConfigureNetworkElementCommand(req,
xxxPackage.eINSTANCE.getMyObject()) {
protected CommandResult doExecute(IProgressMonitor progressMonitor) {
Object o = req.getElementToConfigure();
return this.getCommandResult();
}

protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
Object o = req.getElementToConfigure();

Map params = req.getParameters();
String value = (String) params.get("name of tool clicked");
if (value != null) {
// do something with your object.
}
return this.getCommandResult();
}
};
}



On 02-09-10 10:41, Cedric wrote:
> I am currently designing an editor in which you can create blocks with
> predefined input and output ports. So, I have a certain number of blocks
> which are all of the same type but the difference between them is their
> input and output ports.
> I would like to be able to create the buttons in the palette at runtime:
> all the blocks information (name, ports, ...) would be loaded from a
> configuration file when the program starts. The reason why I would like
> something like that is my users would like to add their own blocks to
> the program and if they have to change only the configuration file, this
> becomes MUCH easier (I can even write a small program to edit the file).
> Otherwise, I will need to edit my model, regenerate the model code and
> recreate the full GMF code, which is obviously not an option.
>
> The way to solve this would be to be able to add a button to the palette
> that "contains" some information about the button to create (typically
> just the type is enough, because all the information can be retrieved
> based on the name). I've looked in the generated code but I can't see
> nowhere code related to the palette. Any slightest hint on how can
> achieve this would be welcome, because I have no clue how to do this
> (and I don't even know if this is possible).
Re: Filling the palette dynamically [message #556779 is a reply to message #556735] Thu, 02 September 2010 15:18 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Thanks a lot Christophe for your detailed answer, it's exactly what I needed.
Re: Filling the palette dynamically [message #556904 is a reply to message #556735] Fri, 03 September 2010 06:28 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello Christophe,

Thanks a lot for your detailed explanation, this is exactly what I need. Thanks for the time you spent to write such a quality answer Smile
Re: Filling the palette dynamically [message #633201 is a reply to message #556735] Fri, 15 October 2010 15:57 Go to previous message
Giovanni De Sossi is currently offline Giovanni De SossiFriend
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hallo Christophe,

I tried to reproduce this, but in my xxx.edit.Helper class I can't find the parameter previously set: where I'm wrong?

Merci,

Giovanni.
Previous Topic:Custom Creation Tool
Next Topic:Intalling GMF 2.1.3 In Eclipse 3.5
Goto Forum:
  


Current Time: Thu Apr 25 15:45:48 GMT 2024

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

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

Back to the top