Search in sources :

Example 1 with WebCellBasedView

use of com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView in project servoy-client by Servoy.

the class WebForm method setTabSeqComponents.

public void setTabSeqComponents(List<Component> tabSequence) {
    boolean defaultSequence = true;
    if (tabSequence != null && tabSequence.size() > 0) {
        defaultSequence = false;
        IDataRenderer formEditorRenderer = formController.getDataRenderers()[FormController.FORM_EDITOR];
        if (formEditorRenderer instanceof WebCellBasedView && !tabSequence.contains(formEditorRenderer)) {
            // this means that we have to identify components that are part of the table view and based on where these are located set the view's tabIndex;
            // when called from JS tabSequence will only contain table columns, not table view as opposed to initialization when tabSequence only contains the view
            int i;
            for (i = 0; i < tabSequence.size(); i++) {
                if (((WebCellBasedView) formEditorRenderer).isColumnIdentifierComponent(tabSequence.get(i))) {
                    // table view should be added to tab sequence
                    ((WebCellBasedView) formEditorRenderer).setTabSeqComponents(tabSequence);
                    tabSequence = new ArrayList<Component>(tabSequence);
                    tabSequence.add(i, (Component) formEditorRenderer);
                    break;
                }
            }
            i++;
            while (i < tabSequence.size()) {
                if (((WebCellBasedView) formEditorRenderer).isColumnIdentifierComponent(tabSequence.get(i))) {
                    tabSequence.remove(i);
                } else {
                    i++;
                }
            }
        }
        int tabIndex = 1;
        for (Component comp : tabSequence) {
            if (comp instanceof IWebFormContainer) {
                ((IWebFormContainer) comp).setTabSequenceIndex(tabIndex);
                tabIndex = WebDataRendererFactory.getContainerGapIndex(tabIndex + WebDataRendererFactory.CONTAINER_RESERVATION_GAP, tabIndex);
                TabIndexHelper.setUpTabIndexAttributeModifier(comp, ISupportWebTabSeq.SKIP);
            } else if (comp instanceof WebCellBasedView) {
                WebCellBasedView tableView = (WebCellBasedView) comp;
                tableView.setTabSequenceIndex(tabIndex);
                tabIndex += WebDataRendererFactory.MAXIMUM_TAB_INDEXES_ON_TABLEVIEW;
                TabIndexHelper.setUpTabIndexAttributeModifier(comp, ISupportWebTabSeq.SKIP);
            } else {
                TabIndexHelper.setUpTabIndexAttributeModifier(comp, tabIndex);
                tabIndex++;
            }
        }
    }
    IDataRenderer[] dataRenderers = formController.getDataRenderers();
    for (IDataRenderer dr : dataRenderers) {
        if (dr != null) {
            // set attributeModifiers for all components
            if (dr instanceof WebCellBasedView) {
                if (defaultSequence) {
                    // normal focus
                    ((WebCellBasedView) dr).setTabSequenceIndex(ISupportWebTabSeq.DEFAULT);
                    ((WebCellBasedView) dr).setTabSeqComponents(null);
                } else if (!tabSequence.contains(dr)) {
                    // it shouldn't gain focus when tabbing ...
                    ((WebCellBasedView) dr).setTabSequenceIndex(-1);
                    ((WebCellBasedView) dr).setTabSeqComponents(null);
                }
            } else {
                Iterator compIt = dr.getComponentIterator();
                if (compIt != null) {
                    while (compIt.hasNext()) {
                        Object obj = compIt.next();
                        if (obj instanceof ISupplyFocusChildren) {
                            for (Component c : ((ISupplyFocusChildren<Component>) obj).getFocusChildren()) {
                                checkIfDefaultOrSkipFocus(defaultSequence, tabSequence, c);
                            }
                        } else if (obj instanceof Component) {
                            checkIfDefaultOrSkipFocus(defaultSequence, tabSequence, (Component) obj);
                        }
                    }
                }
            }
        }
    }
    tabSeqComponentList = tabSequence;
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) IWebFormContainer(com.servoy.j2db.server.headlessclient.dataui.IWebFormContainer) Iterator(java.util.Iterator) ISupplyFocusChildren(com.servoy.j2db.util.ISupplyFocusChildren) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) IComponent(com.servoy.j2db.ui.IComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) Point(java.awt.Point)

