KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > viewmodel > Column


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.viewmodel;
21
22 import java.beans.PropertyEditor JavaDoc;
23 import org.netbeans.spi.viewmodel.ColumnModel;
24 import org.openide.nodes.PropertySupport;
25
26 /**
27  *
28  * @author Jan Jancura
29  */

30 public class Column extends PropertySupport.ReadWrite {
31
32     private PropertyEditor JavaDoc propertyEditor;
33     private ColumnModel columnModel;
34     private TreeTable treeTable;
35
36
37     Column (
38         ColumnModel columnModel,
39         TreeTable treeTable
40     ) {
41         super (
42             columnModel.getID (),
43             columnModel.getType () == null ?
44                 String JavaDoc.class :
45                 columnModel.getType (),
46             columnModel.getDisplayName (),
47             columnModel.getShortDescription ()
48         );
49         this.columnModel = columnModel;
50         this.treeTable = treeTable;
51         setValue (
52             "ComparableColumnTTV",
53             Boolean.valueOf (columnModel.isSortable ())
54         );
55         if (columnModel.getType () == null)
56             // Default column!
57
setValue (
58                 "TreeColumnTTV",
59                 Boolean.TRUE
60             );
61         Character JavaDoc mnemonic = columnModel.getDisplayedMnemonic();
62         if (mnemonic != null) {
63             setValue("ColumnMnemonicCharTTV", mnemonic); // NOI18N
64
}
65         this.propertyEditor = columnModel.getPropertyEditor ();
66     }
67
68     int getColumnWidth () {
69         return columnModel.getColumnWidth ();
70     }
71     
72     void setColumnWidth (int width) {
73         columnModel.setColumnWidth (width);
74     }
75     
76     int getOrderNumber () {
77         Object JavaDoc o = getValue ("OrderNumberTTV");
78         if (o == null) return -1;
79         return ((Integer JavaDoc) o).intValue ();
80     }
81     
82     boolean isDefault () {
83         return columnModel.getType () == null;
84     }
85     
86     public Object JavaDoc getValue () {
87         return null;
88     }
89     
90     public void setValue (Object JavaDoc obj) {
91     }
92
93     public Object JavaDoc getValue (String JavaDoc propertyName) {
94         if ("OrderNumberTTV".equals (propertyName)) {
95             int index = columnModel.getCurrentOrderNumber();
96             if (index != -1)
97                 return new Integer JavaDoc(index);
98         }
99         if ("InvisibleInTreeTableView".equals (propertyName))
100             return Boolean.valueOf (!columnModel.isVisible ());
101         if ("SortingColumnTTV".equals (propertyName))
102             return Boolean.valueOf (columnModel.isSorted ());
103         if ("DescendingOrderTTV".equals (propertyName))
104             return Boolean.valueOf (columnModel.isSortedDescending ());
105         return super.getValue (propertyName);
106     }
107     
108     public void setValue (String JavaDoc propertyName, Object JavaDoc newValue) {
109         if ("OrderNumberTTV".equals (propertyName)) {
110             int index = ((Integer JavaDoc) newValue).intValue();
111             if (treeTable.isCustomizedColumnIndex(this, index)) {
112                 columnModel.setCurrentOrderNumber(index);
113             } else if (index != -1 && columnModel.getCurrentOrderNumber() != -1) {
114                 columnModel.setCurrentOrderNumber(-1);
115             }
116         } else
117         if ("InvisibleInTreeTableView".equals (propertyName)) {
118             columnModel.setVisible (
119                 !((Boolean JavaDoc) newValue).booleanValue ()
120             );
121             treeTable.updateColumnWidths ();
122         } else
123         if ("SortingColumnTTV".equals (propertyName))
124             columnModel.setSorted (
125                 ((Boolean JavaDoc) newValue).booleanValue ()
126             );
127         else
128         if ("DescendingOrderTTV".equals (propertyName))
129             columnModel.setSortedDescending (
130                 ((Boolean JavaDoc) newValue).booleanValue ()
131             );
132         else
133         super.setValue (propertyName, newValue);
134     }
135
136     public PropertyEditor JavaDoc getPropertyEditor () {
137         return propertyEditor;
138     }
139 }
140
141
Popular Tags