Search in sources :

Example 71 with IPersist

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

the class SortableCellViewHeaders method registerHeaderComponent.

private void registerHeaderComponent(SortableCellViewHeader headerComponent) {
    String id = headerComponent.getId();
    IPersist matchingElement = null;
    try {
        Iterator<IPersist> allElements = cellview.getAllObjects();
        while (allElements.hasNext()) {
            IPersist someElement = allElements.next();
            if ((someElement instanceof Field || someElement instanceof GraphicalComponent || someElement instanceof Bean) && id.equals(ComponentFactory.getWebID(form, someElement)) && (someElement instanceof ISupportName)) {
                // // column headers cannot be changed from JS if the according element is not named
                // // so no need to link them
                // String name = ((ISupportName)someElement).getName();
                // if (name != null && name.trim().length() != 0)
                // {
                matchingElement = someElement;
                break;
            // }
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        Debug.log("Cannot link a header component to it's element", e);
    }
    if (matchingElement != null) {
        headerManager.registerHeader(matchingElement, headerComponent);
    }
}
Also used : Field(com.servoy.j2db.persistence.Field) IPersist(com.servoy.j2db.persistence.IPersist) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportName(com.servoy.j2db.persistence.ISupportName) Bean(com.servoy.j2db.persistence.Bean)

Example 72 with IPersist

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

the class CSSPositionPropertyType method toJSON.

private JSONWriter toJSON(JSONWriter writer, String key, CSSPosition object, PropertyDescription pd, DataConversion clientConversion, FormElement formElement, FlattenedSolution fs, Form context) throws JSONException {
    JSONUtils.addKeyIfPresent(writer, key);
    writer.object();
    if (object != null) {
        writer.key("position").value("absolute");
        String top = object.top;
        String bottom = object.bottom;
        if (formElement != null && fs != null && context != null && !formElement.isInDesigner()) {
            // adjust the top for parts.
            IPersist persist = formElement.getPersistIfAvailable();
            if (persist instanceof BaseComponent) {
                AbstractContainer parentContainer = CSSPositionUtils.getParentContainer((BaseComponent) persist);
                Point location = CSSPositionUtils.getLocation(object, parentContainer.getSize());
                Form form = fs.getFlattenedForm(context);
                Part part = form.getPartAt(location.y);
                if (part != null) {
                    if (isSet(top)) {
                        int topStart = form.getPartStartYPos(part.getID());
                        if (topStart > 0) {
                            if (top.endsWith("px")) {
                                top = top.substring(0, top.length() - 2);
                            }
                            int topInteger = Utils.getAsInteger(top, -1);
                            if (topInteger != -1) {
                                top = String.valueOf(topInteger - topStart);
                            } else {
                                top = "calc(" + top + " - " + topStart + "px)";
                            }
                        }
                    }
                    if (isSet(bottom)) {
                        int extraHeight = form.getSize().height - part.getHeight();
                        if (extraHeight > 0) {
                            if (bottom.endsWith("px")) {
                                bottom = bottom.substring(0, bottom.length() - 2);
                            }
                            int bottomInteger = Utils.getAsInteger(bottom, -1);
                            if (bottomInteger != -1) {
                                bottom = String.valueOf(bottomInteger - extraHeight);
                            } else {
                                bottom = "calc(" + bottom + " - " + extraHeight + "px)";
                            }
                        }
                    }
                }
            }
        }
        if (isSet(top))
            writer.key("top").value(addPixels(top));
        if (isSet(object.left))
            writer.key("left").value(addPixels(object.left));
        if (isSet(bottom))
            writer.key("bottom").value(addPixels(bottom));
        if (isSet(object.right))
            writer.key("right").value(addPixels(object.right));
        if (isSet(object.height)) {
            if (isSet(top) && isSet(object.bottom)) {
                writer.key("min-height").value(addPixels(object.height));
            } else
                writer.key("height").value(addPixels(object.height));
        }
        if (isSet(object.width)) {
            if (isSet(object.left) && isSet(object.right)) {
                writer.key("min-width").value(addPixels(object.width));
            } else
                writer.key("width").value(addPixels(object.width));
        }
    }
    writer.endObject();
    return writer;
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) IPersist(com.servoy.j2db.persistence.IPersist) Form(com.servoy.j2db.persistence.Form) Part(com.servoy.j2db.persistence.Part) Point(java.awt.Point) Point(java.awt.Point)

Example 73 with IPersist

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

the class ComponentTypeSabloValue method createComponentIfNeededAndPossible.

protected void createComponentIfNeededAndPossible() {
    // so now we should be able to find a potentially linked foundset property value
    if (componentIsCreated || webObjectContext == null)
        return;
    final FoundsetTypeSabloValue foundsetPropValue = getFoundsetValue();
    if (foundsetPropValue != null)
        foundsetPropValue.addStateChangeListener(getFoundsetStateChangeListener());
    // foundset property value is not yet set or not yet attached to component
    if ((foundsetPropValue == null || foundsetPropValue.getDataAdapterList() == null) && forFoundsetTypedPropertyName != null)
        return;
    componentIsCreated = true;
    IWebFormUI formUI = getParentComponent().findParent(IWebFormUI.class);
    final IDataAdapterList dal = (foundsetPropValue != null ? foundsetPropValue.getDataAdapterList() : formUI.getDataAdapterList());
    if (foundsetPropValue != null) {
        // do this before creating the component so that any attach() methods of it's properties that register data links get caught
        ((FoundsetDataAdapterList) dal).addDataLinkedPropertyRegistrationListener(createDataLinkedPropertyRegistrationListener());
        foundsetLinkedPropOfComponentValueChangeHandler = new FoundsetLinkedValueChangeHandler(foundsetPropValue);
    }
    childComponent = ComponentFactory.createComponent(dal.getApplication(), dal, formElementValue.element, getParentComponent(), formUI.getController().getForm());
    if (foundsetPropValue != null) {
        dataLinkedPropertyRegistrationListener.componentIsNowAvailable();
    }
    childComponent.setDirtyPropertyListener(new IDirtyPropertyListener() {

        @Override
        public void propertyFlaggedAsDirty(String propertyName, boolean dirty, boolean granularUpdate) {
            if (dirty) {
                // this gets called whenever a property is flagged as dirty/changed/to be sent to browser
                if (forFoundsetTypedPropertyName != null && recordBasedProperties.contains(propertyName)) {
                    if (!((FoundsetDataAdapterList) dal).isQuietRecordChangeInProgress() && foundsetPropValue.getFoundset() != null && // if forFoundsetTypedPropertyName != null we are using a foundset DAL, so just cast
                    !foundsetPropValue.getFoundset().isInFindMode()) {
                        // for example valuelist properties can get filtered based on client sent filter in which case the property does change without
                        // any actual change in the record; in this case we need to mark it correctly in viewport as a change
                        foundsetLinkedPropOfComponentValueChangeHandler.valueChangedInFSLinkedUnderlyingValue(propertyName, viewPortChangeMonitor);
                    } else {
                        // else this change was probably determined by the fact that we reuse components, changing the record in the DAL to get data for a specific row;
                        // so we need to clear component changes for this property because we do not notify the parent here (we want to ignore the change) so
                        // we shouldn't keep the property marked as dirty - thus blocking future property changes to generate a valueChanged on parent's monitor
                        childComponent.clearChangedStatusForProperty(propertyName);
                    }
                } else {
                    // non-record related prop. changed...
                    monitor.valueChanged();
                }
            }
        }
    });
    for (String initialChangedProperty : childComponent.getProperties().content.keySet()) {
        if (forFoundsetTypedPropertyName == null || !recordBasedProperties.contains(initialChangedProperty)) {
            // non-record related prop. initially changed...
            monitor.valueChanged();
        }
    }
    childComponent.setComponentContext(new ComponentContext(formElementValue.propertyPath));
    if (componentPropertyDescription != null && Utils.getAsBoolean(componentPropertyDescription.getTag(TAG_ADD_TO_ELEMENTS_SCOPE))) {
        formUI.contributeComponentToElementsScope(formElementValue.element, formElementValue.element.getWebComponentSpec(), childComponent);
    }
    for (String handler : childComponent.getFormElement().getHandlers()) {
        Object value = childComponent.getFormElement().getPropertyValue(handler);
        if (value instanceof String) {
            IPersist function = formUI.getController().getApplication().getFlattenedSolution().searchPersist((String) value);
            Form form = formUI.getController().getForm();
            if (function == null) {
                Debug.warn("Script Method of value '" + value + "' not found trying just the form " + form);
                IPersist child = form.getChild(UUID.fromString((String) value));
                if (child != null) {
                    Debug.warn("Script Method " + child + " on the form " + form + " with uuid " + child.getUUID());
                    function = child;
                }
            }
            if (function != null) {
                childComponent.add(handler, function.getID());
            } else {
                Debug.warn("Event handler for " + handler + " with value '" + value + "' not found (form " + form + ", form element " + childComponent.getFormElement().getName() + ")");
            }
        } else if (value instanceof Number && ((Number) value).intValue() > 0) {
            childComponent.add(handler, ((Number) value).intValue());
        }
    }
    if (foundsetPropValue != null) {
        viewPortChangeMonitor = new ComponentTypeViewportDataChangeMonitor(monitor, new ComponentViewportRowDataProvider((FoundsetDataAdapterList) dal, childComponent, this), this);
        foundsetPropValue.addViewportDataChangeMonitor(viewPortChangeMonitor);
        setDataproviderNameToFoundset();
    }
    addPropagatingPropertyChangeListener(WebFormUI.READONLY, webObjectContext.getProperty(WebFormUI.READONLY));
    if (childComponent.hasChanges())
        monitor.valueChanged();
}
Also used : ComponentContext(com.servoy.j2db.server.ngclient.ComponentContext) Form(com.servoy.j2db.persistence.Form) IDirtyPropertyListener(org.sablo.IDirtyPropertyListener) IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) IPersist(com.servoy.j2db.persistence.IPersist) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) JSONObject(org.json.JSONObject)

