1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.gui.search;
25
26 import java.awt.Component;
27 import java.awt.Dimension;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.Insets;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33
34 import javax.swing.JButton;
35 import javax.swing.JCheckBox;
36 import javax.swing.JDialog;
37 import javax.swing.JLabel;
38 import javax.swing.JOptionPane;
39 import javax.swing.JTextField;
40
41 import com.mindtree.techworks.insight.InsightConstants;
42 import com.mindtree.techworks.insight.eventsearch.EventSearchProvider;
43 import com.mindtree.techworks.insight.eventsearch.SearchCriteria;
44 import com.mindtree.techworks.insight.gui.EventDetailsPresentation;
45 import com.mindtree.techworks.insight.gui.Insight;
46 import com.mindtree.techworks.insight.gui.widgets.StatusBar;
47
48
49
50
51
52
53
54
55
56
57
58 public class SearchEventsFrame extends JDialog {
59
60
61
62
63 private static final long serialVersionUID = -2983953457363093486L;
64
65
66
67
68 private static final int WIDTH = 300;
69 private static final int HEIGHT = 20;
70
71
72
73
74 private static final int FIRST_ATTRIBUTE = 0;
75
76
77
78
79
80 private static final int LAST_ATTRIBUTE = 4;
81
82
83
84
85
86 private static final String[] ATTRIBUTE_NAMES = {
87 InsightConstants.getLiteral("THREAD_NAME_LABEL"),
88 InsightConstants.getLiteral("LOGGER_NAME"),
89 InsightConstants.getLiteral("MESSAGE_LABEL"),
90 InsightConstants.getLiteral("EXCEPTION_LABEL"),
91 InsightConstants.getLiteral("THROWABLE"),
92 };
93
94
95
96
97 protected static final int[] ATTRIBUTE_TYPE_IDS = {
98 SearchCriteria.THREAD_SEARCH,
99 SearchCriteria.CATEGORY_SEARCH,
100 SearchCriteria.MESSAGE_SEARCH,
101 SearchCriteria.EXCEPTION_CLASS_NAME_SEARCH,
102 SearchCriteria.THROWABLE_SEARCH,
103 };
104
105
106
107
108 private GridBagLayout gl;
109 private GridBagConstraints gc;
110
111
112
113
114 protected JTextField searchInputField;
115
116
117
118
119 protected JCheckBox[] logEventAttributeCheckBoxes = new JCheckBox[LAST_ATTRIBUTE + 1];
120
121
122
123
124 protected JButton searchButton;
125 protected JButton closeButton;
126
127
128
129
130 protected Insight insight;
131
132
133
134
135 private EventDetailsPresentation eventDetailsPresentation;
136
137
138
139
140
141 public SearchEventsFrame(Insight insight, EventDetailsPresentation eventDetailsPresentation) {
142 super(JOptionPane.getFrameForComponent(insight),InsightConstants.getLiteral("SEARCH_TITLE"),true);
143 this.insight = insight;
144 this.eventDetailsPresentation = eventDetailsPresentation;
145 gl = new GridBagLayout();
146 gc = new GridBagConstraints();
147 getContentPane().setLayout(gl);
148
149 addComponent(new JLabel(InsightConstants.getLiteral("SEARCH_WHAT")),0,0,0,0,1,1);
150 searchInputField = new JTextField();
151 addComponent(searchInputField,1,0,1,0,4,1);
152
153 addComponent(new JLabel(InsightConstants.getLiteral("SEARCH_ON")),1,1,0,0,1,1);
154
155 int xStartIndex = 2;
156 int yStartIndex = 1;
157 int countPerRowColumn = 2;
158
159 for (int i = FIRST_ATTRIBUTE; i <= LAST_ATTRIBUTE; i++ ) {
160 logEventAttributeCheckBoxes[i] = new JCheckBox(ATTRIBUTE_NAMES[i]);
161 addComponent(logEventAttributeCheckBoxes[i],
162 xStartIndex + (i % countPerRowColumn),
163 yStartIndex + (i / countPerRowColumn),1,0,1,1);
164 }
165
166 ButtonActionProcessor actionProcessor = new ButtonActionProcessor();
167 searchButton = new JButton(InsightConstants.getLiteral("SEARCH"));
168 closeButton = new JButton(InsightConstants.getLiteral("CANCEL"));
169 searchButton.addActionListener(actionProcessor);
170 closeButton.addActionListener(actionProcessor);
171 searchInputField.addActionListener(actionProcessor);
172 addComponent(searchButton,0,LAST_ATTRIBUTE,0,0,1,1);
173 addComponent(closeButton,1,LAST_ATTRIBUTE,0,0,1,1);
174
175 this.searchInputField.setPreferredSize(new Dimension(WIDTH, HEIGHT));
176 }
177
178
179
180
181 public void showFrame() {
182 this.pack();
183
184 int insightX = insight.getX();
185 int insightY = insight.getY();
186 int thisX = insightX + ((this.insight.getWidth() - this.getWidth())/ 2);
187 int thisY = insightY + ((this.insight.getHeight() - this.getHeight())/ 2);
188 this.setLocation(thisX, thisY);
189 this.show();
190 }
191
192
193
194
195 public void hideFrame() {
196 this.hide();
197 }
198
199
200
201
202
203
204
205
206
207
208
209 private final void addComponent(Component c, int gridx, int gridy, int weightx,
210 int weighty, int width, int height) {
211 gc.fill = GridBagConstraints.BOTH;
212 gc.anchor = GridBagConstraints.NORTHWEST;
213 gc.insets = new Insets(5,5,5,5);
214 gc.gridx = gridx;
215 gc.gridy = gridy;
216 gc.weightx = weightx;
217 gc.weighty = weighty;
218 gc.gridwidth = width;
219 gc.gridheight = height;
220 gl.setConstraints( c, gc);
221 getContentPane().add(c);
222 }
223
224
225
226
227
228
229
230
231
232
233 private final class ButtonActionProcessor implements ActionListener {
234
235
236
237
238
239 public void actionPerformed(ActionEvent e) {
240 Object source = e.getSource();
241 if (source == searchButton || source == searchInputField) {
242 String searchText = searchInputField.getText().toUpperCase();
243 if (searchText.trim().length() == 0 ) {
244 StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_NO_SEARCH_TEXT"),false);
245 return;
246 }
247 int searchType = 0;
248 for (int i = FIRST_ATTRIBUTE; i <= LAST_ATTRIBUTE; i++) {
249 if (logEventAttributeCheckBoxes[i].isSelected()) {
250 searchType = searchType | ATTRIBUTE_TYPE_IDS[i];
251 }
252 }
253 if (searchType == 0) {
254 StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_NO_SEARCH_FIELDS"),false);
255 return;
256 }
257
258
259 SearchCriteria searchCriteria = new SearchCriteria(searchType);
260 searchCriteria.setSearchString(searchInputField.getText());
261
262
263 EventSearchProvider eventSearchProvider = new EventSearchProvider(insight, true, eventDetailsPresentation);
264 eventSearchProvider.searchLogEvents(searchCriteria);
265 hideFrame();
266
267 } else if (source == closeButton) {
268 hideFrame();
269 }
270 }
271 }
272 }