Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Inserting an argument after instantiating a class
Inserting an argument after instantiating a class [message #85608] Tue, 05 April 2005 11:44 Go to next message
Elena Demeter is currently offline Elena DemeterFriend
Messages: 152
Registered: July 2009
Senior Member
Hello,

I would like to make it possible for a user to select arguments for the
instantiating a class from the “Property Sheet” after a dropping a
component from the palette.



For example:



1. I drop a MyJButton on the JFrame. The following code will be generated:



myJButton = new MyJButton();



2. I change the property (e.g. "arguments") from <none> to “en”, the text
“english” will be inserted


myJButton = new MyJButton(“english”);




Could you give me a tip how I can implement it :-)



Thank you in advance

Elena
Re: Inserting an argument after instantiating a class [message #85681 is a reply to message #85608] Tue, 05 April 2005 18:11 Go to previous messageGo to next message
Srimanth  is currently offline Srimanth Friend
Messages: 225
Registered: July 2009
Senior Member
Hello,
Currently VE's codegen decoders handle one sturctural feature /
property per expression. If you want the constructor to do many things
all at once you will need to implement your own constructor decoder -
please look at classes ConstructorDecoderHelper and
SWTConstructorDecoderHelper to determine how you can extend them.
Regards,
Sri.

Elena wrote:
> Hello,
>
> I would like to make it possible for a user to select arguments for the
> instantiating a class from the �Property Sheet� after a dropping a
> component from the palette.
>
>
>
> For example:
>
>
>
> 1. I drop a MyJButton on the JFrame. The following code will be generated:
>
>
>
> myJButton = new MyJButton();
>
>
>
> 2. I change the property (e.g. "arguments") from <none> to �en�, the
> text �english� will be inserted
>
>
> myJButton = new MyJButton(�english�);
>
>
>
>
> Could you give me a tip how I can implement it :-)
>
>
>
> Thank you in advance
>
> Elena
>
>
>
>
Re: Inserting an argument after instantiating a class [message #85696 is a reply to message #85681] Tue, 05 April 2005 18:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: myersj.gmail.com

Elena,

Do you have write access to the classes you're trying to use? It'd be
much preferred to have the constructor arguments declared as properties
(with getter/setter methods) and have your class use a no-argument
constructor. This makes your class follow the JavaBean spec, which is
what the VE was designed to handle.

If you cannot modify the classes, you could provide wrapper classes to
the target class that provides a no argument facade.

Hope this helps,
- Jeff


Sri Gunturi wrote:
> Hello,
> Currently VE's codegen decoders handle one sturctural feature /
> property per expression. If you want the constructor to do many things
> all at once you will need to implement your own constructor decoder -
> please look at classes ConstructorDecoderHelper and
> SWTConstructorDecoderHelper to determine how you can extend them.
> Regards,
> Sri.
>
> Elena wrote:
>
>> Hello,
>>
>> I would like to make it possible for a user to select arguments for
>> the instantiating a class from the �Property Sheet� after a dropping a
>> component from the palette.
>>
>>
>>
>> For example:
>>
>>
>>
>> 1. I drop a MyJButton on the JFrame. The following code will be
>> generated:
>>
>>
>>
>> myJButton = new MyJButton();
>>
>>
>>
>> 2. I change the property (e.g. "arguments") from <none> to �en�, the
>> text �english� will be inserted
>>
>>
>> myJButton = new MyJButton(�english�);
>>
>>
>>
>>
>> Could you give me a tip how I can implement it :-)
>>
>>
>>
>> Thank you in advance
>>
>> Elena
>>
>>
>>
>>
Re: Inserting an argument after instantiating a class [message #85849 is a reply to message #85696] Thu, 07 April 2005 12:32 Go to previous messageGo to next message
Elena Demeter is currently offline Elena DemeterFriend
Messages: 152
Registered: July 2009
Senior Member
Hello,



I have seen that it is possible in the properties of the SWT-Table to
change the style from SWT.NONE to SWT.CHECK. In doing so the initalising
string will be changed.



Is this possibility provided only through the class TableBeanInfo.java ?



Thanks in advance
Elena
Re: Inserting an argument after instantiating a class [message #86779 is a reply to message #85849] Mon, 11 April 2005 16:57 Go to previous messageGo to next message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Elena,

> I have seen that it is possible in the properties of the SWT-Table to
> change the style from SWT.NONE to SWT.CHECK. In doing so the initalising
> string will be changed.
>
> Is this possibility provided only through the class TableBeanInfo.java ?

Yes, this piece of custom SWT constructor magic is not part of the
JavaBeans specification and is done in several places. From a user
standpoint if you are creating your own custom SWT controls that inherit
from org.eclipse.swt.Composite then you can write a BeanInfo to provide
the style bits. Look at how we do this for things like ButtonBeanInfo
or ShellBeanInfo to see the pattern used. This is actually based on the
Sweet specification that extends the JavaBeans specification explicitly
for SWT.

If you aren't subclassing Composite then I suggeste you do what Jeff
suggests which is to have getters and setter. In fact even if you are
getters and setters are prefrable because you have a stronger API
contract with whoemever uses your custom widget. Style bits on
constructors really come because certain properties of a widget (usually
those which affect the trim of a widget - the area around where the
children get placed) cannot be altered after construction by Windows
itself. (For example, you can't change whether or not there is a
border, whether or not there are style bars, whether or not a button has
a check box, because all of these would change the area of the client
rectangle). Unless you have your own native widget you are wrapping
then I'd just crank up a getter and setter, although if you do write a
BeanInfo with the Sweet style bits then we'll pick them up.

Best regards,

Joe Winchester
Re: Inserting an argument after instantiating a class [message #86897 is a reply to message #86779] Tue, 12 April 2005 15:43 Go to previous messageGo to next message
Elena Demeter is currently offline Elena DemeterFriend
Messages: 152
Registered: July 2009
Senior Member
Hello,

First of all thank you very-very much for the answer.

(1) Have I understood you right:

I can use the class SweetHelper only if I have a swt component?


(2) But I have a swing Button. Do I have to specify a
PropertySourceAdapter as a WidgetPropertySourceAdapter to enable the
changing of the parameter in the initializing string like SWT.NONE to
SWT.ARROW?


(3) The method "getBeanDescriptor" in the BeanInfo class for my button is
already like in the class for the swt button and I have an override file
like "CheckBox.xmi". But there is not property "style" for my button in
the property sheet like for a swt button. Why?


(4) I tried to keep breakpoints in my BeanInfo class and in SweetHelper.
But they were not reached. Where can I see how the beaninfo for beans is
investigated?


P.S. My company wants me to have an initializing string with parameter.
That's why I cannot use set/get-Methods.

Thank you in advance
Elena
Re: Inserting an argument after instantiating a class [message #87027 is a reply to message #86897] Wed, 13 April 2005 19:11 Go to previous messageGo to next message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Elena,

> (1) Have I understood you right:
> I can use the class SweetHelper only if I have a swt component?

You can use SweetHelper with anything - all it does us add stuff to the
BeanDescriptor with setValue(String,Object) and a key of
"org.eclipse.ve.sweet.stylebits" and value that represents an array of
arrays grouping together the families of style bits together with the
bit value, display name and Java initialization String. You could add
this by hand if you wanted to in just a regular BeanDescriptor -
SweetHelper just makes the API a bit cleaner.

The trick isn't defining the key/value - it's how this affects the VE.
Right now the only code we have to deal with it is with subclasses of
org.eclipse.ve.swt.Widget.

One place is WidgetPropertyDescriptor and if you look at how it gets the
property descriptors and gets and sets the value this is how things like
Button in SWT have properties of "style", "border", "arrowStyle" and
"textAligmnent". The setPropertyValue(Object,Object) method of
WidgetPropertyDescriptor manipaulates the parseTreeAllocation to set the
constructor style bits and code generation picks this up and alters the
code.

> (2) But I have a swing Button. Do I have to specify a
> PropertySourceAdapter as a WidgetPropertySourceAdapter to enable the
> changing of the parameter in the initializing string like SWT.NONE to
> SWT.ARROW?

Yes. You don't have to follow the Sweet convention as all you need is a
contract between your BeanDescriptor and your PropertySourceAdapter.
Given that you setup the parseTreeAllocation correctly in your property
source adapter then code gen will work and the target VM will
instantiate your object correctly.

> (3) The method "getBeanDescriptor" in the BeanInfo class for my button
> is already like in the class for the swt button and I have an override
> file like "CheckBox.xmi". But there is not property "style" for my
> button in the property sheet like for a swt button. Why?

I think it's because you don't have a custom property source adapter.
Look at Widget.override to see how to define one.

> (4) I tried to keep breakpoints in my BeanInfo class and in SweetHelper.
> But they were not reached. Where can I see how the beaninfo for beans is
> investigated?

Debugging the target VMs is something that is supported. Look at the
Help Contents and search for "Using the Visual Editor for Java">"Editing
Java in the Visual Editor">"Testing and Debugging in the Visual
Editor">"Advanced Options for Debugging Java Beans"
Re: Inserting an argument after instantiating a class [message #87378 is a reply to message #87027] Mon, 18 April 2005 06:22 Go to previous message
Elena Demeter is currently offline Elena DemeterFriend
Messages: 152
Registered: July 2009
Senior Member
Thank you for your answer.

Elena
Re: Inserting an argument after instantiating a class [message #606258 is a reply to message #85608] Tue, 05 April 2005 18:11 Go to previous message
Srimanth  is currently offline Srimanth Friend
Messages: 225
Registered: July 2009
Senior Member
Hello,
Currently VE's codegen decoders handle one sturctural feature /
property per expression. If you want the constructor to do many things
all at once you will need to implement your own constructor decoder -
please look at classes ConstructorDecoderHelper and
SWTConstructorDecoderHelper to determine how you can extend them.
Regards,
Sri.

Elena wrote:
> Hello,
>
> I would like to make it possible for a user to select arguments for the
> instantiating a class from the �Property Sheet� after a dropping a
> component from the palette.
>
>
>
> For example:
>
>
>
> 1. I drop a MyJButton on the JFrame. The following code will be generated:
>
>
>
> myJButton = new MyJButton();
>
>
>
> 2. I change the property (e.g. "arguments") from <none> to �en�, the
> text �english� will be inserted
>
>
> myJButton = new MyJButton(�english�);
>
>
>
>
> Could you give me a tip how I can implement it :-)
>
>
>
> Thank you in advance
>
> Elena
>
>
>
>
Re: Inserting an argument after instantiating a class [message #606260 is a reply to message #85681] Tue, 05 April 2005 18:46 Go to previous message
Jeff Myers is currently offline Jeff MyersFriend
Messages: 396
Registered: July 2009
Senior Member
Elena,

Do you have write access to the classes you're trying to use? It'd be
much preferred to have the constructor arguments declared as properties
(with getter/setter methods) and have your class use a no-argument
constructor. This makes your class follow the JavaBean spec, which is
what the VE was designed to handle.

If you cannot modify the classes, you could provide wrapper classes to
the target class that provides a no argument facade.

Hope this helps,
- Jeff


Sri Gunturi wrote:
> Hello,
> Currently VE's codegen decoders handle one sturctural feature /
> property per expression. If you want the constructor to do many things
> all at once you will need to implement your own constructor decoder -
> please look at classes ConstructorDecoderHelper and
> SWTConstructorDecoderHelper to determine how you can extend them.
> Regards,
> Sri.
>
> Elena wrote:
>
>> Hello,
>>
>> I would like to make it possible for a user to select arguments for
>> the instantiating a class from the �Property Sheet� after a dropping a
>> component from the palette.
>>
>>
>>
>> For example:
>>
>>
>>
>> 1. I drop a MyJButton on the JFrame. The following code will be
>> generated:
>>
>>
>>
>> myJButton = new MyJButton();
>>
>>
>>
>> 2. I change the property (e.g. "arguments") from <none> to �en�, the
>> text �english� will be inserted
>>
>>
>> myJButton = new MyJButton(�english�);
>>
>>
>>
>>
>> Could you give me a tip how I can implement it :-)
>>
>>
>>
>> Thank you in advance
>>
>> Elena
>>
>>
>>
>>
Re: Inserting an argument after instantiating a class [message #606282 is a reply to message #85696] Thu, 07 April 2005 12:32 Go to previous message
Elena Demeter is currently offline Elena DemeterFriend
Messages: 152
Registered: July 2009
Senior Member
Hello,



I have seen that it is possible in the properties of the SWT-Table to
change the style from SWT.NONE to SWT.CHECK. In doing so the initalising
string will be changed.



Is this possibility provided only through the class TableBeanInfo.java ?



Thanks in advance
Elena
Re: Inserting an argument after instantiating a class [message #607113 is a reply to message #85849] Mon, 11 April 2005 16:57 Go to previous message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Elena,

> I have seen that it is possible in the properties of the SWT-Table to
> change the style from SWT.NONE to SWT.CHECK. In doing so the initalising
> string will be changed.
>
> Is this possibility provided only through the class TableBeanInfo.java ?

Yes, this piece of custom SWT constructor magic is not part of the
JavaBeans specification and is done in several places. From a user
standpoint if you are creating your own custom SWT controls that inherit
from org.eclipse.swt.Composite then you can write a BeanInfo to provide
the style bits. Look at how we do this for things like ButtonBeanInfo
or ShellBeanInfo to see the pattern used. This is actually based on the
Sweet specification that extends the JavaBeans specification explicitly
for SWT.

If you aren't subclassing Composite then I suggeste you do what Jeff
suggests which is to have getters and setter. In fact even if you are
getters and setters are prefrable because you have a stronger API
contract with whoemever uses your custom widget. Style bits on
constructors really come because certain properties of a widget (usually
those which affect the trim of a widget - the area around where the
children get placed) cannot be altered after construction by Windows
itself. (For example, you can't change whether or not there is a
border, whether or not there are style bars, whether or not a button has
a check box, because all of these would change the area of the client
rectangle). Unless you have your own native widget you are wrapping
then I'd just crank up a getter and setter, although if you do write a
BeanInfo with the Sweet style bits then we'll pick them up.

Best regards,

Joe Winchester
Re: Inserting an argument after instantiating a class [message #607125 is a reply to message #86779] Tue, 12 April 2005 15:43 Go to previous message
Elena Demeter is currently offline Elena DemeterFriend
Messages: 152
Registered: July 2009
Senior Member
Hello,

First of all thank you very-very much for the answer.

(1) Have I understood you right:

I can use the class SweetHelper only if I have a swt component?


(2) But I have a swing Button. Do I have to specify a
PropertySourceAdapter as a WidgetPropertySourceAdapter to enable the
changing of the parameter in the initializing string like SWT.NONE to
SWT.ARROW?


(3) The method "getBeanDescriptor" in the BeanInfo class for my button is
already like in the class for the swt button and I have an override file
like "CheckBox.xmi". But there is not property "style" for my button in
the property sheet like for a swt button. Why?


(4) I tried to keep breakpoints in my BeanInfo class and in SweetHelper.
But they were not reached. Where can I see how the beaninfo for beans is
investigated?


P.S. My company wants me to have an initializing string with parameter.
That's why I cannot use set/get-Methods.

Thank you in advance
Elena
Re: Inserting an argument after instantiating a class [message #607134 is a reply to message #86897] Wed, 13 April 2005 19:11 Go to previous message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Elena,

> (1) Have I understood you right:
> I can use the class SweetHelper only if I have a swt component?

You can use SweetHelper with anything - all it does us add stuff to the
BeanDescriptor with setValue(String,Object) and a key of
"org.eclipse.ve.sweet.stylebits" and value that represents an array of
arrays grouping together the families of style bits together with the
bit value, display name and Java initialization String. You could add
this by hand if you wanted to in just a regular BeanDescriptor -
SweetHelper just makes the API a bit cleaner.

The trick isn't defining the key/value - it's how this affects the VE.
Right now the only code we have to deal with it is with subclasses of
org.eclipse.ve.swt.Widget.

One place is WidgetPropertyDescriptor and if you look at how it gets the
property descriptors and gets and sets the value this is how things like
Button in SWT have properties of "style", "border", "arrowStyle" and
"textAligmnent". The setPropertyValue(Object,Object) method of
WidgetPropertyDescriptor manipaulates the parseTreeAllocation to set the
constructor style bits and code generation picks this up and alters the
code.

> (2) But I have a swing Button. Do I have to specify a
> PropertySourceAdapter as a WidgetPropertySourceAdapter to enable the
> changing of the parameter in the initializing string like SWT.NONE to
> SWT.ARROW?

Yes. You don't have to follow the Sweet convention as all you need is a
contract between your BeanDescriptor and your PropertySourceAdapter.
Given that you setup the parseTreeAllocation correctly in your property
source adapter then code gen will work and the target VM will
instantiate your object correctly.

> (3) The method "getBeanDescriptor" in the BeanInfo class for my button
> is already like in the class for the swt button and I have an override
> file like "CheckBox.xmi". But there is not property "style" for my
> button in the property sheet like for a swt button. Why?

I think it's because you don't have a custom property source adapter.
Look at Widget.override to see how to define one.

> (4) I tried to keep breakpoints in my BeanInfo class and in SweetHelper.
> But they were not reached. Where can I see how the beaninfo for beans is
> investigated?

Debugging the target VMs is something that is supported. Look at the
Help Contents and search for "Using the Visual Editor for Java">"Editing
Java in the Visual Editor">"Testing and Debugging in the Visual
Editor">"Advanced Options for Debugging Java Beans"
Re: Inserting an argument after instantiating a class [message #607159 is a reply to message #87027] Mon, 18 April 2005 06:22 Go to previous message
Elena Demeter is currently offline Elena DemeterFriend
Messages: 152
Registered: July 2009
Senior Member
Thank you for your answer.

Elena
Previous Topic:Code generating
Next Topic:Estimation
Goto Forum:
  


Current Time: Fri Apr 26 03:36:44 GMT 2024

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

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

Back to the top