Example 74 with IPersist

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

the class DebugHeadlessClient method refreshForI18NChange.

public void refreshForI18NChange(boolean recreateForms) {
    List<IFormController> cachedFormControllers = getFormManager().getCachedFormControllers();
    ArrayList<IPersist> formsToReload = new ArrayList<IPersist>();
    for (IFormController fc : cachedFormControllers) formsToReload.add(fc.getForm());
    refreshPersists(formsToReload);
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) ArrayList(java.util.ArrayList) IFormController(com.servoy.j2db.IFormController)

Example 75 with IPersist

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

the class DebugUtils method isReferenceFormUsedInForm.

private static boolean isReferenceFormUsedInForm(final ClientState clientState, final Form referenceForm, Form form) {
    final boolean[] isReferenceFormUsedInForm = { false };
    form.acceptVisitor(new IPersistVisitor() {

        @Override
        public Object visit(IPersist o) {
            if (o instanceof WebComponent) {
                WebComponent wc = (WebComponent) o;
                WebObjectSpecification spec = FormTemplateGenerator.getWebObjectSpecification(wc);
                Collection<PropertyDescription> properties = spec != null ? spec.getProperties(FormComponentPropertyType.INSTANCE) : null;
                if (properties != null && properties.size() > 0) {
                    for (PropertyDescription pd : properties) {
                        Form frm = FormComponentPropertyType.INSTANCE.getForm(wc.getProperty(pd.getName()), clientState.getFlattenedSolution());
                        if (referenceForm.equals(frm)) {
                            isReferenceFormUsedInForm[0] = true;
                            return IPersistVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                        } else {
                            isReferenceFormUsedInForm[0] = isReferenceFormUsedInForm(clientState, referenceForm, frm);
                            if (isReferenceFormUsedInForm[0]) {
                                return IPersistVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                            }
                        }
                    }
                }
            }
            return IPersistVisitor.CONTINUE_TRAVERSAL;
        }
    });
    return isReferenceFormUsedInForm[0];
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebComponent(com.servoy.j2db.persistence.WebComponent) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) IPersist(com.servoy.j2db.persistence.IPersist) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) Collection(java.util.Collection)

Aggregations

IPersist (com.servoy.j2db.persistence.IPersist)84 Point (java.awt.Point)26 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)23 Form (com.servoy.j2db.persistence.Form)22 ArrayList (java.util.ArrayList)22 IFormElement (com.servoy.j2db.persistence.IFormElement)20 BaseComponent (com.servoy.j2db.persistence.BaseComponent)19 HashMap (java.util.HashMap)16 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)14 IComponent (com.servoy.j2db.ui.IComponent)13 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)13 Component (org.apache.wicket.Component)13 AbstractBase (com.servoy.j2db.persistence.AbstractBase)12 JSONObject (org.json.JSONObject)10 PropertyDescription (org.sablo.specification.PropertyDescription)10 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 Tab (com.servoy.j2db.persistence.Tab)8 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)7