Example 2 with WebCellBasedView

use of com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView in project servoy-client by Servoy.

the class WebForm method makeElementsScriptObject.

/**
 * @see com.servoy.j2db.IFormUIInternal#makeElementsScriptObject(org.mozilla.javascript.Scriptable, java.util.Map, com.servoy.j2db.ui.IDataRenderer[],
 *      com.servoy.j2db.IView)
 */
public ElementScope makeElementsScriptObject(Scriptable fs, Map<String, Object[]> hmChildrenJavaMembers, IDataRenderer[] dataRenderers, IView v) {
    ElementScope es = new ElementScope(fs);
    int counter = 0;
    for (int i = FormController.FORM_RENDERER + 1; i < dataRenderers.length; i++) {
        IDataRenderer dr = dataRenderers[i];
        if (dr == null)
            continue;
        Object[] comps = null;
        if (dr instanceof WebMarkupContainer) {
            comps = new Object[((WebMarkupContainer) dr).size()];
            Iterator it = ((WebMarkupContainer) dr).iterator();
            int j = 0;
            while (it.hasNext()) {
                comps[j++] = it.next();
            }
        }
        counter = registerComponentsToScope(fs, es, counter, comps, hmChildrenJavaMembers, dr);
    }
    if (v instanceof WebCellBasedView) {
        Object[] comps = ((WebCellBasedView) v).getComponents();
        counter = registerComponentsToScope(fs, es, counter, comps, hmChildrenJavaMembers, v);
    }
    es.setLocked(true);
    return es;
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) ElementScope(com.servoy.j2db.scripting.ElementScope) Iterator(java.util.Iterator) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Point(java.awt.Point) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 3 with WebCellBasedView

use of com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView in project servoy-client by Servoy.

the class WebForm method registerComponentsToScope.

