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-2006 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: package org.openide.explorer.view;
042:
043: import org.openide.DialogDescriptor;
044: import org.openide.DialogDisplayer;
045: import org.openide.nodes.Node;
046: import org.openide.nodes.Node.Property;
047: import org.openide.util.NbBundle;
048:
049: import java.awt.*;
050:
051: import java.beans.PropertyChangeEvent;
052: import java.beans.PropertyChangeListener;
053:
054: import java.util.ArrayList;
055: import java.util.Iterator;
056: import java.util.TreeMap;
057:
058: import javax.swing.*;
059: import javax.swing.table.AbstractTableModel;
060: import org.openide.awt.Mnemonics;
061:
062: /**
063: * Table model with properties (<code>Node.Property</code>) as columns and nodes (<code>Node</code>) as rows.
064: * It is used as model for displaying node properties in table. Each column is represented by
065: * <code>Node.Property</code> object. Each row is represented by <code>Node</code> object.
066: * Each cell contains <code>Node.Property</code> property which equals with column object
067: * and should be in property sets of row representant (<code>Node</code>).
068: *
069: * @author Jan Rojcek
070: * @since 1.7
071: */
072: public class NodeTableModel extends AbstractTableModel {
073: private static final String ATTR_INVISIBLE = "InvisibleInTreeTableView"; // NOI18N
074: static final String ATTR_COMPARABLE_COLUMN = "ComparableColumnTTV"; // NOI18N
075: static final String ATTR_SORTING_COLUMN = "SortingColumnTTV"; // NOI18N
076: static final String ATTR_DESCENDING_ORDER = "DescendingOrderTTV"; // NOI18N
077: private static final String ATTR_ORDER_NUMBER = "OrderNumberTTV"; // NOI18N
078: private static final String ATTR_TREE_COLUMN = "TreeColumnTTV"; // NOI18N
079: private static final String ATTR_MNEMONIC_CHAR = "ColumnMnemonicCharTTV"; // NOI18N
080: private static final String ATTR_DISPLAY_NAME_WITH_MNEMONIC = "ColumnDisplayNameWithMnemonicTTV"; // NOI18N
081:
082: /** all columns of model */
083: ArrayColumn[] allPropertyColumns = new ArrayColumn[] {};
084:
085: /** visible columns of model */
086: private int[] propertyColumns = new int[] {};
087:
088: /** rows of model */
089: private Node[] nodeRows = new Node[] {};
090:
091: /** sorting column */
092: private int sortColumn = -1;
093:
094: /** if true, at least one column can be used to sort */
095: private boolean existsComparableColumn = false;
096: private Property treeColumnProperty = null;
097:
098: /** listener on node properties changes, recreates displayed data */
099: private PropertyChangeListener pcl = new PropertyChangeListener() {
100: public void propertyChange(PropertyChangeEvent evt) {
101: //fireTableDataChanged();
102: int row = rowForNode((Node) evt.getSource());
103:
104: if (row == -1) {
105: return;
106: }
107:
108: int column = columnForProperty(evt.getPropertyName());
109:
110: if (column == -1) {
111: fireTableRowsUpdated(row, row);
112: } else {
113: fireTableCellUpdated(row, column);
114: }
115: }
116: };
117:
118: /** Set rows.
119: * @param nodes the rows
120: */
121: public void setNodes(Node[] nodes) {
122: for (int i = 0; i < nodeRows.length; i++)
123: nodeRows[i].removePropertyChangeListener(pcl);
124:
125: nodeRows = nodes;
126:
127: for (int i = 0; i < nodeRows.length; i++)
128: nodeRows[i].addPropertyChangeListener(pcl);
129:
130: fireTableDataChanged();
131: }
132:
133: /** Set columns.
134: * @param props the columns
135: */
136: public void setProperties(Property[] props) {
137: int size = props.length;
138: sortColumn = -1;
139:
140: int treePosition = -1;
141:
142: for (int i = 0; i < props.length; i++) {
143: Object o = props[i].getValue(ATTR_TREE_COLUMN);
144: boolean x;
145:
146: if ((o != null) && o instanceof Boolean) {
147: if (((Boolean) o).booleanValue()) {
148: treeColumnProperty = props[i];
149: size--;
150: treePosition = i;
151: }
152: }
153: }
154:
155: allPropertyColumns = new ArrayColumn[size];
156:
157: int visibleCount = 0;
158: existsComparableColumn = false;
159:
160: TreeMap<Double, Integer> sort = new TreeMap<Double, Integer>();
161: int i = 0;
162: int ia = 0;
163:
164: while (i < props.length) {
165: if (i != treePosition) {
166: allPropertyColumns[ia] = new ArrayColumn();
167: allPropertyColumns[ia].setProperty(props[i]);
168:
169: if (isVisible(props[i])) {
170: visibleCount++;
171:
172: Object o = props[i].getValue(ATTR_ORDER_NUMBER);
173:
174: if ((o != null) && o instanceof Integer) {
175: sort
176: .put(new Double(((Integer) o)
177: .doubleValue()), Integer
178: .valueOf(ia));
179: } else {
180: sort.put(new Double(ia + 0.1), new Integer(ia));
181: }
182: } else {
183: allPropertyColumns[ia].setVisibleIndex(-1);
184:
185: Object o = props[i].getValue(ATTR_SORTING_COLUMN);
186:
187: if ((o != null) && o instanceof Boolean) {
188: props[i].setValue(ATTR_SORTING_COLUMN,
189: Boolean.FALSE);
190: }
191: }
192:
193: if (!existsComparableColumn) {
194: Object o = props[i]
195: .getValue(ATTR_COMPARABLE_COLUMN);
196:
197: if ((o != null) && o instanceof Boolean) {
198: existsComparableColumn = ((Boolean) o)
199: .booleanValue();
200: }
201: }
202:
203: ia++;
204: }
205:
206: i++;
207: }
208:
209: // visible columns
210: propertyColumns = new int[visibleCount];
211:
212: int j = 0;
213: Iterator it = sort.values().iterator();
214:
215: while (it.hasNext()) {
216: i = ((Integer) it.next()).intValue();
217: allPropertyColumns[i].setVisibleIndex(j);
218: propertyColumns[j] = i;
219: j++;
220: }
221:
222: fireTableStructureChanged();
223: }
224:
225: /* recompute set of visible columns
226: */
227: private void computeVisiblePorperties(int visCount) {
228: propertyColumns = new int[visCount];
229:
230: TreeMap<Double, Integer> sort = new TreeMap<Double, Integer>();
231:
232: for (int i = 0; i < allPropertyColumns.length; i++) {
233: int vi = allPropertyColumns[i].getVisibleIndex();
234:
235: if (vi == -1) {
236: sort.put(new Double(i - 0.1), Integer.valueOf(i));
237: } else {
238: sort.put(new Double(vi), Integer.valueOf(i));
239: }
240: }
241:
242: int j = 0;
243: Iterator<Integer> it = sort.values().iterator();
244:
245: while (it.hasNext()) {
246: int i = it.next().intValue();
247: Property p = allPropertyColumns[i].getProperty();
248:
249: if (isVisible(p)) {
250: propertyColumns[j] = i;
251: allPropertyColumns[i].setVisibleIndex(j);
252: j++;
253: } else {
254: allPropertyColumns[i].setVisibleIndex(-1);
255:
256: Object o = p.getValue(ATTR_SORTING_COLUMN);
257:
258: if ((o != null) && o instanceof Boolean) {
259: if (((Boolean) o).booleanValue()) {
260: p.setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
261: p
262: .setValue(ATTR_DESCENDING_ORDER,
263: Boolean.FALSE);
264: }
265: }
266: }
267: }
268:
269: fireTableStructureChanged();
270: }
271:
272: /** Get width of visible column.
273: * @param column number
274: * @return column width
275: */
276: int getVisibleColumnWidth(int column) {
277: return allPropertyColumns[propertyColumns[column]].getWidth();
278: }
279:
280: /** Get width of column from whole property set
281: * @param column number
282: * @return column width
283: */
284: int getArrayColumnWidth(int column) {
285: return allPropertyColumns[column].getWidth();
286: }
287:
288: /** Set width of visible column.
289: * @param column number
290: * @param column width
291: */
292: void setVisibleColumnWidth(int column, int width) {
293: allPropertyColumns[propertyColumns[column]].setWidth(width);
294: }
295:
296: /** Set width of column from whole property set
297: * @param column number
298: * @param column width
299: */
300: void setArrayColumnWidth(int column, int width) {
301: allPropertyColumns[column].setWidth(width);
302: }
303:
304: /** Get index of visible column
305: * @param column number from whole property set
306: * @return column index
307: */
308: int getVisibleIndex(int arrayIndex) {
309: return allPropertyColumns[arrayIndex].getVisibleIndex();
310: }
311:
312: /** Get index of visible column
313: * @param column number from whole property set
314: * @return column index
315: */
316: int getArrayIndex(int visibleIndex) {
317: for (int i = 0; i < allPropertyColumns.length; i++) {
318: if (allPropertyColumns[i].getVisibleIndex() == visibleIndex) {
319: return i;
320: }
321: }
322:
323: return -1;
324: }
325:
326: /**
327: * If true, column property should be comparable - allows sorting
328: * @param column Index of a visible column
329: */
330: boolean isComparableColumn(int column) {
331: return isComparableColumnEx(propertyColumns[column]);
332: }
333:
334: /**
335: * If true, column property should be comparable - allows sorting
336: * @param column Index to the array of all properties
337: */
338: boolean isComparableColumnEx(int column) {
339: Property p = allPropertyColumns[column].getProperty();
340: Object o = p.getValue(ATTR_COMPARABLE_COLUMN);
341:
342: if ((o != null) && o instanceof Boolean) {
343: return ((Boolean) o).booleanValue();
344: }
345:
346: return false;
347: }
348:
349: /**
350: * @param column Index to the array of all properties
351: * @return True if the property at the given index is visible
352: */
353: boolean isVisibleColumnEx(int column) {
354: for (int i = 0; i < propertyColumns.length; i++) {
355: if (column == propertyColumns[i]) {
356: return true;
357: }
358: }
359:
360: return false;
361: }
362:
363: /* If true, at least one column is comparable
364: */
365: boolean existsComparableColumn() {
366: return existsComparableColumn;
367: }
368:
369: /**
370: * If true, column is currently used for sorting
371: * @param Index to the array of all properties (the column may not be visible)
372: */
373: boolean isSortingColumnEx(int column) {
374: Property p = allPropertyColumns[column].getProperty();
375: Object o = p.getValue(ATTR_SORTING_COLUMN);
376:
377: if ((o != null) && o instanceof Boolean) {
378: return ((Boolean) o).booleanValue();
379: }
380:
381: return false;
382: }
383:
384: /**
385: * Sets column to be currently used for sorting
386: *@param Index to the array of all properties (the column may not by visible)
387: */
388: void setSortingColumnEx(int column) {
389: if (sortColumn != -1) {
390: Property p = allPropertyColumns[sortColumn].getProperty();
391: p.setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
392: p.setValue(ATTR_DESCENDING_ORDER, Boolean.FALSE);
393: }
394:
395: if (column != -1) {
396: sortColumn = column; //propertyColumns[column];
397:
398: Property p = allPropertyColumns[sortColumn].getProperty();
399: p.setValue(ATTR_SORTING_COLUMN, Boolean.TRUE);
400: } else {
401: sortColumn = -1;
402: }
403: }
404:
405: int translateVisibleColumnIndex(int index) {
406: if (index < 0) {
407: return index;
408: }
409:
410: return propertyColumns[index];
411: }
412:
413: /* Gets column index of sorting column, if it's visible.
414: * Otherwise returns -1.
415: */
416: int getVisibleSortingColumn() {
417: if (sortColumn == -1) {
418: for (int i = 0; i < propertyColumns.length; i++) {
419: if (isSortingColumnEx(propertyColumns[i])) {
420: sortColumn = propertyColumns[i];
421:
422: return i;
423: }
424: }
425: } else {
426: if (isVisible(allPropertyColumns[sortColumn].getProperty())) {
427: return getVisibleIndex(sortColumn);
428: }
429: }
430:
431: return -1;
432: }
433:
434: /* Gets column index of sorting column, if it's visible.
435: * Otherwise returns -1.
436: */
437: int getSortingColumn() {
438: if (sortColumn == -1) {
439: for (int i = 0; i < allPropertyColumns.length; i++) {
440: if (isSortingColumnEx(i)) {
441: sortColumn = i;
442:
443: return i;
444: }
445: }
446: } else {
447: return sortColumn;
448: }
449:
450: return -1;
451: }
452:
453: /* If true, current sorting uses descending order.
454: */
455: boolean isSortOrderDescending() {
456: if (sortColumn == -1) {
457: return false;
458: }
459:
460: Property p = allPropertyColumns[sortColumn].getProperty();
461: Object o = p.getValue(ATTR_DESCENDING_ORDER);
462:
463: if ((o != null) && o instanceof Boolean) {
464: return ((Boolean) o).booleanValue();
465: }
466:
467: return false;
468: }
469:
470: /* Sets sorting order for current sorting.
471: */
472: void setSortOrderDescending(boolean descending) {
473: if (sortColumn != -1) {
474: Property p = allPropertyColumns[sortColumn].getProperty();
475: p.setValue(ATTR_DESCENDING_ORDER, descending ? Boolean.TRUE
476: : Boolean.FALSE);
477: }
478: }
479:
480: /** Returns node property if found in nodes property sets. Could be overriden to
481: * return property which is not in nodes property sets.
482: * @param node represents single row
483: * @param prop represents column
484: * @return nodes property
485: */
486: protected Property getPropertyFor(Node node, Property prop) {
487: Node.PropertySet[] propSets = node.getPropertySets();
488:
489: for (int i = 0; i < propSets.length; i++) {
490: Node.Property[] props = propSets[i].getProperties();
491:
492: for (int j = 0; j < props.length; j++) {
493: if (prop.equals(props[j])) {
494: return props[j];
495: }
496: }
497: }
498:
499: return null;
500: }
501:
502: /** Helper method to ask for a node representant of row.
503: */
504: Node nodeForRow(int row) {
505: return nodeRows[row];
506: }
507:
508: /**
509: * Helper method to ask for a property representant of column.
510: * @param Index of a visible column
511: */
512: Property propertyForColumn(int column) {
513: if (column >= 0) {
514: column = propertyColumns[column];
515: }
516:
517: return propertyForColumnEx(column);
518: }
519:
520: /**
521: * Helper method to ask for a property representant of column.
522: * @param Index to the array of all properties.
523: */
524: Property propertyForColumnEx(int column) {
525: if (column == -1) {
526: return treeColumnProperty;
527: } else {
528: return allPropertyColumns[column].getProperty();
529: }
530: }
531:
532: /**
533: * @return The count of all properties (includes invisible columns)
534: */
535: int getColumnCountEx() {
536: return allPropertyColumns.length;
537: }
538:
539: private int rowForNode(Node node) {
540: for (int i = 0; i < nodeRows.length; i++) {
541: if (node.equals(nodeRows[i])) {
542: return i;
543: }
544: }
545:
546: return -1;
547: }
548:
549: private int columnForProperty(String propName) {
550: for (int i = 0; i < propertyColumns.length; i++) {
551: if (allPropertyColumns[propertyColumns[i]].getProperty()
552: .getName().equals(propName)) {
553: return i;
554: }
555: }
556:
557: return -1;
558: }
559:
560: /** Helper method to ask if column representing a property should be
561: * visible
562: */
563: private boolean isVisible(Property p) {
564: Object o = p.getValue(ATTR_INVISIBLE);
565:
566: if ((o != null) && o instanceof Boolean) {
567: return !((Boolean) o).booleanValue();
568: }
569:
570: return true;
571: }
572:
573: /** Set column representing a property to be visible
574: */
575: private void setVisible(Property p, boolean visible) {
576: p.setValue(ATTR_INVISIBLE, (!visible) ? Boolean.TRUE
577: : Boolean.FALSE);
578: }
579:
580: //
581: // TableModel methods
582: //
583:
584: /** Getter for row count.
585: * @return row count
586: */
587: public int getRowCount() {
588: return nodeRows.length;
589: }
590:
591: /** Getter for column count.
592: * @return column count
593: */
594: public int getColumnCount() {
595: return propertyColumns.length;
596: }
597:
598: /** Getter for property.
599: * @param row table row index
600: * @param column table column index
601: * @return property at (row, column)
602: */
603: public Object getValueAt(int row, int column) {
604: return getPropertyFor(nodeRows[row],
605: allPropertyColumns[propertyColumns[column]]
606: .getProperty());
607: }
608:
609: /** Cell is editable only if it has non null value.
610: * @param row table row index
611: * @param column table column index
612: * @return true if cell contains non null value
613: */
614: public boolean isCellEditable(int row, int column) {
615: return getValueAt(row, column) != null;
616: }
617:
618: /** Getter for column class.
619: * @param column table column index
620: * @return <code>Node.Property.class</code>
621: */
622: public Class getColumnClass(int column) {
623: return Node.Property.class;
624: }
625:
626: /** Getter for column name
627: * @param column table column index
628: * @return display name of property which represents column
629: */
630: public String getColumnName(int column) {
631: return getColumnNameEx(propertyColumns[column]);
632: }
633:
634: /** Getter for column name
635: * @param column table column index
636: * @return display name of property which represents column
637: */
638: String getColumnNameEx(int column) {
639: return allPropertyColumns[column].getProperty()
640: .getDisplayName();
641: }
642:
643: /* display panel to set/unset set of visible columns
644: */
645: boolean selectVisibleColumns(String viewName,
646: String treeColumnName, String treeColumnDesc) {
647: boolean changed = false;
648:
649: javax.swing.JPanel panel = new javax.swing.JPanel();
650: panel.setLayout(new GridBagLayout());
651:
652: panel.getAccessibleContext().setAccessibleName(
653: NbBundle.getBundle(NodeTableModel.class).getString(
654: "ACSN_ColumnDialog"));
655: panel.getAccessibleContext().setAccessibleDescription(
656: NbBundle.getBundle(NodeTableModel.class).getString(
657: "ACSD_ColumnDialog"));
658:
659: ArrayList<JCheckBox> boxes = new ArrayList<JCheckBox>(
660: allPropertyColumns.length);
661: boolean[] oldvalues = new boolean[allPropertyColumns.length];
662: int[] sortpointer = new int[allPropertyColumns.length];
663: GridBagConstraints gridBagConstraints = new GridBagConstraints();
664: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
665: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
666: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12);
667: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
668: gridBagConstraints.weightx = 1.0;
669:
670: GridBagConstraints labelConstraints = new GridBagConstraints();
671: labelConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
672: labelConstraints.anchor = java.awt.GridBagConstraints.WEST;
673: labelConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
674: labelConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
675: labelConstraints.weightx = 1.0;
676:
677: JLabel desc = new JLabel(NbBundle.getBundle(
678: NodeTableModel.class).getString("LBL_ColumnDialogDesc"));
679: panel.add(desc, labelConstraints);
680:
681: GridBagConstraints firstConstraints = new GridBagConstraints();
682: firstConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
683: firstConstraints.anchor = java.awt.GridBagConstraints.WEST;
684: firstConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
685: firstConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
686: firstConstraints.weightx = 1.0;
687:
688: JCheckBox first = new JCheckBox(treeColumnName + ": "
689: + treeColumnDesc, true); // NOI18N
690: first.setEnabled(false);
691: panel.add(first, firstConstraints);
692:
693: String boxtext;
694: TreeMap<String, Integer> sort = new TreeMap<String, Integer>();
695:
696: for (int i = 0; i < allPropertyColumns.length; i++) {
697: oldvalues[i] = isVisible(allPropertyColumns[i]
698: .getProperty());
699: boxtext = getDisplayNameWithMnemonic(allPropertyColumns[i]
700: .getProperty())
701: + ": "
702: + allPropertyColumns[i].getProperty()
703: .getShortDescription(); // NOI18N
704: sort.put(boxtext, Integer.valueOf(i));
705: }
706:
707: Iterator<String> it = sort.keySet().iterator();
708: int j = 0;
709:
710: while (it.hasNext()) {
711: boxtext = it.next();
712:
713: int i = sort.get(boxtext).intValue();
714: JCheckBox b = new JCheckBox(boxtext, oldvalues[i]);
715: Mnemonics.setLocalizedText(b, boxtext);
716: makeAccessibleCheckBox(b, allPropertyColumns[i]
717: .getProperty());
718: sortpointer[j] = i;
719: panel.add(b, gridBagConstraints);
720: boxes.add(b);
721: j++;
722: }
723:
724: String title = NbBundle.getMessage(NodeTableModel.class,
725: "LBL_ColumnDialogTitle");
726:
727: if ((viewName != null) && (viewName.length() > 0)) {
728: title = viewName + " - " + title; // NOI18N
729: }
730:
731: DialogDescriptor dlg = new DialogDescriptor(panel, title, true,
732: DialogDescriptor.OK_CANCEL_OPTION,
733: DialogDescriptor.OK_OPTION,
734: DialogDescriptor.DEFAULT_ALIGN, null, null);
735:
736: final Dialog dialog = DialogDisplayer.getDefault()
737: .createDialog(dlg);
738: dialog.setVisible(true);
739:
740: if (dlg.getValue().equals(DialogDescriptor.OK_OPTION)) {
741: int num = boxes.size();
742: int nv = 0;
743:
744: for (int i = 0; i < num; i++) {
745: JCheckBox b = boxes.get(i);
746:
747: j = sortpointer[i];
748:
749: if (b.isSelected() != oldvalues[j]) {
750: setVisible(allPropertyColumns[j].getProperty(), b
751: .isSelected());
752: changed = true;
753: }
754:
755: if (b.isSelected()) {
756: nv++;
757: }
758: }
759:
760: // Don't allow the user to disable ALL columns
761:
762: /*
763: if (nv == 0) {
764: setVisible( allPropertyColumns[0].getProperty(), true );
765: nv = 1;
766: }
767: */
768: if (changed) {
769: computeVisiblePorperties(nv);
770: }
771: }
772:
773: return changed;
774: }
775:
776: String getDisplayNameWithMnemonic(Property p) {
777: String res = null;
778: Object displayNameWithMnemonic = p
779: .getValue(ATTR_DISPLAY_NAME_WITH_MNEMONIC);
780: if (null != displayNameWithMnemonic
781: && displayNameWithMnemonic.toString().length() > 0) {
782: res = displayNameWithMnemonic.toString();
783: } else {
784: res = p.getDisplayName();
785: }
786: return res;
787: }
788:
789: void makeAccessibleCheckBox(JCheckBox box, Property p) {
790: box.getAccessibleContext()
791: .setAccessibleName(p.getDisplayName());
792: box.getAccessibleContext().setAccessibleDescription(
793: p.getShortDescription());
794:
795: Object mnemonicChar = p.getValue(ATTR_MNEMONIC_CHAR);
796:
797: if ((null != mnemonicChar)
798: && (mnemonicChar.toString().length() > 0)) {
799: box.setMnemonic(mnemonicChar.toString().charAt(0));
800: }
801: }
802:
803: void moveColumn(int from, int to) {
804: int i = propertyColumns[from];
805: int j = propertyColumns[to];
806:
807: propertyColumns[from] = j;
808: propertyColumns[to] = i;
809:
810: allPropertyColumns[i].setVisibleIndex(to);
811: allPropertyColumns[j].setVisibleIndex(from);
812:
813: sortColumn = -1;
814: }
815:
816: /* class representing property column
817: */
818: static class ArrayColumn {
819: /** Property representing column */
820: private Property property;
821:
822: /** Preferred width of column */
823: private int width;
824:
825: ArrayColumn() {
826: }
827:
828: /** Getter for property property.
829: * @return Value of property property.
830: */
831: public Property getProperty() {
832: return this .property;
833: }
834:
835: /** Setter for property property.
836: * @param property New value of property property.
837: */
838: public void setProperty(Property property) {
839: this .property = property;
840: }
841:
842: /** Getter for property width.
843: * @return Value of property width.
844: */
845: public int getWidth() {
846: return this .width;
847: }
848:
849: /** Setter for property width.
850: * @param width New value of property width.
851: */
852: public void setWidth(int width) {
853: this .width = width;
854: }
855:
856: /** Getter for property visibleIndex.
857: * @return Value of property visibleIndex.
858: */
859: public int getVisibleIndex() {
860: Integer order = (Integer) property
861: .getValue(ATTR_ORDER_NUMBER);
862: if (order == null)
863: return -1;
864: else
865: return order.intValue();
866: }
867:
868: /** Setter for property visibleIndex.
869: * @param visibleIndex New value of property visibleIndex.
870: */
871: public void setVisibleIndex(int visibleIndex) {
872: property.setValue(ATTR_ORDER_NUMBER, new Integer(
873: visibleIndex));
874: }
875: }
876: }
|