Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [ve-dev] Extra line when generating code for a new component etc.

I have put a breakpoint in the class you suggested, and looked at the override file.
Following this through, the only method worth putting a breakpoint in is the getText(Object)
method.
I did this, and it gets called firstly after dropping the bean when the dialog opens, and again
later after pressing OK in order to set the text in a tree item.
I don't actually see how the value is being set into the model.
Neither do I see how using the labelProvider override gives me the opportunity do do what I want
in my example, or how it could be the right place to hang such code.
 
Are you saying that I need to do something like :
 
EObject ref = (EObject) element;
EClass meta = ref.eClass();
EStructuralFeature sf = meta.getEStructuralFeature("name");
IJavaInstance toSet = BeanUtilities.createJavaObject("java.lang.String", JavaEditDomainHelper.getResourceSet(fEditDomain), "\"" + nameOfWidget + "\"" );
ref.eSet( sf , toSet  );
 
In order to set the value in the EMF model?
 
If so, are there any generic hooks in the override mechanism (the label provider doesn't seem like the right place) to run code such as this in order to manipulate the EMF model
so that you can generate extra code when dropping a new bean?
 
Perhaps I am misunderstanding what you are saying completely, I don't know.
Any further help in understanding this would be greatly appreciated.
 
 
 
 
-----Original Message-----
From: ve-dev-bounces@xxxxxxxxxxx [mailto:ve-dev-bounces@xxxxxxxxxxx]On Behalf Of Dr Gili Mendel
Sent: 18 May 2006 13:40
To: Discussions people developing code for the Visual Editor project
Subject: Re: [ve-dev] Extra line when generating code for a new component etc.


>In the generated code for the method getMyComponent(), I want to add an extra line
..
>myComponent.setName("myComponent"); <-- Extra line that sets the name of the component to be the name of the field.

More precisely, what you want to do is to set another property, the "name" property to myComponent.  There is a difference here, because the extra line really reflects another bean setting.  This setting must be reflected in the EMF model.  Setting the "name" propery in the model will drive it to the UI, PS, TargetVM, and will generate the line of code for ya.

The question is then, how do you set the name property on the drop, authmatically.

VE is already doing similar things like this:
        When you drop a widget for example, it may (depending on your perf.) open a dialog and ask you for the name to give the bean.
        If you drop a Label, it will automatically set the "text" property (generating the setText() line).


Check out the org.eclipse.ve.swt\overrides\org\eclipse\swt\widgets\Label.override, and take a breakpoint in org.eclipse.ve.internal.java.core.DefaultLabelProviderWithNameAndAttribute






------------
Dr. Gili Mendel
IBM
Software Development
RTP Raleigh, NC
(919)543 6408, tie: 441 6408



Darren Hurt <darren.hurt@xxxxxxxxxx>
Sent by: ve-dev-bounces@xxxxxxxxxxx

05/17/2006 01:33 PM

Please respond to
Discussions people developing code for the Visual Editor project <ve-dev@xxxxxxxxxxx>

To
"'Discussions people developing code for the Visual Editor project'" <ve-dev@xxxxxxxxxxx>
cc
Subject
[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
 
 
 
 
 
 
 
 
 
 
 _______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev


Back to the top