Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [e4-dev] Custom Widget using XWT

Hi,

This mailing is reserved for development team. Please use the e4 newsgroup
for this kind of questions. Find the anwser below.

Here is the anwser:
====================
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.

Hope this helpful.

Best regards
Yves YANG
> Hi,
>
> I want to develop a Custom Widget using XWT, and the Widget have
> properties.
> Who can help me?Some help document or sample E4 project.
>
> Thanks.
>
> --
> 李金山
> 13066507602
> jinshanl@xxxxxxxxx
> http://xiuchebao.com
> _______________________________________________
> e4-dev mailing list
> e4-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/e4-dev
>




Back to the top