Home » Archived » Visual Editor (VE) » adding popup menu to generate code
|
Re: adding popup menu to generate code [message #86943 is a reply to message #86927] |
Wed, 13 April 2005 15:22 |
Eclipse User |
|
|
|
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 #86971 is a reply to message #86958] |
Wed, 13 April 2005 16:47 |
Eclipse User |
|
|
|
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 #86997 is a reply to message #86984] |
Wed, 13 April 2005 17:28 |
Eclipse User |
|
|
|
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 #87042 is a reply to message #87011] |
Wed, 13 April 2005 21:15 |
hung 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 |
Gili Mendel 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 |
hung 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 #607128 is a reply to message #86927] |
Wed, 13 April 2005 15:22 |
Eclipse User |
|
|
|
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 #607130 is a reply to message #86958] |
Wed, 13 April 2005 16:47 |
Eclipse User |
|
|
|
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 #607132 is a reply to message #86984] |
Wed, 13 April 2005 17:28 |
Eclipse User |
|
|
|
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 #607135 is a reply to message #87011] |
Wed, 13 April 2005 21:15 |
hung 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 |
Gili Mendel 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 |
hung 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?
|
|
| |
Goto Forum:
Current Time: Fri Apr 26 09:51:16 GMT 2024
Powered by FUDForum. Page generated in 0.04083 seconds
|