Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » adding popup menu to generate code
adding popup menu to generate code [message #86927] Wed, 13 April 2005 14:03 Go to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Hello,
Can someone advise on how to do this :

I need to add a menu/action, this will add something like
"button.setData("myKey",myObject);" to the initialize() method.

I was able to add the menu (see below). However, I am not sure which
command, or policy to use to insert the code to the VisualEditor. I 've
been looking at RenameJavaBeanObjectActionDelegate.java,
ControlDirectEditPolicy.java, etc... Can someone tell me where I should
start? Thanks.

<extension point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass=" org.eclipse.ve.internal.java.core.IJavaBeanContextMenuContri butor "
id=" org.eclipse.ve.internal.swt.editorpart.settextaction.popup.o bject ">
<filter name="BEANTYPE" value="org.eclipse.swt.widgets.Control"> </filter>
<filter name="PROPERTY" value="data"></filter>
<action
label="Bind (Testing)"
class="com.ibm.vetest.actions.TestVEAction"
id="VEExtTest.newAction1">
</action>
</objectContribution>
Re: adding popup menu to generate code [message #86943 is a reply to message #86927] Wed, 13 April 2005 15:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Basically this piece of code is saying:



> <extension point="org.eclipse.ui.popupMenus">
> <objectContribution
> objectClass=" org.eclipse.ve.internal.java.core.IJavaBeanContextMenuContri butor "

-- This menu will only be on selected items that implement the
IJavaBeanContextMenuContributor interface. In our case the selected
objects from the VE will always be gef EditParts and all of the Java
Beans Editparts will implement this interface. This interface tells us
that the object is a java bean that we can things about (see below).

>
> id=" org.eclipse.ve.internal.swt.editorpart.settextaction.popup.o bject ">

-- This is your unique id for the action you are adding.

> <filter name="BEANTYPE" value="org.eclipse.swt.widgets.Control"> </filter>

- IJavaBeanContextMenuContributors understand filters and certain
filter names, such as BEANTYPE and PROPERTY. In this case BEANTYPE says
that this action will only show on Editparts that are for an
org.eclipse.swt.widgets.Control bean.

> <filter name="PROPERTY" value="data"></filter>

- IJavaBeanContextMenuContributors understand "PROPERTY" to. This says
that it will be visible if the bean (a subclass of Control in this
example) has the property "data".

The rest below is standard popup contributor stuff.
> <action
> label="Bind (Testing)"
> class="com.ibm.vetest.actions.TestVEAction"
> id="VEExtTest.newAction1">
> </action>
> </objectContribution>

So this entire contributions says that this menu item will only show up
when all three below are true:

1) Selected items that implement IJavaBeanContextMenuContributor
2) The Bean that selected item represents is an instanceof (including
subclasses) of org.eclipse.swt.widgets.Control
3) The Bean that selected item represents has a property named "data".

If not all three are satisfied, then the popup will not have this action.

There are other filters available to the
IJavaBeanContextMenuContributor. Take a look at the class
org.eclipse.ve.internal.cde.core.CDEActionFilter to see what filters are
available for general beans.



