Search in sources :

Example 1 with ISupportBounds

use of com.servoy.j2db.persistence.ISupportBounds 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 ISupportBounds

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

the class FormElementHelper method getControlledTabSeqReplacementFor.

/**
 * Generates a Servoy controlled tab-sequence-index. We try to avoid sending default (0 or null) tabSeq even
 * for forms that do use default tab sequence in order to avoid problems with nesting default and non-default tabSeq forms.
 *
 * @param designValue the value the persist holds for the tabSeq.
 * @param form the form containing the persist
 * @param persistIfAvailable the persist. For now, 'component' type properties might work with non-persist-linked FormElements so it could be null.
 * When those become persist based as well this will never be null.
 * @return the requested controlled tabSeq (should make tabSeq be identical to the one shown in developer).
 */
public Integer getControlledTabSeqReplacementFor(Integer designValue, PropertyDescription pd, Form flattenedForm, IPersist persistIfAvailable, // TODO more args will be needed here such as the tabSeq property name or description
FlattenedSolution flattenedSolution, // TODO more args will be needed here such as the tabSeq property name or description
boolean design) {
    // TODO this can be removed when we know we'll always have a persist here; currently don't handle this in any way as it's not supported
    if (persistIfAvailable == null || (nestedCall.get() != null && nestedCall.get().booleanValue()))
        return designValue;
    nestedCall.set(Boolean.TRUE);
    final boolean responsiveForm = flattenedForm.isResponsiveLayout();
    try {
        if (flattenedForm.isFormComponent() && persistIfAvailable instanceof AbstractBase) {
            String mainFormName = ((AbstractBase) persistIfAvailable).getRuntimeProperty(FORM_COMPONENT_FORM_NAME);
            if (mainFormName != null) {
                flattenedForm = flattenedSolution.getFlattenedForm(flattenedSolution.getForm(mainFormName));
                // just return the skip value if this is somehow invalid.
                if (flattenedForm == null)
                    return Integer.valueOf(-2);
            }
        }
        boolean formWasModifiedViaSolutionModel = flattenedSolution.hasCopy(flattenedForm);
        Map<TabSeqProperty, Integer> cachedTabSeq = null;
        if (formWasModifiedViaSolutionModel) {
            Pair<Long, Map<TabSeqProperty, Integer>> pair = flattenedForm.getRuntimeProperty(FORM_TAB_SEQUENCE);
            if (pair != null && flattenedForm.getLastModified() == pair.getLeft().longValue()) {
                cachedTabSeq = pair.getRight();
            }
        } else
            cachedTabSeq = formTabSequences.get(flattenedForm.getUUID());
        if (cachedTabSeq == null) {
            cachedTabSeq = new HashMap<TabSeqProperty, Integer>();
            SortedList<TabSeqProperty> selected = new SortedList<TabSeqProperty>(new Comparator<TabSeqProperty>() {

                public int compare(TabSeqProperty o1, TabSeqProperty o2) {
                    int seq1 = o1.getSeqValue();
                    int seq2 = o2.getSeqValue();
                    if (seq1 == ISupportTabSeq.DEFAULT && seq2 == ISupportTabSeq.DEFAULT) {
                        if (responsiveForm) {
                            if (o1.element.getParent() == o2.element.getParent()) {
                                int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
                                if (positionComparator != 0) {
                                    return positionComparator;
                                }
                            } else {
                                List<ISupportChilds> ancestors = new ArrayList<ISupportChilds>();
                                IPersist persist = o1.element;
                                while (persist.getParent() instanceof AbstractContainer) {
                                    ancestors.add(persist.getParent());
                                    persist = persist.getParent();
                                }
                                persist = o2.element;
                                while (persist.getParent() instanceof AbstractContainer) {
                                    if (ancestors.contains(persist.getParent())) {
                                        // we found the common ancestor
                                        int index = ancestors.indexOf(persist.getParent());
                                        IPersist comparablePersist = index == 0 ? o1.element : ancestors.get(index - 1);
                                        int positionComparator = PositionComparator.comparePoint(false, ((ISupportBounds) comparablePersist).getLocation(), ((ISupportBounds) persist).getLocation());
                                        if (positionComparator != 0) {
                                            return positionComparator;
                                        }
                                    }
                                    persist = persist.getParent();
                                }
                            }
                        } else {
                            int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
                            if (positionComparator != 0) {
                                return positionComparator;
                            }
                        }
                    }
                    return compareTabSeq(seq1, o1.element, seq2, o2.element, flattenedSolution);
                }
            });
            Map<TabSeqProperty, List<TabSeqProperty>> listFormComponentMap = new HashMap<TabSeqProperty, List<TabSeqProperty>>();
            List<TabSeqProperty> listFormComponentElements = null;
            TabSeqProperty listFormComponentTabSeq = null;
            Iterator<IFormElement> iterator = flattenedForm.getFlattenedObjects(null).iterator();
            while (iterator.hasNext()) {
                IFormElement formElement = iterator.next();
                if (FormTemplateGenerator.isWebcomponentBean(formElement)) {
                    String componentType = FormTemplateGenerator.getComponentTypeName(formElement);
                    WebObjectSpecification specification = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(componentType);
                    if (specification != null) {
                        Collection<PropertyDescription> properties = specification.getProperties(NGTabSeqPropertyType.NG_INSTANCE);
                        Collection<PropertyDescription> formComponentProperties = specification.getProperties(FormComponentPropertyType.INSTANCE);
                        boolean isListFormComponent = isListFormComponent(formComponentProperties);
                        if (properties != null && properties.size() > 0) {
                            IBasicWebComponent webComponent = (IBasicWebComponent) formElement;
                            for (PropertyDescription tabSeqProperty : properties) {
                                int tabseq = Utils.getAsInteger(webComponent.getProperty(tabSeqProperty.getName()));
                                TabSeqProperty seqProperty = new TabSeqProperty(formElement, tabSeqProperty.getName());
                                if (listFormComponentTabSeq == null && isListFormComponent) {
                                    listFormComponentTabSeq = seqProperty;
                                    listFormComponentElements = new ArrayList<TabSeqProperty>();
                                    listFormComponentMap.put(listFormComponentTabSeq, listFormComponentElements);
                                }
                                if (tabseq >= 0) {
                                    selected.add(seqProperty);
                                } else {
                                    cachedTabSeq.put(seqProperty, Integer.valueOf(-2));
                                }
                            }
                        }
                        addFormComponentProperties(formComponentProperties, formElement, flattenedSolution, cachedTabSeq, selected, listFormComponentElements, design, new HashSet<String>());
                    }
                } else if (formElement instanceof ISupportTabSeq) {
                    if (((ISupportTabSeq) formElement).getTabSeq() >= 0) {
                        selected.add(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()));
                    } else {
                        cachedTabSeq.put(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()), Integer.valueOf(-2));
                    }
                }
            }
            int i = 1;
            for (TabSeqProperty tabSeq : selected) {
                cachedTabSeq.put(tabSeq, Integer.valueOf(i++));
            }
            for (TabSeqProperty tabSeq : listFormComponentMap.keySet()) {
                List<TabSeqProperty> elements = listFormComponentMap.get(tabSeq);
                if (elements != null) {
                    Integer value = cachedTabSeq.get(tabSeq);
                    // all elements inside list form component have same tabindex as the list itself
                    for (TabSeqProperty tabSeqElement : elements) {
                        cachedTabSeq.put(tabSeqElement, value);
                    }
                }
            }
            if (!formWasModifiedViaSolutionModel) {
                formTabSequences.putIfAbsent(flattenedForm.getUUID(), cachedTabSeq);
            } else {
                flattenedForm.setRuntimeProperty(FORM_TAB_SEQUENCE, new Pair<>(Long.valueOf(flattenedForm.getLastModified()), cachedTabSeq));
            }
        }
        IPersist realPersist = flattenedForm.findChild(persistIfAvailable.getUUID());
        if (realPersist == null) {
            realPersist = persistIfAvailable;
        }
        Integer controlledTabSeq = cachedTabSeq.get(new TabSeqProperty(realPersist, pd.getName()));
        // if not in tabSeq, use "skip" value
        if (controlledTabSeq == null)
            controlledTabSeq = Integer.valueOf(-2);
        return controlledTabSeq;
    } finally {
        nestedCall.set(Boolean.FALSE);
    }
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) SortedList(com.servoy.j2db.util.SortedList) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) List(java.util.List) ArrayList(java.util.ArrayList) SortedList(com.servoy.j2db.util.SortedList) IBasicWebComponent(com.servoy.j2db.persistence.IBasicWebComponent) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) AbstractBase(com.servoy.j2db.persistence.AbstractBase) Point(java.awt.Point) PropertyDescription(org.sablo.specification.PropertyDescription) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) WeakHashMap(java.util.WeakHashMap)

