Search in sources :

Example 11 with FlattenedForm

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

the class FlattenedSolution method loadStyleForForm.

/**
 * Load style for form, look for extend forms in flattenedSolution when possible
 * @param flattenedSolution may be null, fallback to f.getSolution() plus repo load
 * @param f
 */
public static Style loadStyleForForm(FlattenedSolution flattenedSolution, Form form) {
    try {
        String style_name = form.getStyleName();
        if (!(form instanceof FlattenedForm)) {
            Form extendedForm;
            int extended_form_id = form.getExtendsID();
            List<RootObjectReference> modulesMetaData = null;
            // We keep track of visited forms, to avoid infinite loop.
            Set<Integer> visited = new HashSet<Integer>();
            while (style_name == null && extended_form_id > 0) {
                visited.add(new Integer(extended_form_id));
                // if this is hit here with a normal (not flattened form) that has an extend.
                // and that form is a solution modal form. the f.getSolution() doesn't have to find it.
                // because f.getSolution() is the copy solution thats inside the FlattenedSolution.
                // that one doesn't have any other forms. But normally all forms should be flattened.
                extendedForm = flattenedSolution == null ? form.getSolution().getForm(extended_form_id) : flattenedSolution.getForm(extended_form_id);
                if (// check for module form
                flattenedSolution == null && extendedForm == null) {
                    if (modulesMetaData == null) {
                        modulesMetaData = form.getSolution().getRepository().getActiveSolutionModuleMetaDatas(form.getSolution().getID());
                    }
                    for (RootObjectReference moduleMetaData : modulesMetaData) {
                        Solution module = (Solution) form.getSolution().getRepository().getActiveRootObject(moduleMetaData.getMetaData().getRootObjectId());
                        extendedForm = module.getForm(extended_form_id);
                        if (extendedForm != null) {
                            break;
                        }
                    }
                }
                if (extendedForm == null) {
                    // in case referring to no longer existing form
                    break;
                }
                style_name = extendedForm.getStyleName();
                extended_form_id = extendedForm.getExtendsID();
                if (visited.contains(new Integer(extended_form_id))) {
                    // in case of cycle in form inheritance hierarchy
                    break;
                }
            }
        }
        if (style_name == null)
            return null;
        // preload the style at the server
        Style s = (Style) form.getSolution().getRepository().getActiveRootObject(style_name, IRepository.STYLES);
        return s;
    } catch (Exception e) {
        Debug.error(e);
    }
    return null;
}
Also used : FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) RootObjectReference(com.servoy.j2db.persistence.RootObjectReference) Style(com.servoy.j2db.persistence.Style) Solution(com.servoy.j2db.persistence.Solution) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) HashSet(java.util.HashSet)

Example 12 with FlattenedForm

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

the class FlattenedSolution method formCanBeInstantiated.

/**
 * Check whether a form can be instantiated.
 *
 * @param form
 * @return
 */
public boolean formCanBeInstantiated(Form form) {
    if (form != null) {
        if (form.isResponsiveLayout())
            return true;
        // forms without parts are abstract
        List<Form> formHierarchy = new ArrayList<Form>();
        formHierarchy.add(form);
        Form f = form;
        while (true) {
            Iterator<IPersist> allObjects = f.getAllObjects();
            while (allObjects.hasNext()) {
                if (allObjects.next() instanceof Part) {
                    return true;
                }
            }
            if (form instanceof FlattenedForm || f.getExtendsID() <= 0) {
                // no (more) hierarchy to investigate
                break;
            }
            f = getForm(f.getExtendsID());
            if (f == null || formHierarchy.contains(f)) /* prevent cycles */
            {
                break;
            }
            formHierarchy.add(f);
        }
    }
    return false;
}
Also used : FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part) ArrayList(java.util.ArrayList)

Example 13 with FlattenedForm

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

the class DebugHeadlessClient method performRefresh.

private void performRefresh(List<IPersist> changes) {
    Set<IFormController>[] scopesAndFormsToReload = DebugUtils.getScopesAndFormsToReload(this, changes);
    refreshI18NMessages(true);
    for (IFormController controller : scopesAndFormsToReload[0]) {
        if (controller.getForm() instanceof FlattenedForm) {
            FlattenedForm ff = (FlattenedForm) controller.getForm();
            ff.reload();
        }
        controller.getFormScope().reload();
    }
    if (scopesAndFormsToReload[1].size() > 0)
        ((WebFormManager) getFormManager()).reload((scopesAndFormsToReload[1]).toArray(new FormController[0]));
}
Also used : FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) Set(java.util.Set) IFormController(com.servoy.j2db.IFormController)

Example 14 with FlattenedForm

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

the class DebugJ2DBClient method refreshPersistsNow.

private void refreshPersistsNow(Collection<IPersist> changes) {
    if (shutDown)
        return;
    Set<IFormController>[] scopesAndFormsToReload = DebugUtils.getScopesAndFormsToReload(this, changes);
    for (IFormController controller : scopesAndFormsToReload[1]) {
        destroyForm(controller);
    }
    for (IFormController controller : scopesAndFormsToReload[0]) {
        if (controller.getForm() instanceof FlattenedForm) {
            FlattenedForm ff = (FlattenedForm) controller.getForm();
            ff.reload();
        }
        if (!controller.isDestroyed()) {
            controller.getFormScope().reload();
        }
    }
}
Also used : FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Set(java.util.Set) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) IFormController(com.servoy.j2db.IFormController)

Aggregations

FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)14 Form (com.servoy.j2db.persistence.Form)10 IFormController (com.servoy.j2db.IFormController)4 Set (java.util.Set)4 Solution (com.servoy.j2db.persistence.Solution)3 IPersist (com.servoy.j2db.persistence.IPersist)2 ArrayList (java.util.ArrayList)2 IForm (com.servoy.j2db.IForm)1 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 FlattenedLayoutContainer (com.servoy.j2db.persistence.FlattenedLayoutContainer)1 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)1 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)1 Media (com.servoy.j2db.persistence.Media)1 Part (com.servoy.j2db.persistence.Part)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 RootObjectReference (com.servoy.j2db.persistence.RootObjectReference)1 Style (com.servoy.j2db.persistence.Style)1 RemoteException (java.rmi.RemoteException)1