1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.gui;
21
22 import javax.swing.event.EventListenerList;
23 import javax.swing.event.TreeModelEvent;
24 import javax.swing.event.TreeModelListener;
25 import javax.swing.tree.TreeModel;
26 import javax.swing.tree.TreePath;
27
28 import com.puppycrawl.tools.checkstyle.api.DetailAST;
29 import com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode;
30 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
31
32
33
34
35
36 public class ParseTreeTableModel implements TreeModel {
37
38
39 private final ParseTreeTablePresentation pModel;
40
41
42
43
44 private final EventListenerList listenerList = new EventListenerList();
45
46
47
48
49
50
51 public ParseTreeTableModel(DetailAST parseTree) {
52 pModel = new ParseTreeTablePresentation(parseTree);
53 setParseTree(parseTree);
54 }
55
56
57
58
59
60
61 protected final void setParseTree(DetailAST parseTree) {
62 pModel.setRoot(parseTree);
63 final Object[] path = {pModel.getRoot()};
64
65
66 fireTreeStructureChanged(this, path, null, CommonUtil.EMPTY_OBJECT_ARRAY);
67 }
68
69
70
71
72
73
74 protected void setParseMode(ParseMode mode) {
75 pModel.setParseMode(mode);
76 }
77
78
79
80
81
82
83 public int getColumnCount() {
84 return pModel.getColumnCount();
85 }
86
87
88
89
90
91
92
93 public String getColumnName(int column) {
94 return pModel.getColumnName(column);
95 }
96
97
98
99
100
101
102
103
104
105 public Class<?> getColumnClass(int column) {
106 return pModel.getColumnClass(column);
107 }
108
109
110
111
112
113
114
115
116
117 public Object getValueAt(Object node, int column) {
118 return pModel.getValueAt(node, column);
119 }
120
121 @Override
122 public Object getChild(Object parent, int index) {
123 return pModel.getChild(parent, index);
124 }
125
126 @Override
127 public int getChildCount(Object parent) {
128 return pModel.getChildCount(parent);
129 }
130
131 @Override
132 public void valueForPathChanged(TreePath path, Object newValue) {
133
134 }
135
136 @Override
137 public Object getRoot() {
138 return pModel.getRoot();
139 }
140
141 @Override
142 public boolean isLeaf(Object node) {
143 return pModel.isLeaf(node);
144 }
145
146
147 @Override
148 public int getIndexOfChild(Object parent, Object child) {
149 return pModel.getIndexOfChild(parent, child);
150 }
151
152 @Override
153 public void addTreeModelListener(TreeModelListener listener) {
154 listenerList.add(TreeModelListener.class, listener);
155 }
156
157 @Override
158 public void removeTreeModelListener(TreeModelListener listener) {
159 listenerList.remove(TreeModelListener.class, listener);
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173
174 private void fireTreeStructureChanged(Object source, Object[] path,
175 int[] childIndices,
176 Object... children) {
177
178 final Object[] listeners = listenerList.getListenerList();
179 TreeModelEvent event = null;
180
181
182 for (int i = listeners.length - 2; i >= 0; i -= 2) {
183 if (listeners[i] == TreeModelListener.class) {
184
185 if (event == null) {
186 event = new TreeModelEvent(source, path,
187 childIndices, children);
188 }
189 ((TreeModelListener) listeners[i + 1]).treeStructureChanged(event);
190 }
191 }
192 }
193
194
195
196
197
198
199
200
201 public boolean isCellEditable(int column) {
202 return pModel.isCellEditable(column);
203 }
204
205 }