Search in sources :

Example 1 with ISupportExtendsID

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

the class MobileFormLayout method getBodyElementsForRecordView.

public static List<ISupportBounds> getBodyElementsForRecordView(FlattenedSolution editingFlattenedSolution, Form flattenedForm) {
    List<ISupportBounds> elements = new ArrayList<ISupportBounds>();
    Set<String> groups = new HashSet<String>();
    for (IPersist persist : flattenedForm.getAllObjectsAsList()) {
        if (persist instanceof ISupportExtendsID && PersistHelper.isOverrideOrphanElement((ISupportExtendsID) persist)) {
            // skip orphaned overrides
            continue;
        }
        if (persist instanceof IFormElement && persist instanceof AbstractBase) {
            String groupID = ((IFormElement) persist).getGroupID();
            if (groupID == null) {
                if (persist instanceof Portal && ((Portal) persist).isMobileInsetList()) {
                    // inset list
                    elements.add(((Portal) persist));
                } else // tabpanel: list elements or navtab
                if (((AbstractBase) persist).getCustomMobileProperty(IMobileProperties.HEADER_ITEM.propertyName) == null && ((AbstractBase) persist).getCustomMobileProperty(IMobileProperties.FOOTER_ITEM.propertyName) == null) {
                    // regular item
                    elements.add((ISupportBounds) (persist instanceof IFlattenedPersistWrapper ? ((IFlattenedPersistWrapper<?>) persist).getWrappedPersist() : persist));
                }
            } else if (groups.add(groupID)) {
                elements.add(new FormElementGroup(groupID, editingFlattenedSolution, FlattenedForm.getWrappedForm(flattenedForm)));
            }
        }
    }
    // sort by y-position
    Collections.sort(elements, PositionComparator.YX_BOUNDS_COMPARATOR);
    return elements;
}
Also used : ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) FormElementGroup(com.servoy.j2db.persistence.FormElementGroup) ArrayList(java.util.ArrayList) AbstractBase(com.servoy.j2db.persistence.AbstractBase) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) IFormElement(com.servoy.j2db.persistence.IFormElement) IFlattenedPersistWrapper(com.servoy.j2db.persistence.IFlattenedPersistWrapper) IPersist(com.servoy.j2db.persistence.IPersist) Portal(com.servoy.j2db.persistence.Portal) JSPortal(com.servoy.j2db.scripting.solutionmodel.JSPortal) HashSet(java.util.HashSet)

Example 2 with ISupportExtendsID

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

the class JSBase method getOverridePersistIfNeeded.

public static AbstractBase getOverridePersistIfNeeded(AbstractBase persist, AbstractBase finalPersist, IJSParent parent) {
    AbstractBase baseComponent = finalPersist;
    if (persist != null && persist.getAncestor(IRepository.FORMS) != null) {
        IJSParent<?> jsparent = parent;
        while (jsparent != null) {
            if (jsparent.getSupportChild() instanceof Form)
                break;
            jsparent = jsparent.getJSParent();
        }
        if (jsparent != null && jsparent.getSupportChild() instanceof Form && !jsparent.getSupportChild().getUUID().equals(persist.getAncestor(IRepository.FORMS).getUUID())) {
            // inherited persist
            try {
                IPersist parentPersist = persist;
                while (PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist) != null) {
                    parentPersist = PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist);
                }
                // first check if the override persist already exists, and return it in that case
                List<IPersist> children = PersistHelper.getHierarchyChildren((AbstractBase) parent.getSupportChild());
                IPersist form = parent.getSupportChild() instanceof Form ? parent.getSupportChild() : parent.getSupportChild().getAncestor(IRepository.FORMS);
                if (form != null) {
                    for (IPersist p : children) {
                        if (parentPersist.getID() == ((ISupportExtendsID) p).getExtendsID() && form.equals(p.getAncestor(IRepository.FORMS))) {
                            return (AbstractBase) p;
                        }
                    }
                } else {
                    // should not happen
                    Debug.error("Cannot find form of persist " + parent.getSupportChild());
                }
                baseComponent = (AbstractBase) persist.cloneObj(parent.getSupportChild(), false, null, false, false, false);
                baseComponent.copyPropertiesMap(null, true);
                ((ISupportExtendsID) baseComponent).setExtendsID(parentPersist.getID());
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
    }
    return baseComponent;
}
Also used : Form(com.servoy.j2db.persistence.Form) IPersist(com.servoy.j2db.persistence.IPersist) ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) AbstractBase(com.servoy.j2db.persistence.AbstractBase)

