KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > NodeTableModel


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 package org.openide.explorer.view;
20
21 import org.openide.DialogDescriptor;
22 import org.openide.DialogDisplayer;
23 import org.openide.nodes.Node;
24 import org.openide.nodes.Node.Property;
25 import org.openide.util.NbBundle;
26
27 import java.awt.*;
28
29 import java.beans.PropertyChangeEvent JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.TreeMap JavaDoc;
36
37 import javax.swing.*;
38 import javax.swing.table.AbstractTableModel JavaDoc;
39
40
41 /**
42 * Table model with properties (<code>Node.Property</code>) as columns and nodes (<code>Node</code>) as rows.
43 * It is used as model for displaying node properties in table. Each column is represented by
44 * <code>Node.Property</code> object. Each row is represented by <code>Node</code> object.
45 * Each cell contains <code>Node.Property</code> property which equals with column object
46 * and should be in property sets of row representant (<code>Node</code>).
47 *
48 * @author Jan Rojcek
49 * @since 1.7
50 */

51 public class NodeTableModel extends AbstractTableModel JavaDoc {
52     private static final String JavaDoc ATTR_INVISIBLE = "InvisibleInTreeTableView"; // NOI18N
53
static final String JavaDoc ATTR_COMPARABLE_COLUMN = "ComparableColumnTTV"; // NOI18N
54
static final String JavaDoc ATTR_SORTING_COLUMN = "SortingColumnTTV"; // NOI18N
55
static final String JavaDoc ATTR_DESCENDING_ORDER = "DescendingOrderTTV"; // NOI18N
56
private static final String JavaDoc ATTR_ORDER_NUMBER = "OrderNumberTTV"; // NOI18N
57
private static final String JavaDoc ATTR_TREE_COLUMN = "TreeColumnTTV"; // NOI18N
58
private static final String JavaDoc ATTR_MNEMONIC_CHAR = "ColumnMnemonicCharTTV"; // NOI18N
59

60     /** all columns of model */
61     ArrayColumn[] allPropertyColumns = new ArrayColumn[] { };
62
63     /** visible columns of model */
64     private int[] propertyColumns = new int[] { };
65
66     /** rows of model */
67     private Node[] nodeRows = new Node[] { };
68
69     /** sorting column */
70     private int sortColumn = -1;
71
72     /** if true, at least one column can be used to sort */
73     private boolean existsComparableColumn = false;
74     private Property treeColumnProperty = null;
75
76     /** listener on node properties changes, recreates displayed data */
77     private PropertyChangeListener JavaDoc pcl = new PropertyChangeListener JavaDoc() {
78             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
79                 //fireTableDataChanged();
80
int row = rowForNode((Node) evt.getSource());
81
82                 if (row == -1) {
83                     return;
84                 }
85
86                 int column = columnForProperty(evt.getPropertyName());
87
88                 if (column == -1) {
89                     fireTableRowsUpdated(row, row);
90                 } else {
91                     fireTableCellUpdated(row, column);
92                 }
93             }
94         };
95
96     /** Set rows.
97      * @param nodes the rows
98      */

99     public void setNodes(Node[] nodes) {
100         for (int i = 0; i < nodeRows.length; i++)
101             nodeRows[i].removePropertyChangeListener(pcl);
102
103         nodeRows = nodes;
104
105         for (int i = 0; i < nodeRows.length; i++)
106             nodeRows[i].addPropertyChangeListener(pcl);
107
108         fireTableDataChanged();
109     }
110
111     /** Set columns.
112      * @param props the columns
113      */

