Search in sources :

Example 1 with WebClient

use of com.servoy.j2db.server.headlessclient.WebClient in project servoy-client by Servoy.

the class DebugClientHandler method executeMethod.

/**
 * @param persist
 * @param elementName
 */
public void executeMethod(final ISupportChilds persist, final String scopeName, final String methodname) {
    final IApplication serviceProvider = getDebugReadyClient();
    if (serviceProvider != null) {
        final Runnable run = new Runnable() {

            public void run() {
                if (persist instanceof Solution) {
                    try {
                        serviceProvider.getScriptEngine().getScopesScope().executeGlobalFunction(scopeName, methodname, null, false, false);
                    } catch (Exception e) {
                        Debug.log(e);
                    }
                } else if (persist instanceof Form) {
                    try {
                        IFormController fp = serviceProvider.getFormManager().leaseFormPanel(((Form) persist).getName());
                        if (fp != null) {
                            fp.initForJSUsage();
                            fp.setView(fp.getView());
                            fp.executeOnLoadMethod();
                            fp.executeFunction(methodname, null, false, null, false, null);
                        }
                    } catch (Exception e) {
                        Debug.log(e);
                    }
                }
            }
        };
        if (serviceProvider == getDebugHeadlessClient() || serviceProvider == getDebugAuthenticator()) {
            ApplicationServerRegistry.get().getExecutor().execute(new Runnable() {

                public void run() {
                    serviceProvider.invokeLater(run);
                }
            });
        } else if (serviceProvider == getDebugWebClient()) {
            ApplicationServerRegistry.get().getExecutor().execute(new Runnable() {

                public void run() {
                    RequestCycle rc = null;
                    try {
                        // fake a request as much as possible
                        WebClientsApplication fakeApplication = ((WebClient) serviceProvider).getFakeApplication();
                        Application.set(fakeApplication);
                        rc = new WebRequestCycle(fakeApplication, new EmptyRequest(), new WebResponse());
                        serviceProvider.invokeAndWait(run);
                    } finally {
                        Application.unset();
                        rc.detach();
                    }
                }
            });
        } else {
            serviceProvider.invokeLater(run);
        }
    }
}
Also used : WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) IApplication(com.servoy.j2db.IApplication) WebResponse(org.apache.wicket.protocol.http.WebResponse) Form(com.servoy.j2db.persistence.Form) WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) RequestCycle(org.apache.wicket.RequestCycle) EmptyRequest(com.servoy.j2db.server.headlessclient.EmptyRequest) IFormController(com.servoy.j2db.IFormController) WebClientsApplication(com.servoy.j2db.server.headlessclient.WebClientsApplication) WebClient(com.servoy.j2db.server.headlessclient.WebClient) IDebugWebClient(com.servoy.j2db.IDebugWebClient) Solution(com.servoy.j2db.persistence.Solution) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

IApplication (com.servoy.j2db.IApplication)1 IDebugWebClient (com.servoy.j2db.IDebugWebClient)1 IFormController (com.servoy.j2db.IFormController)1 Form (com.servoy.j2db.persistence.Form)1 Solution (com.servoy.j2db.persistence.Solution)1 EmptyRequest (com.servoy.j2db.server.headlessclient.EmptyRequest)1 WebClient (com.servoy.j2db.server.headlessclient.WebClient)1 WebClientsApplication (com.servoy.j2db.server.headlessclient.WebClientsApplication)1 RequestCycle (org.apache.wicket.RequestCycle)1 WebRequestCycle (org.apache.wicket.protocol.http.WebRequestCycle)1 WebResponse (org.apache.wicket.protocol.http.WebResponse)1 CoreException (org.eclipse.core.runtime.CoreException)1