Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [ve-dev] Custom code in a setter


Hi Janak,

If you are talking about doing this for any controls we've already have code gen for, such as JButton, then you can't override it. That is because the property handling is done either on the type of the property (which is String, and we provide a String property editor) or on the feature of the part (which is "text" feature of JButton, and we can't have you overriding this because it would mess other people up).

Now if this is your ULC button, then you can do this by providing a special property editor for the "text" feature of your ULC button. Then we would use that property editor instead for your text property on the button. It would then need to understand this format and look in the property file for text, etc. This is not a simple thing. It needs to find the "Messages" class, parse through it to find the MessageBundle of interest. Load the message bundle, see what strings are available, show those strings, and when one is selected, change the string key in the allocation to this new key. Also it would need to be able to handle "adding" a new string to the bundle.

We have a defect for this but we could never got to it:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=73310

If you come up with a nice editor that can do this and generate the appropriate parse tree (i.e. the format shown), then we would be happy to make it the default for String everywhere. :-)

As for your second question, you can't override it for MyButton. The feature only exists at one level, the JButton level. So the annotation can only apply to JButton and not to MyButton. So you can't change it for only MyButton.

Rich


"Janak Mulani" <janak.mulani@xxxxxxxxx>
Sent by: ve-dev-bounces@xxxxxxxxxxx

05/31/2006 05:37 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
RE: [ve-dev] Custom code in a setter





Hi Rich,

Thanks for the prompt reply.

You suggested the following way of doing resource bundle:

this.setTitle(Messages.getString("TestFrame2.0")); //$NON-NLS-1$

But, how can have the above generated  because when I set "title" in the
property sheet. VE will generate setTitle("TextFrame")? Do I need to specify
an Decoder and code a DeocderHelper to generate the above for "title"
feature?

-------------

I have another question:

In VE 1.1:

Suppose I have a class MyButton extends JButton. In MyButton I want to
provide a custom editor for JButton's "text" property. How do I do it?

I tried specifying in MyButton's override:

<event:Add featureName="eStructuralFeatures">
<addedEObjects xsi:type="ecore:EReference" name="text" unsettable="true">
  <eAnnotations
xsi:type="org.eclipse.ve.internal.cde.decorators:BasePropertyDecorator"
cellEditorClassname="RichDialogVisualEditor/mycompany.visualeditor.propertye
ditor.TextPropertyEditor"/>
  </addedEObjects>
</event:Add>

But I am getting  a ClassCastException:

!ENTRY org.eclipse.ui 4 0 2006-06-01 02:56:25.47
!MESSAGE Failed to execute runnable (java.lang.ClassCastException)
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable
(java.lang.ClassCastException)
                at org.eclipse.swt.SWT.error(SWT.java:2942)
                at org.eclipse.swt.SWT.error(SWT.java:2865)
                at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:126)
                at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3057)
                at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2716)
                at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
                at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
                at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
                at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
                at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
                at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.
java:226)
                at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
                at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
                at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
                at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
                at org.eclipse.core.launcher.Main.run(Main.java:973)
                at org.eclipse.core.launcher.Main.main(Main.java:948)
Caused by: java.lang.ClassCastException
                at
org.eclipse.ve.internal.java.core.BeanProxyAdapter.getBeanPropertyValue(Bean
ProxyAdapter.java:1424)
                at
org.eclipse.ve.internal.java.core.BeanPropertySourceAdapter.getPropertyValue
(BeanPropertySourceAdapter.java:94)
                at
org.eclipse.ve.internal.propertysheet.command.CommandStackPropertySheetEntry
.primGetValues(CommandStackPropertySheetEntry.java:173)
                at
org.eclipse.ve.internal.propertysheet.AbstractPropertySheetEntry.refreshValu
es(AbstractPropertySheetEntry.java:892)
                at
org.eclipse.ve.internal.propertysheet.AbstractPropertySheetEntry.refreshChil
dEntries(AbstractPropertySheetEntry.java:823)
                at
org.eclipse.ve.internal.propertysheet.AbstractPropertySheetEntry.setValues(A
bstractPropertySheetEntry.java:1028)
                at
org.eclipse.ui.views.properties.PropertySheetViewer.setInput(PropertySheetVi
ewer.java:875)
                at
