You are browsing past revisions for this area.

Date Editor Preview
You are previewing another version of this material. This will not become the current version unless you click "Revert." If you change your mind, click "cancel."

The next generation UI

Wazaabi provides a complete a complete model support for describing UI in SWT, SWING and JSF, but can be extended to other UI technologies.


 

Finally  we code !

In this section we will see how to create your Wazaabi Application with a set of code snippet. Notice that all examples in this page are available on the SVN repository in the org.wazaabi.engine.swt.snippets project.

Snippet 1: one Big true Button

In this snippet we open a shell with the Wazaabi viewer and we create a big button.

 


public static void main(String[] args) {

		// init SWT Engine in standalone mode
		SWTStandaloneHelper.init();

		// create the shell
		Display display = new Display();
		Shell mainShell = new Shell(display, SWT.SHELL_TRIM);
		mainShell.setLayout(new FillLayout());
		mainShell.setSize(300, 300);

		// create the viewer
		SWTControlViewer viewer = new SWTControlViewer(mainShell);

		// create a button
		PushButton pushButton = WidgetsFactory.eINSTANCE.createPushButton();
		pushButton.setText("Hello World"); //$NON-NLS-1$

		// Set the content
		viewer.setContents(pushButton);

		mainShell.open();

		while (!mainShell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

Notice that here, the viewer takes as content the push button, that's why all the space is taken by the button.

Snippet 2:  A button into a Composite

In this example the button is a child of a composite.

public static void main(String[] args) {

		// init SWT Engine in standalone mode
		SWTStandaloneHelper.init();

		// create the shell
		Display display = new Display();
		Shell mainShell = new Shell(display, SWT.SHELL_TRIM);
		mainShell.setLayout(new FillLayout());
		mainShell.setSize(300, 300);

		// create the viewer
		SWTControlViewer viewer = new SWTControlViewer(mainShell);

		// create a composite and set its layout
		Composite composite = WidgetsFactory.eINSTANCE.createComposite();
		composite.setLayout(LayoutsFactory.eINSTANCE.createRowLayout());

		// create a pushButton
		PushButton pushButton = WidgetsFactory.eINSTANCE.createPushButton();
		pushButton.setText("Hello World"); //$NON-NLS-1$

		// append the button to composite's children list.
		composite.getChildren().add(pushButton);

		// Set the content
		viewer.setContents(composite);

		mainShell.open();

		while (!mainShell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	} 

Snippet 3: a taste of layout

In this example we show a first Row layout, but the most interesting part is the loading of the model UI. Notice that you will find the UI model into the model directory of the snippet project.

public static void main(String[] args) {

	// init SWT Engine in standalone mode
	SWTStandaloneHelper.init();

	// create the shell
	Display display = new Display();
	Shell mainShell = new Shell(display, SWT.SHELL_TRIM);
	mainShell.setLayout(new FillLayout());
	mainShell.setSize(300, 300);
	SWTControlViewer viewer = new SWTControlViewer(mainShell);

	// EMF requirements for standalone applications
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
			"swtmodel", new XMIResourceFactoryImpl());
	org.wazaabi.model.swt.widgets.WidgetsPackage.eINSTANCE.eClass();

	// load the EMF resource
	Resource resource = new ResourceSetImpl().getResource(URI
			.createURI("models/snippet4.swtmodel"), true); //$NON-NLS-1$

	viewer.setContents(resource.getEObject("/"));
	mainShell.open();

	while (!mainShell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}