001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.widgets.dataview;
029
030/**
031 * This class represents the definition of a column for the table widget used to select data items provided by an I_CmsDataView implementation.<p>
032 */
033public class CmsDataViewColumn {
034
035    /**
036     * The column type.<p>
037     */
038    public static enum Type {
039
040        /** Column contains a text to be displayed. */
041        textType(String.class),
042
043        /** Column contains a value of type Double. */
044        doubleType(Double.class),
045
046        /** Column contains a string representing an URL pointing to an image. */
047        imageType(String.class),
048
049        /** Column contains a value of type Boolean. */
050        booleanType(Boolean.class);
051
052        /** The value class of the column type. */
053        private Class<?> m_class;
054
055        /**
056         * Private constructor for types.<p>
057         *
058         * @param valueClass the value class
059         */
060        private Type(Class<?> valueClass) {
061            m_class = valueClass;
062        }
063
064        /**
065         * Gets the value class for this column type.<p>
066         *
067         * When calling getColumnData on an implementation of I_CmsDataViewItem for a given column, the returned object's class should match the
068         * value class of the column's type.
069         *
070         * @return the value class of the type
071         */
072        public Class<?> getValueClass() {
073
074            return m_class;
075        }
076    }
077
078    /** The preferred width. */
079    private int m_preferredWidth;
080
081    /** The column id. */
082    private String m_id;
083
084    /** True if column should be sortable. */
085    private boolean m_sortable;
086
087    /** The column type. */
088    private Type m_type;
089
090    /** The nice name to be displayed to the user. */
091    private String m_niceName;
092
093    /**
094     * Creates a new column definition.<p>
095     *
096     * @param id the column id (should be unique among the list of columns for an I_CmsDataView implementation)
097     * @param type the column type
098     * @param niceName the user-readable name of the column
099     * @param sortable true if the column should be sortable
100     * @param preferredWidth the preferred width of the column
101     */
102    public CmsDataViewColumn(String id, Type type, String niceName, boolean sortable, int preferredWidth) {
103        m_type = type;
104        m_id = id;
105        m_sortable = sortable;
106        m_niceName = niceName;
107        m_preferredWidth = preferredWidth;
108    }
109
110    /**
111     * Gets the column id.<p>
112     *
113     * The column id is not directly shown to the user; it is used as an internal identifier for the column and should be unique.
114     *
115     * @return the column id
116     */
117    public String getId() {
118
119        return m_id;
120    }
121
122    /**
123     * Gets the 'nice name' to display for this column in the table header.<p>
124     *
125     * @return the nice name
126     */
127    public String getNiceName() {
128
129        return m_niceName;
130    }
131
132    /**
133     * Gets the preferred width of the column in pixels.<p>
134     *
135     * @return the preferred width
136     */
137    public int getPreferredWidth() {
138
139        return m_preferredWidth;
140    }
141
142    /**
143     * Gets the column type.<p>
144     *
145     * @return the column type
146     */
147    public Type getType() {
148
149        return m_type;
150    }
151
152    /**
153     * Returns true if this column should be sortable.<p>
154     *
155     * @return true if the column should be sortable
156     */
157    public boolean isSortable() {
158
159        return m_sortable;
160    }
161
162}