--
Thanks,
Rich Kulp
Re: adding popup menu to generate code [message #86958 is a reply to message #86943] Wed, 13 April 2005 16:30 Go to previous messageGo to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Rich,
Thanks for quick response. I was able to get the popup menu to work.
The hard part is how to use correct policy/command to do generate and
insert code into the current model. Thanks.

Rich Kulp wrote:
> Basically this piece of code is saying:
>
>
>
>> <extension point="org.eclipse.ui.popupMenus">
>> <objectContribution
>> objectClass=" org.eclipse.ve.internal.java.core.IJavaBeanContextMenuContri butor "
>
>
>
> -- This menu will only be on selected items that implement the
> IJavaBeanContextMenuContributor interface. In our case the selected
> objects from the VE will always be gef EditParts and all of the Java
> Beans Editparts will implement this interface. This interface tells us
> that the object is a java bean that we can things about (see below).
>
>>
>> id=" org.eclipse.ve.internal.swt.editorpart.settextaction.popup.o bject ">
>
>
> -- This is your unique id for the action you are adding.
>
>> <filter name="BEANTYPE" value="org.eclipse.swt.widgets.Control">
>> </filter>
>
>
> - IJavaBeanContextMenuContributors understand filters and certain
> filter names, such as BEANTYPE and PROPERTY. In this case BEANTYPE says
> that this action will only show on Editparts that are for an
> org.eclipse.swt.widgets.Control bean.
>
>> <filter name="PROPERTY" value="data"></filter>
>
>
> - IJavaBeanContextMenuContributors understand "PROPERTY" to. This says
> that it will be visible if the bean (a subclass of Control in this
> example) has the property "data".
>
> The rest below is standard popup contributor stuff.
>
>> <action
>> label="Bind (Testing)"
>> class="com.ibm.vetest.actions.TestVEAction"
>> id="VEExtTest.newAction1">
>> </action>
>> </objectContribution>
>
>
> So this entire contributions says that this menu item will only show up
> when all three below are true:
>
> 1) Selected items that implement IJavaBeanContextMenuContributor
> 2) The Bean that selected item represents is an instanceof (including
> subclasses) of org.eclipse.swt.widgets.Control
> 3) The Bean that selected item represents has a property named "data".
>
> If not all three are satisfied, then the popup will not have this action.
>
> There are other filters available to the
> IJavaBeanContextMenuContributor. Take a look at the class
> org.eclipse.ve.internal.cde.core.CDEActionFilter to see what filters are
> available for general beans.
>
>
>
Re: adding popup menu to generate code [message #86971 is a reply to message #86958] Wed, 13 April 2005 16:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Hung wrote:
> Rich,
> Thanks for quick response. I was able to get the popup menu to work.
> The hard part is how to use correct policy/command to do generate and
> insert code into the current model. Thanks.

Yeah, none of that has been made into an api and documented yet. :-(
--
Thanks,
Rich Kulp
Re: adding popup menu to generate code [message #86984 is a reply to message #86971] Wed, 13 April 2005 17:01 Go to previous messageGo to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Again, thanks.
Is that mean it can't be done currently? or there might be a way around
it w/out using API? Any help would be appreciated.

Rich Kulp wrote:
>
>
> Hung wrote:
>
>> Rich,
>> Thanks for quick response. I was able to get the popup menu to work.
>> The hard part is how to use correct policy/command to do generate and
>> insert code into the current model. Thanks.
>
>
> Yeah, none of that has been made into an api and documented yet. :-(
Re: adding popup menu to generate code [message #86997 is a reply to message #86984] Wed, 13 April 2005 17:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Anything possible with coding. :-) You would have to use internal
classes since we have no API classes. How you would do it I don't know.
The code generation part is done by someone else.


--
Thanks,
Rich Kulp
Re: adding popup menu to generate code [message #87011 is a reply to message #86958] Wed, 13 April 2005 17:59 Go to previous messageGo to next message
Gili Mendel is currently offline Gili MendelFriend
Messages: 338
Registered: July 2009
Senior Member
Hung wrote:
> Rich,
> Thanks for quick response. I was able to get the popup menu to work.
> The hard part is how to use correct policy/command to do generate and
> insert code into the current model. Thanks.
>


The following is a bit dirty - VE will not understand it and assume that someone just type this in, but it should work
for you:

The selection will be an EditPart and hence a getModel() will return you the VE IJavaObject associated
with the EditPart.

Once you have access to the VE (EMF) model object, get the CodeGen adapter for it:

BeanDecoderAdapter adapter = (BeanDecoderAdapter) EcoreUtil.getExistingAdapter(object,
ICodeGenAdapter.JVE_CODEGEN_BEAN_PART_ADAPTER)

The adapter will point to the CodeGen BeanPart

BeanPart bp = adapter.getBeanPart();

bp has all the information about the code associated with this object.
The instance/local name (getSimpleName), source expressions (getRefExpressions()) etc.
You than need to figure out where in the source you want to insert your code (using the offsets of one of the current
expressions). The expression offset is from the method (getInitMethod())... so you will have to add these up to get a
full offset ... you
can insert your code to the CU directly if you want to

bp.getModel().getDocumentBuffer().replace
Re: adding popup menu to generate code [message #87042 is a reply to message #87011] Wed, 13 April 2005 21:15 Go to previous messageGo to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
while looking at SWTLabelCreationPolicy.java and
ChangeParentShellObjectActionDelegate.java, I have tried out the
following code to do the insertion. (basically it will set the property
"data" to a string.) It seems to work, but not sure if this is the
correct way to do it.

IJavaObjectInstance model = (IJavaObjectInstance)
selectedEP.getModel(); EStructuralFeature esf =
model.eClass().getEStructuralFeature("data");
ResourceSet rs = model.eResource().getResourceSet();
IJavaObjectInstance ijoi = BeanUtilities.createString(rs,"test");

RuledCommandBuilder cb = new
RuledCommandBuilder(EditDomain.getEditDomain(selectedEP));
cb.applyAttributeSetting((EObject) model, esf, ijoi);
command = cb.getCommand();
command.execute();



Another question : After running the above code, a new expression is
inserted : for example: button.setData("test");
However, I want it to say : button.setData("id","test"); instead. I
looked at BeanUtilities and RuledCommandBuilder.applyAttributeSetting,
but I couldn't find a way to do it.

Thanks for all your help.


Gili Mendel wrote:
> Hung wrote:
>
>> Rich, Thanks for quick response. I was able to get the popup menu
>> to work. The hard part is how to use correct policy/command to do
>> generate and insert code into the current model. Thanks.
>>
>
>
> The following is a bit dirty - VE will not understand it and assume
> that someone just type this in, but it should work for you:
>
> The selection will be an EditPart and hence a getModel() will return
> you the VE IJavaObject associated with the EditPart.
>
> Once you have access to the VE (EMF) model object, get the CodeGen
> adapter for it:
>
> BeanDecoderAdapter adapter = (BeanDecoderAdapter)
> EcoreUtil.getExistingAdapter(object,
> ICodeGenAdapter.JVE_CODEGEN_BEAN_PART_ADAPTER)
>
> The adapter will point to the CodeGen BeanPart
>
> BeanPart bp = adapter.getBeanPart();
>
> bp has all the information about the code associated with this
> object. The instance/local name (getSimpleName), source expressions
> (getRefExpressions()) etc. You than need to figure out where in the
> source you want to insert your code (using the offsets of one of the
> current expressions). The expression offset is from the method
> (getInitMethod())... so you will have to add these up to get a full
> offset ... you can insert your code to the CU directly if you want to
>
>
> bp.getModel().getDocumentBuffer().replace
Re: adding popup menu to generate code [message #87144 is a reply to message #87042] Thu, 14 April 2005 12:45 Go to previous messageGo to next message
Gili Mendel is currently offline Gili MendelFriend
Messages: 338
Registered: July 2009
Senior Member
Hung wrote:
> while looking at SWTLabelCreationPolicy.java and
> ChangeParentShellObjectActionDelegate.java, I have tried out the
> following code to do the insertion. (basically it will set the property
> "data" to a string.) It seems to work, but not sure if this is the
> correct way to do it.
>
> IJavaObjectInstance model = (IJavaObjectInstance)
> selectedEP.getModel(); EStructuralFeature esf =
> model.eClass().getEStructuralFeature("data");
> ResourceSet rs = model.eResource().getResourceSet();
> IJavaObjectInstance ijoi = BeanUtilities.createString(rs,"test");
> RuledCommandBuilder cb = new
> RuledCommandBuilder(EditDomain.getEditDomain(selectedEP));
> cb.applyAttributeSetting((EObject) model, esf, ijoi);
> command = cb.getCommand();
> command.execute();
>
>
>
> Another question : After running the above code, a new expression is
> inserted : for example: button.setData("test");
> However, I want it to say : button.setData("id","test"); instead. I
> looked at BeanUtilities and RuledCommandBuilder.applyAttributeSetting,
> but I couldn't find a way to do it.
>
> Thanks for all your help.
>

yep. That would be the right way to get the default behavior (property setting has a single argument). But also, Since
VE consider "data" to be a property, you can only set it once. i.e., if you try to create a sequence of
setData(key,data) calls VE will replace them. Is this a problem?
Re: adding popup menu to generate code [message #87159 is a reply to message #87144] Thu, 14 April 2005 12:55 Go to previous messageGo to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
I don't know how to insert setData(key,data), and that's what my question is. Actually, I prefer VE
to replace them, so VE's behavior would be perfect in my case. Any idea how can I modify my code to
insert setData(key,data) instead of setData(data)? Thanks.


Gili Mendel wrote:
> Hung wrote:
>
>> while looking at SWTLabelCreationPolicy.java and
>> ChangeParentShellObjectActionDelegate.java, I have tried out the
>> following code to do the insertion. (basically it will set the
>> property "data" to a string.) It seems to work, but not sure if this
>> is the correct way to do it.
>>
>> IJavaObjectInstance model = (IJavaObjectInstance)
>> selectedEP.getModel(); EStructuralFeature esf =
>> model.eClass().getEStructuralFeature("data");
>> ResourceSet rs = model.eResource().getResourceSet();
>> IJavaObjectInstance ijoi = BeanUtilities.createString(rs,"test");
>> RuledCommandBuilder cb = new
>> RuledCommandBuilder(EditDomain.getEditDomain(selectedEP));
>> cb.applyAttributeSetting((EObject) model, esf, ijoi);
>> command = cb.getCommand();
>> command.execute();
>>
>>
>>
>> Another question : After running the above code, a new expression is
>> inserted : for example: button.setData("test");
>> However, I want it to say : button.setData("id","test"); instead. I
>> looked at BeanUtilities and RuledCommandBuilder.applyAttributeSetting,
>> but I couldn't find a way to do it.
>>
>> Thanks for all your help.
>>
>
> yep. That would be the right way to get the default behavior (property
> setting has a single argument). But also, Since VE consider "data" to be
> a property, you can only set it once. i.e., if you try to create a
> sequence of setData(key,data) calls VE will replace them. Is this a
> problem?
Re: adding popup menu to generate code [message #87270 is a reply to message #87159] Fri, 15 April 2005 14:38 Go to previous message
Gili Mendel is currently offline Gili MendelFriend
Messages: 338
Registered: July 2009
Senior Member
Hung wrote:
> I don't know how to insert setData(key,data), and that's what my
> question is. Actually, I prefer VE to replace them, so VE's behavior
> would be perfect in my case. Any idea how can I modify my code to
> insert setData(key,data) instead of setData(data)? Thanks.
>
>



The problem is that the property *data* is define through introspection to be a single argument. What you need
is to override how VE treads the data property... currently it only allows one to define decoders and proxies
for classes not features (opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=91531). What we also need is a formal
support to the Control's data keys (opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=91532).

There is no way to do what you want now by overriding VE.. you will have to change VE's base code to model this which
will enable you to drive/reverse parse this in.

The best you can do for now, is what I have suggested earlier. Get the BeanPart from which you will get the source
offset with its expressions, and insert the code directly to the editor's buffer. On the dialog up, reverse parse that
section of code to figure out if the key is set.
Re: adding popup menu to generate code [message #607128 is a reply to message #86927] Wed, 13 April 2005 15:22 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Basically this piece of code is saying:



> <extension point="org.eclipse.ui.popupMenus">
> <objectContribution
> objectClass=" org.eclipse.ve.internal.java.core.IJavaBeanContextMenuContri butor "

-- This menu will only be on selected items that implement the
IJavaBeanContextMenuContributor interface. In our case the selected
objects from the VE will always be gef EditParts and all of the Java
Beans Editparts will implement this interface. This interface tells us
that the object is a java bean that we can things about (see below).

>
> id=" org.eclipse.ve.internal.swt.editorpart.settextaction.popup.o bject ">

-- This is your unique id for the action you are adding.

> <filter name="BEANTYPE" value="org.eclipse.swt.widgets.Control"> </filter>

- IJavaBeanContextMenuContributors understand filters and certain
filter names, such as BEANTYPE and PROPERTY. In this case BEANTYPE says
that this action will only show on Editparts that are for an
org.eclipse.swt.widgets.Control bean.

> <filter name="PROPERTY" value="data"></filter>

- IJavaBeanContextMenuContributors understand "PROPERTY" to. This says
that it will be visible if the bean (a subclass of Control in this
example) has the property "data".

The rest below is standard popup contributor stuff.
> <action
> label="Bind (Testing)"
> class="com.ibm.vetest.actions.TestVEAction"
> id="VEExtTest.newAction1">
> </action>
> </objectContribution>

So this entire contributions says that this menu item will only show up
when all three below are true:

1) Selected items that implement IJavaBeanContextMenuContributor
2) The Bean that selected item represents is an instanceof (including
subclasses) of org.eclipse.swt.widgets.Control
3) The Bean that selected item represents has a property named "data".

If not all three are satisfied, then the popup will not have this action.

There are other filters available to the
IJavaBeanContextMenuContributor. Take a look at the class
org.eclipse.ve.internal.cde.core.CDEActionFilter to see what filters are
available for general beans.



--
Thanks,
Rich Kulp
Re: adding popup menu to generate code [message #607129 is a reply to message #86943] Wed, 13 April 2005 16:30 Go to previous message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Rich,
Thanks for quick response. I was able to get the popup menu to work.
The hard part is how to use correct policy/command to do generate and
insert code into the current model. Thanks.

Rich Kulp wrote:
> Basically this piece of code is saying:
>
>
>
>> <extension point="org.eclipse.ui.popupMenus">
>> <objectContribution
>> objectClass=" org.eclipse.ve.internal.java.core.IJavaBeanContextMenuContri butor "
>
>
>
> -- This menu will only be on selected items that implement the
> IJavaBeanContextMenuContributor interface. In our case the selected
> objects from the VE will always be gef EditParts and all of the Java
> Beans Editparts will implement this interface. This interface tells us
> that the object is a java bean that we can things about (see below).
>
>>
>> id=" org.eclipse.ve.internal.swt.editorpart.settextaction.popup.o bject ">
>
>
> -- This is your unique id for the action you are adding.
>
>> <filter name="BEANTYPE" value="org.eclipse.swt.widgets.Control">
>> </filter>
>
>
> - IJavaBeanContextMenuContributors understand filters and certain
> filter names, such as BEANTYPE and PROPERTY. In this case BEANTYPE says
> that this action will only show on Editparts that are for an
> org.eclipse.swt.widgets.Control bean.
>
>> <filter name="PROPERTY" value="data"></filter>
>
>
> - IJavaBeanContextMenuContributors understand "PROPERTY" to. This says
> that it will be visible if the bean (a subclass of Control in this
> example) has the property "data".
>
> The rest below is standard popup contributor stuff.
>
>> <action
>> label="Bind (Testing)"
>> class="com.ibm.vetest.actions.TestVEAction"
>> id="VEExtTest.newAction1">
>> </action>
>> </objectContribution>
>
>
> So this entire contributions says that this menu item will only show up
> when all three below are true:
>
> 1) Selected items that implement IJavaBeanContextMenuContributor
> 2) The Bean that selected item represents is an instanceof (including
> subclasses) of org.eclipse.swt.widgets.Control
> 3) The Bean that selected item represents has a property named "data".
>
> If not all three are satisfied, then the popup will not have this action.
>
> There are other filters available to the
> IJavaBeanContextMenuContributor. Take a look at the class
> org.eclipse.ve.internal.cde.core.CDEActionFilter to see what filters are
> available for general beans.
>
>
>
Re: adding popup menu to generate code [message #607130 is a reply to message #86958] Wed, 13 April 2005 16:47 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Hung wrote:
> Rich,
> Thanks for quick response. I was able to get the popup menu to work.
> The hard part is how to use correct policy/command to do generate and
> insert code into the current model. Thanks.

Yeah, none of that has been made into an api and documented yet. :-(
--
Thanks,
Rich Kulp
Re: adding popup menu to generate code [message #607131 is a reply to message #86971] Wed, 13 April 2005 17:01 Go to previous message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Again, thanks.
Is that mean it can't be done currently? or there might be a way around
it w/out using API? Any help would be appreciated.

Rich Kulp wrote:
>
>
> Hung wrote:
>
>> Rich,
>> Thanks for quick response. I was able to get the popup menu to work.
>> The hard part is how to use correct policy/command to do generate and
>> insert code into the current model. Thanks.
>
>
> Yeah, none of that has been made into an api and documented yet. :-(
Re: adding popup menu to generate code [message #607132 is a reply to message #86984] Wed, 13 April 2005 17:28 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Anything possible with coding. :-) You would have to use internal
classes since we have no API classes. How you would do it I don't know.
The code generation part is done by someone else.


--
Thanks,
Rich Kulp
Re: adding popup menu to generate code [message #607133 is a reply to message #86958] Wed, 13 April 2005 17:59 Go to previous message
Gili Mendel is currently offline Gili MendelFriend
Messages: 338
Registered: July 2009
Senior Member
Hung wrote:
> Rich,
> Thanks for quick response. I was able to get the popup menu to work.
> The hard part is how to use correct policy/command to do generate and
> insert code into the current model. Thanks.
>


The following is a bit dirty - VE will not understand it and assume that someone just type this in, but it should work
for you:

The selection will be an EditPart and hence a getModel() will return you the VE IJavaObject associated
with the EditPart.

Once you have access to the VE (EMF) model object, get the CodeGen adapter for it:

BeanDecoderAdapter adapter = (BeanDecoderAdapter) EcoreUtil.getExistingAdapter(object,
ICodeGenAdapter.JVE_CODEGEN_BEAN_PART_ADAPTER)

The adapter will point to the CodeGen BeanPart

BeanPart bp = adapter.getBeanPart();

bp has all the information about the code associated with this object.
The instance/local name (getSimpleName), source expressions (getRefExpressions()) etc.
You than need to figure out where in the source you want to insert your code (using the offsets of one of the current
expressions). The expression offset is from the method (getInitMethod())... so you will have to add these up to get a
full offset ... you
can insert your code to the CU directly if you want to

bp.getModel().getDocumentBuffer().replace
Re: adding popup menu to generate code [message #607135 is a reply to message #87011] Wed, 13 April 2005 21:15 Go to previous message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
while looking at SWTLabelCreationPolicy.java and
ChangeParentShellObjectActionDelegate.java, I have tried out the
following code to do the insertion. (basically it will set the property
"data" to a string.) It seems to work, but not sure if this is the
correct way to do it.

IJavaObjectInstance model = (IJavaObjectInstance)
selectedEP.getModel(); EStructuralFeature esf =
model.eClass().getEStructuralFeature("data");
ResourceSet rs = model.eResource().getResourceSet();
IJavaObjectInstance ijoi = BeanUtilities.createString(rs,"test");

RuledCommandBuilder cb = new
RuledCommandBuilder(EditDomain.getEditDomain(selectedEP));
cb.applyAttributeSetting((EObject) model, esf, ijoi);
command = cb.getCommand();
command.execute();



Another question : After running the above code, a new expression is
inserted : for example: button.setData("test");
However, I want it to say : button.setData("id","test"); instead. I
looked at BeanUtilities and RuledCommandBuilder.applyAttributeSetting,
but I couldn't find a way to do it.

Thanks for all your help.


Gili Mendel wrote:
> Hung wrote:
>
>> Rich, Thanks for quick response. I was able to get the popup menu
>> to work. The hard part is how to use correct policy/command to do
>> generate and insert code into the current model. Thanks.
>>
>
>
> The following is a bit dirty - VE will not understand it and assume
> that someone just type this in, but it should work for you:
>
> The selection will be an EditPart and hence a getModel() will return
> you the VE IJavaObject associated with the EditPart.
>
> Once you have access to the VE (EMF) model object, get the CodeGen
> adapter for it:
>
> BeanDecoderAdapter adapter = (BeanDecoderAdapter)
> EcoreUtil.getExistingAdapter(object,
> ICodeGenAdapter.JVE_CODEGEN_BEAN_PART_ADAPTER)
>
> The adapter will point to the CodeGen BeanPart
>
> BeanPart bp = adapter.getBeanPart();
>
> bp has all the information about the code associated with this
> object. The instance/local name (getSimpleName), source expressions
> (getRefExpressions()) etc. You than need to figure out where in the
> source you want to insert your code (using the offsets of one of the
> current expressions). The expression offset is from the method
> (getInitMethod())... so you will have to add these up to get a full
> offset ... you can insert your code to the CU directly if you want to
>
>
> bp.getModel().getDocumentBuffer().replace
Re: adding popup menu to generate code [message #607142 is a reply to message #87042] Thu, 14 April 2005 12:45 Go to previous message
Gili Mendel is currently offline Gili MendelFriend
Messages: 338
Registered: July 2009
Senior Member
Hung wrote:
> while looking at SWTLabelCreationPolicy.java and
> ChangeParentShellObjectActionDelegate.java, I have tried out the
> following code to do the insertion. (basically it will set the property
> "data" to a string.) It seems to work, but not sure if this is the
> correct way to do it.
>
> IJavaObjectInstance model = (IJavaObjectInstance)
> selectedEP.getModel(); EStructuralFeature esf =
> model.eClass().getEStructuralFeature("data");
> ResourceSet rs = model.eResource().getResourceSet();
> IJavaObjectInstance ijoi = BeanUtilities.createString(rs,"test");
> RuledCommandBuilder cb = new
> RuledCommandBuilder(EditDomain.getEditDomain(selectedEP));
> cb.applyAttributeSetting((EObject) model, esf, ijoi);
> command = cb.getCommand();
> command.execute();
>
>
>
> Another question : After running the above code, a new expression is
> inserted : for example: button.setData("test");
> However, I want it to say : button.setData("id","test"); instead. I
> looked at BeanUtilities and RuledCommandBuilder.applyAttributeSetting,
> but I couldn't find a way to do it.
>
> Thanks for all your help.
>

yep. That would be the right way to get the default behavior (property setting has a single argument). But also, Since
VE consider "data" to be a property, you can only set it once. i.e., if you try to create a sequence of
setData(key,data) calls VE will replace them. Is this a problem?
Re: adding popup menu to generate code [message #607143 is a reply to message #87144] Thu, 14 April 2005 12:55 Go to previous message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
I don't know how to insert setData(key,data), and that's what my question is. Actually, I prefer VE
to replace them, so VE's behavior would be perfect in my case. Any idea how can I modify my code to
insert setData(key,data) instead of setData(data)? Thanks.


Gili Mendel wrote:
> Hung wrote:
>
>> while looking at SWTLabelCreationPolicy.java and
>> ChangeParentShellObjectActionDelegate.java, I have tried out the
>> following code to do the insertion. (basically it will set the
>> property "data" to a string.) It seems to work, but not sure if this
>> is the correct way to do it.
>>
>> IJavaObjectInstance model = (IJavaObjectInstance)
>> selectedEP.getModel(); EStructuralFeature esf =
>> model.eClass().getEStructuralFeature("data");
>> ResourceSet rs = model.eResource().getResourceSet();
>> IJavaObjectInstance ijoi = BeanUtilities.createString(rs,"test");
>> RuledCommandBuilder cb = new
>> RuledCommandBuilder(EditDomain.getEditDomain(selectedEP));
>> cb.applyAttributeSetting((EObject) model, esf, ijoi);
>> command = cb.getCommand();
>> command.execute();
>>
>>
>>
>> Another question : After running the above code, a new expression is
>> inserted : for example: button.setData("test");
>> However, I want it to say : button.setData("id","test"); instead. I
>> looked at BeanUtilities and RuledCommandBuilder.applyAttributeSetting,
>> but I couldn't find a way to do it.
>>
>> Thanks for all your help.
>>
>
> yep. That would be the right way to get the default behavior (property
> setting has a single argument). But also, Since VE consider "data" to be
> a property, you can only set it once. i.e., if you try to create a
> sequence of setData(key,data) calls VE will replace them. Is this a
> problem?
Re: adding popup menu to generate code [message #607151 is a reply to message #87159] Fri, 15 April 2005 14:38 Go to previous message
Gili Mendel is currently offline Gili MendelFriend
Messages: 338
Registered: July 2009
Senior Member
Hung wrote:
> I don't know how to insert setData(key,data), and that's what my
> question is. Actually, I prefer VE to replace them, so VE's behavior
> would be perfect in my case. Any idea how can I modify my code to
> insert setData(key,data) instead of setData(data)? Thanks.
>
>



The problem is that the property *data* is define through introspection to be a single argument. What you need
is to override how VE treads the data property... currently it only allows one to define decoders and proxies
for classes not features (opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=91531). What we also need is a formal
support to the Control's data keys (opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=91532).

There is no way to do what you want now by overriding VE.. you will have to change VE's base code to model this which
will enable you to drive/reverse parse this in.

The best you can do for now, is what I have suggested earlier. Get the BeanPart from which you will get the source
offset with its expressions, and insert the code directly to the editor's buffer. On the dialog up, reverse parse that
section of code to figure out if the key is set.
Previous Topic:how to visually edit an old program made in Visual Age for Java?
Next Topic:ve errors after applying updates
Goto Forum:
  


Current Time: Fri Apr 26 09:51:16 GMT 2024

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

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

Back to the top