Search in sources :

Example 1 with IBasicMainContainer

use of com.servoy.j2db.IBasicMainContainer in project servoy-client by Servoy.

the class NGFormManager method makeSolutionSettings.

public void makeSolutionSettings(Solution s) {
    Solution solution = s;
    Iterator<Form> e = application.getFlattenedSolution().getForms(true);
    // add all forms first, they may be referred to in the login form
    Form first = application.getFlattenedSolution().getForm(solution.getFirstFormID());
    boolean firstFormCanBeInstantiated = application.getFlattenedSolution().formCanBeInstantiated(first);
    if (!firstFormCanBeInstantiated) {
        Solution[] modules = application.getFlattenedSolution().getModules();
        if (modules != null) {
            for (Solution module : modules) {
                if (module.getFirstFormID() > 0) {
                    first = application.getFlattenedSolution().getForm(module.getFirstFormID());
                    firstFormCanBeInstantiated = application.getFlattenedSolution().formCanBeInstantiated(first);
                    if (firstFormCanBeInstantiated)
                        break;
                }
            }
        }
    }
    while (e.hasNext()) {
        Form form = e.next();
        if (application.getFlattenedSolution().formCanBeInstantiated(form)) {
            if (!firstFormCanBeInstantiated)
                first = form;
            firstFormCanBeInstantiated = true;
        }
        // add anyway, the form may be used in scripting
        addForm(form, form.equals(first));
    }
    if (firstFormCanBeInstantiated) {
        // start in browse mode
        application.getModeManager().setMode(IModeManager.EDIT_MODE);
    }
    boolean showLoginForm = (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() == null);
    if (application.getUserUID() == null) {
        ScriptMethod onBeforeLogin = application.getFlattenedSolution().getScriptMethod(solution.getOnBeforeLoginMethodID());
        if (onBeforeLogin != null) {
            try {
                Object[] paramArray = null;
                Object[] clientArray = ((ClientState) application).getPreferedSolutionMethodArguments();
                if (clientArray != null && clientArray.length > 1) {
                    paramArray = new Object[] { clientArray[1] };
                }
                application.getScriptEngine().getScopesScope().executeGlobalFunction(onBeforeLogin.getScopeName(), onBeforeLogin.getName(), Utils.arrayMerge(paramArray, Utils.parseJSExpressions(solution.getFlattenedMethodArguments("onBeforeLoginMethodID"))), false, false);
            } catch (Exception e1) {
                application.reportError(// $NON-NLS-1$
                Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { onBeforeLogin.getName() }), e1);
            }
        }
    }
    if (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() == null) {
        Form login = application.getFlattenedSolution().getForm(solution.getLoginFormID());
        if (application.getFlattenedSolution().formCanBeInstantiated(login) && loginForm == null) {
            // must set the login form early so its even correct if onload of login form is called
            loginForm = login;
            showFormInMainPanel(login.getName());
            // stop and recall this method from security.login(...)!
            return;
        }
    } else if (showLoginForm) {
        // there was a login in onBeforeLogin, so only second call to makeSolutionSettings should go further
        return;
    }
    IBasicMainContainer currentContainer = getCurrentContainer();
    if (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() != null && loginForm != null) {
        if (currentContainer.getController() != null && loginForm.getName().equals(currentContainer.getController().getForm().getName())) {
            hideFormIfVisible(currentContainer.getController());
            currentContainer.setController(null);
        }
        // clear and continue
        loginForm = null;
    }
    ScriptMethod sm = application.getFlattenedSolution().getScriptMethod(solution.getOnOpenMethodID());
    Object[] solutionOpenMethodArgs = null;
    String preferedSolutionMethodName = ((ClientState) application).getPreferedSolutionMethodNameToCall();
    if (preferedSolutionMethodName == null && ((ClientState) application).getPreferedSolutionMethodArguments() != null) {
        solutionOpenMethodArgs = ((ClientState) application).getPreferedSolutionMethodArguments();
    }
    if (sm != null) {
        try {
            application.getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), Utils.arrayMerge(solutionOpenMethodArgs, Utils.parseJSExpressions(solution.getFlattenedMethodArguments("onOpenMethodID"))), false, false);
            if (application.getSolution() == null)
                return;
        } catch (Exception e1) {
            // $NON-NLS-1$
            application.reportError(Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { sm.getName() }), e1);
        }
    }
    if (first != null && getCurrentForm() == null) {
        // we only set if the solution startup did not yet show a form already
        showFormInMainPanel(first.getName());
    }
    if (preferedSolutionMethodName != null && (application.getFlattenedSolution().isMainSolutionLoaded() || solution.getSolutionType() == SolutionMetaData.LOGIN_SOLUTION)) {
        try {
            Object[] args = ((ClientState) application).getPreferedSolutionMethodArguments();
            Pair<String, String> scope = ScopesUtils.getVariableScope(preferedSolutionMethodName);
            GlobalScope gs = application.getScriptEngine().getScopesScope().getGlobalScope(scope.getLeft());
            if (// make sure the function is found before resetting preferedSolutionMethodName
            gs != null && gs.get(scope.getRight()) instanceof Function) {
                // avoid stack overflows when an execute method URL is used to open the solution, and that method does call JSSecurity login
                ((ClientState) application).resetPreferedSolutionMethodNameToCall();
                Object result = application.getScriptEngine().getScopesScope().executeGlobalFunction(scope.getLeft(), scope.getRight(), args, false, false);
                if (application.getSolution().getSolutionType() == SolutionMetaData.AUTHENTICATOR) {
                    application.getRuntimeProperties().put(IServiceProvider.RT_OPEN_METHOD_RESULT, result);
                }
            } else if (application.getFlattenedSolution().isMainSolutionLoaded()) {
                Debug.error("Preferred method '" + preferedSolutionMethodName + "' not found in " + application.getFlattenedSolution() + ".");
                ((ClientState) application).resetPreferedSolutionMethodNameToCall();
            }
        } catch (Exception e1) {
            // $NON-NLS-1$
            application.reportError(// $NON-NLS-1$
            Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { preferedSolutionMethodName }), e1);
        }
    }
}
Also used : ClientState(com.servoy.j2db.ClientState) GlobalScope(com.servoy.j2db.scripting.GlobalScope) IBasicMainContainer(com.servoy.j2db.IBasicMainContainer) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Function(org.mozilla.javascript.Function) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) Solution(com.servoy.j2db.persistence.Solution)

