Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Parsley » How to Customize Context Menu to create child that is not a containment *list*?(menuBuilder addAction 2nd argument is not an EList...what to do?)
icon5.gif  How to Customize Context Menu to create child that is not a containment *list*? [message #1705486] Mon, 17 August 2015 04:39 Go to next message
Ulrich Lang is currently offline Ulrich LangFriend
Messages: 14
Registered: August 2015
Junior Member
Hi!

I've been playing with the Parsley DSL and got stuck with a problem where my metamodel has a containment reference that can only be 0..1, i.e. not 0..*.

I've used exactly the same format for the context menus::

"Pls" is the parent, which contains zero or one "hlpset", which is a "Plset"

Pls mm2 -> #[
actionAdd(
"...",
mm2.hlpset,
factory2.createPlset,
[ x |
x.name = "..."
]
)
]

The DSL gives me the error: "Type mismatch: cannot convert from Plset to EList<? super Plset>".
So I thought I'd cast to EList...changing "mm2.hlpset, " to "mm2.hlpset as EList<Plset>,"
The DSL accepts it and code is generated.
However, when I run it, it either gives me a Null Pointer Exception or the context menu appears, but nothing happens when I select it (i.e, no child created).

It works fine exactly doing the same for all occurrences where the Parent is a list (0..*) of containments in the metamodel thought.

So I'm wondering whether I'm doing something wrong, or whether this is a bug in the API that doesn't accept creating children on metamodel elements that only allow 0...1 children?

Any help would be appreciated!

Thanks!
Ulrich



Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1705535 is a reply to message #1705486] Mon, 17 August 2015 12:22 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 17/08/2015 13:51, Ulrich Lang wrote:
> Hi!
>
> I've been playing with the Parsley DSL and got stuck with a problem
> where my metamodel has a containment reference that can only be 0..1,
> i.e. not 0..*.
> I've used exactly the same format for the context menus::
>
> "Pls" is the parent, which contains zero or one "hlpset", which is a
> "Plset"
>
> Pls mm2 -> #[
> actionAdd(
> "...",
> mm2.hlpset, factory2.createPlset,
> [ x |
> x.name = "..." ]
> )
> ]
>
> The DSL gives me the error: "Type mismatch: cannot convert from Plset to
> EList<? super Plset>". So I thought I'd cast to EList...changing
> "mm2.hlpset, " to "mm2.hlpset as EList<Plset>,"
> The DSL accepts it and code is generated.
> However, when I run it, it either gives me a Null Pointer Exception or
> the context menu appears, but nothing happens when I select it (i.e, no
> child created).
>
> It works fine exactly doing the same for all occurrences where the
> Parent is a list (0..*) of containments in the metamodel thought.
>
> So I'm wondering whether I'm doing something wrong, or whether this is a
> bug in the API that doesn't accept creating children on metamodel
> elements that only allow 0...1 children?
>
> Any help would be appreciated!
>
> Thanks!
> Ulrich

Hi Ulrich

actionAdd was designed to add an element to a list, which is not your
case. We would need a way to specify another kind of action, something
like actionSet for 0..1 relations. (or, in general, to specify more
generic actions).

Would you please file a bug so that we can keep a track of it? We might
be able to implement something by the end of the month, i.e., before the
next release 0.5.0.

Thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1705592 is a reply to message #1705535] Mon, 17 August 2015 16:49 Go to previous messageGo to next message
Ulrich Lang is currently offline Ulrich LangFriend
Messages: 14
Registered: August 2015
Junior Member
Thanks, just did it.
Best
Ulrich

PS I was also wondering about Parsley RAP - there is no modules.parsley in the RAP example, I guess because it's running in the EMF RAP Target. Is there an easy way to "RAPify" the non-RAP Parsley proejcts (e.g. drag & drop generated code into the RAP example? Thanks!
Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1705694 is a reply to message #1705592] Tue, 18 August 2015 12:21 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 17/08/2015 18:49, Ulrich Lang wrote:
> Thanks, just did it.

Great!

> PS I was also wondering about Parsley RAP - there is no modules.parsley

what do you mean by "no modules.parsley"?

> in the RAP example, I guess because it's running in the EMF RAP Target.
> Is there an easy way to "RAPify" the non-RAP Parsley proejcts (e.g. drag
> & drop generated code into the RAP example? Thanks!

as for "RAPify" we basically use the standard techniques for single
sourcing as suggested by RAP documentation itself: you can use either
optional bundle requirements, or, as we do for the development of
Parsley bundles, have a common bundle with "import" requirements
(instead of required bundles) and then have an RCP bundle and a RAP
bundle (that only provide the actual requirements as requested by the
import requirements; i.e., such projects do not contain any sources).

We are also thinking to provide project wizards that already setup such
projects, but in the end, there's nothing specific of Parsley (just
specific for RAP).