Example 3 with ISupportExtendsID

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

the class PersistHelper method getHierarchyChildren.

public static List<IPersist> getHierarchyChildren(AbstractBase parent) {
    if (parent instanceof ISupportExtendsID) {
        List<IPersist> children = new ArrayList<IPersist>();
        List<AbstractBase> parentHierarchy = new ArrayList<AbstractBase>();
        List<Integer> existingIDs = new ArrayList<Integer>();
        AbstractBase element = parent;
        while (element != null && !parentHierarchy.contains(element)) {
            parentHierarchy.add(element);
            element = (AbstractBase) PersistHelper.getSuperPersist((ISupportExtendsID) element);
        }
        for (AbstractBase temp : parentHierarchy) {
            for (IPersist child : temp.getAllObjectsAsList()) {
                if (!(child instanceof ISupportExtendsID))
                    continue;
                Integer extendsID = new Integer(((ISupportExtendsID) child).getExtendsID());
                if (!existingIDs.contains(new Integer(child.getID())) && !existingIDs.contains(extendsID)) {
                    if (PersistHelper.isOverrideOrphanElement((ISupportExtendsID) child)) {
                        // some deleted element
                        continue;
                    }
                    existingIDs.add(child.getID());
                    children.add(child);
                }
                if (extendsID.intValue() > 0 && !existingIDs.contains(extendsID)) {
                    existingIDs.add(extendsID);
                }
            }
        }
        return children;
    } else {
        return parent.getAllObjectsAsList();
    }
}
Also used : ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) IPersist(com.servoy.j2db.persistence.IPersist) ArrayList(java.util.ArrayList) AbstractBase(com.servoy.j2db.persistence.AbstractBase)

Example 4 with ISupportExtendsID

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

the class PersistHelper method hasOverrideChildren.

/**
 * Example if a superform has a tabPanel with a tab, and a derived form adds another tab to the tabpannel then  hasOverrideChildren(derivedTabPanel) returns true
 */
public static boolean hasOverrideChildren(IPersist persist) {
    if (persist instanceof ISupportChilds && persist instanceof ISupportExtendsID) {
        ISupportChilds p = (ISupportChilds) persist;
        ISupportChilds superPersist = (ISupportChilds) PersistHelper.getSuperPersist((ISupportExtendsID) persist);
        if (superPersist == null) {
            return false;
        }
        for (IPersist child : Utils.iterate(p.getAllObjects())) {
            if (child instanceof ISupportExtendsID && !PersistHelper.isOverrideElement((ISupportExtendsID) child)) {
                // is is an etra child element compared to it's super child elements
                return true;
            } else if (((AbstractBase) child).hasOverrideProperties()) {
                return true;
            }
        }
    }
    return false;
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) IPersist(com.servoy.j2db.persistence.IPersist)

Example 5 with ISupportExtendsID

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

the class PersistHelper method getBasePersist.

/**
 * Get highest super persist.
 *
 * @param persist
 * @return
 */
public static IPersist getBasePersist(ISupportExtendsID persist) {
    ISupportExtendsID p = persist;
    while (true) {
        ISupportExtendsID superp = (ISupportExtendsID) PersistHelper.getSuperPersist(p);
        if (superp == null) {
            return p;
        }
        p = superp;
    }
}
Also used : ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID)

Aggregations

ISupportExtendsID (com.servoy.j2db.persistence.ISupportExtendsID)8 IPersist (com.servoy.j2db.persistence.IPersist)6 AbstractBase (com.servoy.j2db.persistence.AbstractBase)5 ArrayList (java.util.ArrayList)4 IFormElement (com.servoy.j2db.persistence.IFormElement)2 ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)2 JSONObject (org.json.JSONObject)2 Form (com.servoy.j2db.persistence.Form)1 FormElementGroup (com.servoy.j2db.persistence.FormElementGroup)1 IFlattenedPersistWrapper (com.servoy.j2db.persistence.IFlattenedPersistWrapper)1 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)1 Portal (com.servoy.j2db.persistence.Portal)1 JSPortal (com.servoy.j2db.scripting.solutionmodel.JSPortal)1 FormComponentPropertyType (com.servoy.j2db.server.ngclient.property.types.FormComponentPropertyType)1 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)1 Point (java.awt.Point)1 HashSet (java.util.HashSet)1 List (java.util.List)1