[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[ve-dev] Extra line when generating code for a new component etc.
|
Hi
there.
I have a couple
more questions regarding extension of the visual editor.
I want to add a new
line every time I add a component in the Visual Editor.
Basically, suppose
I add a new component called myComponent.
In the generated
code for the method getMyComponent(), I want to add an extra
line
as
follows:
private
MyComponent getMyComponent()
{
if(myComponent ==
null)
{
myComponent = new MyComponent();
myComponent.setName("myComponent"); <-- Extra line that
sets the name of the component to be the name of the
field.
}
return
myComponent;
}
After reading the
tutorial and poking around, I tried to use the override mechanism, and
have managed to add my own ComponentDecoder and ConstructorDecoderHelper
and
set up the override
XMI file correctly.
I have made the
generate method of the helper append the extra line.
Unfortunately, when
code is generated, although my override is definitely picked up (I have logging
in there that confirms that my decoder
is invoked and the
correct string returned), the resulting generated code does not contain my extra
line!
Do you have any
idea why this is happening?
(I verify that I
have a constructor in my component decoder by the line
fFeatureMapper.getFeature(null).equals(getAllocationFeature((IJavaObjectInstance)
fbeanPart.getEObject())))
Is there any other
way of achieving what I want, via the override mechanism or
whatever?
Additionally, I
would like to change the code generation so that actual components are
constructed in the variable declarations.
That is, instead of
having
private MyComponent myComponent = null;
I
would like to have:
private MyComponent myComponent = new
MyComponent();
and if possible to replace the lazy initialization in the getMethod with
a simple getter, although this last point isn't crucial.
Is there any way of
doing this?
It looks like
another case of using more or less the same override mechanism, but I'm not
sure.
The reason is that
some of the code I generate for my beans refers to other beans. If the methods
aren't called in the correct order
then it is
possible that the bean being referred to will not have been
created.
For example, suppose
that MyComponent has a property myProperty whose type is another component,
and that you enter the
name of the
component in a customizer/property editor. Suppose this results in
generated code
MyComponent comp
= new MyComponent();
comp.setMyProperty(anotherComponent);
If anotherComponent
has not yet been created, then this generated code will just set the value to be
null.
I have tried making
the generated code
comp.setMyProperty(getAnotherComponent());
instead, but the parser seems unable to deal
with this.
Darren Hurt