Class SwtHtmlContext

  • All Implemented Interfaces:
    GUIContext, HTMLContext, HTTPReplyHandler, Closeable, AutoCloseable

    public class SwtHtmlContext
    extends AbstractHTMLContext
    This GUIContext encapsulates the HTML of this context in a browser widget in SWT. Therefore when setting the initial content, a browser widget will be created and the URL will be set appropriately. The widget will also be closed again when closing this context.
    • Field Detail

      • parentSwtContext

        protected final org.apache.commons.lang3.mutable.Mutable<SWTContext> parentSwtContext
        The parent SWT-context containing the Eclipse-Editor.
      • clientService

        protected final ClientService clientService
        The client service to retrieve a session token from to access the HTTP service.
      • browser

        protected final org.apache.commons.lang3.mutable.Mutable<org.eclipse.swt.browser.Browser> browser
        Browser widget for displaying HTML content in the template
      • contextCleanup

        protected final Cleanup<RuntimeException> contextCleanup
        The clean-up for closing the context and all related resources.
    • Constructor Detail

      • SwtHtmlContext

        public SwtHtmlContext​(Thread thread,
                              SWTContext parentSwtContext,
                              HTTPService httpService,
                              ClientService clientService,
                              String sessionId)
        Creates a new HTML context based on the Eclipse-Browser-widget.
        Parameters:
        thread - The thread which executes the application using this context.
        We must not keep a strong reference to this thread! Otherwise memory leaks may occur.
        parentSwtContext - The parent SWT-context containing the Eclipse-Editor.
        httpService - The HTTP service for deregistering this reply handler.
        clientService - The client service to retrieve a session token from to access the HTTP service.
        sessionId - The ID of the session in which the GUI context is needed (required for deregistering this reply handler).
    • Method Detail

      • setInitialContent

        public void setInitialContent​(String html)
        Sets the initial (HTML-)content of this context, that is the designated content is sent as response to the first to the client for visualising the executed application. Feedback/data can be retrieved via the usage of the provided URL and by HTMLContext.waitForHTTPReply(long).
        The content is only provided once. Afterwards, HTMLContext.setResponse(HTTPReply, Response) has to be used for sending HTML to the user. If you want to set the initial content, be sure to set it before the first request arrives! However, you need not set it here, you can also provide it to a received empty request.
        An InvalidExecutorThreadException will be thrown if the method is not called by the main thread of the corresponding component. Besides setting the initial content, this method also creates a new browser (in Eclipse) having the parent provided in the constructor and a parameterless URL provided by the superclass of this HTMLContext.
        Specified by:
        setInitialContent in interface HTMLContext
        Overrides:
        setInitialContent in class AbstractHTMLContext
        Parameters:
        html - The content of this HTML-context, that is the user-interface in HTML for the executed application.