001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.viewmodel;
043:
044: import java.beans.PropertyEditor;
045: import javax.swing.SwingUtilities;
046: import org.netbeans.spi.viewmodel.ColumnModel;
047: import org.openide.nodes.PropertySupport;
048:
049: /**
050: *
051: * @author Jan Jancura
052: */
053: public class Column extends PropertySupport.ReadWrite {
054:
055: private PropertyEditor propertyEditor;
056: private ColumnModel columnModel;
057: private TreeTable treeTable;
058:
059: Column(ColumnModel columnModel, TreeTable treeTable) {
060: super (columnModel.getID(),
061: columnModel.getType() == null ? String.class
062: : columnModel.getType(), columnModel
063: .getDisplayName(), columnModel
064: .getShortDescription());
065: this .columnModel = columnModel;
066: this .treeTable = treeTable;
067: setValue("ComparableColumnTTV", Boolean.valueOf(columnModel
068: .isSortable()));
069: if (columnModel.getType() == null)
070: // Default column!
071: setValue("TreeColumnTTV", Boolean.TRUE);
072: Character mnemonic = columnModel.getDisplayedMnemonic();
073: if (mnemonic != null) {
074: setValue("ColumnMnemonicCharTTV", mnemonic); // NOI18N
075: }
076: this .propertyEditor = columnModel.getPropertyEditor();
077: }
078:
079: int getColumnWidth() {
080: return columnModel.getColumnWidth();
081: }
082:
083: void setColumnWidth(int width) {
084: columnModel.setColumnWidth(width);
085: }
086:
087: int getOrderNumber() {
088: Object o = getValue("OrderNumberTTV");
089: if (o == null)
090: return -1;
091: return ((Integer) o).intValue();
092: }
093:
094: int getModelOrderNumber() {
095: return columnModel.getCurrentOrderNumber();
096: }
097:
098: boolean isDefault() {
099: return columnModel.getType() == null;
100: }
101:
102: public Object getValue() {
103: return null;
104: }
105:
106: public void setValue(Object obj) {
107: }
108:
109: public Object getValue(String propertyName) {
110: if ("OrderNumberTTV".equals(propertyName)) {
111: if (!columnModel.isVisible())
112: return -1;
113: int index = columnModel.getCurrentOrderNumber();
114: if (index != -1) {
115: index = treeTable.getColumnVisibleIndex(this , index);
116: }
117: //System.err.println("Get order of "+this.getDisplayName()+" => "+index);
118: if (index == -1) {
119: return null;
120: } else {
121: return new Integer(index);
122: }
123: }
124: if ("InvisibleInTreeTableView".equals(propertyName))
125: return Boolean.valueOf(!columnModel.isVisible());
126: if ("SortingColumnTTV".equals(propertyName))
127: return Boolean.valueOf(columnModel.isSorted());
128: if ("DescendingOrderTTV".equals(propertyName))
129: return Boolean.valueOf(columnModel.isSortedDescending());
130: return super .getValue(propertyName);
131: }
132:
133: public void setValue(String propertyName, Object newValue) {
134: if ("OrderNumberTTV".equals(propertyName)) {
135: int index = ((Integer) newValue).intValue();
136: //System.err.println("Set order of "+this.getDisplayName()+" <= "+newValue);
137: if (index != -1) {
138: index = treeTable.getColumnGlobalIndex(this , index);
139: columnModel.setCurrentOrderNumber(index);
140: }
141: } else if ("InvisibleInTreeTableView".equals(propertyName)) {
142: columnModel
143: .setVisible(!((Boolean) newValue).booleanValue());
144: SwingUtilities.invokeLater(new Runnable() {
145: public void run() {
146: treeTable.updateColumnWidths();
147: }
148: });
149: } else if ("SortingColumnTTV".equals(propertyName))
150: columnModel.setSorted(((Boolean) newValue).booleanValue());
151: else if ("DescendingOrderTTV".equals(propertyName))
152: columnModel.setSortedDescending(((Boolean) newValue)
153: .booleanValue());
154: else
155: super .setValue(propertyName, newValue);
156: }
157:
158: public PropertyEditor getPropertyEditor() {
159: return propertyEditor;
160: }
161: }
|