source: java/main/src/main/java/com/framsticks/gui/table/ListPanel.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 2.5 KB
RevLine 
[99]1package com.framsticks.gui.table;
2
3
4import com.framsticks.gui.ModifiablePanel;
[100]5import com.framsticks.params.Access;
[99]6import com.framsticks.params.ListAccess;
[100]7import com.framsticks.params.Param;
8import com.framsticks.util.FramsticksException;
[99]9import com.framsticks.util.lang.Casting;
10
[100]11import org.apache.logging.log4j.Logger;
12import org.apache.logging.log4j.LogManager;
[99]13
14import javax.swing.*;
15
16/**
17 * Panel contains table and allows to manages displaying columns.
18 */
19@SuppressWarnings("serial")
20public class ListPanel extends ModifiablePanel {
21
[100]22        private static final Logger log = LogManager.getLogger(ListPanel.class.getName());
[99]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());
[100]32                log.debug("creating ListPanel for {} using config {}", parameters.framsClass, config);
[99]33
[100]34                tableModel = new TableModel(this);
[99]35                if (config != null) {
36                        for (String id : config.getColumnsNames()) {
[100]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                                }
[99]44                        }
45                } else {
[105]46                        for (Param param : framsClass.getParams()) {
[99]47                                if (provider.getMaximumColumnNumber() != null && tableModel.getColumnCount() >= provider.getMaximumColumnNumber()) {
48                                        break;
49                                }
[100]50                                tableModel.addColumnIfSupported(param);
[99]51                        }
52                }
53
54                table = new JTable(tableModel);
[100]55                tableModel.setupTable();
[101]56                table.setShowGrid(false);
[100]57
[99]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
[101]75        protected void revertChanges() {
76        }
77
78        @Override
[100]79        public void pullValuesFromLocalToUser(Access access) {
[99]80                tableModel.attachSource(Casting.throwCast(ListAccess.class, access));
[101]81                refreshControlButtons();
[99]82        }
83
84        @Override
85        public String getTitle() {
86                return "List";
87        }
[100]88
89        /**
90         * @return the table
91         */
92        public JTable getTable() {
93                return table;
94        }
[101]95
[99]96}
Note: See TracBrowser for help on using the repository browser.