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

Difference between revisions of "XWT/FAQ"

< XWT
m (Yves.yang.soyatec.com moved page E4/XWT/FAQ to XWT/FAQ: new standalone project)
 
(8 intermediate revisions by the same user not shown)
Line 6: Line 6:
  
 
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<br>class DecoratedText, a Text with a decoration to indicate the input is mandadory  
 
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<br>class DecoratedText, a Text with a decoration to indicate the input is mandadory  
<pre>package ext.custom;</pre><pre>public class DecoratedText extends Composite {
+
<pre>package ext.custom;
 +
public class DecoratedText extends Composite {
 
   private Image decorator;
 
   private Image decorator;
 
   private Text text;
 
   private Text text;
Line 17: Line 18:
 
     ...
 
     ...
 
   }
 
   }
 
+
}
}</pre><pre>enum Display {
+
enum Display {
 
   None, Always, Error, ToolTip;
 
   None, Always, Error, ToolTip;
 
}</pre>  
 
}</pre>  
Line 38: Line 39:
 
This is the solution to use if you want to override all existing SWT standard widgets.<br>
 
This is the solution to use if you want to override all existing SWT standard widgets.<br>
  
==== 2. In XWT<br> ====
+
==== 2. In XWT<br> ====
  
You can create your custom widget in XWT, it consists of two files: Java class for event handling and XWT resource.
+
You can create your custom widget in XWT, it consists of two files: Java class for event handling and XWT resource.  
  
DecoratedText.java
+
DecoratedText.java  
<pre>
+
<pre>package ext.custom;
package ext.custom;</pre><pre>public class DecoratedText {
+
public class DecoratedText {
 
   private Display display;
 
   private Display display;
   ...</pre><pre>  // event handling methods
+
   ...  
 +
  // event handling methods
 
   ...
 
   ...
}</pre>
+
}</pre>  
DecoratedText.xwt
+
DecoratedText.xwt  
 
<pre>  &lt;Composite x:Class="ext.custom.DecoratedText"&gt;
 
<pre>  &lt;Composite x:Class="ext.custom.DecoratedText"&gt;
 
     &lt;Label/&gt;
 
     &lt;Label/&gt;
 
     &lt;Text/&gt;
 
     &lt;Text/&gt;
 
   &lt;/Composite&gt;
 
   &lt;/Composite&gt;
</pre>
+
</pre>  
This component is used in the same way in XWT as Widget in Java.
+
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.<br><br>
+
I recommend to use XWT solution since it allow to change the appearance dynamically, event in runtime.<br><br>

Latest revision as of 11:32, 18 November 2013

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 recommend to use XWT solution since it allow to change the appearance dynamically, event in runtime.

Back to the top