Is that what you were asking?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1705726 is a reply to message #1705694] Tue, 18 August 2015 15:04 Go to previous messageGo to next message
Ulrich Lang is currently offline Ulrich LangFriend
Messages: 14
Registered: August 2015
Junior Member
>> PS I was also wondering about Parsley RAP - there is no modules.parsley
> what do you mean by "no modules.parsley"?

Apologies. I meant that the Parsley RAP example is not a DSL example.

> We are also thinking to provide project wizards that already setup such
>projects, but in the end, there's nothing specific of Parsley (just
> specific for RAP).

Actually that would be great! I am really not a UI developer, and I need a rapidly customizable EMF model editor (e.g. if the Ecore model changes), and any wizards would help. The DSL helps a lot already, which makes EMF Parsley a great fit for my goals.

Regarding the original bug/feature request, I noticed that there is the same issue with viewerContentProvider: while you can show a single 0..1 child, you cannot use the "+" to show several 0..1 children or a mix of 0..1/0..*. The DSL complains about "+". It seems in the code you are using concat of ELists <O>, which obviously doesn't work if the input isn't an EList but the actual object O. Do you want me to submit another bug request?

Thanks!
Ulrich
Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1705844 is a reply to message #1705726] Wed, 19 August 2015 12:37 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 18/08/2015 17:04, Ulrich Lang wrote:
>>> PS I was also wondering about Parsley RAP - there is no modules.parsley
>> what do you mean by "no modules.parsley"?
>
> Apologies. I meant that the Parsley RAP example is not a DSL example.

Hi

you probably refer to the example we talk about in the documentation;
but you can import another example from Parsley which has a version for
RCP and one for RAP. The treeform is implemented with the DSL and the
MANIFEST shows the single sourcing technique I was telling you about
with the import packates:
http://git.eclipse.org/c/emf-parsley/org.eclipse.emf-parsley.git/tree/examples/org.eclipse.emf.parsley.examples.cdo.treeform/META-INF/MANIFEST.MF

then there's a bundle .rcp and one .rap.

So you can use the DSL even in a project which is meant to be used in a
RAP environment as well :)

We should probably document that example as well.

>> We are also thinking to provide project wizards that already setup such
>> projects, but in the end, there's nothing specific of Parsley (just
>> specific for RAP).
>
> Actually that would be great! I am really not a UI developer, and I need
> a rapidly customizable EMF model editor (e.g. if the Ecore model
> changes), and any wizards would help. The DSL helps a lot already,
> which makes EMF Parsley a great fit for my goals.

as said above, you can still use the DSL in a RAP project; it's just
that the setup of dependencies has to be manually modified for the
moment (e.g., with import packages)

>
> Regarding the original bug/feature request, I noticed that there is the
> same issue with viewerContentProvider: while you can show a single 0..1
> child, you cannot use the "+" to show several 0..1 children or a mix of
> 0..1/0..*. The DSL complains about "+". It seems in the code you are
> using concat of ELists <O>, which obviously doesn't work if the input
> isn't an EList but the actual object O. Do you want me to submit
> another bug request?

