Versions Compared

Key

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

...

Clicking on this item should navigate to the injected sample custom view:

Clicking on the Fetch Data button with the mouse, or pressing the spacebar will update the view with new data.

Note that pressing slash (/) will display the "Quick Help" panel:

...

Also of note, pressing the T key will toggle the "theme" between light and dark:

...

To create a custom view requires both client-side and server-side resources; the clienclient-side consists of HTML, JavaScript, and CSS files, and the server-side consists of Java classes.

...

(2) List of application view descriptors, defining which category the view appears under in the GUI navigation pane (if not a hidden view), the display text internal identifier for the linkview, and the internal identifier display text for the viewlink:

Code Block
languagejava
 // List of application views
private final List<UiView> uiViews = ImmutableList.of(
        new UiView(UiView.Category.OTHER, "samplesampleCustom", "Sample Custom")
);

 

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

...

Salient features to note:

 

(1) implement createRequestHandlers() to provide request handler implementations for specific event types from our view:

Warning

Currently we only have one GUI archetype, which is written as a Tabular View. (We need to create an additional (simpler) archetype for custom views.) So, for now, just note that the details below are subject to change...

 

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

In this simple example, we only have to deal with a single event type, but this is where others would be declared if our view generated additional events.

 

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

Code Block
languagejava
private static final String SAMPLE_CUSTOM_DATA_REQ = "sampleCustomDataRequest";
...
private final class SampleCustomDataRequestHandler extends RequestHandler {
    private SampleCustomDataRequestHandler() {
        super(SAMPLE_CUSTOM_DATA_REQ);
    }
    ...
}

Note that this class extends RequestHandler, which defines an abstract process() method to be implemented by subclasses.

 

(3) implement process() method:

Code Block
languagejava
private static final String SAMPLE_CUSTOM_DATA_RESP = "sampleCustomDataResponse";

private static final String NUMBER = "number";
private static final String SQUARE = "square";
private static final String CUBE = "cube";
private static final String MESSAGE = "message";
private static final String MSG_FORMAT = "Next incrememt is %d units";

private long someNumber = 1;
private long someIncrement = 1;
...
 
@Override
public void process(long sid, ObjectNode payload
Code Block
languagejava
@Override
protected Collection<RequestHandler> createRequestHandlers() {
    return ImmutableSet.of(
            new SampleDataRequestHandler(),someIncrement++;
    someNumber += someIncrement;
    log.debug("Computing data for {}...", someNumber);

    ObjectNode result = objectNode();
    result.put(NUMBER, someNumber);
    result.put(SQUARE, someNumber * someNumber);
    result.put(CUBE, someNumber * someNumber * someNumber);
    new SampleDetailRequestHandler()result.put(MESSAGE, String.format(MSG_FORMAT, someIncrement + 1));
    sendMessage(SAMPLE_CUSTOM_DATA_RESP, 0, result);
}

The process method is invoked every time a "sampleCustomDataRequest" event is received from the client. 

(2) request handler implementations ...

Info

Remaining template files to be documented...

Note

The sid parameter (sequence ID) is deprecated.

Info

The payload parameter provides the payload of the event, but we are not using it in this sample code.

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