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