114     public void setProperties(Property[] props) {
115         int size = props.length;
116         sortColumn = -1;
117
118         int treePosition = -1;
119
120         for (int i = 0; i < props.length; i++) {
121             Object JavaDoc o = props[i].getValue(ATTR_TREE_COLUMN);
122             boolean x;
123
124             if ((o != null) && o instanceof Boolean JavaDoc) {
125                 if (((Boolean JavaDoc) o).booleanValue()) {
126                     treeColumnProperty = props[i];
127                     size--;
128                     treePosition = i;
129                 }
130             }
131         }
132
133         allPropertyColumns = new ArrayColumn[size];
134
135         int visibleCount = 0;
136         existsComparableColumn = false;
137
138         TreeMap JavaDoc<Double JavaDoc, Integer JavaDoc> sort = new TreeMap JavaDoc<Double JavaDoc, Integer JavaDoc>();
139         int i = 0;
140         int ia = 0;
141
142         while (i < props.length) {
143             if (i != treePosition) {
144                 allPropertyColumns[ia] = new ArrayColumn();
145                 allPropertyColumns[ia].setProperty(props[i]);
146
147                 if (isVisible(props[i])) {
148                     visibleCount++;
149
150                     Object JavaDoc o = props[i].getValue(ATTR_ORDER_NUMBER);
151
152                     if ((o != null) && o instanceof Integer JavaDoc) {
153                         sort.put(new Double JavaDoc(((Integer JavaDoc) o).doubleValue()), Integer.valueOf(ia));
154                     } else {
155                         sort.put(new Double JavaDoc(ia + 0.1), new Integer JavaDoc(ia));
156                     }
157                 } else {
158                     allPropertyColumns[ia].setVisibleIndex(-1);
159
160                     Object JavaDoc o = props[i].getValue(ATTR_SORTING_COLUMN);
161
162                     if ((o != null) && o instanceof Boolean JavaDoc) {
163                         props[i].setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
164                     }
165                 }
166
167                 if (!existsComparableColumn) {
168                     Object JavaDoc o = props[i].getValue(ATTR_COMPARABLE_COLUMN);
169
170                     if ((o != null) && o instanceof Boolean JavaDoc) {
171                         existsComparableColumn = ((Boolean JavaDoc) o).booleanValue();
172                     }
173                 }
174
175                 ia++;
176             }
177
178             i++;
179         }
180
181         // visible columns
182
propertyColumns = new int[visibleCount];
183
184         int j = 0;
185         Iterator JavaDoc it = sort.values().iterator();
186
187         while (it.hasNext()) {
188             i = ((Integer JavaDoc) it.next()).intValue();
189             allPropertyColumns[i].setVisibleIndex(j);
190             propertyColumns[j] = i;
191             j++;
192         }
193
194         fireTableStructureChanged();
195     }
196
197     /* recompute set of visible columns
198      */

199     private void computeVisiblePorperties(int visCount) {
200         propertyColumns = new int[visCount];
201
202         TreeMap JavaDoc<Double JavaDoc, Integer JavaDoc> sort = new TreeMap JavaDoc<Double JavaDoc, Integer JavaDoc>();
203
204         for (int i = 0; i < allPropertyColumns.length; i++) {
205             int vi = allPropertyColumns[i].getVisibleIndex();
206
207             if (vi == -1) {
208                 sort.put(new Double JavaDoc(i - 0.1), Integer.valueOf(i));
209             } else {
210                 sort.put(new Double JavaDoc(vi), Integer.valueOf(i));
211             }
212         }
213
214         int j = 0;
215         Iterator JavaDoc<Integer JavaDoc> it = sort.values().iterator();
216
217         while (it.hasNext()) {
218             int i = it.next().intValue();
219             Property p = allPropertyColumns[i].getProperty();
220
221             if (isVisible(p)) {
222                 propertyColumns[j] = i;
223                 allPropertyColumns[i].setVisibleIndex(j);
224                 j++;
225             } else {
226                 allPropertyColumns[i].setVisibleIndex(-1);
227
228                 Object JavaDoc o = p.getValue(ATTR_SORTING_COLUMN);
229
230                 if ((o != null) && o instanceof Boolean JavaDoc) {
231                     if (((Boolean JavaDoc) o).booleanValue()) {
232                         p.setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
233                         p.setValue(ATTR_DESCENDING_ORDER, Boolean.FALSE);
234                     }
235                 }
236             }
237         }
238
239         fireTableStructureChanged();
240     }
241
242     /** Get width of visible column.
243      * @param column number
244      * @return column width
245      */

246     int getVisibleColumnWidth(int column) {
247         return allPropertyColumns[propertyColumns[column]].getWidth();
248     }
249
250     /** Get width of column from whole property set
251      * @param column number
252      * @return column width
253      */

254     int getArrayColumnWidth(int column) {
255         return allPropertyColumns[column].getWidth();
256     }
257
258     /** Set width of visible column.
259      * @param column number
260      * @param column width
261      */

