Home » Eclipse Projects » Eclipse 4 » XWT. Composite with XWT UI.
XWT. Composite with XWT UI. [message #575793] |
Tue, 11 May 2010 10:52 |
Konstantin Scheglov 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 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? Which features of XWT I will lose by doing so? Something important in databinding?
--
Konstantin Scheglov,
Instantiations, Inc.
Konstantin Scheglov,
Google, Inc.
|
|
|
Re: XWT. Composite with XWT UI. [message #575820 is a reply to message #575793] |
Tue, 11 May 2010 19:06 |
Yves YANG 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.
|
|
|
Goto Forum:
Current Time: Thu Apr 25 12:25:32 GMT 2024
Powered by FUDForum. Page generated in 0.04006 seconds
|