source: java/main/src/main/java/com/framsticks/gui/table/TableModel.java @ 100

Last change on this file since 100 was 100, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

File size: 4.6 KB
Line 
1package com.framsticks.gui.table;
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.LinkedList;
6import java.util.List;
7
8import javax.swing.JCheckBox;
9import javax.swing.JComponent;
10import javax.swing.JTable;
11import javax.swing.UIManager;
12import javax.swing.event.TableModelEvent;
13import javax.swing.event.TableModelListener;
14
15import org.apache.logging.log4j.Logger;
16import org.apache.logging.log4j.LogManager;
17
18import com.framsticks.params.Access;
19import com.framsticks.params.ListAccess;
20import com.framsticks.params.Param;
21import com.framsticks.params.PrimitiveParam;
22import com.framsticks.params.types.ProcedureParam;
23import com.framsticks.util.lang.Casting;
24
25public class TableModel implements javax.swing.table.TableModel {
26
27        private static final Logger log = LogManager.getLogger(TableModel.class);
28
29        protected List<TableModelListener> listeners = new LinkedList<>();
30        protected ListAccess access;
31        protected Access elementAccess;
32        protected final List<Column> columns = new ArrayList<>();
33        protected final ListPanel listPanel;
34        protected JTable table;
35
36        /**
37         * @param listPanel
38         */
39        public TableModel(ListPanel listPanel) {
40                this.listPanel = listPanel;
41        }
42
43        /**
44         * @return the listPanel
45         */
46        public ListPanel getListPanel() {
47                return listPanel;
48        }
49
50        public JTable getTable() {
51                return listPanel.getTable();
52        }
53
54        protected void refreshAll() {
55                for (TableModelListener l : listeners) {
56                        l.tableChanged(new TableModelEvent(this));
57                }
58        }
59
60        /**
61         * @param table the table to set
62         */
63        public void setupTable() {
64                getTable().setDefaultRenderer(ProcedureParam.class, new ProcedureRenderer());
65                getTable().setDefaultEditor(ProcedureParam.class, new ProcedureEditor(new JCheckBox()));
66        }
67
68        public void attachSource(ListAccess access) {
69                this.access = Casting.assertCast(ListAccess.class, access.cloneAccess().select(access.getSelected()));
70
71                this.elementAccess = this.access.getElementAccess().cloneAccess();
72                log.debug("attached {}", access);
73                refreshAll();
74        }
75
76        @Override
77        public void addTableModelListener(TableModelListener listener) {
78                listeners.add(listener);
79        }
80
81        @Override
82        public Class<?> getColumnClass(int columnIndex) {
83                // log.debug("returning column type {}", columnParams.get(columnIndex).getStorageType());
84                return columns.get(columnIndex).getColumnClass();
85        }
86
87        @Override
88        public int getColumnCount() {
89                // log.debug("returning column count {}", columnParams.size());
90                return columns.size();
91        }
92
93        @Override
94        public String getColumnName(int columnIndex) {
95                return columns.get(columnIndex).getParam().getName();
96        }
97
98        @Override
99        public int getRowCount() {
100                // log.debug("returning row count {}", access.getParamCount());
101                return access == null ? 0 : access.getParamCount();
102        }
103
104        @Override
105        public Object getValueAt(int rowIndex, int columnIndex) {
106                assert (rowIndex < access.getParamCount() && columnIndex < columns.size());
107
108                return columns.get(columnIndex).getValueAt(rowIndex);
109        }
110
111        @Override
112        public boolean isCellEditable(int rowIndex, int columnIndex) {
113                return columns.get(columnIndex).isEditable();
114        }
115
116        @Override
117        public void removeTableModelListener(TableModelListener listener) {
118                listeners.remove(listener);
119        }
120
121
122        @Override
123        public void setValueAt(Object value, int rowIndex, int columnIndex) {
124                assert (rowIndex < access.getParamCount() && columnIndex < columns.size());
125                // Object object = getObjectAt(rowIndex, columnIndex);
126                // if (object == null) {
127                //      return;
128                // }
129                columns.get(columnIndex).setValueAt(rowIndex, value);
130        }
131
132        public void addColumn(Column column) {
133                log.debug("added {}", column);
134                columns.add(column);
135        }
136
137        /**
138         * @return the access
139         */
140        public ListAccess getAccess() {
141                return access;
142        }
143
144        /**
145         * @return the elementAccess
146         */
147        public Access getElementAccess() {
148                return elementAccess;
149        }
150
151        /**
152         * @return the columnParams
153         */
154        public List<Column> getColumns() {
155                return Collections.unmodifiableList(columns);
156        }
157
158
159        public boolean addColumnIfSupported(Param param) {
160                if (param instanceof PrimitiveParam) {
161                        addColumn(new PrimitiveColumn((PrimitiveParam<?>) param, this));
162                        return true;
163                }
164                if (param instanceof ProcedureParam) {
165                        if (((ProcedureParam) param).getArgumentsType().size() == 0) {
166                                addColumn(new ProcedureColumn((ProcedureParam) param, this));
167                                return true;
168                        }
169                        return false;
170                }
171                return false;
172        }
173
174        public static void transferCellAppeariance(JTable table, JComponent component, boolean isSelected) {
175                if (isSelected) {
176                        component.setForeground(table.getSelectionForeground());
177                        component.setBackground(table.getSelectionBackground());
178                } else {
179                        component.setForeground(table.getForeground());
180                        component.setBackground(UIManager.getColor("Button.background"));
181                }
182
183        }
184
185}
Note: See TracBrowser for help on using the repository browser.