Search in sources :

Example 1 with IEclipseToBrowserFunction

use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.

the class StsBrowserManager method doCall.

private void doCall(final IEclipseToBrowserFunction function) {
    Display.getDefault().asyncExec(() -> {
        IEclipseToBrowserFunction provider = function;
        if (provider != null) {
            String fname = provider.getFunctionName();
            try {
                Object[] fargs = provider.getArguments();
                // System.out.println("doCall "+fname+" "+Arrays.asList(fargs));
                String code = "window." + fname + serializeArguments(fargs);
                boolean success = browser.execute(code);
                // System.out.println("doCall("+fname+") => "+success);
                if (!success) {
                    throw new ExecutionException("Problems executing script: '" + code + "'");
                }
            } catch (Exception e) {
                StatusManager.getManager().handle(new Status(IStatus.ERROR, BrowserPlugin.PLUGIN_ID, "Could not call browser function extension: " + fname, e));
            }
        }
        if (DEBUG) {
            printPageHtml();
        }
    });
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IEclipseToBrowserFunction(org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction) ExecutionException(org.eclipse.core.commands.ExecutionException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 2 with IEclipseToBrowserFunction

use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.

the class StsBrowserManager method dispose.

public void dispose() {
    disposed = true;
    for (IEclipseToBrowserFunction function : onLoadFunctions) {
        function.dispose();
    }
    if (browser_function != null) {
        browser_function.dispose();
        browser_function = null;
    }
}
Also used : IEclipseToBrowserFunction(org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction)

Example 3 with IEclipseToBrowserFunction

use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.

the class StsBrowserManager method setClient.

public void setClient(Browser browser) {
    this.browser = browser;
    browser.execute("window.ide = {\n" + "	call: function () {\n" + "		return ide_call.apply(this, arguments);\n" + "	}\n" + "}");
    if (browser_function == null) {
        browser_function = new BrowserFunction(browser, "ide_call") {

            @Override
            public Object function(Object[] arguments) {
                call((String) arguments[0], (String) arguments[1]);
                return false;
            }
        };
    }
    onLoadFunctions = new ArrayList<IEclipseToBrowserFunction>();
    String oldUrl = currentUrl;
    currentUrl = browser.getUrl();
    // System.out.println("oldUrl: "+oldUrl);
    // System.out.println("newUrl: "+currentUrl);
    // Need to remove any query parameters that might break pattern matching for extensions
    currentUrl = StringUtils.substringBeforeLast(currentUrl, "?");
    currentUrl = StringUtils.substringBeforeLast(currentUrl, "&");
    loadInitialFunctions();
}
Also used : IEclipseToBrowserFunction(org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) IEclipseToBrowserFunction(org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction)

Example 4 with IEclipseToBrowserFunction

use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.

the class StsBrowserManager method callOnBrowser.

/**
 * Calls Javascript functions <i>to</i> the browser, refreshing the browser
 * after each call
 */
public void callOnBrowser(final Collection<IEclipseToBrowserFunction> functions) {
    final Collection<IEclipseToBrowserFunction> waitingFunctions = new CopyOnWriteArrayList<IEclipseToBrowserFunction>();
    IEclipseToBrowserFunction.Callback callback = new IEclipseToBrowserFunction.Callback() {

        @Override
        public void ready(final IEclipseToBrowserFunction function) {
            if (waitingFunctions.remove(function)) {
                if (!disposed) {
                    doCall(function);
                }
            }
        }
    };
    for (IEclipseToBrowserFunction function : functions) {
        if (!function.isReady()) {
            waitingFunctions.add(function);
            function.setCallback(callback);
        } else {
            doCall(function);
        }
    }
    callback.ready(null);
}
Also used : IEclipseToBrowserFunction(org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

IEclipseToBrowserFunction (org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction)4 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)1