Package de.aristaflow.adept2.ui.swtgui
Class SwtHtmlContext
- java.lang.Object
-
- de.aristaflow.adept2.ui.htmlgui.AbstractHTMLContext
-
- de.aristaflow.adept2.ui.swtgui.SwtHtmlContext
-
- All Implemented Interfaces:
GUIContext
,HTMLContext
,HTTPReplyHandler
,Closeable
,AutoCloseable
public class SwtHtmlContext extends AbstractHTMLContext
ThisGUIContext
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SwtHtmlContext.BrowserCloseTask
The clean-up task for closing the browser.-
Nested classes/interfaces inherited from class de.aristaflow.adept2.ui.htmlgui.AbstractHTMLContext
AbstractHTMLContext.HtmlContextCleanupTask
-
Nested classes/interfaces inherited from interface de.aristaflow.adept2.ui.htmlgui.HTMLContext
HTMLContext.Attachment, HTMLContext.CloseIgnoringAttachment, HTMLContext.HTTPReply, HTMLContext.Response
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.lang3.mutable.Mutable<org.eclipse.swt.browser.Browser>
browser
Browser widget for displaying HTML content in the templateprotected ClientService
clientService
The client service to retrieve a session token from to access the HTTP service.protected Cleanup<RuntimeException>
contextCleanup
The clean-up for closing the context and all related resources.protected org.apache.commons.lang3.mutable.Mutable<SWTContext>
parentSwtContext
The parent SWT-context containing the Eclipse-Editor.-
Fields inherited from class de.aristaflow.adept2.ui.htmlgui.AbstractHTMLContext
baseURL, cleanup, DEFAULT_FINAL_RESPONSE, finalResponse, httpService, initialContentString, logger, relRes, replies, replyHandlerTerminated, responses, sessionID, thread
-
-
Constructor Summary
Constructors Constructor Description SwtHtmlContext(Thread thread, SWTContext parentSwtContext, HTTPService httpService, ClientService clientService, String sessionId)
Creates a new HTML context based on the Eclipse-Browser-widget.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes thisHTMLContext
.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.-
Methods inherited from class de.aristaflow.adept2.ui.htmlgui.AbstractHTMLContext
checkForValidExecutorThread, close, getRelativeLink, getRelativeLink, getResponse, getURL, getURL, setBaseURL, setBaseURL, setFinalResponse, setFinalResponse, setResponse, waitForHTTPReply
-
-
-
-
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
-
close
public void close()
Description copied from interface:HTMLContext
Closes thisHTMLContext
. Implementations have to clean up which usually involves deregistering the HTML-context from the corresponding HTTP-server, for instanceHTTPService.deregisterReplyHandler(de.aristaflow.adept2.base.sessionmanagement.SessionToken, String)
. Additionally, a final response should be set here in case it has not been set before. This will unblock threads currently waiting for a response that will not come any more.
-
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 providedURL
and byHTMLContext.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.
AnInvalidExecutorThreadException
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 interfaceHTMLContext
- Overrides:
setInitialContent
in classAbstractHTMLContext
- Parameters:
html
- The content of this HTML-context, that is the user-interface in HTML for the executed application.
-
-