Search in sources :

Example 81 with IPersist

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

the class FormElementHelper method fillsWidth.

private boolean fillsWidth(Form form) {
    if ((form.getScrollbars() & ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) == ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) {
        Part part = getBodyPart(form);
        int startPos = form.getPartStartYPos(part.getID());
        int endPos = part.getHeight();
        Iterator<IPersist> it = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
        while (it.hasNext()) {
            IPersist persist = it.next();
            if (persist instanceof GraphicalComponent && ((GraphicalComponent) persist).getLabelFor() != null)
                continue;
            if (persist instanceof BaseComponent) {
                BaseComponent bc = (BaseComponent) persist;
                if ((bc.getAnchors() & (IAnchorConstants.WEST + IAnchorConstants.EAST)) == (IAnchorConstants.WEST + IAnchorConstants.EAST)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) Point(java.awt.Point)

Example 82 with IPersist

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

the class ComponentFactory method createComponent.

@SuppressWarnings("nls")
public static WebFormComponent createComponent(IApplication application, IDataAdapterList dataAdapterList, FormElement fe, Container parentToAddTo, Form form) {
    // TODO anything to do here for custom special types?
    WebFormComponent webComponent = new WebFormComponent(fe.getName(), fe, dataAdapterList);
    if (parentToAddTo != null)
        parentToAddTo.add(webComponent);
    String name = fe.getName();
    IPersist persist = fe.getPersistIfAvailable();
    int elementSecurity = 0;
    if (persist != null) {
        boolean getItDirectlyBasedOnPersistAndForm = true;
        // FormComponent's child security is the security of the FormComponent
        if (fe.isFormComponentChild()) {
            String feName = fe.getName();
            // form component children security access is currently dictated by the root form component component security settings; currently one only has the Security tab in form editors not in form component editors;
            // for example if you have a form that contains a form component component A pointing to form component X that has in it a form component component B that points to form component Y
            // then the children of both X and Y in this case have the same security settings as 'root' form component component which is A;
            // so find the 'root' form component component persist and get it's access rights; this should always be found!
            String formComponentName = feName.substring(0, feName.indexOf('$'));
            for (IPersist p : form.getFlattenedFormElementsAndLayoutContainers()) {
                if (p instanceof IFormElement && formComponentName.equals(((IFormElement) p).getName())) {
                    elementSecurity = application.getFlattenedSolution().getSecurityAccess(p.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
                    getItDirectlyBasedOnPersistAndForm = false;
                    break;
                }
            }
            if (getItDirectlyBasedOnPersistAndForm)
                Debug.warn("'Root' form component including component on form " + form.getName() + " was not found when trying to determine access rights for a child of a form component: " + name);
        } else if (persist.getParent() instanceof Portal) {
            elementSecurity = application.getFlattenedSolution().getSecurityAccess(((Portal) persist.getParent()).getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
            getItDirectlyBasedOnPersistAndForm = false;
        }
        if (getItDirectlyBasedOnPersistAndForm) {
            elementSecurity = application.getFlattenedSolution().getSecurityAccess(persist.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
        }
        if (!((elementSecurity & IRepository.VIEWABLE) != 0)) {
            webComponent.setVisible(false);
        }
    }
    WebObjectSpecification componentSpec = fe.getWebComponentSpec(false);
    // first convert formElement-to-Sablo and store them in the webComponent
    for (String propName : fe.getRawPropertyValues().keySet()) {
        // TODO this if should not be necessary. currently in the case of "printable" hidden property
        if (componentSpec.getProperty(propName) == null)
            continue;
        Object value = fe.getPropertyValueConvertedForWebComponent(propName, webComponent, (DataAdapterList) dataAdapterList);
        fillProperty(value, fe.getPropertyValue(propName), componentSpec.getProperty(propName), webComponent);
    }
    // then after all of them are converted above attach them to the webComponent (so that when attach is called on any ISmartPropertyValue at least all the other properties are converted
    // this could help initialize smart properties that depend on each other faster then if we would convert and then attach right away each value)
    webComponent.propertiesInitialized();
    // overwrite accessible
    if (persist != null) {
        if (// element not accessible
        !((elementSecurity & IRepository.ACCESSIBLE) != 0)) {
            webComponent.setProperty(WebFormUI.ENABLED, false);
            Object enableValue = webComponent.getRawPropertyValue(WebFormUI.ENABLED);
            if (enableValue instanceof NGEnabledSabloValue) {
                ((NGEnabledSabloValue) enableValue).setAccessible(false);
            }
        } else {
            int formSecurity = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
            if (// form not accessible
            !((formSecurity & IRepository.ACCESSIBLE) != 0)) {
                webComponent.setProperty(WebFormUI.ENABLED, false);
                Object enableValue = webComponent.getRawPropertyValue(WebFormUI.ENABLED);
                if (enableValue instanceof NGEnabledSabloValue) {
                    ((NGEnabledSabloValue) enableValue).setAccessible(false);
                }
            }
        }
    }
    boolean[] foundOnDataChangeInDPConfigFromSpec = new boolean[] { false };
    componentSpec.getProperties(DataproviderPropertyType.INSTANCE, true).forEach((propertyFromSpec) -> {
        // the property type found here is for a 'dataprovider' property from the spec file of this component
        Object configOfDPOrFoundsetLinkedDP = propertyFromSpec.getConfig();
        DataproviderConfig dpConfig;
        if (configOfDPOrFoundsetLinkedDP instanceof FoundsetLinkedConfig)
            dpConfig = (DataproviderConfig) ((FoundsetLinkedConfig) configOfDPOrFoundsetLinkedDP).getWrappedConfig();
        else
            dpConfig = (DataproviderConfig) configOfDPOrFoundsetLinkedDP;
        if (dpConfig.getOnDataChange() != null && form.getOnElementDataChangeMethodID() > 0) {
            foundOnDataChangeInDPConfigFromSpec[0] = true;
            webComponent.add(dpConfig.getOnDataChange(), form.getOnElementDataChangeMethodID());
        }
    });
    // TODO should this be a part of type conversions for handlers instead?
    for (String eventName : componentSpec.getHandlers().keySet()) {
        Object eventValue = fe.getPropertyValue(eventName);
        if (eventValue instanceof String) {
            IPersist function = application.getFlattenedSolution().getScriptMethod((String) eventValue);
            if (function == null) {
                function = application.getFlattenedSolution().searchPersist((String) eventValue);
                if (function == null) {
                    Debug.warn("Script Method of value '" + eventValue + "' for handler " + eventName + " not found trying just the form " + form);
                    IPersist child = form.getChild(UUID.fromString((String) eventValue));
                    if (child != null) {
                        Debug.warn("Script Method " + child + " on the form " + form + " with uuid " + child.getUUID());
                        function = child;
                    } else {
                        Debug.warn("Still not found on Form " + form + " Script Method of value '" + eventValue + "' for handler " + eventName);
                    }
                }
            }
            if (function != null) {
                webComponent.add(eventName, function.getID());
            } else {
                Debug.warn("Event handler for " + eventName + " with value '" + eventValue + "' not found (form " + form + ", form element " + name + ")");
            }
        } else if (eventValue instanceof Number && ((Number) eventValue).intValue() > 0) {
            webComponent.add(eventName, ((Number) eventValue).intValue());
        } else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSGAINEDMETHODID.getPropertyName()) && (form.getOnElementFocusGainedMethodID() > 0)) {
            webComponent.add(eventName, form.getOnElementFocusGainedMethodID());
        } else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSLOSTMETHODID.getPropertyName()) && (form.getOnElementFocusLostMethodID() > 0)) {
            webComponent.add(eventName, form.getOnElementFocusLostMethodID());
        } else if (!foundOnDataChangeInDPConfigFromSpec[0] && Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONDATACHANGEMETHODID.getPropertyName()) && (form.getOnElementDataChangeMethodID() > 0)) {
            // legacy behavior - based on hard-coded handler name (of component)
            webComponent.add(eventName, form.getOnElementDataChangeMethodID());
        }
    }
    // just created, it should have no changes.
    webComponent.clearChanges();
    return webComponent;
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) FoundsetLinkedConfig(com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) Portal(com.servoy.j2db.persistence.Portal) NGEnabledSabloValue(com.servoy.j2db.server.ngclient.property.types.NGEnabledSabloValue) DataproviderConfig(com.servoy.j2db.server.ngclient.property.DataproviderConfig)

Example 83 with IPersist

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

the class FormElement method getLabel.

public IFormElement getLabel() {
    IFormElement label = null;
    String name = (String) getPropertyValue(StaticContentSpecLoader.PROPERTY_NAME.getPropertyName());
    if (name != null && form != null) {
        Iterator<IPersist> formElementsIte = form.getAllObjects();
        IPersist p;
        while (formElementsIte.hasNext()) {
            p = formElementsIte.next();
            if (p instanceof GraphicalComponent && name.equals(((GraphicalComponent) p).getLabelFor())) {
                label = (GraphicalComponent) p;
                break;
            }
        }
    }
    return label;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent)

Example 84 with IPersist

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

the class ComponentFactory method createComponent.

/**
 * Create a component
 *
 * @param meta the definition
 * @param el the event listener such as action,mouse event listeners, can be null (Example:makes possible for button to call script)
 */
public static IComponent createComponent(IApplication application, Form form, IPersist meta, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
    IComponent c = createComponentEx(application, form, meta, dataProviderLookup, el, printing);
    // set groupID property
    if (meta instanceof IFormElement && ((IFormElement) meta).getGroupID() != null) {
        String groupId = ((IFormElement) meta).getGroupID();
        if (groupId != null) {
            setComponentProperty(application, c, GROUPID_COMPONENT_PROPERTY, groupId);
        }
    }
    // Extra call so that focusable is user set...
    if (c instanceof Component) {
        Component comp = (Component) c;
        if (comp.isFocusable())
            comp.setFocusable(true);
        OrientationApplier.setOrientationToAWTComponent(comp, application.getLocale(), application.getSolution().getTextOrientation());
    }
    int access = application.getFlattenedSolution().getSecurityAccess(meta.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
    if (access != -1) {
        boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
        if (!b_visible) {
            if (c instanceof ISupportSecuritySettings) {
                ((ISupportSecuritySettings) c).setViewable(false);
            } else {
                c.setComponentVisible(false);
            }
        }
        if (c instanceof ISupportSecuritySettings) {
            boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
            if (!b_accessible)
                ((ISupportSecuritySettings) c).setAccessible(false);
        }
    }
    // special case requested by ayton (have own security interface)
    if (c instanceof ITabPanel && meta instanceof TabPanel) {
        try {
            int i = 0;
            Iterator<IPersist> it = ((TabPanel) meta).getTabs();
            while (it.hasNext()) {
                Tab t = (Tab) it.next();
                int access1 = application.getFlattenedSolution().getSecurityAccess(t.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
                if (access1 != -1) {
                    boolean b_accessible = ((access1 & IRepository.ACCESSIBLE) != 0);
                    boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
                    if (!b_accessible || !b_visible)
                        ((ITabPanel) c).setTabEnabledAt(i, false);
                }
                i++;
            }
        } catch (Exception e) {
            Debug.error(e);
        }
    }
    return c;
}
Also used : ITabPanel(com.servoy.j2db.ui.ITabPanel) TabPanel(com.servoy.j2db.persistence.TabPanel) RuntimeTabPanel(com.servoy.j2db.ui.scripting.RuntimeTabPanel) IComponent(com.servoy.j2db.ui.IComponent) ITabPanel(com.servoy.j2db.ui.ITabPanel) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IFormElement(com.servoy.j2db.persistence.IFormElement) Tab(com.servoy.j2db.persistence.Tab) IPersist(com.servoy.j2db.persistence.IPersist) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) AbstractRuntimeValuelistComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeValuelistComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IAnchoredComponent(com.servoy.j2db.ui.IAnchoredComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) WebComponent(com.servoy.j2db.persistence.WebComponent) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) ISupportSecuritySettings(com.servoy.j2db.ui.ISupportSecuritySettings)

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