Search in sources :

Example 1 with ISupportSecuritySettings

use of com.servoy.j2db.ui.ISupportSecuritySettings in project servoy-client by Servoy.

the class FormController method createDataRenderers.

private void createDataRenderers(int viewType) throws Exception {
    int v = viewType;
    if (getDataSource() == null) {
        // form not based on any datasource
        v = LOCKED_RECORD_VIEW;
    }
    application.getDataRenderFactory().prepareRenderers(application, form);
    Part bodyPart = null;
    Map<Part, IDataRenderer> part_panels = new LinkedHashMap<Part, IDataRenderer>();
    Iterator<Part> e2 = form.getParts();
    while (e2.hasNext()) {
        Part part = e2.next();
        Color partColor = ComponentFactory.getPartBackground(application, part, form);
        // extract the body (bgcolor)
        if (part.getPartType() == Part.BODY) {
            bodyPart = part;
            bgColor = partColor;
            Pair<IStyleSheet, IStyleRule> partStyle = ComponentFactory.getStyleForBasicComponent(application, part, form);
            bodyRule = partStyle != null ? partStyle.getRight() : null;
        }
        if (part.getPartType() == Part.BODY && v == FormController.LOCKED_TABLE_VIEW) {
            // don't create part, view == part
            continue;
        }
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, part), part.toString(), application, (part.getPartType() == Part.BODY));
        dr.initDragNDrop(this, form.getPartStartYPos(part.getID()));
        dataRenderers[part.getPartType()] = dr;
        dr.setName(part.toString());
        part_panels.put(part, dr);
        if (part.getPartType() == Part.BODY) {
            int onRenderMethodID = form.getOnRenderMethodID();
            if (onRenderMethodID > 0) {
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
            }
        }
        dr.setBackground(partColor);
    }
    tabSequence.clear();
    application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), tabSequence);
    if (bodyPart != null && (v == FormController.LOCKED_LIST_VIEW || v == IForm.LIST_VIEW)) {
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, bodyPart), bodyPart.toString(), application, true);
        int onRenderMethodID = form.getOnRenderMethodID();
        if (onRenderMethodID > 0) {
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
        }
        // apply bgcolor to renderer
        if (bgColor != null) {
            dr.setBackground(bgColor);
        }
        dataRenderers[FORM_RENDERER] = dr;
        dr.setName(bodyPart.toString());
        part_panels = new LinkedHashMap<Part, IDataRenderer>();
        part_panels.put(bodyPart, dr);
        application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), null);
    }
    // apply security
    int access = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
    if (access != -1) {
        boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
        if (!b_accessible) {
            for (IDataRenderer dataRenderer : dataRenderers) {
                if (dataRenderer != null) {
                    Iterator<? extends IComponent> componentIterator = dataRenderer.getComponentIterator();
                    while (componentIterator.hasNext()) {
                        IComponent c = componentIterator.next();
                        if (c instanceof ISupportSecuritySettings) {
                            if (!b_accessible)
                                ((ISupportSecuritySettings) c).setAccessible(b_accessible);
                        }
                    }
                }
            }
        }
    }
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) IComponent(com.servoy.j2db.ui.IComponent) Color(java.awt.Color) LinkedHashMap(java.util.LinkedHashMap) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) Part(com.servoy.j2db.persistence.Part) IStyleRule(com.servoy.j2db.util.IStyleRule) ISupportSecuritySettings(com.servoy.j2db.ui.ISupportSecuritySettings)

Example 2 with ISupportSecuritySettings

use of com.servoy.j2db.ui.ISupportSecuritySettings 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

IComponent (com.servoy.j2db.ui.IComponent)2 ISupportSecuritySettings (com.servoy.j2db.ui.ISupportSecuritySettings)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 IFormElement (com.servoy.j2db.persistence.IFormElement)1 IPersist (com.servoy.j2db.persistence.IPersist)1 Part (com.servoy.j2db.persistence.Part)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 Tab (com.servoy.j2db.persistence.Tab)1 TabPanel (com.servoy.j2db.persistence.TabPanel)1 WebComponent (com.servoy.j2db.persistence.WebComponent)1 IAnchoredComponent (com.servoy.j2db.ui.IAnchoredComponent)1 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)1 ITabPanel (com.servoy.j2db.ui.ITabPanel)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 AbstractRuntimeValuelistComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeValuelistComponent)1 IFormatScriptComponent (com.servoy.j2db.ui.scripting.IFormatScriptComponent)1 RuntimeTabPanel (com.servoy.j2db.ui.scripting.RuntimeTabPanel)1