Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » XWT. Composite with XWT UI.
XWT. Composite with XWT UI. [message #532832] Tue, 11 May 2010 10:52 Go to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
How to create normal SWT Composite with UI created in XWT?
Also same Composite should be used for handling events.

So, I've tried to use x:Class in XWT file, but this causes infinite recursion.
public class Composite_1 extends Composite {
	public Composite_1(Composite parent, int style) {
		super(parent, style);
		setLayout(new FillLayout());
		// load XWT
		String name = Composite_1.class.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX;
		try {
			URL url = Composite_1.class.getResource(name);
			XWT.load(this, url);
		} catch (Throwable e) {
			throw new Error("Unable to load " + name, e);
		}
	}
}


<Composite xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" x:Class="test.Composite_1">
	<Composite.layout>
		<RowLayout/>
	</Composite.layout>
	<Button text="Double click me!"/>
</Composite>


I think that reason is that XWT creates each time new instance of Composite_1, which tries to load XWT file, etc.

Is it possible to avoid x:Class instance, if given "parent" container is already instance of this class?

I'm aware of this discussion, but I want standalone SWT Composite, not just way to use nested XWT files. I.e. just keep XWT as internal details. Is this wrong idea? Which features of XWT I will lose by doing so? Something important in databinding?


Konstantin Scheglov,
Google, Inc.
Re: XWT. Composite with XWT UI. [message #532994 is a reply to message #532832] Tue, 11 May 2010 19:06 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 688
Registered: July 2009
Senior Member
"Konstantin Scheglov" <Konstantin.Scheglov@gmail.com> wrote in message
news:hsbctv$1qs$1@build.eclipse.org...
> How to create normal SWT Composite with UI created in XWT?
> Also same Composite should be used for handling events.
>
> So, I've tried to use x:Class in XWT file, but this causes infinite
> recursion.
>
> public class Composite_1 extends Composite {
> public Composite_1(Composite parent, int style) {
> super(parent, style);
> setLayout(new FillLayout());
> // load XWT
> String name = Composite_1.class.getSimpleName() +
> IConstants.XWT_EXTENSION_SUFFIX;
> try {
> URL url = Composite_1.class.getResource(name);
> XWT.load(this, url);
> } catch (Throwable e) {
> throw new Error("Unable to load " + name, e);
> }
> }
> }
>
>
> <Composite xmlns="http://www.eclipse.org/xwt/presentation"
> xmlns:x="http://www.eclipse.org/xwt" x:Class="test.Composite_1">
> <Composite.layout>
> <RowLayout/>
> </Composite.layout>
> <Button text="Double click me!"/>
> </Composite>
>
> I think that reason is that XWT creates each time new instance of
> Composite_1, which tries to load XWT file, etc.
Yes, each time, the XWT Loader will create an instance for each
specification of x:Class.

To prevent the creation, you can use the loadWithOptions() with the option
IXWTLoader.CLASS_PROPERTY

URL url = UserComposite.class.getResource(name);
Map<String, Object> options = new HashMap<String, Object>();
options.put(IXWTLoader.CLASS_PROPERTY, this);
options.put(IXWTLoader.CONTAINER_PROPERTY, this);
XWT.loadWithOptions(url, options);

In this case, you should remove the x:Class attribute in the XWT file.

>
> Is it possible to avoid x:Class instance, if given "parent" container is
> already instance of this class?

We do it in inverse order. If the current element type is compatible with
x:Class, we reuse the x:Class instance, instead of creating a new one.

>
> I'm aware of
> http://www.mail-archive.com/e4-dev@eclipse.org/msg02099.html , but I want
> standalone SWT Composite, not just way to use nested XWT files. I.e. just
> keep XWT as internal details. Is this wrong idea?

Franckly speaking, I have never considered this way to use XWT. My
understanding is this solution provides a solution to define a SWT composite
in XWT, which can be used in standard SWT programming API. But programming
approach is not really the focus of XWT.

> Which features of XWT I will lose by doing so? Something important in
> databinding?
I don't know exactly. XWT is not designed to work in this way.

Best regards
Yves YANG
> --
> Konstantin Scheglov,
> Instantiations, Inc.
Re: XWT. Composite with XWT UI. [message #532995 is a reply to message #532994] Tue, 11 May 2010 19:10 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 688
Registered: July 2009
Senior Member
>> Which features of XWT I will lose by doing so? Something important in
>> databinding?
> I don't know exactly. XWT is not designed to work in this way.

For sure, we lost the flexibility.

Best regards
Yves YANG
>> --
>> Konstantin Scheglov,
>> Instantiations, Inc.
>
>
Re: XWT. Composite with XWT UI. [message #533062 is a reply to message #532994] Wed, 12 May 2010 07:25 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
OK, thank you.
It seems to work in general, but there is one problem with using such Composite in XWT itself.

For <p:MyComposite> it creates not MyComposite class, but Composite, becase <Composite> is used as root element in XWT file. As I can see, existing of XWT file is checked before checking if type of Metaclass is Widget.

So, when I use this Composite in Java SWT code, I can for example set properties defined in MyComposite.

	public void setText(String text) {
		Button button = (Button) XWT.findElementByName(m_control, "button");
		button.setText(text);
	}


But XWT creates wrong/incompatible type, so fails to set property value.

java.lang.IllegalArgumentException: object is not an instance of declaring class
	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:597)
	at org.eclipse.e4.xwt.javabean.metadata.properties.BeanProperty.setValue(BeanProperty.java:85)
	at org.eclipse.e4.xwt.javabean.ResourceLoader.initSegmentAttribute(ResourceLoader.java:1645)
	at org.eclipse.e4.xwt.javabean.ResourceLoader.initAttribute(ResourceLoader.java:1414)
	at org.eclipse.e4.xwt.javabean.ResourceLoader.init(ResourceLoader.java:1080)
	at org.eclipse.e4.xwt.javabean.ResourceLoader.doCreate(ResourceLoader.java:634)
	at com.instantiations.designer.xwt.parser.XWTParser$4$1.doCreate(XWTParser.java:177)


Konstantin Scheglov,
Google, Inc.
Re: XWT. Composite with XWT UI. [message #575839 is a reply to message #532994] Tue, 11 May 2010 19:10 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 688
Registered: July 2009
Senior Member
>> Which features of XWT I will lose by doing so? Something important in
>> databinding?
> I don't know exactly. XWT is not designed to work in this way.

For sure, we lost the flexibility.

Best regards
Yves YANG
>> --
>> Konstantin Scheglov,
>> Instantiations, Inc.
>
>
Re: XWT. Composite with XWT UI. [message #575875 is a reply to message #532994] Wed, 12 May 2010 07:25 Go to previous message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
OK, thank you.
It seems to work in general, but there is one problem with using such Composite in XWT itself.

For <p:MyComposite> it creates not MyComposite class, but Composite, becase <Composite> is used as root element in XWT file. As I can see, existing of XWT file is checked before checking if type of Metaclass is Widget.

So, when I use this Composite in Java SWT code, I can for example set properties defined in MyComposite.

public void setText(String text) {
Button button = (Button) XWT.findElementByName(m_control, "button");
button.setText(text);
}


But XWT creates wrong/incompatible type, so fails to set property value.

java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.e4.xwt.javabean.metadata.properties.BeanProperty .setValue(BeanProperty.java:85)
at org.eclipse.e4.xwt.javabean.ResourceLoader.initSegmentAttrib ute(ResourceLoader.java:1645)
at org.eclipse.e4.xwt.javabean.ResourceLoader.initAttribute(Res ourceLoader.java:1414)
at org.eclipse.e4.xwt.javabean.ResourceLoader.init(ResourceLoad er.java:1080)
at org.eclipse.e4.xwt.javabean.ResourceLoader.doCreate(Resource Loader.java:634)
at com.instantiations.designer.xwt.parser.XWTParser$4$1.doCreat e(XWTParser.java:177)

--
Konstantin Scheglov,
Instantiations, Inc.


Konstantin Scheglov,
Google, Inc.
Previous Topic:XWT. Composite with XWT UI.
Next Topic:Annotatoin @UIEventHandler and @EventHandler
Goto Forum:
  


Current Time: Fri Apr 26 07:49:16 GMT 2024

Powered by FUDForum. Page generated in 0.03229 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top