Example 2 with IBasicMainContainer

use of com.servoy.j2db.IBasicMainContainer in project servoy-client by Servoy.

the class WebForm method formMethodExecution.

/*
	 * @see com.servoy.j2db.ISupportFormExecutionState#formMethodExecution()
	 */
@Override
public FormExecutionState formMethodExecution() {
    FormController fc = getController();
    IBasicFormManager formManager = fc.getBasicFormManager();
    if (formManager != null) {
        IBasicMainContainer currentContainer = formManager.getCurrentContainer();
        MainPage formPage = getMainPage();
        if (currentContainer != formPage) {
            FormExecutionState formExecutionState = new FormExecutionState();
            formExecutionState.mainContainer = currentContainer;
            formExecutionState.mainContainerName = currentContainer.getContainerName();
            ((WebFormManager) formManager).setCurrentContainer(formPage, getContainerName());
            return formExecutionState;
        }
    }
    return null;
}
Also used : FormController(com.servoy.j2db.FormController) IBasicMainContainer(com.servoy.j2db.IBasicMainContainer) IBasicFormManager(com.servoy.j2db.IBasicFormManager) ISupportFormExecutionState(com.servoy.j2db.ISupportFormExecutionState) FormExecutionState(com.servoy.j2db.FormExecutionState)

Aggregations

IBasicMainContainer (com.servoy.j2db.IBasicMainContainer)2 ClientState (com.servoy.j2db.ClientState)1 FormController (com.servoy.j2db.FormController)1 FormExecutionState (com.servoy.j2db.FormExecutionState)1 IBasicFormManager (com.servoy.j2db.IBasicFormManager)1 ISupportFormExecutionState (com.servoy.j2db.ISupportFormExecutionState)1 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)1 Form (com.servoy.j2db.persistence.Form)1 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)1 Solution (com.servoy.j2db.persistence.Solution)1 GlobalScope (com.servoy.j2db.scripting.GlobalScope)1 Function (org.mozilla.javascript.Function)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1