PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/netbeans-7.3/openide.explorer/src/org/openide/explorer/view/NodeTableModel.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 848 lines | 486 code | 151 blank | 211 comment | 111 complexity | b1f062277a0ea41bb4fa6f682bc55843 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.openide.explorer.view;
  45. import org.openide.DialogDescriptor;
  46. import org.openide.DialogDisplayer;
  47. import org.openide.nodes.Node;
  48. import org.openide.nodes.Node.Property;
  49. import org.openide.util.NbBundle;
  50. import java.awt.*;
  51. import java.beans.PropertyChangeEvent;
  52. import java.beans.PropertyChangeListener;
  53. import java.util.ArrayList;
  54. import java.util.Iterator;
  55. import java.util.TreeMap;
  56. import javax.swing.*;
  57. import javax.swing.table.AbstractTableModel;
  58. import org.openide.awt.Mnemonics;
  59. /**
  60. * Table model with properties (<code>Node.Property</code>) as columns and nodes (<code>Node</code>) as rows.
  61. * It is used as model for displaying node properties in table. Each column is represented by
  62. * <code>Node.Property</code> object. Each row is represented by <code>Node</code> object.
  63. * Each cell contains <code>Node.Property</code> property which equals with column object
  64. * and should be in property sets of row representant (<code>Node</code>).
  65. *
  66. * @author Jan Rojcek
  67. * @since 1.7
  68. */
  69. public class NodeTableModel extends AbstractTableModel {
  70. private static final String ATTR_INVISIBLE = "InvisibleInTreeTableView"; // NOI18N
  71. static final String ATTR_COMPARABLE_COLUMN = "ComparableColumnTTV"; // NOI18N
  72. static final String ATTR_SORTING_COLUMN = "SortingColumnTTV"; // NOI18N
  73. static final String ATTR_DESCENDING_ORDER = "DescendingOrderTTV"; // NOI18N
  74. private static final String ATTR_ORDER_NUMBER = "OrderNumberTTV"; // NOI18N
  75. private static final String ATTR_TREE_COLUMN = "TreeColumnTTV"; // NOI18N
  76. private static final String ATTR_MNEMONIC_CHAR = "ColumnMnemonicCharTTV"; // NOI18N
  77. private static final String ATTR_DISPLAY_NAME_WITH_MNEMONIC = "ColumnDisplayNameWithMnemonicTTV"; // NOI18N
  78. /** all columns of model */
  79. ArrayColumn[] allPropertyColumns = new ArrayColumn[] { };
  80. /** visible columns of model */
  81. private int[] propertyColumns = new int[] { };
  82. /** rows of model */
  83. private Node[] nodeRows = new Node[] { };
  84. /** sorting column */
  85. private int sortColumn = -1;
  86. /** if true, at least one column can be used to sort */
  87. private boolean existsComparableColumn = false;
  88. private Property treeColumnProperty = null;
  89. /** listener on node properties changes, recreates displayed data */
  90. private PropertyChangeListener pcl = new PropertyChangeListener() {
  91. public void propertyChange(PropertyChangeEvent evt) {
  92. //fireTableDataChanged();
  93. int row = rowForNode((Node) evt.getSource());
  94. if (row == -1) {
  95. return;
  96. }
  97. int column = columnForProperty(evt.getPropertyName());
  98. if (column == -1) {
  99. fireTableRowsUpdated(row, row);
  100. } else {
  101. fireTableCellUpdated(row, column);
  102. }
  103. }
  104. };
  105. /** Set rows.
  106. * @param nodes the rows
  107. */
  108. public void setNodes(Node[] nodes) {
  109. for (int i = 0; i < nodeRows.length; i++)
  110. nodeRows[i].removePropertyChangeListener(pcl);
  111. nodeRows = nodes;
  112. for (int i = 0; i < nodeRows.length; i++)
  113. nodeRows[i].addPropertyChangeListener(pcl);
  114. fireTableDataChanged();
  115. }
  116. /** Set columns.
  117. * @param props the columns
  118. */
  119. public void setProperties(Property[] props) {
  120. int size = props.length;
  121. sortColumn = -1;
  122. treeColumnProperty = null;
  123. int treePosition = -1;
  124. for (int i = 0; i < props.length; i++) {
  125. Object o = props[i].getValue(ATTR_TREE_COLUMN);
  126. boolean x;
  127. if ((o != null) && o instanceof Boolean) {
  128. if (((Boolean) o).booleanValue()) {
  129. treeColumnProperty = props[i];
  130. size--;
  131. treePosition = i;
  132. }
  133. }
  134. }
  135. allPropertyColumns = new ArrayColumn[size];
  136. int visibleCount = 0;
  137. existsComparableColumn = false;
  138. TreeMap<Double, Integer> sort = new TreeMap<Double, Integer>();
  139. int i = 0;
  140. int ia = 0;
  141. while (i < props.length) {
  142. if (i != treePosition) {
  143. allPropertyColumns[ia] = new ArrayColumn();
  144. allPropertyColumns[ia].setProperty(props[i]);
  145. if (isVisible(props[i])) {
  146. visibleCount++;
  147. Object o = props[i].getValue(ATTR_ORDER_NUMBER);
  148. if ((o != null) && o instanceof Integer) {
  149. sort.put(new Double(((Integer) o).doubleValue()), Integer.valueOf(ia));
  150. } else {
  151. sort.put(new Double(ia + 0.1), new Integer(ia));
  152. }
  153. } else {
  154. allPropertyColumns[ia].setVisibleIndex(-1);
  155. Object o = props[i].getValue(ATTR_SORTING_COLUMN);
  156. if ((o != null) && o instanceof Boolean) {
  157. props[i].setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
  158. }
  159. }
  160. if (!existsComparableColumn) {
  161. Object o = props[i].getValue(ATTR_COMPARABLE_COLUMN);
  162. if ((o != null) && o instanceof Boolean) {
  163. existsComparableColumn = ((Boolean) o).booleanValue();
  164. }
  165. }
  166. ia++;
  167. }
  168. i++;
  169. }
  170. // visible columns
  171. propertyColumns = new int[visibleCount];
  172. int j = 0;
  173. Iterator it = sort.values().iterator();
  174. while (it.hasNext()) {
  175. i = ((Integer) it.next()).intValue();
  176. allPropertyColumns[i].setVisibleIndex(j);
  177. propertyColumns[j] = i;
  178. j++;
  179. }
  180. fireTableStructureChanged();
  181. }
  182. /* recompute set of visible columns
  183. */
  184. private void computeVisiblePorperties(int visCount) {
  185. propertyColumns = new int[visCount];
  186. TreeMap<Double, Integer> sort = new TreeMap<Double, Integer>();
  187. for (int i = 0; i < allPropertyColumns.length; i++) {
  188. int vi = allPropertyColumns[i].getVisibleIndex();
  189. if (vi == -1) {
  190. sort.put(new Double(i - 0.1), Integer.valueOf(i));
  191. } else {
  192. sort.put(new Double(vi), Integer.valueOf(i));
  193. }
  194. }
  195. int j = 0;
  196. Iterator<Integer> it = sort.values().iterator();
  197. while (it.hasNext()) {
  198. int i = it.next().intValue();
  199. Property p = allPropertyColumns[i].getProperty();
  200. if (isVisible(p)) {
  201. propertyColumns[j] = i;
  202. allPropertyColumns[i].setVisibleIndex(j);
  203. j++;
  204. } else {
  205. allPropertyColumns[i].setVisibleIndex(-1);
  206. Object o = p.getValue(ATTR_SORTING_COLUMN);
  207. if ((o != null) && o instanceof Boolean) {
  208. if (((Boolean) o).booleanValue()) {
  209. p.setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
  210. p.setValue(ATTR_DESCENDING_ORDER, Boolean.FALSE);
  211. }
  212. }
  213. }
  214. }
  215. fireTableStructureChanged();
  216. }
  217. /** Get width of visible column.
  218. * @param column number
  219. * @return column width
  220. */
  221. int getVisibleColumnWidth(int column) {
  222. return allPropertyColumns[propertyColumns[column]].getWidth();
  223. }
  224. /** Get width of column from whole property set
  225. * @param column number
  226. * @return column width
  227. */
  228. int getArrayColumnWidth(int column) {
  229. return allPropertyColumns[column].getWidth();
  230. }
  231. /** Set width of visible column.
  232. * @param column number
  233. * @param column width
  234. */
  235. void setVisibleColumnWidth(int column, int width) {
  236. allPropertyColumns[propertyColumns[column]].setWidth(width);
  237. }
  238. /** Set width of column from whole property set
  239. * @param column number
  240. * @param column width
  241. */
  242. void setArrayColumnWidth(int column, int width) {
  243. allPropertyColumns[column].setWidth(width);
  244. }
  245. /** Get index of visible column
  246. * @param column number from whole property set
  247. * @return column index
  248. */
  249. int getVisibleIndex(int arrayIndex) {
  250. return allPropertyColumns[arrayIndex].getVisibleIndex();
  251. }
  252. /** Get index of visible column
  253. * @param column number from whole property set
  254. * @return column index
  255. */
  256. int getArrayIndex(int visibleIndex) {
  257. for (int i = 0; i < allPropertyColumns.length; i++) {
  258. if (allPropertyColumns[i].getVisibleIndex() == visibleIndex) {
  259. return i;
  260. }
  261. }
  262. return -1;
  263. }
  264. /**
  265. * If true, column property should be comparable - allows sorting
  266. * @param column Index of a visible column
  267. */
  268. boolean isComparableColumn(int column) {
  269. return isComparableColumnEx(propertyColumns[column]);
  270. }
  271. /**
  272. * If true, column property should be comparable - allows sorting
  273. * @param column Index to the array of all properties
  274. */
  275. boolean isComparableColumnEx(int column) {
  276. Property p = allPropertyColumns[column].getProperty();
  277. Object o = p.getValue(ATTR_COMPARABLE_COLUMN);
  278. if ((o != null) && o instanceof Boolean) {
  279. return ((Boolean) o).booleanValue();
  280. }
  281. return false;
  282. }
  283. /**
  284. * @param column Index to the array of all properties
  285. * @return True if the property at the given index is visible
  286. */
  287. boolean isVisibleColumnEx(int column) {
  288. for (int i = 0; i < propertyColumns.length; i++) {
  289. if (column == propertyColumns[i]) {
  290. return true;
  291. }
  292. }
  293. return false;
  294. }
  295. /* If true, at least one column is comparable
  296. */
  297. boolean existsComparableColumn() {
  298. return existsComparableColumn;
  299. }
  300. /**
  301. * If true, column is currently used for sorting
  302. * @param Index to the array of all properties (the column may not be visible)
  303. */
  304. boolean isSortingColumnEx(int column) {
  305. Property p = allPropertyColumns[column].getProperty();
  306. Object o = p.getValue(ATTR_SORTING_COLUMN);
  307. if ((o != null) && o instanceof Boolean) {
  308. return ((Boolean) o).booleanValue();
  309. }
  310. return false;
  311. }
  312. /**
  313. * Sets column to be currently used for sorting
  314. *@param Index to the array of all properties (the column may not by visible)
  315. */
  316. void setSortingColumnEx(int column) {
  317. if (sortColumn != -1) {
  318. Property p = allPropertyColumns[sortColumn].getProperty();
  319. p.setValue(ATTR_SORTING_COLUMN, Boolean.FALSE);
  320. p.setValue(ATTR_DESCENDING_ORDER, Boolean.FALSE);
  321. }
  322. if (column != -1) {
  323. sortColumn = column; //propertyColumns[column];
  324. Property p = allPropertyColumns[sortColumn].getProperty();
  325. p.setValue(ATTR_SORTING_COLUMN, Boolean.TRUE);
  326. } else {
  327. sortColumn = -1;
  328. }
  329. }
  330. int translateVisibleColumnIndex(int index) {
  331. if (index < 0) {
  332. return index;
  333. }
  334. return propertyColumns[index];
  335. }
  336. /* Gets column index of sorting column, if it's visible.
  337. * Otherwise returns -1.
  338. */
  339. int getVisibleSortingColumn() {
  340. if (sortColumn == -1) {
  341. for (int i = 0; i < propertyColumns.length; i++) {
  342. if (isSortingColumnEx(propertyColumns[i])) {
  343. sortColumn = propertyColumns[i];
  344. return i;
  345. }
  346. }
  347. } else {
  348. if (isVisible(allPropertyColumns[sortColumn].getProperty())) {
  349. return getVisibleIndex(sortColumn);
  350. }
  351. }
  352. return -1;
  353. }
  354. /* Gets column index of sorting column, if it's visible.
  355. * Otherwise returns -1.
  356. */
  357. int getSortingColumn() {
  358. if (sortColumn == -1) {
  359. for (int i = 0; i < allPropertyColumns.length; i++) {
  360. if (isSortingColumnEx(i)) {
  361. sortColumn = i;
  362. return i;
  363. }
  364. }
  365. } else {
  366. return sortColumn;
  367. }
  368. return -1;
  369. }
  370. /* If true, current sorting uses descending order.
  371. */
  372. boolean isSortOrderDescending() {
  373. if (sortColumn == -1) {
  374. return false;
  375. }
  376. Property p = allPropertyColumns[sortColumn].getProperty();
  377. Object o = p.getValue(ATTR_DESCENDING_ORDER);
  378. if ((o != null) && o instanceof Boolean) {
  379. return ((Boolean) o).booleanValue();
  380. }
  381. return false;
  382. }
  383. /* Sets sorting order for current sorting.
  384. */
  385. void setSortOrderDescending(boolean descending) {
  386. if (sortColumn != -1) {
  387. Property p = allPropertyColumns[sortColumn].getProperty();
  388. p.setValue(ATTR_DESCENDING_ORDER, descending ? Boolean.TRUE : Boolean.FALSE);
  389. }
  390. }
  391. /** Returns node property if found in nodes property sets. Could be overriden to
  392. * return property which is not in nodes property sets.
  393. * @param node represents single row
  394. * @param prop represents column
  395. * @return nodes property
  396. */
  397. protected Property getPropertyFor(Node node, Property prop) {
  398. Node.PropertySet[] propSets = node.getPropertySets();
  399. for (int i = 0; i < propSets.length; i++) {
  400. Node.Property[] props = propSets[i].getProperties();
  401. for (int j = 0; j < props.length; j++) {
  402. if (prop.equals(props[j])) {
  403. return props[j];
  404. }
  405. }
  406. }
  407. return null;
  408. }
  409. /** Helper method to ask for a node representant of row.
  410. */
  411. Node nodeForRow(int row) {
  412. return nodeRows[row];
  413. }
  414. /**
  415. * Helper method to ask for a property representant of column.
  416. * @param Index of a visible column
  417. */
  418. Property propertyForColumn(int column) {
  419. if (column >= 0) {
  420. column = propertyColumns[column];
  421. }
  422. return propertyForColumnEx(column);
  423. }
  424. /**
  425. * Helper method to ask for a property representant of column.
  426. * @param Index to the array of all properties.
  427. */
  428. Property propertyForColumnEx(int column) {
  429. if (column == -1) {
  430. return treeColumnProperty;
  431. } else {
  432. return allPropertyColumns[column].getProperty();
  433. }
  434. }
  435. /**
  436. * @return The count of all properties (includes invisible columns)
  437. */
  438. int getColumnCountEx() {
  439. return allPropertyColumns.length;
  440. }
  441. private int rowForNode(Node node) {
  442. for (int i = 0; i < nodeRows.length; i++) {
  443. if (node.equals(nodeRows[i])) {
  444. return i;
  445. }
  446. }
  447. return -1;
  448. }
  449. private int columnForProperty(String propName) {
  450. for (int i = 0; i < propertyColumns.length; i++) {
  451. if (allPropertyColumns[propertyColumns[i]].getProperty().getName().equals(propName)) {
  452. return i;
  453. }
  454. }
  455. return -1;
  456. }
  457. /** Helper method to ask if column representing a property should be
  458. * visible
  459. */
  460. private boolean isVisible(Property p) {
  461. Object o = p.getValue(ATTR_INVISIBLE);
  462. if ((o != null) && o instanceof Boolean) {
  463. return !((Boolean) o).booleanValue();
  464. }
  465. return true;
  466. }
  467. /** Set column representing a property to be visible
  468. */
  469. private void setVisible(Property p, boolean visible) {
  470. p.setValue(ATTR_INVISIBLE, (!visible) ? Boolean.TRUE : Boolean.FALSE);
  471. }
  472. //
  473. // TableModel methods
  474. //
  475. /** Getter for row count.
  476. * @return row count
  477. */
  478. public int getRowCount() {
  479. return nodeRows.length;
  480. }
  481. /** Getter for column count.
  482. * @return column count
  483. */
  484. public int getColumnCount() {
  485. return propertyColumns.length;
  486. }
  487. /** Getter for property.
  488. * @param row table row index
  489. * @param column table column index
  490. * @return property at (row, column)
  491. */
  492. public Object getValueAt(int row, int column) {
  493. return getPropertyFor(nodeRows[row], allPropertyColumns[propertyColumns[column]].getProperty());
  494. }
  495. /** Cell is editable only if it has non null value.
  496. * @param row table row index
  497. * @param column table column index
  498. * @return true if cell contains non null value
  499. */
  500. @Override
  501. public boolean isCellEditable(int row, int column) {
  502. return getValueAt(row, column) != null;
  503. }
  504. /** Getter for column class.
  505. * @param column table column index
  506. * @return <code>Node.Property.class</code>
  507. */
  508. @Override
  509. public Class getColumnClass(int column) {
  510. return Node.Property.class;
  511. }
  512. /** Getter for column name
  513. * @param column table column index
  514. * @return display name of property which represents column
  515. */
  516. @Override
  517. public String getColumnName(int column) {
  518. return getColumnNameEx(propertyColumns[column]);
  519. }
  520. /** Getter for column name
  521. * @param column table column index
  522. * @return display name of property which represents column
  523. */
  524. String getColumnNameEx(int column) {
  525. return allPropertyColumns[column].getProperty().getDisplayName();
  526. }
  527. /* display panel to set/unset set of visible columns
  528. */
  529. boolean selectVisibleColumns(String viewName, String treeColumnName, String treeColumnDesc) {
  530. boolean changed = false;
  531. javax.swing.JPanel panel = new javax.swing.JPanel();
  532. panel.setLayout(new GridBagLayout());
  533. panel.getAccessibleContext().setAccessibleName(
  534. NbBundle.getMessage(NodeTableModel.class, "ACSN_ColumnDialog") );
  535. panel.getAccessibleContext().setAccessibleDescription(
  536. NbBundle.getMessage(NodeTableModel.class, "ACSD_ColumnDialog") );
  537. ArrayList<JCheckBox> boxes = new ArrayList<JCheckBox>(allPropertyColumns.length);
  538. boolean[] oldvalues = new boolean[allPropertyColumns.length];
  539. int[] sortpointer = new int[allPropertyColumns.length];
  540. GridBagConstraints gridBagConstraints = new GridBagConstraints();
  541. gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  542. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  543. gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12);
  544. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  545. gridBagConstraints.weightx = 1.0;
  546. GridBagConstraints labelConstraints = new GridBagConstraints();
  547. labelConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  548. labelConstraints.anchor = java.awt.GridBagConstraints.WEST;
  549. labelConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
  550. labelConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  551. labelConstraints.weightx = 1.0;
  552. JLabel desc = new JLabel(NbBundle.getMessage(NodeTableModel.class, "LBL_ColumnDialogDesc"));
  553. panel.add(desc, labelConstraints);
  554. GridBagConstraints firstConstraints = new GridBagConstraints();
  555. firstConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  556. firstConstraints.anchor = java.awt.GridBagConstraints.WEST;
  557. firstConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
  558. firstConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  559. firstConstraints.weightx = 1.0;
  560. JCheckBox first = new JCheckBox(treeColumnName + ": " + treeColumnDesc, true); // NOI18N
  561. first.setEnabled(false);
  562. panel.add(first, firstConstraints);
  563. String boxtext;
  564. TreeMap<String, Integer> sort = new TreeMap<String, Integer>();
  565. for (int i = 0; i < allPropertyColumns.length; i++) {
  566. oldvalues[i] = isVisible(allPropertyColumns[i].getProperty());
  567. boxtext = getDisplayNameWithMnemonic( allPropertyColumns[i].getProperty() )
  568. + ": "
  569. + allPropertyColumns[i].getProperty().getShortDescription(); // NOI18N
  570. sort.put(boxtext, Integer.valueOf(i));
  571. }
  572. Iterator<String> it = sort.keySet().iterator();
  573. int j = 0;
  574. while (it.hasNext()) {
  575. boxtext = it.next();
  576. int i = sort.get(boxtext).intValue();
  577. JCheckBox b = new JCheckBox(boxtext, oldvalues[i]);
  578. Mnemonics.setLocalizedText(b, boxtext);
  579. makeAccessibleCheckBox(b, allPropertyColumns[i].getProperty());
  580. sortpointer[j] = i;
  581. panel.add(b, gridBagConstraints);
  582. boxes.add(b);
  583. j++;
  584. }
  585. String title = NbBundle.getMessage(NodeTableModel.class, "LBL_ColumnDialogTitle");
  586. if ((viewName != null) && (viewName.length() > 0)) {
  587. title = viewName + " - " + title; // NOI18N
  588. }
  589. DialogDescriptor dlg = new DialogDescriptor(
  590. panel, title, true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
  591. DialogDescriptor.DEFAULT_ALIGN, null, null
  592. );
  593. final Dialog dialog = DialogDisplayer.getDefault().createDialog(dlg);
  594. dialog.setVisible(true);
  595. if (dlg.getValue().equals(DialogDescriptor.OK_OPTION)) {
  596. int num = boxes.size();
  597. int nv = 0;
  598. for (int i = 0; i < num; i++) {
  599. JCheckBox b = boxes.get(i);
  600. j = sortpointer[i];
  601. if (b.isSelected() != oldvalues[j]) {
  602. setVisible(allPropertyColumns[j].getProperty(), b.isSelected());
  603. changed = true;
  604. }
  605. if (b.isSelected()) {
  606. nv++;
  607. }
  608. }
  609. // Don't allow the user to disable ALL columns
  610. /*
  611. if (nv == 0) {
  612. setVisible( allPropertyColumns[0].getProperty(), true );
  613. nv = 1;
  614. }
  615. */
  616. if (changed) {
  617. computeVisiblePorperties(nv);
  618. }
  619. }
  620. return changed;
  621. }
  622. String getDisplayNameWithMnemonic( Property p ) {
  623. String res = null;
  624. Object displayNameWithMnemonic = p.getValue(ATTR_DISPLAY_NAME_WITH_MNEMONIC);
  625. if( null !=displayNameWithMnemonic && displayNameWithMnemonic.toString().length() > 0 ) {
  626. res = displayNameWithMnemonic.toString();
  627. } else {
  628. res = p.getDisplayName();
  629. }
  630. return res;
  631. }
  632. void makeAccessibleCheckBox(JCheckBox box, Property p) {
  633. box.getAccessibleContext().setAccessibleName(p.getDisplayName());
  634. box.getAccessibleContext().setAccessibleDescription(p.getShortDescription());
  635. Object mnemonicChar = p.getValue(ATTR_MNEMONIC_CHAR);
  636. if ((null != mnemonicChar) && (mnemonicChar.toString().length() > 0)) {
  637. box.setMnemonic(mnemonicChar.toString().charAt(0));
  638. }
  639. }
  640. void moveColumn(int from, int to) {
  641. int i = propertyColumns[from];
  642. int j = propertyColumns[to];
  643. propertyColumns[from] = j;
  644. propertyColumns[to] = i;
  645. allPropertyColumns[i].setVisibleIndex(to);
  646. allPropertyColumns[j].setVisibleIndex(from);
  647. sortColumn = -1;
  648. }
  649. /* class representing property column
  650. */
  651. static class ArrayColumn {
  652. /** Property representing column */
  653. private Property property;
  654. /** Preferred width of column */
  655. private int width;
  656. ArrayColumn() {
  657. }
  658. /** Getter for property property.
  659. * @return Value of property property.
  660. */
  661. public Property getProperty() {
  662. return this.property;
  663. }
  664. /** Setter for property property.
  665. * @param property New value of property property.
  666. */
  667. public void setProperty(Property property) {
  668. this.property = property;
  669. }
  670. /** Getter for property width.
  671. * @return Value of property width.
  672. */
  673. public int getWidth() {
  674. return this.width;
  675. }
  676. /** Setter for property width.
  677. * @param width New value of property width.
  678. */
  679. public void setWidth(int width) {
  680. this.width = width;
  681. }
  682. /** Getter for property visibleIndex.
  683. * @return Value of property visibleIndex.
  684. */
  685. public int getVisibleIndex() {
  686. Integer order = (Integer) property.getValue(ATTR_ORDER_NUMBER);
  687. if (order == null) return -1;
  688. else return order.intValue();
  689. }
  690. /** Setter for property visibleIndex.
  691. * @param visibleIndex New value of property visibleIndex.
  692. */
  693. public void setVisibleIndex(int visibleIndex) {
  694. property.setValue(ATTR_ORDER_NUMBER, new Integer(visibleIndex));
  695. }
  696. }
  697. }