Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Dynamic palette and parts
Dynamic palette and parts [message #222117] Fri, 20 March 2009 16:58 Go to next message
Andreas Schoeneck is currently offline Andreas SchoeneckFriend
Messages: 22
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.
--------------040405020201070803040303
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

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?

Is there a similar mechanism for what I want the EditParts/Figures to
behave? To clarify: Let us say the above mentioned type attribute holds
up to n distinct values. These values are determined at runtime and for
each value there shall be a tool on the palette that can create a
generic node figure on the canvas with a label that shows this
attribute's value.

It would even help me if you give me a hint or link or anything that
points me to the correct documentation location.

Thanks in advance.

Regards

--------------040405020201070803040303
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


--------------040405020201070803040303--
Re: Dynamic palette and parts [message #222132 is a reply to message #222117] Fri, 20 March 2009 18:22 Go to previous messageGo to next message
Eclipse UserFriend
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 #222161 is a reply to message #222132] Sat, 21 March 2009 10:44 Go to previous messageGo to next message
Andreas Schoeneck is currently offline Andreas SchoeneckFriend
Messages: 22
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.
--------------050004000906020805020408
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi urs, thanks for your reply

unfortunately it seems that I am using a different version of GMF.
Perhaps I assume this due to not being familiar with the concepts you
use. In my createXXXGroup() methods a PaletteGroup is used rather than a
PaletteDrawer. There's no createRegisteredActions method by default
(perhaps I am a bit confused about which of your methods are generated
and which aren't) and I don't know where to take the ActionDescription
class from.
Nevertheless what you wrote is what I need I think - if only the above
mentioned issues were resolved. They may only exist due to my lack of
experience/intelligence in advanced GMF stuff, so I beg you for being
patient with me.

Regards
Andy

urs zeidler schrieb:

> 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.


--------------050004000906020805020408
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


--------------050004000906020805020408--
Re: Dynamic palette and parts [message #222350 is a reply to message #222132] Mon, 23 March 2009 12:46 Go to previous messageGo to next message
Andreas Schoeneck is currently offline Andreas SchoeneckFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #222848 is a reply to message #222389] Thu, 26 March 2009 11:22 Go to previous messageGo to next message
Andreas Schoeneck is currently offline Andreas SchoeneckFriend
Messages: 22
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.
--------------040300050506060002030603
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

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;
}

The Request I get in doDefaultElementCreation is slightly different, it
is of type
org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelatio nshipRequest

How to get this together?

Regards and many thanks so far as well as in advance
Andreas


--------------040300050506060002030603
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


--------------040300050506060002030603--
Re: Dynamic palette and parts [message #222865 is a reply to message #222848] Thu, 26 March 2009 13:52 Go to previous message
Eclipse UserFriend
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.
Previous Topic:SubClassing TransactionalEditingDomain
Next Topic:WrapTextCellEditor problem
Goto Forum:
  


Current Time: Fri Apr 19 07:20:03 GMT 2024

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

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

Back to the top