001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Anahide Tchertchian
018 */
019package org.nuxeo.ecm.platform.forms.layout.service;
020
021import org.jboss.seam.ScopeType;
022import org.jboss.seam.annotations.Name;
023import org.jboss.seam.annotations.Scope;
024
025/**
026 * Helper component to count number of columns rendered in a layout context.
027 * <p>
028 * Useful when rendering listing layouts in a PDF table, where number of columns need to be known in advance.
029 *
030 * @since 5.4.2
031 */
032// TODO: move this dependency to Seam elsewhere
033@Name("layoutColumnCounter")
034@Scope(ScopeType.EVENT)
035public class LayoutColumnCounter {
036
037    protected Integer index;
038
039    public Integer getCurrentIndex() {
040        return index;
041    }
042
043    public void setCurrentIndex(Integer index) {
044        this.index = index;
045    }
046
047    public void increment() {
048        if (index == null) {
049            index = new Integer(0);
050        }
051        this.index = new Integer(index.intValue() + 1);
052    }
053
054    public void decrement() {
055        if (index == null) {
056            index = new Integer(0);
057        }
058        this.index = new Integer(index.intValue() - 1);
059    }
060
061}