View Javadoc

1   /*
2    *  File: AbstractColumn.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.ui.table.model;
12  
13  import java.util.List;
14  import java.util.Vector;
15  
16  /***
17   * Abstract base implemenation of an IColumn.
18   * 
19   * @author Peter Kliem
20   * @version $Id: AbstractColumn.java 180 2007-01-07 18:44:01Z olk $
21   */
22  public abstract class AbstractColumn implements IColumn {
23      /*** column listeners. */
24      protected List<IColumnListener> _listeners;
25  
26      /***
27       * Inform listeners about a value change.
28       * 
29       * @param row row
30       * @param column column
31       * @param oldValue old value
32       * @param newValue new value
33       */
34      protected void fireValueChanged(IRow row, IColumn column, Object oldValue, Object newValue) {
35          if (_listeners != null) {
36              for (IColumnListener listener : _listeners) {
37                  listener.valueChanged(row, column, oldValue, newValue);
38              }
39          }
40      }
41  
42      /***
43       * {@inheritDoc}
44       */
45      public synchronized void addColumnListener(IColumnListener cl) {
46          if (_listeners == null) {
47              _listeners = new Vector<IColumnListener>();
48          }
49          _listeners.add(cl);
50      }
51  
52      /***
53       * {@inheritDoc}
54       */
55      public void remColumnListener(IColumnListener cl) {
56          if (_listeners != null) {
57              _listeners.remove(cl);
58          }
59      }
60  
61      /***
62       * Default implementation: no difference to getContentClass(). {@inheritDoc}
63       */
64      public Class<?> getContentClass(IRow row) {
65          return getContentClass();
66      }
67  
68      /***
69       * Header display always defaults to true. {@inheritDoc}
70       */
71      public boolean displayHeader() {
72          return true;
73      }
74  
75      /***
76       * Deafult: cols are aditable.
77       * 
78       * @return true
79       */
80      public boolean isEditable() {
81          return true;
82      }
83  
84      /***
85       * Default: delegate to <code>isEditable</code>. {@inheritDoc}
86       */
87      public boolean isEditable(IRow row) {
88          return isEditable();
89      }
90  
91  }