1 package fr.ifremer.quadrige2.ui.swing.common.table;
2
3 /*-
4 * #%L
5 * Quadrige2 Core :: Quadrige2 UI Common
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2017 Ifremer
10 * %%
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * #L%
24 */
25
26
27 import org.jdesktop.swingx.JXTable;
28
29 import javax.swing.ListSelectionModel;
30 import javax.swing.table.JTableHeader;
31 import javax.swing.table.TableColumnModel;
32 import javax.swing.table.TableModel;
33 import java.util.Vector;
34
35 /**
36 * A JXTable that create a SwingTableHeader at init time (useful to prevent NPE on specific context. ex: table in dialog)
37 * <p/>
38 * By default, the SwingTableHeader is set by AbstractTableUIHandler#initTable
39 * <p/>
40 * Created by Ludovic on 13/05/2015.
41 */
42 public class SwingTable extends JXTable {
43
44 /**
45 * <p>Constructor for SwingTable.</p>
46 */
47 public SwingTable() {
48 }
49
50 /**
51 * <p>Constructor for SwingTable.</p>
52 *
53 * @param dm a {@link TableModel} object.
54 */
55 public SwingTable(TableModel dm) {
56 super(dm);
57 }
58
59 /**
60 * <p>Constructor for SwingTable.</p>
61 *
62 * @param dm a {@link TableModel} object.
63 * @param cm a {@link TableColumnModel} object.
64 */
65 public SwingTable(TableModel dm, TableColumnModel cm) {
66 super(dm, cm);
67 }
68
69 /**
70 * <p>Constructor for SwingTable.</p>
71 *
72 * @param dm a {@link TableModel} object.
73 * @param cm a {@link TableColumnModel} object.
74 * @param sm a {@link ListSelectionModel} object.
75 */
76 public SwingTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
77 super(dm, cm, sm);
78 }
79
80 /**
81 * <p>Constructor for SwingTable.</p>
82 *
83 * @param numRows a int.
84 * @param numColumns a int.
85 */
86 public SwingTable(int numRows, int numColumns) {
87 super(numRows, numColumns);
88 }
89
90 /**
91 * <p>Constructor for SwingTable.</p>
92 *
93 * @param rowData a {@link Vector} object.
94 * @param columnNames a {@link Vector} object.
95 */
96 public SwingTable(Vector<?> rowData, Vector<?> columnNames) {
97 super(rowData, columnNames);
98 }
99
100 /**
101 * <p>Constructor for SwingTable.</p>
102 *
103 * @param rowData an array of {@link Object} objects.
104 * @param columnNames an array of {@link Object} objects.
105 */
106 public SwingTable(Object[][] rowData, Object[] columnNames) {
107 super(rowData, columnNames);
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 protected JTableHeader createDefaultTableHeader() {
113 return new SwingTableHeader(columnModel);
114 }
115
116 /** {@inheritDoc} */
117 @Override
118 public SwingTableHeader getTableHeader() {
119 return (SwingTableHeader) super.getTableHeader();
120 }
121
122 /** {@inheritDoc} */
123 @Override
124 public void setSortable(boolean sortable) {
125 super.setSortable(sortable);
126 if (hasSortController()) {
127 getSortController().setSortable(sortable);
128 }
129 }
130 }