PageRenderTime 42ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/projects/netbeans-7.3/bugtracking/src/org/netbeans/modules/bugtracking/issuetable/NodeTableModel.java

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