Package org.apache.cocoon.woody.formmodel

Examples of org.apache.cocoon.woody.formmodel.Repeater$RepeaterRow


        super.delete(id);
    }

    public void delete(int index) {
        if (delegate instanceof Repeater) {
            Repeater repeater = (Repeater)delegate;
            if (index >= 0 && index < repeater.getSize()) {
                repeater.removeRow(index);
                return;
            }
        } else if (delegate instanceof MultiValueField) {
            MultiValueField field = (MultiValueField)delegate;
            Object[] values = (Object[])field.getValue();
View Full Code Here


    public void put(String id, Scriptable start, Object value) {
        if (delegate instanceof Repeater) {
            if (id.equals("length")) {
                int len = (int)Context.toNumber(value);
                Repeater repeater = (Repeater)delegate;
                int size = repeater.getSize();
                if (size > len) {
                    while (repeater.getSize() > len) {
                        repeater.removeRow(repeater.getSize() -1);
                    }
                } else {
                    for (int i = size; i < len; ++i) {
                        repeater.addRow();
                    }
                }
            }
        } else if (delegate != null) {
            Widget sub = delegate.getWidget(id);
            if (sub instanceof Field) {
                Field field = (Field)sub;
                value = unwrap(value);
                if (value instanceof Double) {
                    // make woody accept a JS Number
                    Class typeClass =
                        field.getFieldDefinition().getDatatype().getTypeClass();
                    if (typeClass == long.class || typeClass == Long.class) {
                        value = new Long(((Number)value).longValue());
                    } else if (typeClass == int.class || typeClass == Integer.class) {
                        value = new Integer(((Number)value).intValue());
                    } else if (typeClass == float.class || typeClass == Float.class) {
                        value = new Float(((Number)value).floatValue());
                    } else if (typeClass == short.class || typeClass == Short.class) {
                        value = new Short(((Number)value).shortValue());
                    }
                }
                field.setValue(value);
                return;
            } else if (sub instanceof BooleanField) {
                BooleanField field = (BooleanField)sub;
                value = unwrap(value);
                field.setValue(value);
            } else if (sub instanceof Repeater) {
                Repeater repeater = (Repeater)sub;
                if (value instanceof NativeArray) {
                    NativeArray arr = (NativeArray)value;
                    Object length = getProperty(arr, "length");
                    int len = ((Number)length).intValue();
                    for (int i = repeater.getSize(); i >= len; --i) {
                        repeater.removeRow(i);
                    }
                    for (int i = 0; i < len; i++) {
                        Object elemValue = getProperty(arr, i);
                        if (elemValue instanceof Scriptable) {
                            Scriptable s = (Scriptable)elemValue;
                            Object[] ids = s.getIds();
                            ScriptableWidget wid = wrap(repeater.getRow(i));
                            for (int j = 0; j < ids.length; j++) {
                                String idStr = ids[j].toString();
                                wid.put(idStr, wid, getProperty(s, idStr));
                            }
                        }
View Full Code Here

        this.deleteIfEmpty = deleteIfEmpty;
    }

    public void loadFormFromModel(Widget frmModel, JXPathContext jctx) {
        // Find the repeater and clear it
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
       
        if (this.clearOnLoad) {
            repeater.removeRows();
        }

        // Move to repeater context
        Pointer ptr = jctx.getPointer(this.repeaterPath);
        if (ptr.getNode() != null) {
            // There are some nodes to load from
           
            JXPathContext repeaterContext = jctx.getRelativeContext(ptr);
            // build a jxpath iterator for pointers
            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);

            //iterate through it
            int rowNum = 0;
            while (rowPointers.hasNext()) {
                // Get a row. It is created if needed (depends on clearOnLoad)
                Repeater.RepeaterRow thisRow;
                if (repeater.getSize() > rowNum) {
                    thisRow = repeater.getRow(rowNum);
                } else {
                    thisRow = repeater.addRow();
                }
                rowNum++;
    
                // make a jxpath sub context on the iterated element
                Pointer jxp = (Pointer) rowPointers.next();
View Full Code Here

            getLogger().debug("done loading rows " + toString());
    }

    public void saveFormToModel(Widget frmModel, JXPathContext jctx) throws BindingException {
        // Find the repeater
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);

        if (repeater.getSize() == 0 && this.deleteIfEmpty) {
            // Repeater is empty : erase all
            jctx.removeAll(this.repeaterPath);

        } else {
            // Repeater is not empty
           
            // Move to repeater context and create the path if needed
            JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath));

            // Delete all that is already present
            repeaterContext.removeAll(this.rowPath);

            for (int i = 0; i < repeater.getSize(); i++) {
                String path = this.rowPath + '[' + (i+1) + ']';
                Pointer rowPtr = repeaterContext.createPath(path);
                JXPathContext rowContext = repeaterContext.getRelativeContext(rowPtr);
                this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext);
            }
        }
    }
View Full Code Here

     * objectModelContext and Repeater to the repeated rows before handing
     * over to the actual binding-children.
     */
    public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
        // Find the repeater
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
        repeater.removeRows();

        // build a jxpath iterator for pointers
        JXPathContext repeaterContext = jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));
        Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);

        //iterate through it
        while (rowPointers.hasNext()) {
            // create a new row, take that as the frmModelSubContext
            Repeater.RepeaterRow thisRow = repeater.addRow();

            // make a jxpath ObjectModelSubcontext on the iterated element
            Pointer jxp = (Pointer) rowPointers.next();
            JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);