Example 3 with ISupportBounds

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

the class JSBaseContainer method getLastPosition.

private int getLastPosition() {
    int position = 0;
    Iterator<IPersist> components = getFlattenedContainer().getAllObjects();
    while (components.hasNext()) {
        IPersist component = components.next();
        if (component instanceof ISupportBounds) {
            Point location = ((ISupportBounds) component).getLocation();
            if (location != null) {
                if (location.x > position) {
                    position = location.x;
                }
                if (location.y > position) {
                    position = location.y;
                }
            }
        }
    }
    return position + 1;
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) Point(java.awt.Point) Point(java.awt.Point)

Example 4 with ISupportBounds

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

the class Utils method getBounds.

/**
 * Get the rectangle that surrounds all elements
 *
 * @param elements
 * @return the rectangle
 */
public static Rectangle getBounds(Iterator<?> elements) {
    int minx = -1;
    int miny = -1;
    int maxx = -1;
    int maxy = -1;
    while (elements != null && elements.hasNext()) {
        Object element = elements.next();
        if (element instanceof ISupportBounds) {
            java.awt.Point location = CSSPositionUtils.getLocation((ISupportBounds) element);
            java.awt.Dimension size = CSSPositionUtils.getSize(((ISupportBounds) element));
            if (location != null && size != null) {
                if (minx == -1 || minx > location.x)
                    minx = location.x;
                if (miny == -1 || miny > location.y)
                    miny = location.y;
                if (maxx == -1 || maxx < location.x + size.width)
                    maxx = location.x + size.width;
                if (maxy == -1 || maxy < location.y + size.height)
                    maxy = location.y + size.height;
            }
        }
    }
    return new Rectangle(minx, miny, maxx - minx, maxy - miny);
}
Also used : Rectangle(java.awt.Rectangle) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) JSONObject(org.json.JSONObject) XMLObject(org.mozilla.javascript.xml.XMLObject) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds)

