Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
...
[INFO] Installing /Users/simonh/dev/meow/sample/meowster-sample/target/meowster-sample-1.0-SNAPSHOT.oar to
  /Users/simonh/.m2/repository/org/meowster/app/sample/meowster-sample/1.0-SNAPSHOT/meowster-sample-1.0-SNAPSHOT.oar
...

...

This section gives a brief introduction to the files generated filesby the archetype. 

AppComponent

This is the base Application class and may be used for non-UI related functionality (not addressed in this tutorial). 

...

(2) List of application view descriptors, defining which category categories the view appears views appear under in the GUI navigation pane, the internal identifier identifiers for the viewviews, and the corresponding display text for the link:

Code Block
languagejava
private static final String VIEW_ID = "sampleCustom";
private static final String VIEW_TEXT = "Sample Custom";
...
private final List<UiView> uiViews = ImmutableList.of(
        new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT)
);

Note that our application only contributes a single view, though more could be defined here if needed.

 

(3) Declaration of a UiMessageHandlerFactory to generate message handlers on demand. The example factory generates a single handler each time, AppUiMessageHandler, described below:

Code Block
languagejava
// Factory for UI message handlers
private final UiMessageHandlerFactory messageHandlerFactory =
        () -> ImmutableList.of(
                new AppUiMessageHandler()
        );

Generally, there should be one message handler for each contributed view.

 

(4) Declaration of a UiExtension, configured with the previously declared UI view descriptors and message handler factory:

Code Block
languagejava
// Application UI extension
protected UiExtension extension =
        new UiExtension.Builder(getClass().getClassLoader(), uiViews)
                .messageHandlerFactory(messageHandlerFactory)
                .build();

...

This class extends UiMessageHandler to implement code to handle events from the (client-side) sample application custom view.

 

Salient features to note:

...

Code Block
languagejava
@Override
protected Collection<RequestHandler> createRequestHandlers() {
    return ImmutableSet.of(
            new SampleCustomDataRequestHandler()
    );
}

There should be a request handler class for each event type generated by our view. In this simple example, case we only have to deal with a single event type, but this is where other event type handlers would be declared if our view generated additional events, so we only have one handler.

 

(2) define SampleCustomDataRequestHandler class to handle "sampleCustomDataRequest" events from the client. 

...

Info

The payload parameter provides the payload of the request event, but we are not using it which in this exampleparticular case carries no data.

The method creates and populates an ObjectNode instance with data to be (transformed into JSON and) shipped off back to the client.

...