That's not actually a bug, if I understand correctly your scenario: the
type system (inherited by Xtext's Xbase) requires that the two
expressions of a '+' are compliant, so you can "sum" two collections,
two strings, but not a collection and an object.

So your custom "children" can return a single object and we'll wrap it
for you in a collection; but if you want to return a list which mixes
collections and single elements and concatenate them with '+' you'll
have to wrap the single element manually, e.g., with newArrayList (a
utility method which is part of the runtime library), e.g.,

o.myelements + newArrayList(o.myfield)

does that help?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1705923 is a reply to message #1705844] Thu, 20 August 2015 07:29 Go to previous messageGo to next message
Ulrich Lang is currently offline Ulrich LangFriend
Messages: 14
Registered: August 2015
Junior Member
Hi Lorenzo

Thanks! Yes, the newArrayList works, I hope you can still put a fix (e.g. specific keyword) for the 0..1 problem in the context menus in the next version. That would be great! I got it working on RCP.

Regarding the RAP single sourcing , I failed miserably today, breaking my workspace numerous times :/ I am not sure where the problem is, so I cannot pinpoint whether this has anything to do with Parsley or not. I will keep you posted.

Best,
Ulrich
Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1705955 is a reply to message #1705923] Thu, 20 August 2015 12:13 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 20/08/2015 09:29, Ulrich Lang wrote:
> Hi Lorenzo
>
> Thanks! Yes, the newArrayList works, I hope you can still put a fix
> (e.g. specific keyword) for the 0..1 problem in the context menus in the
> next version. That would be great! I got it working on RCP.
> Regarding the RAP single sourcing , I failed miserably today, breaking
> my workspace numerous times :/ I am not sure where the problem is, so I
> cannot pinpoint whether this has anything to do with Parsley or not. I
> will keep you posted.

Hi

please keep in mind that if you use import requirements, then in the
workspace (or at least in the target platform) you need bundles that
provide such requirements or the Java files won't compile.

E.g. in Parsley, we develop the Java classes in the parsley.common
project, with import requirements, and then we have parsley project
(parsley.rap in the rap development workspace, respectively) which has
required bundles that provide the import requirements...

I don't know whether these are the problems you get in your case.

In any case, for single sourcing, you need two workspaces for
development: one for RCP and one for RAP.

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1706202 is a reply to message #1705955] Mon, 24 August 2015 18:39 Go to previous messageGo to next message
Ulrich Lang is currently offline Ulrich LangFriend
Messages: 14
Registered: August 2015
Junior Member
Hi Lorenzo,

Sorry for the delay in responding, I was held up with some deadlines.
Thanks for your help. I will play with single sourcing again this week.

Best,
Ulrich
Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1706342 is a reply to message #1705955] Wed, 26 August 2015 06:44 Go to previous messageGo to next message
Ulrich Lang is currently offline Ulrich LangFriend
Messages: 14
Registered: August 2015
Junior Member
Hi Lorenzo,

I have it working with RAP now Smile Had to add org.eclipse.xtext.xbase.lib into the dependencies to make this work at runtime.

Will report back if I find any other things that could go into the documentation.

It would be great to hear from you if there are any news about how to use actionAdd for 0..1 children. At the moment my editor displays a whole load of stuff in the context menus that shouldn't be available to the user.

Thanks!!!
Ulrich

PS In a previous version of this comment I suggested a feature, but then realized that it already does that Smile Great!! (One useful feature that I thought could be added to the viewerContentProvider would be some sort of keyword that says "complete tree of children". So if display something, the entire tree hanging off that displayed tree element also displays. That would (at least for my usecase) allow for great flexibility without having to manually type in (and update) many model elements in the DSL.)

[Updated on: Wed, 26 August 2015 07:25]

Report message to a moderator

Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1706612 is a reply to message #1706342] Fri, 28 August 2015 07:33 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 26/08/2015 08:44, Ulrich Lang wrote:
> Hi Lorenzo,
>
> I have it working with RAP now :) The only problem is that the
> newArrayList workaround gives me an error in RAP - apparently the
> relevant bundle is missing
> (org.eclipse.xtext.xbase.lib.CollectionLiterals)? However, I've
> installed XText into the Target Platform and that bundle is ticked in
> the run configuration.
> Is there anything specific I have to do/install to make this work? Thanks!
>
> Best,
> Ulrich
>

Hi

mh... that's strange... in the launch configuration do you get any error
if you press the validate button?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: How to Customize Context Menu to create child that is not a containment *list*? [message #1708615 is a reply to message #1705486] Fri, 18 September 2015 06:51 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 17/08/2015 13:51, Ulrich Lang wrote:
> Hi!
>
> I've been playing with the Parsley DSL and got stuck with a problem
> where my metamodel has a containment reference that can only be 0..1,
> i.e. not 0..*.
> I've used exactly the same format for the context menus::
>
> "Pls" is the parent, which contains zero or one "hlpset", which is a
> "Plset"
>
> Pls mm2 -> #[
> actionAdd(
> "...",
> mm2.hlpset, factory2.createPlset,
> [ x |
> x.name = "..." ]
> )
> ]
>
> The DSL gives me the error: "Type mismatch: cannot convert from Plset to
> EList<? super Plset>". So I thought I'd cast to EList...changing
> "mm2.hlpset, " to "mm2.hlpset as EList<Plset>,"
> The DSL accepts it and code is generated.
> However, when I run it, it either gives me a Null Pointer Exception or
> the context menu appears, but nothing happens when I select it (i.e, no
> child created).
>
> It works fine exactly doing the same for all occurrences where the
> Parent is a list (0..*) of containments in the metamodel thought.
>
> So I'm wondering whether I'm doing something wrong, or whether this is a
> bug in the API that doesn't accept creating children on metamodel
> elements that only allow 0...1 children?
>
> Any help would be appreciated!
>
> Thanks!
> Ulrich
>
>
>
>

Hi

the problem is fixed in the new release 0.5.0 which is already
available, please have a look at the updated documentation (and
migration guide).

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Adding an operation to a Form
Next Topic:Context menu in SelectionTreeView
Goto Forum:
  


Current Time: Thu Mar 28 23:22:53 GMT 2024

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

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

Back to the top