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?)
How to Customize Context Menu to create child that is not a containment *list*? [message #1705486] |
Mon, 17 August 2015 04:39 |
Ulrich Lang 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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| |
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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| |
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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| |
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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| | | |
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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Goto Forum:
Current Time: Sat Nov 09 01:22:00 GMT 2024
Powered by FUDForum. Page generated in 0.06220 seconds
|