Search in sources :

Example 1 with XulOverlay

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();
    }
}
Also used : XulOverlay(org.pentaho.ui.xul.XulOverlay) KettleException(org.pentaho.di.core.exception.KettleException) XulException(org.pentaho.ui.xul.XulException) XulEventHandler(org.pentaho.ui.xul.impl.XulEventHandler) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 2 with XulOverlay

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();
}
Also used : JsArray(com.google.gwt.core.client.JsArray) RequestBuilder(com.google.gwt.http.client.RequestBuilder) AbstractCommand(org.pentaho.mantle.client.commands.AbstractCommand) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) XulOverlay(org.pentaho.ui.xul.XulOverlay) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay) RequestCallback(com.google.gwt.http.client.RequestCallback) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay)

Example 3 with XulOverlay

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);
    }
}
Also used : XulOverlay(org.pentaho.ui.xul.XulOverlay) SingletonPentahoObjectReference(org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration)

Example 4 with XulOverlay

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());
}
Also used : XulOverlay(org.pentaho.ui.xul.XulOverlay) Test(org.junit.Test)

Example 5 with XulOverlay

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();
}
Also used : XulOverlay(org.pentaho.ui.xul.XulOverlay) XulException(org.pentaho.ui.xul.XulException)

Aggregations

XulOverlay (org.pentaho.ui.xul.XulOverlay)12 ArrayList (java.util.ArrayList)6 MantleXulOverlay (org.pentaho.mantle.client.objects.MantleXulOverlay)3 IPluginPerspective (org.pentaho.platform.api.engine.perspective.pojo.IPluginPerspective)3 JsArray (com.google.gwt.core.client.JsArray)2 Request (com.google.gwt.http.client.Request)2 RequestBuilder (com.google.gwt.http.client.RequestBuilder)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 RequestException (com.google.gwt.http.client.RequestException)2 Response (com.google.gwt.http.client.Response)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Facet (org.codehaus.enunciate.Facet)2 JsXulOverlay (org.pentaho.mantle.client.ui.xul.JsXulOverlay)2 DefaultPluginPerspective (org.pentaho.platform.plugin.services.pluginmgr.perspective.pojo.DefaultPluginPerspective)2 XulException (org.pentaho.ui.xul.XulException)2 DefaultXulOverlay (org.pentaho.ui.xul.impl.DefaultXulOverlay)2 XulEventHandler (org.pentaho.ui.xul.impl.XulEventHandler)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1