Home » Modeling » GMF (Graphical Modeling Framework) » Dynamic palette and parts
|
Re: Dynamic palette and parts [message #222132 is a reply to message #222117] |
Fri, 20 March 2009 18:22 |
Eclipse User |
|
|
|
Originally posted by: me.urszeidler.de
Andreas Schoeneck schrieb:
> Hi,
>
> what I want to do recently is to dynamically add items to the palette
> that create the same figure/domain element but with a different
> attribute (e.g. type) value.
>
> What I read is that I have to make use of PaletteService. Unfortunately
> I can't find any (non-API) documentation on how to use it. Can anyone
> point me to this?
>
My current approach for this is to put some data in the ExtendedData map of the creation request, and then use this data in the CreationCommand and
initialize the domain object with it.
here is an example :
in XXXPaletteFactory
/**
* Creates "actions" palette tool group
*
* @generated
*/
private PaletteContainer createActions1Group() {
PaletteDrawer paletteContainer = new PaletteDrawer(Messages.Actions1Group_title);
createRegisterdActions(paletteContainer);
return paletteContainer;
}
/**
* Creates the dynamic generator tool entrys.
*
* @param paletteContainer
*/
private void createRegisterdActions(PaletteDrawer paletteContainer) {
Collection<ActionDescription> list = Activator.getDefault().getRegistry().getActiondescriptions() ;
for (ActionDescription generatorDescriptor : list) {
List/* <IElementType> */types = new ArrayList/* <IElementType> */(1);
IElementType elementTypes;
types.add(WorkflowElementTypes.Action_2001);
ActionToolEntry entry = new ActionToolEntry(generatorDescriptor.getActionInstance().getN ame(), generatorDescriptor
.getDescription(), types, generatorDescriptor);
// TODO : set the large icon also
if (generatorDescriptor.getSmallIcon() != null)
entry.setSmallIcon(Activator.getDefault()
.getBundledImageDescriptor(generatorDescriptor.getOwner().ge tConstibutorID(), generatorDescriptor.getSmallIcon()));
// entry.setLargeIcon(generatorDescriptor.getLargeIcon());
paletteContainer.add(entry);
}
}
Will create dynamically tool entrys, in this case in an "action" group.
/**
* A specialized Tool entry to provide the descriptor to the request.
* @author urs
*
*/
private static class ActionToolEntry extends ToolEntry {
public ActionToolEntry(String label, String shortDesc, List types, ActionDescription generatorDescriptor) {
super(label, shortDesc, null, null);
this.descriptor = generatorDescriptor;
this.elementTypes = types;
}
private final List elementTypes;
private ActionDescription descriptor;
/**
* @generated
*/
public Tool createTool() {
Tool tool = new UnspecifiedTypeCreationTool (elementTypes){
protected Request createTargetRequest() {
CreateUnspecifiedTypeRequest actionCreateRequest = new CreateUnspecifiedTypeRequest(elementTypes, getPreferencesHint());
actionCreateRequest.getExtendedData().put("generator_descriptor ", descriptor);
return actionCreateRequest;
}
};
tool.setProperties(getToolProperties());
return tool;
}
}
This tool entry puts the descriptor for the element to create in the ExtendedData map.
In the XXXCreateCommand
@Override
protected EObject doDefaultElementCreation() {
EObject eo = super.doDefaultElementCreation();
Object parameter = getRequest().getParameter("generator_descriptor");
if (parameter instanceof ActionDescription) {
ActionDescription descriptor = (ActionDescription) parameter;
Action action = (Action) eo;
action.setName(descriptor.getName());
Action actionInstance = descriptor.getActionInstance();
//TODO : add some features to generic generator (type)(id)
Collection<OutParameter> out = EcoreUtil.copyAll(actionInstance.getOut());
action.getOut().addAll(out);
Collection<InParameter> in = EcoreUtil.copyAll(actionInstance.getIn());
action.getIn().addAll(in);
action.setId(descriptor.getQuallifiedName());
}
return eo;
}
just override the doDefaultElementCreation() and get the descriptor from the request, and use it to configure your element.
If some one has a more elegant solution, I would be pleased to know.
greetings, urs.
|
|
| |
Re: Dynamic palette and parts [message #222350 is a reply to message #222132] |
Mon, 23 March 2009 12:46 |
Andreas Schoeneck Messages: 22 Registered: July 2009 |
Junior Member |
|
|
This is a multi-part message in MIME format.
--------------020303050807070308050703
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
Thanks again, Urs.
After getting through the code you posted, I figured out, which classes
belong to your domain model and which belong to GMF/GEF runtime/core or
whatsoever.
For demonstration purposes I've done this with simple strings:
This method is used to add the supposed tools to the tool group
(in the XXXPaletteFactory)
private void createSomeActions(PaletteGroup paletteContainer) {
Collection<String> sampleList = new ArrayList<String>();
fillTheCollection(sampleList); // just fill with some strings
for (String singleDataString: sampleList) {
List types = new ArrayList(1);
types.add(MyModelEditorElementTypes.ANode_2002);
MyCustomToolEntry entry = new MyCustomToolEntry(
MyModelEditor.diagram.part.Messages.ANode1CreationTool_title + "/"
+ singleDataString,
MyModelEditor.diagram.part.Messages.ANode1CreationTool_desc,
// TODO: add the correct icons
null, null, types, singleDataString);
paletteContainer.add(entry);
}
}
This class is the custom ToolEntry class:
(is mainly the same as you posted)
public class MyCustomToolEntry extends ToolEntry {
private String additionalData; // could be anything
private final List elementTypes;
public MyCustomToolEntry(String label, String shortDesc,
ImageDescriptor iconSmall, ImageDescriptor iconLarge, List types,
String aData) {
super(label, shortDesc, iconSmall, iconLarge);
additionalData = aData;
elementTypes = types;
}
public Tool createTool() {
Tool tool = new UnspecifiedTypeCreationTool (elementTypes){
protected Request createTargetRequest() {
CreateUnspecifiedTypeRequest actionCreateRequest = new
CreateUnspecifiedTypeRequest(elementTypes,
getPreferencesHint());
// set the additional data
actionCreateRequest.getExtendedData().put(
"additional_data", additionalData);
return actionCreateRequest;
}
};
tool.setProperties(getToolProperties());
return tool;
}
}
And - last but not least - the overridden
XXXCreateCommand.doDefaultElementCreation():
@Override
protected EObject doDefaultElementCreation() {
EObject eo = super.doDefaultElementCreation();
Object parameter = getRequest().getParameter("additional_data");
if (parameter instanceof String) {
String additionalData = (String)parameter;
// get domain model element
ANode node = (ANode) eo;
// do something with the additional data
// (here we set a property of a domain element)
node.setDescription(additionalData);
}
return eo;
}
For what one has to modify:
ANode - is my generic (node in this case) domain model element, use yours
String - used for demonstration purposes, could be any data that shall
be passed to the creation
"additional_data" - the key of the additional data passed to the
creation, one could add more data or use a different string as key
MyModelEditorXXX - the generated classes that hold strings etc., use yours
fillTheCollection(...) - a sample method that fills up the string
collection (with random bullshit so far), can be anything that fills up
your additional data collection dynamically
What is left?
- Use the correct icons. Maybe this can be achieved by using a different
superclass for MyCustomToolEntry. Advice needed.
- Either have the quick creation assistant to support this or remove all
the items from it. I can't do neither. Advice needed.
If anyone can solve the issues mentioned here, your contribution would
be very much appreciated.
Thanks in advance.
Regards
Andy
--------------020303050807070308050703
Content-Type: text/x-vcard; charset=utf-8;
name="as_maps.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="as_maps.vcf"
begin:vcard
fn:Andreas Schoeneck
n:Schoeneck;Andreas
email;internet:as.maps@gmail.com
x-mozilla-html:FALSE
version:2.1
end:vcard
--------------020303050807070308050703--
|
|
|
Re: Dynamic palette and parts [message #222389 is a reply to message #222350] |
Mon, 23 March 2009 16:15 |
Eclipse User |
|
|
|
Originally posted by: me.urszeidler.de
> ANode - is my generic (node in this case) domain model element, use yours
> String - used for demonstration purposes, could be any data that shall
> be passed to the creation
> "additional_data" - the key of the additional data passed to the
> creation, one could add more data or use a different string as key
> MyModelEditorXXX - the generated classes that hold strings etc., use yours
> fillTheCollection(...) - a sample method that fills up the string
> collection (with random bullshit so far), can be anything that fills up
> your additional data collection dynamically
>
That's it.
> What is left?
> - Use the correct icons. Maybe this can be achieved by using a different
> superclass for MyCustomToolEntry. Advice needed.
MyCustomToolEntry entry = new MyCustomToolEntry(
MyModelEditor.diagram.part.Messages.ANode1CreationTool_title + "/"
+ singleDataString,
MyModelEditor.diagram.part.Messages.ANode1CreationTool_desc,
// TODO: add the correct icons
null, null, types, singleDataString);
Your TODO is absolute right, thats the point where you can define your icons.
> - Either have the quick creation assistant to support this or remove all
> the items from it. I can't do neither. Advice needed.
>
That's a point I'm also interesting in. To remove is simple, in XXXModelingAssistantProvider just
remove the corresponding types form the list. Or you could disable it in the preferences.
But the ModelingAssistantProvider is quite cool, so the best is keep it.
So the question is how to supply the ModelingAssistantProvider with additional entrys.
> If anyone can solve the issues mentioned here, your contribution would
> be very much appreciated.
>
> Thanks in advance.
>
> Regards
> Andy
|
|
| |
Re: Dynamic palette and parts [message #222865 is a reply to message #222848] |
Thu, 26 March 2009 13:52 |
Eclipse User |
|
|
|
Originally posted by: me.urszeidler.de
Andreas Schoeneck schrieb:
> Hey, this is me again!
>
> Urs, do you know, how all the stuff can be achieved with connections?
> The createTargetRequest method does not seem to be able to pass the
> parameter to the creation request. Do I have to override a different
> method? Or is there another request to return?
> Maybe I am just too stupid today, please help me. My code looks as follows.
>
> in MyCustomLinktoolEntry:
> public Tool createTool() {
> Tool tool = new UnspecifiedTypeConnectionTool (elementTypes){
> protected Request createTargetRequest() {
> CreateUnspecifiedTypeConnectionRequest actionCreateRequest =
> new CreateUnspecifiedTypeConnectionRequest(
> elementTypes, false, getPreferencesHint());
> actionCreateRequest.getExtendedData().put(
> "entry_type", entryType);
> return actionCreateRequest;
> }
> };
> tool.setProperties(getToolProperties());
> return tool;
> }
>
Why not doing something like this :
Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes){
@Override
protected Request createTargetRequest() {
Request req = super.createTargetRequest();
actionCreateRequest.getExtendedData().put("entry_type", entryType);
return req;
}
If your link is an "typebased" link there is an analog XXXCreateCommand with somethink like this :
/**
* @generated
*/
protected EObject doDefaultElementCreation() {
Transition newElement = WorkflowFactory.eINSTANCE.createTransition();
//where you could do the same as for nodes
getSource().getTransitions().add(newElement);
newElement.setTarget(getTarget());
return newElement;
}
If it is a reference link, there is no element in your semantic model you could configure, but you could configure the view, but I'm not sure where
you could intercept.
greetings, urs.
|
|
|
Goto Forum:
Current Time: Fri Apr 19 07:20:03 GMT 2024
Powered by FUDForum. Page generated in 0.02334 seconds
|