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 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



Back to the top