262     void setVisibleColumnWidth(int column, int width) {
263         allPropertyColumns[propertyColumns[column]].setWidth(width);
264     }
265
266     /** Set width of column from whole property set
267      * @param column number
268      * @param column width
269      */

270     void setArrayColumnWidth(int column, int width) {
271         allPropertyColumns[column].setWidth(width);
272     }
273
274     /** Get index of visible column
275      * @param column number from whole property set
276      * @return column index
277      */

278     int getVisibleIndex(int arrayIndex) {
279         return allPropertyColumns[arrayIndex].getVisibleIndex();
280     }
281
282     /** Get index of visible column
283      * @param column number from whole property set
284      * @return column index
285      */

286     int getArrayIndex(int visibleIndex) {
287         for (int i = 0; i < allPropertyColumns.length; i++) {
288             if (allPropertyColumns[i].getVisibleIndex() == visibleIndex) {
289                 return i;
290             }
291         }
292
293         return -1;
294     }
295
296     /**
297      * If true, column property should be comparable - allows sorting
298      * @param column Index of a visible column
299      */

300     boolean isComparableColumn(int column) {
301         return isComparableColumnEx(propertyColumns[column]);
302     }
303
304     /**
305      * If true, column property should be comparable - allows sorting
306      * @param column Index to the array of all properties
307      */

308     boolean isComparableColumnEx(int column) {
309         Property p = allPropertyColumns[column].getProperty();
310         Object JavaDoc o = p.getValue(ATTR_COMPARABLE_COLUMN);
311
312         if ((o != null) && o instanceof Boolean JavaDoc) {
313             return ((Boolean JavaDoc) o).booleanValue();
314         }
315
316         return false;
317     }
318
319     /**
320      * @param column Index to the array of all properties
321      * @return True if the property at the given index is visible
322      */

323     boolean isVisibleColumnEx(int column) {
324         for (int i = 0; i < propertyColumns.length; i++) {
325             if (column == propertyColumns[i]) {
326                 return true;
327             }
328         }
329
330         return false;
331     }
332
333     /* If true, at least one column is comparable
334      */

335     boolean existsComparableColumn() {
336         return existsComparableColumn;
337     }
338
339     /**
340      * If true, column is currently used for sorting
341      * @param Index to the array of all properties (the column may not be visible)
342      */

343     boolean isSortingColumnEx(int column) {
344         Property p = allPropertyColumns[column].getProperty();
345         Object JavaDoc o = p.getValue(ATTR_SORTING_COLUMN);
346
347         if ((o != null) && o instanceof Boolean JavaDoc) {
348             return ((Boolean JavaDoc) o).booleanValue();
349         }
350
351         return false;
352     }
353
354     /**
355      * Sets column to be currently used for sorting
356      *@param Index to the array of all properties (the column may not by visible)
357      */

358     void setSortingColumnEx(int column) {
359         if (sortColumn != -1) {
360             Property p = allPropertyColumns[sortColumn].getProperty();
361             p.setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
362             p.setValue(ATTR_DESCENDING_ORDER, Boolean.FALSE);
363         }
364
365         if (column != -1) {
366             sortColumn = column; //propertyColumns[column];
367

368             Property p = allPropertyColumns[sortColumn].getProperty();
369             p.setValue(ATTR_SORTING_COLUMN, Boolean.TRUE);
370         } else {
371             sortColumn = -1;
372         }
373     }
374
375     int translateVisibleColumnIndex(int index) {
376         if (index < 0) {
377             return index;
378         }
379
380         return propertyColumns[index];
381     }
382
383     /* Gets column index of sorting column, if it's visible.
384      * Otherwise returns -1.
385      */

386     int getVisibleSortingColumn() {
387         if (sortColumn == -1) {
388             for (int i = 0; i < propertyColumns.length; i++) {
389                 if (isSortingColumnEx(propertyColumns[i])) {
390                     sortColumn = propertyColumns[i];
391
392                     return i;
393                 }
394             }
395         } else {
396             if (isVisible(allPropertyColumns[sortColumn].getProperty())) {
397                 return getVisibleIndex(sortColumn);
398             }
399         }
400
401         return -1;
402     }
403
404     /* Gets column index of sorting column, if it's visible.
405      * Otherwise returns -1.
406      */

