use of org.pentaho.ui.xul.XulOverlay in project pentaho-kettle by pentaho.
the class SpoonPerspectiveManager method activatePerspective.
/**
* Activates the given instance of the class literal passed in. Activating a perspective first deactivates the current
* perspective removing any overlays its applied to the UI. It then switches the main deck to display the perspective
* UI and applies the optional overlays to the main Spoon XUL container.
*
* @param clazz
* SpoonPerspective class literal
* @throws KettleException
* throws a KettleException if no perspective is found for the given parameter
*/
public void activatePerspective(Class<? extends SpoonPerspective> clazz) throws KettleException {
if (this.forcePerspective) {
// we are currently prevented from switching perspectives
return;
}
SpoonPerspective sp = perspectives.get(clazz);
if (sp == null) {
throw new KettleException("Could not locate perspective by class: " + clazz);
}
PerspectiveManager perspectiveManager = getPerspectiveManagerMap().get(sp);
if (perspectiveManager != null) {
perspectiveManager.initializeIfNeeded();
}
unloadPerspective(activePerspective);
activePerspective = sp;
List<XulOverlay> overlays = sp.getOverlays();
if (overlays != null) {
for (XulOverlay overlay : overlays) {
try {
ResourceBundle res = null;
if (overlay.getResourceBundleUri() != null) {
try {
res = GlobalMessageUtil.getBundle(overlay.getResourceBundleUri(), SpoonPerspectiveManager.class);
} catch (MissingResourceException ignored) {
// Ignore errors
}
} else {
try {
res = GlobalMessageUtil.getBundle(overlay.getOverlayUri().replace(".xul", ".properties"), SpoonPerspectiveManager.class);
} catch (MissingResourceException ignored) {
// Ignore errors
}
}
if (res == null) {
res = new XulSpoonResourceBundle(sp.getClass());
}
domContainer.loadOverlay(overlay.getOverlayUri(), res);
} catch (XulException e) {
log.logError("Error activate perspective", e);
}
}
}
List<XulEventHandler> theXulEventHandlers = sp.getEventHandlers();
if (theXulEventHandlers != null) {
for (XulEventHandler handler : theXulEventHandlers) {
domContainer.addEventHandler(handler);
}
}
sp.setActive(true);
if (sp.equals(activePerspective)) {
deck.setSelectedIndex(deck.getChildNodes().indexOf(deck.getElementById("perspective-" + sp.getId())));
getSpoon().enableMenus();
}
}
use of org.pentaho.ui.xul.XulOverlay in project pentaho-platform by pentaho.
the class MantleXul method fetchPluginOverlays.
private void fetchPluginOverlays() {
AbstractCommand cmd = new AbstractCommand() {
protected void performOperation(boolean feedback) {
performOperation();
}
protected void performOperation() {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/plugin-manager/overlays";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
public void onResponseReceived(Request request, Response response) {
JsArray<JsXulOverlay> jsoverlays = JsXulOverlay.parseJson(JsonUtils.escapeJsonForEval(response.getText()));
ArrayList<XulOverlay> overlays = new ArrayList<XulOverlay>();
for (int i = 0; i < jsoverlays.length(); i++) {
JsXulOverlay o = jsoverlays.get(i);
MantleXulOverlay overlay;
overlay = new MantleXulOverlay(o.getId(), o.getOverlayUri(), o.getSource(), o.getResourceBundleUri(), Integer.parseInt(o.getPriority()));
overlays.add(overlay);
}
MantleXul.this.addOverlays(overlays);
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "plugin/data-access/api/permissions/hasDataAccess";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
public void onResponseReceived(Request request, Response response) {
if (response.getText().equals("true")) {
controller.loadOverlay("dataaccess");
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
};
cmd.execute();
}
use of org.pentaho.ui.xul.XulOverlay in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method registerOverlays.
private void registerOverlays(IPlatformPlugin plugin) {
int priority = plugin.getOverlays().size();
for (XulOverlay overlay : plugin.getOverlays()) {
// preserve ordering as it may be significant
final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<XulOverlay>(XulOverlay.class).object(overlay).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).priority(priority).build(), XulOverlay.class);
priority--;
registerReference(plugin.getId(), referenceHandle);
}
}
use of org.pentaho.ui.xul.XulOverlay in project pentaho-platform by pentaho.
the class DefaultPluginManagerIT method INTEGRATION_test4_GetOverlays.
@Test
public void INTEGRATION_test4_GetOverlays() throws Exception {
microPlatform.start();
PluginMessageLogger.clear();
pluginManager.reload();
System.err.println(PluginMessageLogger.prettyPrint());
List<XulOverlay> overlays = pluginManager.getOverlays();
// $NON-NLS-1$
assertNotNull("Overlays is null", overlays);
System.err.println(overlays);
// $NON-NLS-1$
assertEquals("Wrong number of overlays", 3, overlays.size());
XulOverlay overlay = overlays.get(0);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong overlay id", "overlay1", overlay.getId());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong overlay resource uri", "uri1", overlay.getResourceBundleUri());
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node1") != -1);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node2") != -1);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node3") == -1);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node4") == -1);
// $NON-NLS-1$
assertNull("Overlay URI should be null", overlay.getOverlayUri());
overlay = overlays.get(1);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong overlay id", "overlay2", overlay.getId());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Wrong overlay resource uri", "uri2", overlay.getResourceBundleUri());
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node1") == -1);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node2") == -1);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node3") != -1);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Wrong overlay content", overlay.getSource().indexOf("<node4") != -1);
// $NON-NLS-1$
assertNull("Overlay URI should be null", overlay.getOverlayUri());
}
use of org.pentaho.ui.xul.XulOverlay in project pentaho-kettle by pentaho.
the class SpoonPerspectiveManager method unloadPerspective.
private void unloadPerspective(SpoonPerspective per) {
per.setActive(false);
List<XulOverlay> overlays = per.getOverlays();
if (overlays != null) {
for (XulOverlay overlay : overlays) {
try {
domContainer.removeOverlay(overlay.getOverlayUri());
} catch (XulException e) {
log.logError("Error unload perspective", e);
}
}
}
getSpoon().enableMenus();
}
Aggregations