Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Setting a Property of a component programmatically
Setting a Property of a component programmatically [message #137473] Thu, 03 May 2007 08:38 Go to next message
Mario Ortegón is currently offline Mario Ortegón
Messages: 19
Registered: July 2009
Junior Member
Greetings,

I am trying to add an extension to the Visual Editor, that would allow
me to do drag & drop into a selected component in order to change some
property. So far, I've seen the code that allows you t make a custom
editor for the properties view, but I have found no example on how to
set the property and force the code generation.

I was able to use the IBeanProxy class to invoke the set method on the
second virtual machine, and the property is rendered correctly in the
second virtual machine. However, the code is not generated.

I get the list of selected edit parts by using:

List selected = vePart.getPrimaryViewer().getSelectedEditParts();

(Where vePart is an instance of JavaVisualEditorPart)


I iterate through them, loooking for Edit Parts and java object instances:

for (Iterator iter = selected.iterator(); iter.hasNext();) {
EditPart part = (EditPart)iter.next();
Object obj = part.getModel();
if (obj instanceof JavaObjectInstance) {
JavaObjectInstance joi = (JavaObjectInstance)obj;

// More code here

}
}


If the object is a JavaObjectInstance, then I set the value

IBeanProxy proxy = BeanProxyUtilities.getBeanProxy(joi);
IBeanProxy valProxy =
proxy.getProxyFactoryRegistry().getBeanProxyFactory().create BeanProxyWith( "SomeString");
IMethodProxy setTypeMethodProxy =
proxy.getTypeProxy().getMethodProxy("setPropText", "java.lang.String");
setTypeMethodProxy.invoke(proxy, valProxy);

Of course, I realize this is wrong, as this will only set the value on
the second virtual machine but nothing is said about generation.
Checking into the code for a custom editor, I see that you need to
return a IJavaInstance object by using BeanUtilities.createJavaObject,
however I fail to see how this is used to generate the code.

I am able to get the EditDomain, the ResourceSet and the init code from
the EditPart.

Any ideas?

thanks in advance!
Re: Setting a Property of a component programmatically [message #138019 is a reply to message #137473] Mon, 11 June 2007 06:09 Go to previous message
Eclipse User
Originally posted by: rashmi_h_r.yahoo.com

Hi,
You can set a String valued property using the CommandBuilder from the
package org.eclipse.ve.internal.cde.commands. I dont know if this is the
correct way but it works.

EStructuralFeature sf =
model.eClass().getEStructuralFeature("PropertyName");
if (sf != null && !model.eIsSet(sf)) {
ResourceSet resourceSet = EMFEditDomainHelper.getResourceSet(editDomain);
IJavaInstance newPropertyValue= BeanUtilities.createString(resourceSet,
"NewPropertyValue");
CommandBuilder cb = new CommandBuilder();
cb.applyAttributeSetting(model, sf, newPropertyValue);
command = cb.getCommand();
command.execute();
}

Hope this helps you.
Regards,
Rashmi H.R
Re: Setting a Property of a component programmatically [message #615335 is a reply to message #137473] Mon, 11 June 2007 06:09 Go to previous message
Eclipse User
Originally posted by: rashmi_h_r.yahoo.com

Hi,
You can set a String valued property using the CommandBuilder from the
package org.eclipse.ve.internal.cde.commands. I dont know if this is the
correct way but it works.

EStructuralFeature sf =
model.eClass().getEStructuralFeature("PropertyName");
if (sf != null && !model.eIsSet(sf)) {
ResourceSet resourceSet = EMFEditDomainHelper.getResourceSet(editDomain);
IJavaInstance newPropertyValue= BeanUtilities.createString(resourceSet,
"NewPropertyValue");
CommandBuilder cb = new CommandBuilder();
cb.applyAttributeSetting(model, sf, newPropertyValue);
command = cb.getCommand();
command.execute();
}

Hope this helps you.
Regards,
Rashmi H.R
Previous Topic:How can I check-out VE 1.3?
Next Topic:Extending VE Palette: EMF problem
Goto Forum:
  


Current Time: Mon Jul 28 14:39:50 EDT 2014

Powered by FUDForum. Page generated in 0.03335 seconds