407     int getSortingColumn() {
408         if (sortColumn == -1) {
409             for (int i = 0; i < allPropertyColumns.length; i++) {
410                 if (isSortingColumnEx(i)) {
411                     sortColumn = i;
412
413                     return i;
414                 }
415             }
416         } else {
417             return sortColumn;
418         }
419
420         return -1;
421     }
422
423     /* If true, current sorting uses descending order.
424      */

425     boolean isSortOrderDescending() {
426         if (sortColumn == -1) {
427             return false;
428         }
429
430         Property p = allPropertyColumns[sortColumn].getProperty();
431         Object JavaDoc o = p.getValue(ATTR_DESCENDING_ORDER);
432
433         if ((o != null) && o instanceof Boolean JavaDoc) {
434             return ((Boolean JavaDoc) o).booleanValue();
435         }
436
437         return false;
438     }
439
440     /* Sets sorting order for current sorting.
441      */

442     void setSortOrderDescending(boolean descending) {
443         if (sortColumn != -1) {
444             Property p = allPropertyColumns[sortColumn].getProperty();
445             p.setValue(ATTR_DESCENDING_ORDER, descending ? Boolean.TRUE : Boolean.FALSE);
446         }
447     }
448
449     /** Returns node property if found in nodes property sets. Could be overriden to
450      * return property which is not in nodes property sets.
451      * @param node represents single row
452      * @param prop represents column
453      * @return nodes property
454      */

455     protected Property getPropertyFor(Node node, Property prop) {
456         Node.PropertySet[] propSets = node.getPropertySets();
457
458         for (int i = 0; i < propSets.length; i++) {
459             Node.Property[] props = propSets[i].getProperties();
460
461             for (int j = 0; j < props.length; j++) {
462                 if (prop.equals(props[j])) {
463                     return props[j];
464                 }
465             }
466         }
467
468         return null;
469     }
470
471     /** Helper method to ask for a node representant of row.
472      */

473     Node nodeForRow(int row) {
474         return nodeRows[row];
475     }
476
477     /**
478      * Helper method to ask for a property representant of column.
479      * @param Index of a visible column
480      */

481     Property propertyForColumn(int column) {
482         if (column >= 0) {
483             column = propertyColumns[column];
484         }
485
486         return propertyForColumnEx(column);
487     }
488
489     /**
490      * Helper method to ask for a property representant of column.
491      * @param Index to the array of all properties.
492      */

493     Property propertyForColumnEx(int column) {
494         if (column == -1) {
495             return treeColumnProperty;
496         } else {
497             return allPropertyColumns[column].getProperty();
498         }
499     }
500
501     /**
502      * @return The count of all properties (includes invisible columns)
503      */

504     int getColumnCountEx() {
505         return allPropertyColumns.length;
506     }
507
508     private int rowForNode(Node node) {
509         for (int i = 0; i < nodeRows.length; i++) {
510             if (node.equals(nodeRows[i])) {
511                 return i;
512             }
513         }
514
515         return -1;
516     }
517
518     private int columnForProperty(String JavaDoc propName) {
519         for (int i = 0; i < propertyColumns.length; i++) {
520             if (allPropertyColumns[propertyColumns[i]].getProperty().getName().equals(propName)) {
521                 return i;
522             }
523         }
524
525         return -1;
526     }
527
528     /** Helper method to ask if column representing a property should be
529      * visible
530      */

531     private boolean isVisible(Property p) {
532         Object JavaDoc o = p.getValue(ATTR_INVISIBLE);
533
534         if ((o != null) && o instanceof Boolean JavaDoc) {
535             return !((Boolean JavaDoc) o).booleanValue();
536         }
537
538         return true;
539     }
540
541     /** Set column representing a property to be visible
542      */

543     private void setVisible(Property p, boolean visible) {
544         p.setValue(ATTR_INVISIBLE, (!visible) ? Boolean.TRUE : Boolean.FALSE);
545     }
546
547     //
548
// TableModel methods
549
//
550

551     /** Getter for row count.
552      * @return row count
553      */

