-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathServerLogPanel.java
More file actions
392 lines (334 loc) · 19.1 KB
/
ServerLogPanel.java
File metadata and controls
392 lines (334 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
package com.mirth.connect.plugins.serverlog;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.prefs.Preferences;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import org.jdesktop.swingx.decorator.Highlighter;
import org.jdesktop.swingx.decorator.HighlighterFactory;
import com.mirth.connect.client.ui.Frame;
import com.mirth.connect.client.ui.LoadedExtensions;
import com.mirth.connect.client.ui.Mirth;
import com.mirth.connect.client.ui.PlatformUI;
import com.mirth.connect.client.ui.RefreshTableModel;
import com.mirth.connect.client.ui.UIConstants;
import com.mirth.connect.client.ui.components.MirthFieldConstraints;
import com.mirth.connect.client.ui.components.MirthTable;
import com.mirth.connect.plugins.DashboardTablePlugin;
public class ServerLogPanel extends javax.swing.JPanel {
private static final String ID_COLUMN_HEADER = "Id";
private static final String CHANNEL_COLUMN_HEADER = "Channel";
private static final String LOG_INFO_COLUMN_HEADER = "Log Information";
private JPopupMenu rightclickPopup;
private static final int PAUSED = 0;
private static final int RESUMED = 1;
private int state = PAUSED; // initialized the state as PAUSED so that when the administrator first opens up and calls the adjustPauseResumeButton method, it'll be in the RESUMED state.
private int currentServerLogSize;
private Preferences userPreferences;
private Frame parent;
private ServerLogClient serverLogClient;
/** Creates new form ServerLogPanel */
public ServerLogPanel(ServerLogClient serverLogClient) {
this.parent = PlatformUI.MIRTH_FRAME;
this.serverLogClient = serverLogClient;
initComponents();
initLayouts();
clearLog.setIcon(UIConstants.ICON_X);
clearLog.setToolTipText("Clear Displayed Log");
logSizeChange.setIcon(UIConstants.ICON_CHECK);
logSizeChange.setToolTipText("Change Log Display Size");
makeLogTextArea();
logSizeTextField.setDocument(new MirthFieldConstraints(2, false, false, true)); // max 100. all numbers. default to 50.
userPreferences = Preferences.userNodeForPackage(Mirth.class);
currentServerLogSize = userPreferences.getInt("serverLogSize", 50);
logSizeTextField.setText(currentServerLogSize + "");
}
/*
* This method overwrites the setting layout part in initComponent generated code by NetBeans,
* because NetBeans wouldn't support the vertical alignment well enough.
*/
public void initLayouts() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(2, 2, 2).addComponent(pauseResume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(2, 2, 2).addComponent(clearLog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 336, Short.MAX_VALUE).addComponent(logSizeText).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(logSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(2, 2, 2).addComponent(logSizeChange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(2, 2, 2)).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE).addGap(0, 0, 0).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER).addComponent(pauseResume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(clearLog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(logSizeChange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(logSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(logSizeText))));
}
/**
* Makes the status table with all current server information.
*/
public void makeLogTextArea() {
updateTable(null);
logTable.setDoubleBuffered(true);
logTable.setSelectionMode(0);
logTable.getColumnExt(ID_COLUMN_HEADER).setVisible(false);
logTable.packTable(UIConstants.COL_MARGIN);
logTable.setRowHeight(UIConstants.ROW_HEIGHT);
logTable.setOpaque(true);
logTable.setRowSelectionAllowed(true);
logTable.setSortable(false);
logTable.setFocusable(false);
logTable.setHorizontalScrollEnabled(true);
logTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
createPopupMenu();
jScrollPane1.setViewportView(logTable);
// listen for trigger button and double click to edit channel.
logTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
if (logTable.rowAtPoint(new Point(evt.getX(), evt.getY())) == -1) {
return;
}
if (evt.getClickCount() >= 2) {
// synchronizing this to prevent ArrayIndexOutOfBoundsException since the server log table is constantly being redrawn.
synchronized (this) {
new ViewServerLogContentDialog(parent, String.valueOf(logTable.getModel().getValueAt(logTable.convertRowIndexToModel(logTable.getSelectedRow()), 2)));
}
}
}
});
}
public void createPopupMenu() {
JMenuItem menuItem;
//Create the popup menu.
rightclickPopup = new JPopupMenu();
menuItem = new JMenuItem("Pause Log");
menuItem.setIcon(UIConstants.ICON_PAUSE);
menuItem.addActionListener(new PauseResumeActionListener());
rightclickPopup.add(menuItem);
menuItem = new JMenuItem("Resume Log");
menuItem.setIcon(UIConstants.ICON_RESUME);
menuItem.addActionListener(new PauseResumeActionListener());
rightclickPopup.add(menuItem);
rightclickPopup.addSeparator();
menuItem = new JMenuItem("Clear Log");
menuItem.setIcon(UIConstants.ICON_X);
menuItem.addActionListener(new ClearLogActionListener());
rightclickPopup.add(menuItem);
// initially show 'Pause', hide 'Resume'
adjustPauseResumeButton();
//Add listener to the text area so the popup menu can come up.
MouseListener popupListener = new PopupListener(rightclickPopup);
jScrollPane1.addMouseListener(popupListener);
logTable.addMouseListener(popupListener);
}
class PauseResumeActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
adjustPauseResumeButton();
}
}
class ClearLogActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// "clear log" only affects on the client side.
// because clearing log on one client should NOT affect other clients' logs.
// clear logs on client side only.
serverLogClient.clearLog();
}
}
/**
* This method won't be called when it's in the PAUSED state.
*
* @param serverLogs
*/
public synchronized void updateTable(LinkedList<ServerLogItem> serverLogs) {
Object[][] tableData;
if (serverLogs != null) {
List<Object[]> dataList = new ArrayList<Object[]>();
String serverId = null;
for (DashboardTablePlugin plugin : LoadedExtensions.getInstance().getDashboardTablePlugins().values()) {
serverId = plugin.getServerId();
if (serverId != null) {
break;
}
}
for (ServerLogItem item : serverLogs) {
if (serverId == null || serverId.equals(item.getServerId())) {
dataList.add(new Object[] { item.getId(), item.getChannelName(), item });
}
}
tableData = dataList.toArray(new Object[dataList.size()][]);
} else {
tableData = new Object[0][3];
}
if (logTable != null) {
RefreshTableModel model = (RefreshTableModel) logTable.getModel();
model.refreshDataVector(tableData);
} else {
logTable = new MirthTable();
logTable.setModel(new RefreshTableModel(tableData, new String[] {
ID_COLUMN_HEADER,
CHANNEL_COLUMN_HEADER,
LOG_INFO_COLUMN_HEADER
}) {
boolean[] canEdit = new boolean[] { false, false, false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
}
if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR);
logTable.setHighlighters(highlighter);
}
}
public boolean isPaused() {
return state == PAUSED;
}
public void adjustPauseResumeButton() {
if (state == RESUMED) {
state = PAUSED;
pauseResume.setIcon(UIConstants.ICON_RESUME);
pauseResume.setToolTipText("Resume Log");
rightclickPopup.getComponent(0).setVisible(false);
rightclickPopup.getComponent(1).setVisible(true);
} else {
state = RESUMED;
pauseResume.setIcon(UIConstants.ICON_PAUSE);
pauseResume.setToolTipText("Pause Log");
rightclickPopup.getComponent(0).setVisible(true);
rightclickPopup.getComponent(1).setVisible(false);
}
}
class PopupListener extends MouseAdapter {
JPopupMenu popup;
PopupListener(JPopupMenu popupMenu) {
popup = popupMenu;
}
public void mousePressed(MouseEvent e) {
checkPopup(e);
}
public void mouseClicked(MouseEvent e) {
checkPopup(e);
}
public void mouseReleased(MouseEvent e) {
checkPopup(e);
}
private void checkPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
}
public int getCurrentServerLogSize() {
return currentServerLogSize;
}
// @formatter:off
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT
* modify this code. The content of this method is always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
logSizeTextField = new javax.swing.JTextField();
logSizeText = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
logTable = null;
clearLog = new com.mirth.connect.client.ui.components.IconButton();
logSizeChange = new com.mirth.connect.client.ui.components.IconButton();
pauseResume = new com.mirth.connect.client.ui.components.IconButton();
logSizeTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
logSizeTextField.setMaximumSize(new java.awt.Dimension(45, 19));
logSizeTextField.setMinimumSize(new java.awt.Dimension(45, 19));
logSizeTextField.setPreferredSize(new java.awt.Dimension(45, 19));
logSizeText.setText("Log Size:");
jScrollPane1.setViewportView(logTable);
clearLog.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearLogActionPerformed(evt);
}
});
logSizeChange.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
logSizeChangeActionPerformed(evt);
}
});
pauseResume.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pauseResumeActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(pauseResume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(clearLog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 316, Short.MAX_VALUE)
.addComponent(logSizeText)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(logSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(logSizeChange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(5, 5, 5))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(clearLog, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(logSizeChange, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(logSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(logSizeText)))
.addComponent(pauseResume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
}// </editor-fold>//GEN-END:initComponents
// @formatter:on
private void clearLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearLogActionPerformed
// "clear log" only affects on the client side.
// because clearing log on one client should NOT affect other clients' logs.
// clear logs on client side only.
serverLogClient.clearLog();
}//GEN-LAST:event_clearLogActionPerformed
private void logSizeChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logSizeChangeActionPerformed
// NOTE: the log size on the server is always 100, which is max. because if there are multiple clients connected to the same server,
// it has to be able to support the maximum allowed in case some client has it set at 99.
// i.e. this log size change only affects on the client side.
if (logSizeTextField.getText().length() == 0) {
parent.alertWarning(this, "Please enter a valid number.");
return;
}
int newServerLogSize = Integer.parseInt(logSizeTextField.getText());
if (newServerLogSize != currentServerLogSize) {
if (newServerLogSize <= 0) {
parent.alertWarning(this, "Please enter a log size that is larger than 0.");
} else {
userPreferences.putInt("serverLogSize", newServerLogSize);
currentServerLogSize = newServerLogSize;
serverLogClient.resetServerLogSize(newServerLogSize);
}
}
}//GEN-LAST:event_logSizeChangeActionPerformed
private void pauseResumeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseResumeActionPerformed
adjustPauseResumeButton();
}//GEN-LAST:event_pauseResumeActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private com.mirth.connect.client.ui.components.IconButton clearLog;
private javax.swing.JScrollPane jScrollPane1;
private com.mirth.connect.client.ui.components.IconButton logSizeChange;
private javax.swing.JLabel logSizeText;
private javax.swing.JTextField logSizeTextField;
private com.mirth.connect.client.ui.components.MirthTable logTable;
private com.mirth.connect.client.ui.components.IconButton pauseResume;
// End of variables declaration//GEN-END:variables
}