Opening Views Programmatically from a Web based Red App
Sabre Red 360 Software Development Kit provides capability to open views programmatically from any web based Red App. For this purpose there is WorkbenchUtils utility class in package com.sabre.edge.platform.core.ui.handlers .
Dependencies and classes
Below you can find a list of required dependencies and classes.
Minimal Required Dependency
-
com.sabre.edge.platform.core.ui
The following code snippet demonstrates how to open browser view programmatically:
LauncherParams parameters = new LauncherParams.LauncherParamsBuilder(String viewId, String viewName, String pluginId)
.url(String url)
.insertJavaScript(String jsString)
.additionalParams(Map <String, String> additionalParams)
.build();
new WorkbenchUtils().openBrowserView(String commandId, LauncherParams parameters);
LauncherParams is a utility class that will help in setting up the parameters required for opening the view.
The required parameters are:
-
ViewId - String value, id of the view
-
ViewName - String value, name of the view
-
pluginId - String value, plugin id
-
Url - String value, url to load in the view
The optional parameters are:
-
JsString - String value, javascript code to be executed on the view opened
-
AdditionalParams - Map <String, String>, to send any additional key value pair data
To make the view persistent/restorable, add parameter restorable="true" when you register your view in plugin.xml like below:
<extension
point="org.eclipse.ui.views">
<view class="com.sabre.edge.platform.optional.webkit.views.WebkitView"
icon="images/icon.png"
id="com.sabre.redapp.example.openeditor.view.OpenWebkitViewUrl"
name="Open View to load URL"
restorable="true"/>
</extension>
To make the view open programmatically You need to register your view to OpenWebkitViewHandler handler in plugin.xml. Example shown below:
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="com.sabre.edge.platform.optional.webkit.handlers.OpenWebkitViewHandler"
id="com.sabre.redapp.example.openeditor.view.OpenWebkitViewUrl"
name="Open View Url">
<commandParameter
id="viewId"
name="viewId"
optional="true">
</commandParameter>
</command>
</extension>
Opening Views using Plugin Extension point from a Web based Red App:
The following steps demonstrate how you can configure your view to execute javascript using plugin extension points:
1) Register your view to org.eclipse.ui.views as shown in below snippet.
<extension point="org.eclipse.ui.views">
<view
class="com.sabre.edge.platform.optional.webkit.views.WebkitView"
icon="images/icon.png"
id="com.sabre.redapp.example.openeditor.view.OpenWebkitViewJs"
name="Open View to execute js"
restorable="false"/>
</extension>
2) Register default handler 'com.sabre.edge.platform.optional.webkit.handlers.OpenWebkitViewHandler' and you command parameters like viewId and javascript as shown below:
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="com.sabre.edge.platform.optional.webkit.handlers.OpenWebkitViewHandler"
id="com.sabre.redapp.example.openeditor.view.OpenWebkitViewJs"
name="Open View Js">
<commandParameter
id="viewId"
name="viewId"
optional="true">
</commandParameter>
<commandParameter
id="javascript"
name="javascript"
optional="true">
</commandParameter>
</command>
</extension>
3) Provide view id and javascript command parameter value and load url that has js functions defined in html file:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:com.sabre.edge.toolbar.sidebar">
<command
commandId="com.sabre.redapp.example.openeditor.view.OpenWebkitViewJs"
icon="images/icon.png"
label="Open View"
style="push"
tooltip="Open View">
<parameter
name="viewId"
value="com.sabre.redapp.example.openeditor.view.OpenWebkitViewJs"">
</parameter>
<parameter
name="javascript"
value="display();">
</parameter>
</command>
</menuContribution>
</extension>
<extension
point="com.sabre.edge.platform.core.ui.viewApp">
<viewApp
browserURL="${plugin_resources}/html/view.html"
viewId="com.sabre.redapp.example.openeditor.view.OpenWebkitViewJs" />
</extension>