554     public int getRowCount() {
555         return nodeRows.length;
556     }
557
558     /** Getter for column count.
559      * @return column count
560      */

561     public int getColumnCount() {
562         return propertyColumns.length;
563     }
564
565     /** Getter for property.
566      * @param row table row index
567      * @param column table column index
568      * @return property at (row, column)
569      */

570     public Object JavaDoc getValueAt(int row, int column) {
571         return getPropertyFor(nodeRows[row], allPropertyColumns[propertyColumns[column]].getProperty());
572     }
573
574     /** Cell is editable only if it has non null value.
575      * @param row table row index
576      * @param column table column index
577      * @return true if cell contains non null value
578      */

579     public boolean isCellEditable(int row, int column) {
580         return getValueAt(row, column) != null;
581     }
582
583     /** Getter for column class.
584      * @param column table column index
585      * @return <code>Node.Property.class</code>
586      */

587     public Class JavaDoc getColumnClass(int column) {
588         return Node.Property.class;
589     }
590
591     /** Getter for column name
592      * @param column table column index
593      * @return display name of property which represents column
594      */

595     public String JavaDoc getColumnName(int column) {
596         return getColumnNameEx(propertyColumns[column]);
597     }
598
599     /** Getter for column name
600      * @param column table column index
601      * @return display name of property which represents column
602      */

603     String JavaDoc getColumnNameEx(int column) {
604         return allPropertyColumns[column].getProperty().getDisplayName();
605     }
606
607     /* display panel to set/unset set of visible columns
608      */

