Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

XWT/FAQ

< XWT
Revision as of 21:08, 17 December 2009 by Yves.yang.soyatec.com (Talk | contribs)

I want to develop a Custom Widget using XWT, and the Widget have properties. How to do ?

There are two ways to develop reusable Custom Widgets:

1. In Java

You develop your widget in Java as usual. And this widget can be used directly in XWT using a customized name space: for example we have a
class DecoratedText, a Text with a decoration to indicate the input is mandadory

package ext.custom;
public class DecoratedText extends Composite {
  private Image decorator;
  private Text text;
  private Display display; 
  ... 
  public DecoratedText(Composite parent, int style) {
    text = new Text(parent, SWT.BORDER);
    ...
 }
}
enum Display {
 None, Always, Error, ToolTip;
}

You can use it in your XWT as following:

  <Composite xmlns:c="clr-namespace:ext.custom">
     <c:DecoratedText text="name" decorator="<path>" display="Always"/>
  </Composite>

Here you have created a prefix for a namespace corresponding to you java package, and then you can use it in your code with class java classes in
the package. The model should respect the Java Bean specification, XWT will reflect your classe and map the XML to this class automatically. If
your class doesn't respect this standard, you need to create a Metaclass and register it in XWT to let XWT knows.

You can also choice to use the default namespace, to do so, you need to register your class:

   XWT.registerMetaclass(DecoratedText.class);

This call makes your class in part of standard widget. You can use as simply like

  <Composite>
     <DecoratedText text="name" decorator="<path>" display="Always"/>
  </Composite>

This is the solution to use if you want to override all existing SWT standard widgets.

2. In XWT

You can create your custom widget in XWT, it consists of two files: Java class for event handling and XWT resource.

DecoratedText.java

package ext.custom;
public class DecoratedText {
  private Display display;
...
   // event handling methods
  ...
}

DecoratedText.xwt

  <Composite x:Class="ext.custom.DecoratedText">
     <Label/>
     <Text/>
  </Composite>

This component is used in the same way in XWT as Widget in Java.

I recommand to use XWT solution since it allow to change the appearance with dynamically, event in runtime.

Back to the top