1 | package com.framsticks.gui.table; |
---|
2 | |
---|
3 | |
---|
4 | import com.framsticks.gui.ModifiablePanel; |
---|
5 | import com.framsticks.params.Access; |
---|
6 | import com.framsticks.params.ListAccess; |
---|
7 | import com.framsticks.params.Param; |
---|
8 | import com.framsticks.util.FramsticksException; |
---|
9 | import com.framsticks.util.lang.Casting; |
---|
10 | |
---|
11 | import org.apache.logging.log4j.Logger; |
---|
12 | import org.apache.logging.log4j.LogManager; |
---|
13 | |
---|
14 | import javax.swing.*; |
---|
15 | |
---|
16 | /** |
---|
17 | * Panel contains table and allows to manages displaying columns. |
---|
18 | */ |
---|
19 | @SuppressWarnings("serial") |
---|
20 | public class ListPanel extends ModifiablePanel { |
---|
21 | |
---|
22 | private static final Logger log = LogManager.getLogger(ListPanel.class.getName()); |
---|
23 | |
---|
24 | protected final TableModel tableModel; |
---|
25 | protected final JTable table; |
---|
26 | protected final JScrollPane scrollPane; |
---|
27 | |
---|
28 | public ListPanel(Parameters parameters, ListPanelProvider provider) { |
---|
29 | super(parameters); |
---|
30 | |
---|
31 | final ColumnsConfig config = provider.getColumnsConfigs().get(framsClass.getName()); |
---|
32 | log.debug("creating ListPanel for {} using config {}", parameters.framsClass, config); |
---|
33 | |
---|
34 | tableModel = new TableModel(this); |
---|
35 | if (config != null) { |
---|
36 | for (String id : config.getColumnsNames()) { |
---|
37 | Param param = framsClass.getParam(id); |
---|
38 | if (param == null) { |
---|
39 | throw new FramsticksException().msg("requested param not found in frams class").arg("param", id).arg("frams class", framsClass); |
---|
40 | } |
---|
41 | if (!tableModel.addColumnIfSupported(param)) { |
---|
42 | throw new FramsticksException().msg("param is not supported in table view").arg("param", param).arg("frams class", framsClass); |
---|
43 | } |
---|
44 | } |
---|
45 | } else { |
---|
46 | for (Param param : framsClass.getParams()) { |
---|
47 | if (provider.getMaximumColumnNumber() != null && tableModel.getColumnCount() >= provider.getMaximumColumnNumber()) { |
---|
48 | break; |
---|
49 | } |
---|
50 | tableModel.addColumnIfSupported(param); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | table = new JTable(tableModel); |
---|
55 | tableModel.setupTable(); |
---|
56 | table.setShowGrid(false); |
---|
57 | |
---|
58 | scrollPane = new JScrollPane(table); |
---|
59 | setupContentComponent(scrollPane); |
---|
60 | |
---|
61 | table.getTableHeader().setReorderingAllowed(false); |
---|
62 | table.setColumnSelectionAllowed(false); |
---|
63 | table.setCellSelectionEnabled(false); |
---|
64 | table.setColumnSelectionAllowed(false); |
---|
65 | |
---|
66 | this.revalidate(); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | @Override |
---|
71 | protected void applyChanges() { |
---|
72 | } |
---|
73 | |
---|
74 | @Override |
---|
75 | protected void revertChanges() { |
---|
76 | } |
---|
77 | |
---|
78 | @Override |
---|
79 | public void pullValuesFromLocalToUser(Access access) { |
---|
80 | tableModel.attachSource(Casting.throwCast(ListAccess.class, access)); |
---|
81 | refreshControlButtons(); |
---|
82 | } |
---|
83 | |
---|
84 | @Override |
---|
85 | public String getTitle() { |
---|
86 | return "List"; |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * @return the table |
---|
91 | */ |
---|
92 | public JTable getTable() { |
---|
93 | return table; |
---|
94 | } |
---|
95 | |
---|
96 | } |
---|