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 "E4/XWTDesigner"

< E4
Line 67: Line 67:
 
In the previous example, we just rewrite Java code in XML. This example illustrates the separation between UI and event handling.  
 
In the previous example, we just rewrite Java code in XML. This example illustrates the separation between UI and event handling.  
  
Click [http://www.eclipse.org/wiki/demo/EventHandler.html here]&nbsp;to check the video
+
Click [http://www.eclipse.org/wiki/demo/EventHandler.html here]&nbsp;to check the video  
  
 
The appearance is defined in XWT. <source lang="xml">
 
The appearance is defined in XWT. <source lang="xml">
Line 159: Line 159:
 
The data context of Label should be a person.  
 
The data context of Label should be a person.  
  
=== JFace integration  ===
+
=== <br> ===
 
+
The following example shows the JFace direct integration with ListViewer.
+
 
+
We have a Class Company that has a name and a collection of Employee. The company is bound to the root Composite object. The child Text is bound to Name of company and ListViewer to property employees of type Java Collection.
+
 
+
<source lang="xml">  
+
<Composite xmlns="http://www.eclipse.org/xwt/presentation"
+
    xmlns:x="http://www.eclipse.org/xwt"
+
    xmlns:j="clr-namespace:jface.listviewer"
+
    x:DataContext="{StaticResource myCompany}">
+
  <Composite.layout>
+
      <GridLayout numColumns="2"/>
+
  </Composite.layout>
+
  <x:Composite.Resources>
+
      <j:Company x:Key="myCompany" Name="Soyatec">
+
        <j:Company.employees>
+
            <j:Employee Name="Thomas"/>
+
            <j:Employee Name="Jin"/>
+
        </j:Company.employees>
+
      </j:Company>
+
  </x:Composite.Resources>
+
  <Label text="Name"/>
+
  <Text text="{Binding Path=Name}"/>
+
  <ListViewer input="{Binding Path=employees}">
+
      <ListViewer.contentProvider>
+
        <j:ContentProvider/>
+
      </ListViewer.contentProvider>
+
      <ListViewer.labelProvider>
+
        <j:LabelProvider/>
+
      </ListViewer.labelProvider>
+
 
+
      <ListViewer.control.layoutData>
+
        <GridData horizontalAlignment="FILL"
+
            grabExcessHorizontalSpace="true"
+
            horizontalSpan="2"/>
+
      </ListViewer.control.layoutData>
+
  </ListViewer>
+
</Composite>
+
</source>
+
 
+
== Features  ==
+
 
+
=== Extensibility and Re-usability  ===
+
 
+
In case, if you have your own layout named as ui.MyGridLayout, it can be used directly. The code will be: <source lang="xml">
+
<Composite xmlns="http://www.eclipse.org/xwt/presentation"
+
    xmlns:x="http://www.eclipse.org/xwt"
+
    xmlns:y="cls-namespace:ui">
+
    <Composite.layout>
+
        <y:MyGridLayout numColumns="2"/>
+
    </Composite.layout>
+
    <Label text="Hello, world"/>
+
    <Text x:style="BORDER">
+
        <Text.layoutData>
+
          <GridData horizontalAlignment="FILL"
+
              grabExcessHorizontalSpace="true"/>
+
        </Text.layoutData>
+
    </Text>
+
</Composite>
+
</source>
+
 
+
In the same way, a customized UI component can be used directly:
+
 
+
<source lang="xml">
+
<Composite xmlns="http://www.eclipse.org/xwt/presentation"
+
    xmlns:x="http://www.eclipse.org/xwt"
+
    xmlns:y="cls-namespace:ui">
+
    <Composite.layout>
+
        <GridLayout numColumns="2"/>
+
    </Composite.layout>
+
    <y:PersonView />
+
        <y:PersonView.layoutData>
+
          <GridData horizontalAlignment="FILL"
+
              grabExcessHorizontalSpace="true"/>
+
        </y:PersonView.layoutData>
+
    </y:PersonView>
+
</Composite>
+
</source>
+
 
+
Where the ui.PersonView is a UI component developed by two files:
+
 
+
XWT file PersonView.xwt <source lang="xml">
+
<Composite xmlns="http://www.eclipse.org/xwt/presentation"
+
    xmlns:x="http://www.eclipse.org/xwt"
+
    x:Class="ui.PersonView"
+
    xmlns:y="cls-namespace:ui">
+
    <Composite.layout>
+
        <GridLayout numColumns="2"/>
+
    </Composite.layout>
+
    <Label text="Name"/>
+
    <Text x:style="BORDER">
+
        <Text.layoutData>
+
          <GridData horizontalAlignment="FILL"
+
              grabExcessHorizontalSpace="true"/>
+
        </Text.layoutData>
+
    </Text>
+
</Composite>
+
</source>
+
 
+
Java class PersonView.java <source lang="java">
+
package ui;
+
import org.eclipse.swt.widgets.Composite;
+
 
+
public class PersonView extends Composite {
+
  ...
+
}
+
</source>
+
 
+
=== Style  ===
+
 
+
XWT is a high extensible framework. It can be extended easily in almost all aspects, including Style. When we talk about the Style, we talk about CSS in general. Indeed, CSS is one of more used declarative style solution in Web. But it is not the only one.
+
 
+
From the point of view of its definition, there are two kinds of style: inline style and external style. Inline style is defined in UI resource file. External style is specified in a separated file.
+
 
+
XWT provides a general style concept.
+
 
+
==== Inline style  ====
+
 
+
==== External style  ====
+
 
+
===== Basic concept  =====
+
 
+
===== CSS  =====
+
 
+
=== Dynamic UI  ===
+
 
+
==== Control binding  ====
+
 
+
Control binding is a kind of data binding, but UI control is used as data binding source.
+
 
+
==== Trigger  ====
+
 
+
===== Property Trigger  =====
+
 
+
See this post: [http://dev.eclipse.org/blogs/yvesyang/2009/10/12/xwt-ui-trigger-1/ Property Trigger]
+
 
+
===== Data Trigger  =====
+
 
+
See this post: [http://dev.eclipse.org/blogs/yvesyang/2009/11/01/xwt-data-trigger-2/ Data Trigger]
+
 
+
===== Event Trigger  =====
+
 
+
=== Data Binding  ===
+
 
+
==== Java Bean Binding and Pojo Binding  ====
+
 
+
==== EMF Binding  ====
+
 
+
==== XML Binding  ====
+
 
+
==== User-defined Binding  ====
+
 
+
=== Animation  ===
+
 
+
==== Property Animation  ====
+
 
+
{| border="1" cellspacing="1" cellpadding="1" width="200"
+
|-
+
| '''''Class'''''
+
| '''''Properties'''''
+
| '''''Widget'''''
+
|-
+
| ColorAnimation
+
| background, foreground
+
| Control
+
|-
+
| IntAnimation
+
| alpha
+
| Shell
+
|-
+
| PointAnimation
+
| location
+
| Control
+
|-
+
| SizeAnimation
+
| size
+
| Control
+
|-
+
| RectangleAnimation
+
| bounds
+
| Control
+
|}
+
 
+
==== Using Key Frames  ====
+
 
+
== Plugins  ==
+
 
+
XWT framework consists of several plugins. Each plugin has a specifc role.
+
 
+
{| style="width: 504px; height: 129px" border="1" cellspacing="1" cellpadding="1" width="504"
+
|-
+
| Plugins
+
| Description
+
|-
+
| org.eclipse.e4.xwt
+
| Main plugin of XWT. It&nbsp;contains&nbsp;XWT&nbsp;engine,&nbsp;and it&nbsp;is&nbsp;independent of eclipse. It can&nbsp;be&nbsp;bundled directly in a standalone Java application.
+
|-
+
| org.eclipse.e4.xwt.emf
+
| It is an integration plugin, which provides some default configuration to&nbsp;work with EMF dynamic object such as data converter, data provider.&nbsp;&nbsp;&nbsp;
+
|-
+
| org.eclipse.e4.xwt.pde
+
| This&nbsp;plugin connects XWT in eclipse environment by providing:some extension points for the Metaclass, Style, etc.&nbsp;It defines the default implementation of IViewPart and IEditorPart.&nbsp;
+
|-
+
| org.eclipse.e4.xwt.css
+
| It is an integration with CSS style..
+
|-
+
| org.eclipse.e4.xwt.forms
+
| This plugin makes eclipse forms be marked up natively.
+
|-
+
| org.eclipse.e4.xwt.xml
+
| This&nbsp;plugin enables XWT&nbsp;UI form to connect&nbsp;the same data binding expression with XML file.&nbsp;
+
|-
+
| org.eclipse.e4.xwt.workbench
+
| It is an integration plugin of XWT in e4 workbench.&nbsp;It defines the&nbsp;default view part and editor.&nbsp;
+
|}
+
 
+
== Environment and integration  ==
+
 
+
=== e4 Workbench integration  ===
+
 
+
=== EMF integration  ===
+
 
+
The plugin org.eclipse.e4.xwt.emf handles the connection of XWT with EMF. Particuliarily, il provides the data binding with EMF dynamic object, known as EObject.
+
 
+
=== Eclipse RCP integration  ===
+
 
+
== WYSIWYG Designer  ==
+
 
+
In e4 build, there are two editors:
+
 
+
*XML based editor with instant preview is provided.
+
*WYSIWYG Designer
+
 
+
Some screen shots can be found in this blog: [http://dev.eclipse.org/blogs/yvesyang/2009/11/02/xwt-designer/ XWT Designer]
+
 
+
== References  ==
+
 
+
==== SWT Developer Guide  ====
+
 
+
[[E4/XWT/SWT2XWT|SWT to XWT Mapping roles]]
+
 
+
== [[E4/XWT/FAQ|FAQ]]  ==
+
 
+
== Web Demos  ==
+
 
+
[http://wiki.eclipse.org/E4/XWT/Running_the_demos XWT Demos]
+
 
+
== Articles and Tutorials  ==
+
 
+
*[http://www.ibm.com/developerworks/opensource/library/os-eclipse-e4/?S_TACT=105AGX01&S_CMP=HP Eclipse e4 highlights - Yi Ming Huang, Software Engineer, IBM ]
+
*[http://dev.eclipse.org/blogs/yvesyang/2009/01/17/xwt-getting-started/ Hello, world! - Yves YANG]
+
*[http://www.vogella.de/articles/EclipseE4/ar01s05.html Lars Vogel's Tutorial]
+
  
 
== Work Areas  ==
 
== Work Areas  ==

Revision as of 05:45, 3 February 2010


E4/XWT Designer

What is XWT Designer?

XWT stands for eclipse XML Window Toolkit. It is a powerful and lightweight declarative UI framework designed for Eclipse, based on XML as markup language.

XWT simplifies UI development by a physical separation of UI definition in XML from the run-time logic in programing language. It is very intuitive for creating interfaces directly or via tools such as Visual editor. especially for people with a background in web design and technologies.

Getting started

Hello, world!

Here is a simple example.Click here to check the video

<Shell xmlns="http://www.eclipse.org/xwt/presentation"
    xmlns:x="http://www.eclipse.org/xwt">
    <Shell.layout>
       <FillLayout/>
    </Shell.layout>
    <Button text="Hello, world!">
    </Button>
</Shell>

The same UI can be developed in Java corresponding:

Shell parent = new Shell();
parent.setLayout(new FillLayout());
Button button = new Button(parent, SWT.NONE);
button.setText("Hello, world!");
XAMl4SWT HelloWorld.png To load and start a simple application, we use the class XWT:
Shell shell = (Shell)XWT.load(file);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
   if (!shell.getDisplay().readAndDispatch()) {
	shell.getDisplay().sleep();
   }
}
Or it's better to use the following API to handle event loop:
XWT.open(uri);
It is possible to load a UI resource under a Composite:
XWT.load(parent, uri);

To use XWT, your project must import at least the following plugins
org.eclipse.swt
org.eclipse.jface
org.eclipse.e4.xwt
org.eclipse.jface.databinding
org.eclipse.core.databinding
com.ibm.icu

Event Handling

In the previous example, we just rewrite Java code in XML. This example illustrates the separation between UI and event handling.

Click here to check the video

The appearance is defined in XWT.
<Shell xmlns="http://www.eclipse.org/xwt/presentation"
    xmlns:x="http://www.eclipse.org/xwt"
    x:Class="ui.EventHandler">
    <Shell.layout>
       <GridLayout/>
    </Shell.layout>
    <Button text="Click Me" SelectionEvent="onSelection">
    </Button>
</Shell>

The extension attribute x:Class declares the Java class to handle all events. The Button event is handled by clickButton method in the class ui.EventHandler. The association is setup during the loading:

package ui;
import org.eclipse.swt.Event;
import org.eclipse.swt.Button;
 
public class EventHandler {
    protected void onSelection(Event event) {
        Button button = (Button )event.widget;
        button.setText("Hello World");
    }
}
When the button gets selected, the method onSelection is invoked to change the Button text to "Hello World!".

Layout

<Composite xmlns="http://www.eclipse.org/xwt/presentation"
    xmlns:x="http://www.eclipse.org/xwt">
   <Composite.layout>
       <GridLayout numColumns="2"/>
   </Composite.layout>
   <Label text="Hello, world"/>
   <Text x:style="BORDER">
      <Text.layoutData>
         <GridData horizontalAlignment="FILL"
            grabExcessHorizontalSpace="true"/>
      </Text.layoutData>
   </Text>   
</Composite>


  1. The simple element name (<Composite>) corresponds to a class name.
  2. The qualified element name (i.g. <Composite.layout>) corresponds to a property defined by an element.
  3. The default namespace corresponds to system packages.
  4. User defined package can be declared as a namespace in the format: ”clr-namespace:<package>=<jar>”
This is functionally equivalent to:
Composite parent = new Composite(shell, SWT.NONE);
parent.setLayout(new GridLayout(2, false);
Label label = new Label(parent, SWT.NULL);
label.setText("Hello, world");
Text text = new Text(parent, SWT.BORDER);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

Data Binding

The DataBinding engine relies on Eclipse DataBinding component. To enable this feature, your project must import at least the following plugins.Click here to check the video[1] 
org.eclipse.swt
org.eclipse.jface
org.eclipse.e4.xwt
org.eclipse.jface.databinding
org.eclipse.core.databinding
org.eclipse.core.databinding.beans
org.eclipse.core.databinding.property
com.ibm.icu

If we bind the text attribute of Label to a property “Name” of a Person, here is the data binding expression:

<Label text="{binding path=Name}"/>
It has the same result as following, but the expression is in pure XML:
 
<Label>
   <Label.text>
      <Binding path=”Name”/>
   </Label.text>
<Label>

The data context of Label should be a person.


Work Areas

Interested Parties

  • Thales (Defense)
  • Saab (Defense)
  • CCR (Reinsurance)

Contributors

Soyatec Initial and main contributor
Hasan Ceylan
  • Data Binding Validation
  • Bug report
Erdal Karaca
  • eclipse xform
  • Bug report

Back to the top