Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Genmodel property "Creation sub-menus"
Genmodel property "Creation sub-menus" [message #1079543] Sun, 04 August 2013 19:28 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi,

I was looking through the properties of the genmodel and found an boolean attribute called Creation sub-menus. The documentation in the EMF book says:

Quote:

This property determines whether to organize qualified child creation actions into submenus. In the case where an object can have children of the same type via more than one of its features, setting this property to true results in a submenu per feature.


This option might be interesting for me, but I don't really understand the part object can have children of the same type via more than one of its features. Can someone give me an example (metamodel) where this case would match? Or have I to implement the sub-menu by myself in the according itemprovider?

Cheers,
Phil
Re: Genmodel property "Creation sub-menus" [message #1079861 is a reply to message #1079543] Mon, 05 August 2013 07:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Phil,

If you have a class X with two references r1 and r2 of class Y, then the
create menu needs to make it clear when creating a child Y whether it
should end up in reference r1 verses r2.


On 04/08/2013 9:28 PM, Phil H wrote:
> Hi,
>
> I was looking through the properties of the genmodel and found an
> boolean attribute called Creation sub-menus. The documentation in the
> EMF book says:
>
> Quote:
>> This property determines whether to organize qualified child creation
>> actions into submenus. In the case where an object can have children
>> of the same type via more than one of its features, setting this
>> property to true results in a submenu per feature.
>
>
> This option might be interesting for me, but I don't really understand
> the part object can have children of the same type via more than one
> of its features. Can someone give me an example (metamodel) where this
> case would match? Or have I to implement the sub-menu by myself in the
> according itemprovider?
>
> Cheers,
> Phil
Re: Genmodel property "Creation sub-menus" [message #1080113 is a reply to message #1079861] Mon, 05 August 2013 13:37 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Thx Ed,

that make sense.

Is there a way to implement my own sub-menu for one specific class altough it don't match this case?

For example I have a class X which has a * containment reference to class Y. I would like now to implement a sub-menu inside the Create Child menu of class X where I can choose between different creations of class Y. For example one child creation command would then create a class Y with a specific value, another would set a predefined name attribute and so on.. Is this possible or would it be much effort?

Cheers,
Phil
Re: Genmodel property "Creation sub-menus" [message #1080126 is a reply to message #1080113] Mon, 05 August 2013 13:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Phil,

Comments below.

On 05/08/2013 3:37 PM, Phil H wrote:
> Thx Ed,
>
> that make sense.
>
> Is there a way to implement my own sub-menu for one specific class
> altough it don't match this case?
In the XyzActionBarContributor you could special how the child creation
menus are constructed.
>
> For example I have a class X which has a * containment reference to
> class Y. I would like now to implement a sub-menu inside the Create
> Child menu of class X where I can choose between different creations
> of class Y. For example one child creation command would then create a
> class Y with a specific value, another would set a predefined name
> attribute and so on.. Is this possible or would it be much effort?
You'd also want to specialize the item providers to create additional
descriptors.
>
> Cheers,
> Phil
Re: Genmodel property "Creation sub-menus" [message #1090178 is a reply to message #1080126] Mon, 19 August 2013 20:30 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Finally I got it managed to extend my New Child menu. Now it's possible to create childrens of the same class, initialized with different properties. Since the New Child menu has now some entries, I would like to bundle them into a submenu. Is emf supporting this? Maybe the create submenu could be extended to support this?

Cheers,
Phil
Re: Genmodel property "Creation sub-menus" [message #1091528 is a reply to message #1090178] Wed, 21 August 2013 16:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
There's the Creation Sub-menus property in the GenModel...

On 19/08/2013 10:30 PM, Phil H wrote:
> Finally I got it managed to extend my New Child menu. Now it's
> possible to create childrens of the same class, initialized with
> different properties. Since the New Child menu has now some entries, I
> would like to bundle them into a submenu. Is emf supporting this?
> Maybe the create submenu could be extended to support this?
>
> Cheers,
> Phil
Re: Genmodel property "Creation sub-menus" [message #1094387 is a reply to message #1091528] Sun, 25 August 2013 16:23 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
The Creation Sub-menus property is set to true but it doesn't work as you can see in the attached image.
  • Attachment: submenu.jpg
    (Size: 16.19KB, Downloaded 55 times)
Re: Genmodel property "Creation sub-menus" [message #1094732 is a reply to message #1094387] Mon, 26 August 2013 05:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Phil,

It only produces qualification if a given type of object can be created
for more than one feature of the class. You'll see your generated item
provider plugin.properties contains properties generated from the
template like this:

_UI_CreateChild_text = {0}
_UI_CreateChild_text2 = {1} <%if (genModel.isCreationSubmenus()) {%>|
<%}%>{0}
_UI_CreateChild_text3 = {1}

You could change all three to look like "{1} | {0}" and then you'll get
submenus for all features with more than one type of child. Check the
behavior of
org.eclipse.example.library.presentation.XyzActionBarContributor.extractSubmenuActions(Collection<IAction>)
to see in the debugger whether it's working as you expect.


On 25/08/2013 6:23 PM, Phil H wrote:
> The Creation Sub-menus property is set to true but it doesn't work as you can see in the attached image.
>
Re: Genmodel property &amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;quot; [message #1095068 is a reply to message #1094732] Mon, 26 August 2013 15:24 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

changing the plugin.properties to:

_UI_CreateChild_text = {1} | {0}
_UI_CreateChild_text2 = {1} | {0}
_UI_CreateChild_text3 = {1} | {0}


hasn't any impact on the menu I mentioned before. There is no submenu although the elements are intances of the same class. Whereas items where I haven't customized the getText method seems to have now an additional submenu (which I don't want btw):

index.php/fa/16041/0/

Unfortunately I couldn't found the method you mentioned using Ctrl-Shift-T.

I don't really understand how the submenu are working, so it's hard for me to find a solution
  • Attachment: submenu.jpg
    (Size: 8.25KB, Downloaded 135 times)
Re: Genmodel property &amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;quot; [message #1095158 is a reply to message #1095068] Mon, 26 August 2013 18:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Phil,

Can you find the XyzActionBarContributor class?


On 26/08/2013 5:24 PM, Phil H wrote:
> Hi Ed,
>
> changing the plugin.properties to:
>
>
> _UI_CreateChild_text = {1} | {0}
> _UI_CreateChild_text2 = {1} | {0}
> _UI_CreateChild_text3 = {1} | {0}
>
>
> hasn't any impact on the menu I mentioned before. There is no submenu although the elements are intances of the same class. Whereas items where I haven't customized the getText method seems to have now an additional submenu (which I don't want btw):
>
>
>
> Unfortunately I couldn't found the method you mentioned using Ctrl-Shift-T.
>
> I don't really understand how the submenu are working, so it's hard for me to find a solution
Re: Genmodel property &amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;quot; [message #1096458 is a reply to message #1095158] Wed, 28 August 2013 12:23 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

yes I've found that class and the extractSubmenuActions(Collection<IAction>) is every time called except for the one wich has got more than one child instance of the same class. That's weird for me as I can't explain this behaviour. I customized the collectNewChildDescriptors method of this item provider, so that's maybe causing this?

The default one generated looks in my case:

_UI_CreateChild_text = {0}
_UI_CreateChild_text2 = {1} | {0}
_UI_CreateChild_text3 = {1}


changing _UI_CreateChild_text to {1} | {0} provides submenus for all childs except the one I mentioned.

Cheers,
Phil
Re: Genmodel property &amp;amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;amp;quot; [message #1096587 is a reply to message #1096458] Wed, 28 August 2013 15:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Phil,

Comments below.

On 28/08/2013 2:23 PM, Phil H wrote:
> Hi Ed,
>
> yes I've found that class and the
> extractSubmenuActions(Collection<IAction>) is every time called except
> for the one wich has got more than one child instance of the same
> class. That's weird for me as I can't explain this behaviour. I
> customized the collectNewChildDescriptors method of this item
> provider, so that's maybe causing this?
It could be, but I can't guess at what you might have done there...
>
> The default one generated looks in my case:
>
>
> _UI_CreateChild_text = {0}
> _UI_CreateChild_text2 = {1} | {0}
> _UI_CreateChild_text3 = {1}
>
>
> changing _UI_CreateChild_text to {1} | {0} provides submenus for all
> childs except the one I mentioned.
>
> Cheers,
> Phil
Re: Genmodel property &amp;amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;amp;quot; [message #1096688 is a reply to message #1096587] Wed, 28 August 2013 18:30 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
I want to achieve that elements are initialized with specific values so I changed collectNewChildDescriptors in this way:

HardwareElement microcontroller = PldFactory.eINSTANCE.createHardwareElement();
microcontroller.setElementType(ElementType.MICROCONTROLLER);

// adding Microncontroller
newChildDescriptors.add(createChildParameter(PldPackage.Literals.HARDWARE_ELEMENT__HARDWARE_ELEMENTS,microcontroller));

HardwareElement core = PldFactory.eINSTANCE.createHardwareElement();
core.setElementType(ElementType.CORE);

// adding Core
newChildDescriptors.add(createChildParameter(PldPackage.Literals.HARDWARE_ELEMENT__HARDWARE_ELEMENTS,core));

and so on...


Another thing what I've done is implementing the getCreateChildText method:

if (child instanceof HardwareElement) {
HardwareElement hw = (HardwareElement) child;
ElementType type = hw.getElementType();

switch (type) {
case MICROCONTROLLER:
	return "Microcontroller";
case CORE:
	return "Core";

and so on...


can you spot any problems which this code?
Re: Genmodel property &amp;amp;amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;amp;a [message #1097120 is a reply to message #1096688] Thu, 29 August 2013 08:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Phil,

Comments below.

On 28/08/2013 8:30 PM, Phil H wrote:
> I want to achieve that elements are initialized with specific values
> so I changed collectNewChildDescriptors in this way:
>
>
> HardwareElement microcontroller =
> PldFactory.eINSTANCE.createHardwareElement();
> microcontroller.setElementType(ElementType.MICROCONTROLLER);
>
> // adding Microncontroller
> newChildDescriptors.add(createChildParameter(PldPackage.Literals.HARDWARE_ELEMENT__HARDWARE_ELEMENTS,microcontroller));
>
>
> HardwareElement core = PldFactory.eINSTANCE.createHardwareElement();
> core.setElementType(ElementType.CORE);
>
> // adding Core
> newChildDescriptors.add(createChildParameter(PldPackage.Literals.HARDWARE_ELEMENT__HARDWARE_ELEMENTS,core));
>
>
> and so on...
>
>
> Another thing what I've done is implementing the getCreateChildText
> method:
>
>
> if (child instanceof HardwareElement) {
> HardwareElement hw = (HardwareElement) child;
> ElementType type = hw.getElementType();
>
> switch (type) {
> case MICROCONTROLLER:
> return "Microcontroller";
> case CORE:
> return "Core";
>
> and so on...
>
>
> can you spot any problems which this code?
Yes, keep in mind that the splitting into submenus is based on this
text containing a "|" to separate the name of the submenu from the name
of the item in that submenu; so here you need to ensure you return a
string containing a "|".
Re: Genmodel property &amp;amp;amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;amp;a [message #1099299 is a reply to message #1097120] Sun, 01 September 2013 13:07 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
That has done the trick, tx Ed!!

As you can see in the attached the sub-menu has no icon. Is it possible to assign an icon to the submenu?

  • Attachment: sub-menu.jpg
    (Size: 8.99KB, Downloaded 48 times)
Re: Genmodel property &amp;amp;amp;amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;a [message #1099451 is a reply to message #1099299] Sun, 01 September 2013 18:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
You can specialize
org.eclipse.emf.edit.provider.ItemProviderAdapter.getCreateChildImage(Object,
Object, Object, Collection<?>)

On 01/09/2013 3:07 PM, Phil H wrote:
> That has done the trick, tx Ed!!
>
> As you can see in the attached the sub-menu has no icon. Is it possible to assign an icon to the submenu?
>
>
Re: Genmodel property &amp;amp;amp;amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;amp;a [message #1100014 is a reply to message #1099451] Mon, 02 September 2013 14:34 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

that's what I've tried so far. It works for child entries, but for the sub-menu an icon is never displayed, no matter what the method returns.
  • Attachment: sub-menu.png
    (Size: 2.85KB, Downloaded 46 times)
Re: Genmodel property &amp;amp;amp;amp;amp;amp;amp;amp;quot;Creation sub-menus&amp;amp;amp;a [message #1100434 is a reply to message #1100014] Tue, 03 September 2013 05:42 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Phil,

I've never seen a submenu with icons in Eclipse. I'm not sure that's
possible. The generated code doesn't do such a thing, so you'd have to
write that yourself.

On 02/09/2013 4:34 PM, Phil H wrote:
> Hi Ed,
>
> that's what I've tried so far. It works for child entries, but for the sub-menu an icon is never displayed, no matter what the method returns.
Previous Topic: DOM node to an EMF object?
Next Topic:how to handle deletion in one way reference
Goto Forum:
  


Current Time: Fri Dec 19 03:28:01 GMT 2014

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

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