1 19 20 package org.netbeans.modules.viewmodel; 21 22 import java.beans.PropertyEditor ; 23 import org.netbeans.spi.viewmodel.ColumnModel; 24 import org.openide.nodes.PropertySupport; 25 26 30 public class Column extends PropertySupport.ReadWrite { 31 32 private PropertyEditor 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 .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 setValue ( 58 "TreeColumnTTV", 59 Boolean.TRUE 60 ); 61 Character mnemonic = columnModel.getDisplayedMnemonic(); 62 if (mnemonic != null) { 63 setValue("ColumnMnemonicCharTTV", mnemonic); } 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 o = getValue ("OrderNumberTTV"); 78 if (o == null) return -1; 79 return ((Integer ) o).intValue (); 80 } 81 82 boolean isDefault () { 83 return columnModel.getType () == null; 84 } 85 86 public Object getValue () { 87 return null; 88 } 89 90 public void setValue (Object obj) { 91 } 92 93 public Object getValue (String propertyName) { 94 if ("OrderNumberTTV".equals (propertyName)) { 95 int index = columnModel.getCurrentOrderNumber(); 96 if (index != -1) 97 return new Integer (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 propertyName, Object newValue) { 109 if ("OrderNumberTTV".equals (propertyName)) { 110 int index = ((Integer ) 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 ) newValue).booleanValue () 120 ); 121 treeTable.updateColumnWidths (); 122 } else 123 if ("SortingColumnTTV".equals (propertyName)) 124 columnModel.setSorted ( 125 ((Boolean ) newValue).booleanValue () 126 ); 127 else 128 if ("DescendingOrderTTV".equals (propertyName)) 129 columnModel.setSortedDescending ( 130 ((Boolean ) newValue).booleanValue () 131 ); 132 else 133 super.setValue (propertyName, newValue); 134 } 135 136 public PropertyEditor getPropertyEditor () { 137 return propertyEditor; 138 } 139 } 140 141 | Popular Tags |