View Javadoc
1   /**
2    * This file Copyright (c) 2011-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.workbench.column.definition;
35  
36  /**
37   * Base implementation for all special ColumnDefinitions. Some subclass do not add additional
38   * behavior but still are required because in jcr we configure ColumnDefinition to Column mappings
39   * and only with specific Definitions we know what Column-Type to map to.
40   */
41  public abstract class AbstractColumnDefinition implements ColumnDefinition {
42  
43      private String name;
44  
45      private String label;
46  
47      private int width = -1;
48  
49      private float expandRatio = 0;
50  
51      private boolean sortable = false;
52  
53      private Class<? extends ColumnFormatter> formatterClass;
54  
55      private String propertyName;
56  
57      private boolean displayInChooseDialog = true;
58  
59      private boolean searchable = true;
60  
61      private boolean editable = false;
62  
63      private boolean enabled = true;
64  
65      private Class<? extends ColumnAvailabilityRule> ruleClass;
66  
67      @Override
68      public String getPropertyName() {
69          return propertyName;
70      }
71  
72      public void setPropertyName(String propertyName) {
73          this.propertyName = propertyName;
74      }
75  
76      @Override
77      public String getName() {
78          return name;
79      }
80  
81      public void setName(String name) {
82          this.name = name;
83          // propertyName falls back to name if not explicitly configured
84          if (getPropertyName() == null) {
85              setPropertyName(name);
86          }
87      }
88  
89      /**
90       * {@inheritDoc}
91       * <p>
92       * Default value is -1, meaning no explicit width assigned.
93       */
94      @Override
95      public int getWidth() {
96          return width;
97      }
98  
99      public void setWidth(int width) {
100         this.width = width;
101     }
102 
103     @Override
104     public String getLabel() {
105         return label;
106     }
107 
108     public void setLabel(String label) {
109         this.label = label;
110     }
111 
112     @Override
113     public boolean isSortable() {
114         return sortable;
115     }
116 
117     public void setSortable(boolean sortable) {
118         this.sortable = sortable;
119     }
120 
121     @Override
122     public Class<? extends ColumnFormatter> getFormatterClass() {
123         return this.formatterClass;
124     }
125 
126     public void setFormatterClass(Class<? extends ColumnFormatter> formatterClass) {
127         this.formatterClass = formatterClass;
128     }
129 
130     /**
131      * The concrete type represented in this column, ie Long, Double, Date, etc. By default, it
132      * assumes a String (which should be a good match in most cases). Subclasses are responsible for
133      * returning the actual type.
134      */
135     @Override
136     public Class<?> getType() {
137         return String.class;
138     }
139 
140     /**
141      * By default returns <code>true</code>.
142      */
143     @Override
144     public boolean isDisplayInChooseDialog() {
145         return displayInChooseDialog;
146     }
147 
148     public void setDisplayInChooseDialog(boolean displayInChooseDialog) {
149         this.displayInChooseDialog = displayInChooseDialog;
150     }
151 
152     /**
153      * {@inheritDoc}
154      * <p>
155      * Default value is 1.0.
156      */
157     @Override
158     public float getExpandRatio() {
159         return expandRatio;
160     }
161 
162     public void setExpandRatio(float expandRatio) {
163         this.expandRatio = expandRatio;
164     }
165 
166     /**
167      * {@inheritDoc}
168      * <p>
169      * By default returns <code>true</code>.
170      */
171     @Override
172     public boolean isSearchable() {
173         return searchable;
174     }
175 
176     public void setSearchable(boolean searchable) {
177         this.searchable = searchable;
178     }
179 
180     @Override
181     public boolean isEditable() {
182         return editable;
183     }
184 
185     public void setEditable(boolean editable) {
186         this.editable = editable;
187     }
188 
189     @Override
190     public boolean isEnabled() {
191         return enabled;
192     }
193 
194     public void setEnabled(boolean enabled) {
195         this.enabled = enabled;
196     }
197 
198     @Override
199     public Class<? extends ColumnAvailabilityRule> getRuleClass() {
200         return this.ruleClass;
201     }
202 
203     public void setRuleClass(Class<? extends ColumnAvailabilityRule> ruleClass) {
204         this.ruleClass = ruleClass;
205     }
206 
207 }