private int registerComponentsToScope(Scriptable fs, ElementScope es, int counter, Object[] comps, Map<String, Object[]> hmChildrenJavaMembers, Object parent) {
    if (comps != null) {
        for (Object comp : comps) {
            if (comp instanceof WebCellBasedView) {
                WebCellBasedView portal = (WebCellBasedView) comp;
                counter = registerComponentsToScope(fs, es, counter, portal.getComponents(), hmChildrenJavaMembers, comp);
            }
            String name = null;
            if (comp instanceof WrapperContainer) {
                comp = ((WrapperContainer) comp).getDelegate();
            }
            if (comp instanceof IComponent) {
                name = ((IComponent) comp).getName();
            } else if (comp instanceof java.awt.Component) {
                name = ((java.awt.Component) comp).getName();
            }
            if (comp instanceof WebImageBeanHolder) {
                comp = ((WebImageBeanHolder) comp).getDelegate();
            } else if (comp instanceof WebBeanHolder) {
                comp = ((WebBeanHolder) comp).getDelegate();
            }
            String groupName = FormElementGroup.getName((String) formController.getComponentProperty(comp, ComponentFactory.GROUPID_COMPONENT_PROPERTY));
            Object scriptable = comp;
            if (comp instanceof IScriptableProvider)
                scriptable = ((IScriptableProvider) comp).getScriptObject();
            JavaMembers jm = ScriptObjectRegistry.getJavaMembers(scriptable.getClass(), ScriptableObject.getTopLevelScope(fs));
            // $NON-NLS-1$
            boolean named = name != null && !name.equals("") && !name.startsWith(ComponentFactory.WEB_ID_PREFIX);
            if (groupName != null || named) {
                try {
                    Scriptable s;
                    if (parent instanceof WebCellBasedView) {
                        s = new CellNativeJavaObject(fs, comp, jm, (WebCellBasedView) parent);
                    } else {
                        s = new NativeJavaObject(fs, scriptable, jm);
                    }
                    if (named) {
                        es.put(name, fs, s);
                        es.put(counter++, fs, s);
                        hmChildrenJavaMembers.put(name, new Object[] { jm, scriptable });
                    }
                    if (groupName != null) {
                        Object group = es.get(groupName, fs);
                        if (group == Scriptable.NOT_FOUND) {
                            group = new NativeJavaObject(fs, new RuntimeGroup(groupName), ScriptObjectRegistry.getJavaMembers(RuntimeGroup.class, ScriptableObject.getTopLevelScope(fs)));
                            es.put(groupName, fs, group);
                            es.put(counter++, fs, group);
                        }
                        if (scriptable instanceof IRuntimeComponent && group instanceof NativeJavaObject && ((NativeJavaObject) group).unwrap() instanceof RuntimeGroup) {
                            ((RuntimeGroup) (((NativeJavaObject) group).unwrap())).addScriptBaseMethodsObj((IRuntimeComponent) scriptable);
                        }
                    }
                } catch (Throwable ex) {
                    // incase classdefnot founds are thrown for beans,applets/plugins
                    Debug.error(ex);
                }
            }
        }
    }
    return counter;
}
Also used : WebImageBeanHolder(com.servoy.j2db.server.headlessclient.dataui.WebImageBeanHolder) JavaMembers(org.mozilla.javascript.JavaMembers) IComponent(com.servoy.j2db.ui.IComponent) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Scriptable(org.mozilla.javascript.Scriptable) RuntimeGroup(com.servoy.j2db.scripting.RuntimeGroup) WebBeanHolder(com.servoy.j2db.server.headlessclient.dataui.WebBeanHolder) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IComponent(com.servoy.j2db.ui.IComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Example 4 with WebCellBasedView

use of com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView in project servoy-client by Servoy.

the class WebForm method getFormAnchorInfo.

@SuppressWarnings("unchecked")
public FormAnchorInfo getFormAnchorInfo() {
    formAnchorInfo = new FormAnchorInfo(formController.getName(), formController.getForm().getSize(), formController.getForm().getUUID());
    final Map<String, ISupportAnchors> elements = new HashMap<String, ISupportAnchors>();
    Iterator<IPersist> e1 = formController.getForm().getAllObjects();
    while (e1.hasNext()) {
        IPersist obj = e1.next();
        if (obj instanceof ISupportAnchors && obj instanceof ISupportBounds) {
            elements.put(ComponentFactory.getWebID(formController.getForm(), obj), (ISupportAnchors) obj);
        }
    }
    // In case we are in table view.
    if (view instanceof WebCellBasedView) {
        WebCellBasedView formPart = (WebCellBasedView) view;
        formAnchorInfo.addPart(Part.getDisplayName(Part.BODY), formPart.getMarkupId(), 50);
        formAnchorInfo.isTableView = true;
        formAnchorInfo.bodyContainerId = formPart.getMarkupId();
    }
    // Find the id of the form navigator, if any.
    visitChildren(Component.class, new IVisitor() {

        public Object component(Component component) {
            if (component instanceof WebDefaultRecordNavigator) {
                formAnchorInfo.navigatorWebId = component.getMarkupId();
                return IVisitor.CONTINUE_TRAVERSAL;
            } else if (component instanceof WebTabPanel) {
                return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
            } else
                return IVisitor.CONTINUE_TRAVERSAL;
        }
    });
    visitChildren(WebDataRenderer.class, new IVisitor() {

        public Object component(Component component) {
            WebDataRenderer formPart = (WebDataRenderer) component;
            final FormPartAnchorInfo part = formAnchorInfo.addPart(formPart.getFormPartName(), formPart.getMarkupId(), formPart.getSize().height);
            if (Part.getDisplayName(Part.BODY).equals(formPart.getFormPartName())) {
                Component parent = formPart.getParent();
                formAnchorInfo.bodyContainerId = parent.getMarkupId();
            }
            formPart.visitChildren(ISupportWebBounds.class, new IVisitor() {

                public Object component(Component comp) {
                    String id = comp.getId();
                    ISupportAnchors obj = elements.get(id);
                    if (obj != null) {
                        int anchors = obj.getAnchors();
                        if (((anchors > 0 && anchors != IAnchorConstants.DEFAULT)) || (comp instanceof WebTabPanel) || (comp instanceof IButton)) {
                            Rectangle r = ((ISupportWebBounds) comp).getWebBounds();
                            if (r != null) {
                                if (anchors == 0)
                                    anchors = IAnchorConstants.DEFAULT;
                                int hAlign = -1;
                                int vAlign = -1;
                                if (obj instanceof ISupportTextSetup) {
                                    ISupportTextSetup alignedObj = (ISupportTextSetup) obj;
                                    hAlign = alignedObj.getHorizontalAlignment();
                                    vAlign = alignedObj.getVerticalAlignment();
                                }
                                String imageDisplayURL = null;
                                boolean isRandomParamRemoved = false;
                                if (comp instanceof IImageDisplay) {
                                    Object[] aImageDisplayURL = WebBaseButton.getImageDisplayURL((IImageDisplay) comp, false);
                                    imageDisplayURL = (String) aImageDisplayURL[0];
                                    isRandomParamRemoved = ((Boolean) aImageDisplayURL[1]).booleanValue();
                                }
                                part.addAnchoredElement(comp.getMarkupId(), anchors, r, hAlign, vAlign, comp.getClass(), imageDisplayURL, isRandomParamRemoved);
                            }
                        }
                    }
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
        }
    });
    return formAnchorInfo;
}
Also used : FormPartAnchorInfo(com.servoy.j2db.server.headlessclient.FormAnchorInfo.FormPartAnchorInfo) WebDataRenderer(com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) IImageDisplay(com.servoy.j2db.server.headlessclient.dataui.IImageDisplay) ISupportTextSetup(com.servoy.j2db.persistence.ISupportTextSetup) Rectangle(java.awt.Rectangle) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Point(java.awt.Point) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) IPersist(com.servoy.j2db.persistence.IPersist) WebDefaultRecordNavigator(com.servoy.j2db.server.headlessclient.dataui.WebDefaultRecordNavigator) IButton(com.servoy.j2db.ui.IButton) WebTabPanel(com.servoy.j2db.server.headlessclient.dataui.WebTabPanel) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IComponent(com.servoy.j2db.ui.IComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Example 5 with WebCellBasedView

use of com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView in project servoy-client by Servoy.

the class WebForm method initView.

/**
 * @see com.servoy.j2db.IFormUIInternal#initView(com.servoy.j2db.IApplication, com.servoy.j2db.FormController, int)
 */
public IView initView(IApplication app, FormController fp, int viewType) {
    boolean addHeaders = true;
    view = null;
    final Form f = fp.getForm();
    DataRendererRecordModel rendererModel = new DataRendererRecordModel();
    // int viewType = f.getView();
    if (viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW) {
        // list views do not have headers
        addHeaders = false;
    }
    // String orientation = OrientationApplier.getHTMLContainerOrientation(app.getLocale(), app.getSolution().getTextOrientation());
    IDataRenderer[] dataRenderers = fp.getDataRenderers();
    for (int i = 0; i < dataRenderers.length; i++) {
        if (i == Part.TITLE_HEADER || i == Part.HEADER || i == Part.LEADING_GRAND_SUMMARY || i == Part.TRAILING_GRAND_SUMMARY || i == Part.FOOTER) {
            if (dataRenderers[Part.HEADER] != null) {
                addHeaders = false;
            }
            WebDataRenderer dr = (WebDataRenderer) dataRenderers[i];
            if (dr != null) {
                dr.setDefaultModel(rendererModel);
                container.add(dr);
            }
        }
    }
    defaultNavigator = null;
    if (viewType == IForm.RECORD_VIEW || viewType == IForm.LOCKED_RECORD_VIEW) {
        // $NON-NLS-1$
        view = new WebRecordView("View");
        if (f.getNavigatorID() == Form.NAVIGATOR_DEFAULT) {
            defaultNavigator = new WebDefaultRecordNavigator(this);
            ((WebRecordView) view).add(defaultNavigator);
        }
        // Body
        WebDataRenderer body = (WebDataRenderer) dataRenderers[FormController.FORM_EDITOR];
        if (body != null) {
            ((WebRecordView) view).add(body);
            body.setDefaultModel(rendererModel);
            body.setParentView(view);
        } else {
        // ((WebRecordView)view).add(new WebMarkupContainer());
        }
    } else if (viewType == FormController.TABLE_VIEW || viewType == FormController.LOCKED_TABLE_VIEW || viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW) {
        // try
        // {
        // Iterator it = f.getParts();
        // while (it.hasNext())
        // {
        // Part p = (Part) it.next();
        // if (p.getPartType() == Part.HEADER)
        // {
        // addHeaders = false;
        // break;
        // }
        // }
        // }
        // catch (RepositoryException e)
        // {
        // Debug.error(e);
        // }
        Part body = null;
        Iterator<Part> e2 = fp.getForm().getParts();
        while (e2.hasNext()) {
            Part part = e2.next();
            if (part.getPartType() == Part.BODY) {
                body = part;
                break;
            }
        }
        if (body == null) {
            // Special case, form in tableview with no body. just create a default view object.
            // $NON-NLS-1$
            view = new WebRecordView("View");
            return view;
        } else {
            int startY = fp.getForm().getPartStartYPos(body.getID());
            int endY = body.getHeight();
            int sizeHint = endY;
            if (// small body and body is last
            (sizeHint - startY) <= 40 && fp.getForm().getSize().height == sizeHint) {
                sizeHint += Math.max(endY, 200 - sizeHint);
            }
            RuntimePortal viewScriptable = new RuntimePortal(new ChangesRecorder(null, null), app);
            view = new WebCellBasedView("View", app, viewScriptable, f, f, app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), f), fp.getScriptExecuter(), addHeaders, startY, endY, sizeHint, viewType);
            viewScriptable.setComponent((WebCellBasedView) view, f);
            if (dataRenderers[FormController.FORM_EDITOR] != null)
                dataRenderers[FormController.FORM_EDITOR].destroy();
            dataRenderers[FormController.FORM_EDITOR] = (WebCellBasedView) view;
        }
    }
    if (container.get("View") != null) {
        container.replace((WebMarkupContainer) view);
    } else {
        container.add((WebMarkupContainer) view);
    }
    return view;
}
Also used : WebRecordView(com.servoy.j2db.server.headlessclient.dataui.WebRecordView) WebDataRenderer(com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Point(java.awt.Point) ChangesRecorder(com.servoy.j2db.server.headlessclient.dataui.ChangesRecorder) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal) WebDefaultRecordNavigator(com.servoy.j2db.server.headlessclient.dataui.WebDefaultRecordNavigator) Part(com.servoy.j2db.persistence.Part) Iterator(java.util.Iterator)

Aggregations

WebCellBasedView (com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView)5 Point (java.awt.Point)4 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)4 ScriptableObject (org.mozilla.javascript.ScriptableObject)4 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 IComponent (com.servoy.j2db.ui.IComponent)3 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)3 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)3 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)3 Iterator (java.util.Iterator)3 Component (org.apache.wicket.Component)3 WebDataRenderer (com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer)2 WebDefaultRecordNavigator (com.servoy.j2db.server.headlessclient.dataui.WebDefaultRecordNavigator)2 IForm (com.servoy.j2db.IForm)1 Form (com.servoy.j2db.persistence.Form)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)1 ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)1 ISupportTextSetup (com.servoy.j2db.persistence.ISupportTextSetup)1 Part (com.servoy.j2db.persistence.Part)1