org.eclipse.ui.views.properties.PropertySheetPage.selectionChanged(PropertyS
heetPage.java:392)
                at
org.eclipse.ve.internal.propertysheet.EToolsPropertySheetPage.superSelection
Changed(EToolsPropertySheetPage.java:250)
                at
org.eclipse.ve.internal.propertysheet.EToolsPropertySheetPage.access$2(ETool
sPropertySheetPage.java:243)
                at
org.eclipse.ve.internal.propertysheet.EToolsPropertySheetPage$1.run(EToolsPr
opertySheetPage.java:236)
                at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
                at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
                ... 18 more

Could you please tell me where am I going wrong?

What is the right way of achieving the desired behaviour?

Thanks and regards,

Janak

-----Original Message-----
From: ve-dev-bounces@xxxxxxxxxxx [mailto:ve-dev-bounces@xxxxxxxxxxx]On
Behalf Of Rich Kulp
Sent: Thursday, June 01, 2006 1:41 AM
To: Discussions people developing code for the Visual Editor project
Subject: Re: [ve-dev] Custom code in a setter



Hi,

It won't work at all in VE 1.1, but,

You can do it in VE 1.2, but it won't be understood on parsing. It will put
a little "!" on the JButton and saying something about it did not understand
method calls to "this" that are not methods that return bean parts, such as
getJButton(). It would understand getJButton() but it wouldn't understand
getFromResourceBundle("..."). You'll get a msg like:

java.lang.IllegalArgumentException: IWAV0167E Access by method name
(getFromResourceBundle) (not by proxy) requires a receiver.

Or if you made it this.getFromResourceBundle() you would get the the
message:

java.lang.NoSuchMethodException:
javax.swing.JFrame.getFromResourceBundle(java.lang.String)

The reasons for this are (1) the first case is we just didn't allow general
calls without "this" in front. This is old hangaround from before we
understood this.call to some extent. We should of fixed that one. (2) is
because even though we have the "this" there, we don't have an actual
instance of "this" on the remote vm. We instead have an instance of the
superclass. So if it was a method of the superclass, then
this.getFromResourceBundle() would of worked.

So there is only two ways to make this work:

The method must be a method of the superclass and you must use this.get....
It is a static public or protected method on your subclass, BUT it won't
work until the class has been saved, recompiled, and a new vm started. Until
then the method would not be available to the remote vm.

Further constraints are that if you use the standard string property editor,
it will remove your get statement and replace it with a hard-coded string.
-------------------------


However Janak, I recommend instead of coming up with your own way of doing
resource bundles, use the  standard Eclipse NLS method of externalization.
The one that will be provided for you by the standard Eclipse externalize
string action. We do understand these and it won't be something special. It
would be a standard format that everyone else already understands.

this.setTitle(Messages.getString("TestFrame2.0")); //$NON-NLS-1$

Where Messages is a class with a static getString method on it, the
typcially format created by Eclipse would be:

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Messages {
       private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$

       private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
                       .getBundle(BUNDLE_NAME);

       private Messages() {
       }

       public static String getString(String key) {
               try {
                       return RESOURCE_BUNDLE.getString(key);
               } catch (MissingResourceException e) {
                       return '!' + key + '!';
               }
       }
}



Rich


"Janak Mulani" <janak.mulani@xxxxxxxxx>
Sent by: ve-dev-bounces@xxxxxxxxxxx
05/31/2006 01:54 PM Please respond to
Discussions people developing code for the Visual Editor project
<ve-dev@xxxxxxxxxxx>

To"ve-Dev@Eclipse. Org" <ve-dev@xxxxxxxxxxx>
cc
Subject[ve-dev] Custom code in a setter







Hi,

Will VE 1.2 allow generation of a setter with custom code?

For instance, for the text property of JButton would it be possible to
generate:

private JButton getJButton() {
                                if (jButton == null) {
                                                 jButton = new JButton();
>>>>>>>>
jButton.setText(getFromResourceBundle("AbortButtonKey"));
                                }
                                return jButton;
               }

Is there some way of doing this in VE 1.1?

Thanks and regards,

Janak

_______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev

_______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev


Back to the top