Example 5 with ISupportBounds

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

the class FormLayoutGenerator method generateFormElement.

// private static boolean canContainComponents(WebComponentSpecification spec)
// {
// Map<String, PropertyDescription> properties = spec.getProperties();
// for (PropertyDescription propertyDescription : properties.values())
// {
// String simpleTypeName = propertyDescription.getType().getName().replaceFirst(spec.getName() + ".", "");
// if (simpleTypeName.equals(ComponentPropertyType.TYPE_NAME)) return true;
// Object configObject = propertyDescription.getConfig();
// if (configObject != null)
// {
// try
// {
// if (configObject instanceof JSONObject && ((JSONObject)configObject).has(DesignerFilter.DROPPABLE))
// {
// Object droppable = ((JSONObject)configObject).get(DesignerFilter.DROPPABLE);
// if (droppable instanceof Boolean && (Boolean)droppable)
// {
// if (simpleTypeName.equals("tab")) return true;
// }
// }
// }
// catch (JSONException e)
// {
// Debug.log(e);
// }
// }
// }
// return false;
// }
public static void generateFormElement(PrintWriter writer, FormElement fe, Form form) {
    IPersist fePersist = fe.getPersistIfAvailable();
    String name = fe.getName();
    boolean selectable = fe.isFormComponentChild() ? name.indexOf('$' + FormElement.SVY_NAME_PREFIX) == -1 : true;
    writer.print("<");
    writer.print(fe.getTagname());
    writer.print(" name='");
    writer.print(name);
    writer.print("'");
    if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
        String elementName = name;
        if (elementName.startsWith("svy_") && fePersist != null) {
            elementName = "svy_" + fePersist.getUUID().toString();
        }
        writer.print(" data-svy-name='");
        writer.print(form.getName() + "." + elementName);
        writer.print("'");
    }
    String designId = getDesignId(fe);
    if (designId != null) {
        if (form.isResponsiveLayout()) {
            writer.print(" svy-id='");
            writer.print(designId);
            writer.print("'");
            if (fePersist instanceof ISupportBounds) {
                writer.print(" svy-location='");
                writer.print(((ISupportBounds) fePersist).getLocation().x);
                writer.print("'");
            }
            if (!selectable) {
                writer.print(" svy-non-selectable='noname'");
            }
            writer.print(" svy-formelement-type='");
            writer.print(fe.getTypeName());
            writer.print("'");
            JSONObject ngClass = new JSONObject();
            List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
            if (typeAndPropertyNames[0].size() > 0) {
                writer.print(" svy-types='");
                writer.print("[" + String.join(",", typeAndPropertyNames[0]) + "]");
                writer.print("'");
                writer.print(" svy-types-properties='");
                writer.print("[" + String.join(",", typeAndPropertyNames[1]) + "]");
                writer.print("'");
                ngClass.put("drop_highlight", "<canContainDraggedElement('" + fe.getTypeName() + "',['" + String.join("','", typeAndPropertyNames[0]) + "'])<");
            }
            List<String> forbiddenComponentNames = fe.getForbiddenComponentNames();
            if (forbiddenComponentNames.size() > 0) {
                writer.print(" svy-forbidden-components='");
                writer.print("[" + String.join(",", forbiddenComponentNames) + "]");
                writer.print("'");
            }
            String directEditPropertyName = getDirectEditProperty(fe);
            if (directEditPropertyName != null) {
                writer.print(" directEditPropertyName='");
                writer.print(directEditPropertyName);
                writer.print("'");
            }
            if (// is this inherited or override element?
            !fe.getForm().equals(form) || fePersist instanceof ISupportExtendsID && PersistHelper.getSuperPersist((ISupportExtendsID) fePersist) != null) {
                ngClass.put("inheritedElement", true);
            }
            if (fe.isFormComponentChild()) {
                ngClass.put("formComponentChild", true);
            }
            ngClass.put("invisible_element", "<getDesignFormControllerScope().model('" + designId + "').svyVisible == false<".toString());
            // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
            ngClass.put("highlight_child_element", "<design_highlight=='highlight_element'<".toString());
            writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
        }
        writer.print(" svy-model=\"model('");
        writer.print(designId);
        writer.print("')\"");
        writer.print(" svy-api=\"api('");
        writer.print(designId);
        writer.print("')\"");
        writer.print(" svy-handlers=\"handlers('");
        writer.print(designId);
        writer.print("')\"");
        writer.print(" svy-servoyApi=\"servoyApi('");
        writer.print(designId);
        writer.print("')\"");
        if (fePersist instanceof IFormElement) {
            writer.print(" form-index=" + ((IFormElement) fePersist).getFormIndex() + "");
        }
    } else {
        writer.print(" svy-model='model.");
        writer.print(name);
        writer.print("'");
        writer.print(" svy-api='api.");
        writer.print(name);
        writer.print("'");
        writer.print(" svy-handlers='handlers.");
        writer.print(name);
        writer.print("'");
        writer.print(" svy-servoyApi='handlers.");
        writer.print(name);
        writer.print(".svy_servoyApi'");
    }
    writer.print(">");
    writer.print("</");
    writer.print(fe.getTagname());
    writer.print(">");
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)7 IPersist (com.servoy.j2db.persistence.IPersist)5 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 IFormElement (com.servoy.j2db.persistence.IFormElement)3 HashMap (java.util.HashMap)3 List (java.util.List)3 JSONObject (org.json.JSONObject)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)2 ISupportExtendsID (com.servoy.j2db.persistence.ISupportExtendsID)2 Rectangle (java.awt.Rectangle)2 Map (java.util.Map)2 WeakHashMap (java.util.WeakHashMap)2 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)2 PropertyDescription (org.sablo.specification.PropertyDescription)2 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)2 AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)1 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)1 Form (com.servoy.j2db.persistence.Form)1