609     boolean selectVisibleColumns(String JavaDoc viewName, String JavaDoc treeColumnName, String JavaDoc treeColumnDesc) {
610         boolean changed = false;
611
612         javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc();
613         panel.setLayout(new GridBagLayout());
614         
615         panel.getAccessibleContext().setAccessibleName(
616                 NbBundle.getBundle(NodeTableModel.class).getString("ACSN_ColumnDialog") );
617         panel.getAccessibleContext().setAccessibleDescription(
618                 NbBundle.getBundle(NodeTableModel.class).getString("ACSD_ColumnDialog") );
619
620         ArrayList JavaDoc<JCheckBox> boxes = new ArrayList JavaDoc<JCheckBox>(allPropertyColumns.length);
621         boolean[] oldvalues = new boolean[allPropertyColumns.length];
622         int[] sortpointer = new int[allPropertyColumns.length];
623         GridBagConstraints gridBagConstraints = new GridBagConstraints();
624         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
625         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
626         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
627         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
628         gridBagConstraints.weightx = 1.0;
629
630         GridBagConstraints labelConstraints = new GridBagConstraints();
631         labelConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
632         labelConstraints.anchor = java.awt.GridBagConstraints.WEST;
633         labelConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
634         labelConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
635         labelConstraints.weightx = 1.0;
636
637         JLabel desc = new JLabel(NbBundle.getBundle(NodeTableModel.class).getString("LBL_ColumnDialogDesc"));
638         panel.add(desc, labelConstraints);
639
640         GridBagConstraints firstConstraints = new GridBagConstraints();
641         firstConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
642         firstConstraints.anchor = java.awt.GridBagConstraints.WEST;
643         firstConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
644         firstConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
645         firstConstraints.weightx = 1.0;
646
647         JCheckBox first = new JCheckBox(treeColumnName + ": " + treeColumnDesc, true); // NOI18N
648
first.setEnabled(false);
649         panel.add(first, firstConstraints);
650
651         String JavaDoc boxtext;
652         TreeMap JavaDoc<String JavaDoc, Integer JavaDoc> sort = new TreeMap JavaDoc<String JavaDoc, Integer JavaDoc>();
653
654         for (int i = 0; i < allPropertyColumns.length; i++) {
655             oldvalues[i] = isVisible(allPropertyColumns[i].getProperty());
656             boxtext = allPropertyColumns[i].getProperty().getDisplayName() + ": " +
657                 allPropertyColumns[i].getProperty().getShortDescription(); // NOI18N
658
sort.put(boxtext, Integer.valueOf(i));
659         }
660
661         Iterator JavaDoc<String JavaDoc> it = sort.keySet().iterator();
662         int j = 0;
663
664         while (it.hasNext()) {
665             boxtext = it.next();
666
667             int i = sort.get(boxtext).intValue();
668             JCheckBox b = new JCheckBox(boxtext, oldvalues[i]);
669             makeAccessibleCheckBox(b, allPropertyColumns[i].getProperty());
670             sortpointer[j] = i;
671             panel.add(b, gridBagConstraints);
672             boxes.add(b);
673             j++;
674         }
675
676         String JavaDoc title = NbBundle.getMessage(NodeTableModel.class, "LBL_ColumnDialogTitle");
677
678         if ((viewName != null) && (viewName.length() > 0)) {
679             title = viewName + " - " + title; // NOI18N
680
}
681
682         DialogDescriptor dlg = new DialogDescriptor(
683                 panel, title, true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
684                 DialogDescriptor.DEFAULT_ALIGN, null, null
685             );
686
687         final Dialog dialog = DialogDisplayer.getDefault().createDialog(dlg);
688         dialog.setVisible(true);
689
690         if (dlg.getValue().equals(DialogDescriptor.OK_OPTION)) {
691             int num = boxes.size();
692             int nv = 0;
693
694             for (int i = 0; i < num; i++) {
695                 JCheckBox b = boxes.get(i);
696
697                 j = sortpointer[i];
698
699                 if (b.isSelected() != oldvalues[j]) {
700                     setVisible(allPropertyColumns[j].getProperty(), b.isSelected());
701                     changed = true;
702                 }
703
704                 if (b.isSelected()) {
705                     nv++;
706                 }
707             }
708
709             // Don't allow the user to disable ALL columns
710

711             /*
712             if (nv == 0) {
713                 setVisible( allPropertyColumns[0].getProperty(), true );
714                 nv = 1;
715             }
716              */

717             if (changed) {
718                 computeVisiblePorperties(nv);
719             }
720         }
721
722         return changed;
723     }
724
725     void makeAccessibleCheckBox(JCheckBox box, Property p) {
726         box.getAccessibleContext().setAccessibleName(p.getDisplayName());
727         box.getAccessibleContext().setAccessibleDescription(p.getShortDescription());
728
729         Object JavaDoc mnemonicChar = p.getValue(ATTR_MNEMONIC_CHAR);
730
731         if ((null != mnemonicChar) && (mnemonicChar.toString().length() > 0)) {
732             box.setMnemonic(mnemonicChar.toString().charAt(0));
733         }
734     }
735
736     void moveColumn(int from, int to) {
737         int i = propertyColumns[from];
738         int j = propertyColumns[to];
739
740         propertyColumns[from] = j;
741         propertyColumns[to] = i;
742
743         allPropertyColumns[i].setVisibleIndex(to);
744         allPropertyColumns[j].setVisibleIndex(from);
745
746         sortColumn = -1;
747     }
748
749     /* class representing property column
750      */

751     static class ArrayColumn {
752         /** Property representing column */
753         private Property property;
754
755         /** Preferred width of column */
756         private int width;
757
758         /** Column index in table, if it's visible */
759         private int visibleIndex;
760
761         ArrayColumn() {
762         }
763
764         /** Getter for property property.
765          * @return Value of property property.
766          */

767         public Property getProperty() {
768             return this.property;
769         }
770
771         /** Setter for property property.
772          * @param property New value of property property.
773          */

774         public void setProperty(Property property) {
775             this.property = property;
776         }
777
778         /** Getter for property width.
779          * @return Value of property width.
780          */

781         public int getWidth() {
782             return this.width;
783         }
784
785         /** Setter for property width.
786          * @param width New value of property width.
787          */

788         public void setWidth(int width) {
789             this.width = width;
790         }
791
792         /** Getter for property visibleIndex.
793          * @return Value of property visibleIndex.
794          */

795         public int getVisibleIndex() {
796             return this.visibleIndex;
797         }
798
799         /** Setter for property visibleIndex.
800          * @param visibleIndex New value of property visibleIndex.
801          */

802         public void setVisibleIndex(int visibleIndex) {
803             this.visibleIndex = visibleIndex;
804             property.setValue(ATTR_ORDER_NUMBER, new Integer JavaDoc(visibleIndex));
805         }
806     }
807 }
808
Popular Tags