Search in sources :

Example 1 with IBasicWebComponent

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

the class FormLayoutGenerator method getTabSeq.

private static int getTabSeq(IFormElement o) {
    int seq = 0;
    if (o instanceof ISupportTabSeq) {
        seq = ((ISupportTabSeq) o).getTabSeq();
    }
    if (o instanceof IBasicWebComponent) {
        String componentType = FormTemplateGenerator.getComponentTypeName(o);
        WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(componentType);
        if (spec != null) {
            Collection<PropertyDescription> properties = spec.getProperties(NGTabSeqPropertyType.NG_INSTANCE);
            if (properties != null && properties.size() > 0) {
                IBasicWebComponent webComponent = (IBasicWebComponent) o;
                for (PropertyDescription tabSeqProperty : properties) {
                    seq = Utils.getAsInteger(webComponent.getProperty(tabSeqProperty.getName()));
                    break;
                }
            }
        }
    }
    return seq;
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) IBasicWebComponent(com.servoy.j2db.persistence.IBasicWebComponent)

Example 2 with IBasicWebComponent

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

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

the class PersistBasedFormElementImpl method getFormElementPropertyValues.

public Map<String, Object> getFormElementPropertyValues(FlattenedSolution fs, Map<String, PropertyDescription> specProperties, PropertyPath propertyPath) {
    Map<String, String> parsedAttributes = new HashMap<String, String>();
    if (persist instanceof BaseComponent) {
        Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) persist).getMergedAttributes());
        if (attributes != null && attributes.size() > 0) {
            attributes.forEach((key, value) -> {
                if (value != null && key != null)
                    parsedAttributes.put(StringEscapeUtils.escapeEcmaScript(key), value);
            });
        }
    }
    if (persist instanceof IBasicWebComponent) {
        if (FormTemplateGenerator.isWebcomponentBean(persist)) {
            JSONObject jsonProperties = ((IBasicWebComponent) persist).getFlattenedJson();
            if (jsonProperties == null)
                jsonProperties = new ServoyJSONObject();
            // convert from persist design-time value (which might be non-json) to the expected value
            Map<String, Object> jsonMap = processPersistProperties(fs, specProperties, propertyPath);
            // this is handled separately as NG component definition
            jsonMap.remove(IContentSpecConstantsBase.PROPERTY_BEANXML);
            // this is handled separately as NG component definition
            jsonMap.remove(IContentSpecConstants.PROPERTY_JSON);
            try {
                // add beanXML (which is actually a JSON string here) defined properties to the map
                formElement.convertFromJSONToFormElementValues(fs, specProperties, jsonMap, formElement.getWebComponentSpec().getHandlers(), jsonProperties, propertyPath);
            } catch (Exception ex) {
                Debug.error("Error while parsing bean design json", ex);
                jsonMap.put("error", "Error while parsing bean design json(bean not supported in NGClient?): " + persist);
            }
            if (parsedAttributes.size() > 0) {
                jsonMap.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
            }
            return jsonMap;
        } else {
            Map<String, Object> defaultProperties = new HashMap<String, Object>();
            defaultProperties.put(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), ((IBasicWebComponent) persist).getSize());
            defaultProperties.put(StaticContentSpecLoader.PROPERTY_NAME.getPropertyName(), ((IBasicWebComponent) persist).getName());
            defaultProperties.put("error", "Bean not supported in NGClient: " + persist);
            return defaultProperties;
        }
    } else if (persist instanceof AbstractBase) {
        Map<String, Object> map = processPersistProperties(fs, specProperties, propertyPath);
        if (persist instanceof Field && ((Field) persist).getDisplayType() == Field.MULTISELECT_LISTBOX) {
            map.put("multiselectListbox", Boolean.TRUE);
        } else if (persist instanceof TabPanel) {
            convertFromTabPanelToNGProperties((IFormElement) persist, fs, map, specProperties, propertyPath);
        } else if (persist instanceof Portal) {
            convertFromPortalToNGProperties((Portal) persist, fs, map, specProperties, propertyPath);
        }
        if (parsedAttributes.size() > 0) {
            map.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
        }
        return map;
    } else {
        return Collections.emptyMap();
    }
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) BaseComponent(com.servoy.j2db.persistence.BaseComponent) HashMap(java.util.HashMap) AbstractBase(com.servoy.j2db.persistence.AbstractBase) JSONException(org.json.JSONException) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Field(com.servoy.j2db.persistence.Field) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Portal(com.servoy.j2db.persistence.Portal) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IBasicWebComponent(com.servoy.j2db.persistence.IBasicWebComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with IBasicWebComponent

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

the class FormElementHelper method addFormComponentProperties.

private void addFormComponentProperties(Collection<PropertyDescription> formComponentProperties, IFormElement formElement, FlattenedSolution flattenedSolution, Map<TabSeqProperty, Integer> cachedTabSeq, List<TabSeqProperty> selected, List<TabSeqProperty> listFormComponentElements, boolean design, Set<String> recursionCheck) {
    if (formComponentProperties != null && formComponentProperties.size() > 0) {
        boolean isListFormComponent = isListFormComponent(formComponentProperties);
        // avoid infinite cycle here
        FormElement formComponentEl = FormElementHelper.INSTANCE.getFormElement(formElement, flattenedSolution, null, design);
        for (PropertyDescription property : formComponentProperties) {
            Object frmValue = formComponentEl.getPropertyValue(property.getName());
            Form frm = FormComponentPropertyType.INSTANCE.getForm(frmValue, flattenedSolution);
            if (frm == null)
                continue;
            if (!recursionCheck.add(frm.getName())) {
                // $NON-NLS-1$
                Debug.error("recursive reference found between (List)FormComponents: " + recursionCheck);
                continue;
            }
            // do not use the formcomponentcache, we do not want formelement with wrong tabseq to be cached, must caclulate first the sequence
            List<IFormElement> elements = generateFormComponentPersists(formComponentEl, property, (JSONObject) frmValue, frm, flattenedSolution);
            for (IFormElement element : elements) {
                if (element instanceof ISupportTabSeq) {
                    if (isListFormComponent && listFormComponentElements != null) {
                        listFormComponentElements.add(new TabSeqProperty(element, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()));
                    } else if (((ISupportTabSeq) element).getTabSeq() >= 0) {
                        selected.add(new TabSeqProperty(element, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName(), CSSPositionUtils.getLocation(formElement)));
                    } else {
                        cachedTabSeq.put(new TabSeqProperty(element, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()), Integer.valueOf(-2));
                    }
                } else if (FormTemplateGenerator.isWebcomponentBean(element)) {
                    String nestedDomponentType = FormTemplateGenerator.getComponentTypeName(element);
                    WebObjectSpecification nestedSpecification = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(nestedDomponentType);
                    if (nestedSpecification != null) {
                        Collection<PropertyDescription> nestedProperties = nestedSpecification.getProperties(NGTabSeqPropertyType.NG_INSTANCE);
                        if (nestedProperties != null && nestedProperties.size() > 0) {
                            IBasicWebComponent webComponent = (IBasicWebComponent) element;
                            for (PropertyDescription tabSeqProperty : nestedProperties) {
                                int tabseq = Utils.getAsInteger(webComponent.getProperty(tabSeqProperty.getName()));
                                if (tabseq >= 0 && isListFormComponent && listFormComponentElements != null) {
                                    // all elements will have the tabseq of the list
                                    listFormComponentElements.add(new TabSeqProperty(element, tabSeqProperty.getName()));
                                } else if (tabseq >= 0) {
                                    selected.add(new TabSeqProperty(element, tabSeqProperty.getName(), CSSPositionUtils.getLocation(formElement)));
                                } else {
                                    cachedTabSeq.put(new TabSeqProperty(element, tabSeqProperty.getName()), Integer.valueOf(-2));
                                }
                            }
                        }
                        nestedProperties = nestedSpecification.getProperties(FormComponentPropertyType.INSTANCE);
                        addFormComponentProperties(nestedProperties, element, flattenedSolution, cachedTabSeq, selected, listFormComponentElements, design, recursionCheck);
                    }
                }
            }
            recursionCheck.remove(frm.getName());
        }
    }
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) Form(com.servoy.j2db.persistence.Form) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) IFormElement(com.servoy.j2db.persistence.IFormElement) PropertyDescription(org.sablo.specification.PropertyDescription) IFormElement(com.servoy.j2db.persistence.IFormElement) Collection(java.util.Collection) IBasicWebObject(com.servoy.j2db.persistence.IBasicWebObject) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IChildWebObject(com.servoy.j2db.persistence.IChildWebObject) IBasicWebComponent(com.servoy.j2db.persistence.IBasicWebComponent)

Aggregations

IBasicWebComponent (com.servoy.j2db.persistence.IBasicWebComponent)4 ISupportTabSeq (com.servoy.j2db.persistence.ISupportTabSeq)3 PropertyDescription (org.sablo.specification.PropertyDescription)3 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)2 IFormElement (com.servoy.j2db.persistence.IFormElement)2 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONObject (org.json.JSONObject)2 AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 Field (com.servoy.j2db.persistence.Field)1 Form (com.servoy.j2db.persistence.Form)1 IBasicWebObject (com.servoy.j2db.persistence.IBasicWebObject)1 IChildWebObject (com.servoy.j2db.persistence.IChildWebObject)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)1 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)1 Portal (com.servoy.j2db.persistence.Portal)1