Search in sources :

Example 16 with Form

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

the class NGFormManager method showFormInContainer.

@Override
public IFormController showFormInContainer(String formName, IBasicMainContainer container, String title, boolean closeAll, String dialogName) {
    if (loginForm != null && loginForm.getName() != formName) {
        // not allowed to leave here...or show anything else than login form
        return null;
    }
    // $NON-NLS-1$
    if (formName == null)
        throw new IllegalArgumentException(application.getI18NMessage("servoy.formManager.error.SettingVoidForm"));
    IFormController currentMainShowingForm = container.getController();
    boolean sameForm = (currentMainShowingForm != null && formName.equals(currentMainShowingForm.getName()));
    if (sameForm && currentMainShowingForm.isFormVisible())
        return leaseFormPanel(currentMainShowingForm.getName());
    final Form f = possibleForms.get(formName);
    if (f == null) {
        return null;
    }
    try {
        int access = application.getFlattenedSolution().getSecurityAccess(f.getUUID(), f.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
        if (access != -1) {
            boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
            if (!b_visible) {
                // $NON-NLS-1$
                application.reportWarningInStatus(application.getI18NMessage("servoy.formManager.warningAccessForm"));
                return null;
            }
        }
        // handle old panel
        if (currentMainShowingForm != null) {
            // leave forms in browse mode // TODO can this be set if notifyVisible returns false (current form is being kept)
            if (application.getModeManager().getMode() != IModeManager.EDIT_MODE) {
                application.getModeManager().setMode(IModeManager.EDIT_MODE);
            }
            IWebFormController fp = leaseFormPanel(currentMainShowingForm.getName());
            if (fp != null && !sameForm) {
                List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
                boolean ok = fp.notifyVisible(false, invokeLaterRunnables);
                if (invokeLaterRunnables.size() > 0)
                    wrapInShowLoadingIndicator(invokeLaterRunnables);
                Utils.invokeLater(application, invokeLaterRunnables);
                // solution closed in onhide method of previous form?
                if (application.getSolution() == null)
                    return null;
                if (!ok) {
                    return fp;
                }
            }
        }
        // set main
        IFormController tmpForm = currentMainShowingForm;
        final IWebFormController fp = leaseFormPanel(formName);
        currentMainShowingForm = fp;
        if (fp != null) {
            // test if solution is closed in the onload method.
            if (application.getSolution() == null)
                return null;
            setCurrentControllerJS(fp);
            // add to history
            getHistory(container).add(fp.getName());
            container.setController(fp);
            // show panel as main
            List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
            fp.notifyVisible(true, invokeLaterRunnables);
            String titleText = title;
            if (titleText == null)
                titleText = f.getTitleText();
            // $NON-NLS-1$
            if (titleText == null || titleText.equals(""))
                titleText = fp.getName();
            // $NON-NLS-1$
            if (NO_TITLE_TEXT.equals(titleText))
                titleText = "";
            container.setTitle(titleText);
            fp.getFormUI().setParentWindowName(container.getContainerName());
            if (invokeLaterRunnables.size() > 0)
                wrapInShowLoadingIndicator(invokeLaterRunnables);
            Utils.invokeLater(application, invokeLaterRunnables);
        } else {
            container.setController(null);
        }
        // $NON-NLS-1$
        J2DBGlobals.firePropertyChange(this, "form", tmpForm, currentMainShowingForm);
        return fp;
    } catch (Exception e) {
        Debug.error(e);
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ArrayList(java.util.ArrayList) IFormController(com.servoy.j2db.IFormController)

Example 17 with Form

use of com.servoy.j2db.persistence.Form 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 18 with Form

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

the class NGFormManager method leaseFormPanel.

@Override
public IWebFormController leaseFormPanel(String formName) {
    if (formName == null)
        return null;
    String name = formName;
    IWebFormController fp = createdFormControllers.get(name);
    if (fp == null) {
        Form f = possibleForms.get(formName);
        if (f == null)
            return null;
        try {
            // $NON-NLS-1$
            application.blockGUII18NMessage("servoy.formManager.loadingForm", formName);
            f = application.getFlattenedSolution().getFlattenedForm(f, false);
            fp = new WebFormController((INGApplication) application, f, name);
            createdFormControllers.put(fp.getName(), fp);
            fp.init();
            updateLeaseHistory(fp);
            fp.setView(fp.getView());
            fp.executeOnLoadMethod();
        } finally {
            application.releaseGUI();
        }
    } else {
        addAsLastInLeaseHistory(fp);
    }
    return fp;
}
Also used : WebFormController(com.servoy.j2db.server.ngclient.component.WebFormController) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm)

Example 19 with Form

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

the class ContainersScope method findFormComponentContainers.

private static void findFormComponentContainers(Iterator<WebComponent> components, Map<String, List<String>> namesToLayout, FlattenedSolution fs) {
    while (components.hasNext()) {
        WebComponent component = components.next();
        String typeName = (String) component.getProperty(IContentSpecConstants.PROPERTY_TYPENAME);
        WebComponentSpecProvider.getInstance();
        WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(typeName);
        if (spec != null) {
            Collection<PropertyDescription> pd = spec.getProperties(FormComponentPropertyType.INSTANCE);
            if (pd != null && !pd.isEmpty()) {
                PropertyDescription prop = pd.iterator().next();
                Object val = component.getProperty(prop.getName());
                Form fcomp = FormComponentPropertyType.INSTANCE.getForm(val, fs);
                if (fcomp != null && fcomp.isResponsiveLayout()) {
                    fillNames(fcomp.getLayoutContainers(), namesToLayout, fs);
                }
            }
        }
    }
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebComponent(com.servoy.j2db.persistence.WebComponent) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) Form(com.servoy.j2db.persistence.Form)

Example 20 with Form

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

the class ServoyFunctionPropertyType method toJSON.

public JSONWriter toJSON(JSONWriter writer, String key, Object object, PropertyDescription pd, DataConversion clientConversion, FlattenedSolution fs, FormElement fe, WebFormComponent formComponent) throws JSONException {
    Map<String, Object> map = new HashMap<>();
    if (object != null && fs != null) {
        // $NON-NLS-1$
        String[] components = object.toString().split("-");
        if (components.length == 5) {
            String scriptString = null;
            // this is a uuid
            ScriptMethod sm = fs.getScriptMethod(object.toString());
            if (sm != null) {
                ISupportChilds parent = sm.getParent();
                if (parent instanceof Solution) {
                    scriptString = "scopes." + sm.getScopeName() + "." + sm.getName();
                } else if (parent instanceof Form) {
                    if (formComponent != null) {
                        // use the real, runtime form
                        scriptString = formComponent.getDataAdapterList().getForm().getForm().getName() + "." + sm.getName();
                    } else {
                        scriptString = ((Form) parent).getName() + "." + sm.getName();
                    }
                } else if (parent instanceof TableNode && fe != null) {
                    scriptString = "entity." + fe.getForm().getName() + "." + sm.getName();
                }
                object = scriptString;
            } else
                Debug.log("can't find a scriptmethod for: " + object);
        }
    }
    try {
        if (object instanceof String) {
            addScriptToMap((String) object, map);
        } else if (object instanceof NativeFunction) {
            nativeFunctionToJSON((NativeFunction) object, map);
        } else if (object instanceof FunctionWrapper && ((FunctionWrapper) object).getWrappedFunction() instanceof NativeFunction) {
            nativeFunctionToJSON((NativeFunction) ((FunctionWrapper) object).getWrappedFunction(), map);
        } else if (object instanceof Map) {
            map = new HashMap<String, Object>((Map<String, Object>) object);
            if (map.get("script") instanceof String)
                addScriptToMap((String) map.get("script"), map);
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    return JSONUtils.toBrowserJSONFullValue(writer, key, map.size() == 0 ? null : map, null, clientConversion, null);
}
Also used : FunctionWrapper(com.servoy.j2db.scripting.FunctionWrapper) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) HashMap(java.util.HashMap) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) NativeFunction(org.mozilla.javascript.NativeFunction) JSONException(org.json.JSONException) TableNode(com.servoy.j2db.persistence.TableNode) JSONObject(org.json.JSONObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) HashMap(java.util.HashMap) Map(java.util.Map) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

Form (com.servoy.j2db.persistence.Form)146 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)35 ArrayList (java.util.ArrayList)32 Point (java.awt.Point)26 FlattenedSolution (com.servoy.j2db.FlattenedSolution)24 IPersist (com.servoy.j2db.persistence.IPersist)22 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)20 JSONObject (org.json.JSONObject)20 Solution (com.servoy.j2db.persistence.Solution)16 Dimension (java.awt.Dimension)15 Part (com.servoy.j2db.persistence.Part)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)14 FormController (com.servoy.j2db.FormController)13 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)12 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)11 IForm (com.servoy.j2db.IForm)11 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)11 FormElement (com.servoy.j2db.server.ngclient.FormElement)11 HashMap (java.util.HashMap)11 JSFunction (org.mozilla.javascript.annotations.JSFunction)11