001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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
062            m_class = valueClass;
063        }
064
065        /**
066         * Gets the value class for this column type.<p>
067         *
068         * When calling getColumnData on an implementation of I_CmsDataViewItem for a given column, the returned object's class should match the
069         * value class of the column's type.
070         *
071         * @return the value class of the type
072         */
073        public Class<?> getValueClass() {
074
075            return m_class;
076        }
077    }
078
079    /** The preferred width. */
080    private int m_preferredWidth;
081
082    /** The column id. */
083    private String m_id;
084
085    /** True if column should be sortable. */
086    private boolean m_sortable;
087
088    /** The column type. */
089    private Type m_type;
090
091    /** The nice name to be displayed to the user. */
092    private String m_niceName;
093
094    /**
095     * Creates a new column definition.<p>
096     *
097     * @param id the column id (should be unique among the list of columns for an I_CmsDataView implementation)
098     * @param type the column type
099     * @param niceName the user-readable name of the column
100     * @param sortable true if the column should be sortable
101     * @param preferredWidth the preferred width of the column
102     */
103    public CmsDataViewColumn(String id, Type type, String niceName, boolean sortable, int preferredWidth) {
104
105        m_type = type;
106        m_id = id;
107        m_sortable = sortable;
108        m_niceName = niceName;
109        m_preferredWidth = preferredWidth;
110    }
111
112    /**
113     * Gets the column id.<p>
114     *
115     * The column id is not directly shown to the user; it is used as an internal identifier for the column and should be unique.
116     *
117     * @return the column id
118     */
119    public String getId() {
120
121        return m_id;
122    }
123
124    /**
125     * Gets the 'nice name' to display for this column in the table header.<p>
126     *
127     * @return the nice name
128     */
129    public String getNiceName() {
130
131        return m_niceName;
132    }
133
134    /**
135     * Gets the preferred width of the column in pixels.<p>
136     *
137     * @return the preferred width
138     */
139    public int getPreferredWidth() {
140
141        return m_preferredWidth;
142    }
143
144    /**
145     * Gets the column type.<p>
146     *
147     * @return the column type
148     */
149    public Type getType() {
150
151        return m_type;
152    }
153
154    /**
155     * Returns true if this column should be sortable.<p>
156     *
157     * @return true if the column should be sortable
158     */
159    public boolean isSortable() {
160
161        return m_sortable;
162    }
163
164}