Samstag, 10. Dezember 2011

gwt-plug: getting started

Preparation

  1. Download gwt-plug
  2. Add the gwt-plug-x.x.jar and gwt-plug-x.x-sources.jar to your project's classpath
  3. Add gwt-plug's GWT module as dependency to your GWT application's *.gwt.xml files:
    <inherits name="de.richsource.gwtplug.GwtPlug" />

Create the API

To make your GWT applications talk to each other, you must define a common language. In this case this language is defined by a Java interface.
Let's create one:
public interface ExampleService {
    String doSomethingWithThatString(String input);
}


To mark that interface as exportable to other GWT appications running in the same host page, we have to create a marker interface that extends "de.richsource.gwtplug.client.PluginComponent" with our newly created "ExampleService" as generic argument:
public interface ExampleServicePluginComponent extends PluginComponent<ExampleService> {}

Both, the "ExampleService" and the marker "ExampleServicePluginComponent" must be accessible by your GWT applications that will be able to communicate. But it's not necessary to have both interfaces in the same GWT module.

Export an instance

Now you need an implementation of the "ExampleService":
public class ExampleServiceImpl implements ExampleService {
    String doSomethingWithThatString(String input) {
        return "Foo"+input;
    }
}


You can create an instance of the "ExampleService" as you would normally do:
ExampleService instance = new ExampleServiceImpl();

To export your instance in one of your plugins do:
PluginComponentManager.initialize();
PluginComponentManager.export(instance); }


Import and use an instance

On the other side you have the consuming GWT application. That one doesn't need to provide an implementation of the "ExampleService". Instead you must register a listener at the "PluginComponentManager" to get informed if a new plugin component is registered with the plugin system:
PluginComponentManager.addListener(new PluginComponentRegisteredListener() {
    public void pluginComponentRegistered(Object importedComponent) {
        if(importedComponent instanceof ExampleService) {
            String result = ((ExampleService) importedComponent).doSomethingWithThatString("bar");
            RootPanel.get().add(new Label(result));
        }
    }
}); PluginComponentManager.initialize();


The "PluginComponentManager.initialize();" must be called after registering the listener to ensure that you always get informed for new plugin components even if they are already added.

Additional information

The common steps to initialize your plugins are:
  1. Register listeners to handle new plugin components added by other GWT applications
  2. Initialize the "PluginComponentManager" to register for new plugin components and read the already added components once
  3. Export plugin components to be used by other GWT allications
This order must be used to make it correctly working.

My new open source project: gwt-plug

I created a new open source project @ googlecode.com:
https://code.google.com/p/gwt-plug/
It provides basic functionality to connect different GWT applications in one host page using Java interfaces.

Montag, 28. März 2011

GwtGL examples and Opera

A few weeks ago, a preview of Opera with WebGL support was published.

I activated Opera in the GwtGL examples (not live on http://gwtgl-examples.appspot.com/):

Now our *.gwt.xml looks like this:


GwtGL and GWT 2.2 Canvas

As mentioned in my last post, GwtGL 0.9 will bring basic support for the GWT 2.2 Canvas widget.

But how must the Code be changed to use that?
At the moment, you have sth. like this to initialize your WebGLCanvas:
WebGLCanvas webGLCanvas = new WebGLCanvas("500px", "500px");
glContext = webGLCanvas.getGlContext();
glContext.viewport(0, 0, 500, 500);
[...]
To use the GWT 2.2 Canvas you must include the GWT module containing the canvas widget:
<inherits name='com.google.gwt.canvas.Canvas'/>
and change the initialization code to:
webGLCanvas = Canvas.createIfSupported();
webGLCanvas.setCoordinateSpaceHeight(500);
webGLCanvas.setCoordinateSpaceWidth(500);
glContext = (WebGLRenderingContext) webGLCanvas.getContext("experimental-webgl");

glContext.viewport(0, 0, 500, 500);

[...]
Remember: The Canvas and WebGLRenderingContext can both be null if the browser doesn't support Canvas or WebGL.


Now that it's possible to use a standard GWT widget for GwtGL, our own WebGLCanvas will be deprecated. But we don't delete it as you can't use the WebGLContextAttributes with the GWT 2.2 Canvas.

Montag, 21. März 2011

Updated GwtGL Roadmap

Much has changed in the last weeks:
  • WebGL 1.0 is final! 
  • Google Chrome 10 supports WebGL
  • Firefox 4 (of course with WebGL support) is on its way
  • A first preview of Opera with WebGL support was released
So we decided to update the GwtGL roadmap. We planned 3 releases:
  • 0.3 will be released to support Chrome 10 and Firefox 4
  • 0.9 will provide support for the GWT 2.2 Canvas widget together with a renewal of the WebGlRenderingContext.
  • 1.0 will be our first stable release
Sadly GwtGL 0.9 will break some of the existing APIs.

Montag, 22. Februar 2010

GwtGL release 0.1

GwtGL (the WebGL binding for GWT) has reached its first release.
A short overview of the things we've done in the last ~2 months:
  • A generator based approach to bind the methods and constants of the WebGLRenderingContex
  • A JavaScriptObject for every object in the WebGL specification
  • A basic object oriented wrapper with enums and a set of wrapper objects
  • All with JavaDocs
  • Documentation in our wiki 
  • Demos
The best moment in this time was in the beginning (after 2 days of work) when the first triangle rendered without JavaScript error ;)

Have fun playing with GwtGL and the demos.