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,

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:
  1. The method must be a method of the superclass and you must use this.get....
  2. 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


Back to the top