View Full Code Here

     * updated, inserted or removed.  Depending on what happened the appropriate
     * child-bindings are alowed to visit the narrowed contexts.
     */
    public void saveFormToModel(Widget frmModel, JXPathContext jxpc) throws BindingException {
        // Find the repeater
        Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);

        // and his context
        JXPathContext repeaterContext =
            jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));

        // create set of updatedRowIds
        Set updatedRowIds = new HashSet();
        //create list of rows to insert at end
        List rowsToInsert = new ArrayList();

        // iterate rows...       
        int formRowCount = repeater.getSize();
        for (int i = 0; i < formRowCount; i++) {
            Repeater.RepeaterRow thisRow = repeater.getRow(i);

            Widget rowIdWidget = thisRow.getWidget(this.uniqueRowId);
            Object rowIdValue = rowIdWidget.getValue();

            if (rowIdValue != null) {
View Full Code Here

        if (inWidgetElement && elementNestingCounter == widgetElementNesting &&
                namespaceURI.equals(Constants.WT_NS)
                && (localName.equals("widget") || localName.equals("repeater-widget"))) {

            if (repeaterWidget) {
                Repeater repeater = (Repeater)widget;
                WidgetReplacingPipe rowPipe = new WidgetReplacingPipe();
                XMLByteStreamInterpreter interpreter = new XMLByteStreamInterpreter();
                int rowCount = repeater.getSize();
                Object saxFragment = xmlCompiler.getSAXFragment();
                for (int i = 0; i < rowCount; i++) {
                    Repeater.RepeaterRow row = repeater.getRow(i);
                    rowPipe.init(row);
                    rowPipe.setContentHandler(contentHandler);
                    rowPipe.setLexicalHandler(lexicalHandler);
                    interpreter.setConsumer(rowPipe);
                    interpreter.deserialize(saxFragment);
View Full Code Here

        if (inWidgetElement && elementNestingCounter == widgetElementNesting &&
                namespaceURI.equals(Constants.WT_NS)
                && (localName.equals("widget") || localName.equals("repeater-widget"))) {

            if (repeaterWidget) {
                Repeater repeater = (Repeater)widget;
                WidgetReplacingPipe rowPipe = new WidgetReplacingPipe();
                XMLByteStreamInterpreter interpreter = new XMLByteStreamInterpreter();
                int rowCount = repeater.getSize();
                Object saxFragment = xmlCompiler.getSAXFragment();
                for (int i = 0; i < rowCount; i++) {
                    Repeater.RepeaterRow row = repeater.getRow(i);
                    rowPipe.init(row, pipeContext);
                    rowPipe.setContentHandler(contentHandler);
                    rowPipe.setLexicalHandler(lexicalHandler);
                    interpreter.setConsumer(rowPipe);
                    interpreter.deserialize(saxFragment);
View Full Code Here

     */
    public void handleActionEvent(ActionEvent actionEvent) {
        String command = actionEvent.getActionCommand();

        if (command.equals(this.addCommand)) {
            Repeater repeater =
                (Repeater) form.getWidget(this.repeaterName);
            repeater.addRow();
        } else if (command.equals(this.removeCommand)) {
            removeSelectedRows();
        }
    }
View Full Code Here

            removeSelectedRows();
        }
    }

    private void removeSelectedRows() {
        Repeater repeater = (Repeater) form.getWidget(this.repeaterName);
        for (int i = repeater.getSize() - 1; i >= 0; i--) {
            boolean selected =
                ((Boolean) repeater
                    .getRow(i)
                    .getWidget(this.selectId)
                    .getValue())
                    .booleanValue();
            if (selected)
                repeater.removeRow(i);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.woody.formmodel.Repeater$RepeaterRow

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.