1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
|
12
|
package org.eclipse.pde.internal.runtime.logview;
|
13
|
|
14
|
import java.io.BufferedReader;
|
15
|
import java.io.BufferedWriter;
|
16
|
import java.io.File;
|
17
|
import java.io.FileInputStream;
|
18
|
import java.io.FileOutputStream;
|
19
|
import java.io.IOException;
|
20
|
import java.io.InputStreamReader;
|
21
|
import java.io.OutputStreamWriter;
|
22
|
import java.io.PrintWriter;
|
23
|
import java.io.StringWriter;
|
24
|
import java.lang.reflect.InvocationTargetException;
|
25
|
import java.util.ArrayList;
|
26
|
import java.util.Comparator;
|
27
|
|
28
|
import org.eclipse.core.runtime.ILogListener;
|
29
|
import org.eclipse.core.runtime.IProgressMonitor;
|
30
|
import org.eclipse.core.runtime.IStatus;
|
31
|
import org.eclipse.core.runtime.Path;
|
32
|
import org.eclipse.core.runtime.Platform;
|
33
|
import org.eclipse.core.runtime.Preferences;
|
34
|
import org.eclipse.core.runtime.Status;
|
35
|
import org.eclipse.core.runtime.jobs.Job;
|
36
|
import org.eclipse.jface.action.Action;
|
37
|
import org.eclipse.jface.action.IMenuListener;
|
38
|
import org.eclipse.jface.action.IMenuManager;
|
39
|
import org.eclipse.jface.action.IStatusLineManager;
|
40
|
import org.eclipse.jface.action.IToolBarManager;
|
41
|
import org.eclipse.jface.action.MenuManager;
|
42
|
import org.eclipse.jface.action.Separator;
|
43
|
import org.eclipse.jface.dialogs.IDialogSettings;
|
44
|
import org.eclipse.jface.dialogs.MessageDialog;
|
45
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
46
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
47
|
import org.eclipse.jface.util.Policy;
|
48
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
49
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
50
|
import org.eclipse.jface.viewers.ISelection;
|
51
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
52
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
53
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
54
|
import org.eclipse.jface.viewers.TreeViewer;
|
55
|
import org.eclipse.jface.viewers.Viewer;
|
56
|
import org.eclipse.jface.viewers.ViewerComparator;
|
57
|
import org.eclipse.jface.window.Window;
|
58
|
import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
|
59
|
import org.eclipse.pde.internal.runtime.PDERuntimePlugin;
|
60
|
import org.eclipse.pde.internal.runtime.PDERuntimePluginImages;
|
61
|
import org.eclipse.swt.SWT;
|
62
|
import org.eclipse.swt.custom.BusyIndicator;
|
63
|
import org.eclipse.swt.events.DisposeEvent;
|
64
|
import org.eclipse.swt.events.DisposeListener;
|
65
|
import org.eclipse.swt.events.SelectionAdapter;
|
66
|
import org.eclipse.swt.events.SelectionEvent;
|
67
|
import org.eclipse.swt.graphics.Color;
|
68
|
import org.eclipse.swt.graphics.Image;
|
69
|
import org.eclipse.swt.graphics.Point;
|
70
|
import org.eclipse.swt.graphics.Rectangle;
|
71
|
import org.eclipse.swt.layout.GridData;
|
72
|
import org.eclipse.swt.layout.GridLayout;
|
73
|
import org.eclipse.swt.widgets.Composite;
|
74
|
import org.eclipse.swt.widgets.Display;
|
75
|
import org.eclipse.swt.widgets.Event;
|
76
|
import org.eclipse.swt.widgets.Menu;
|
77
|
import org.eclipse.swt.widgets.Shell;
|
78
|
import org.eclipse.swt.widgets.Text;
|
79
|
import org.eclipse.swt.widgets.Tree;
|
80
|
import org.eclipse.swt.widgets.TreeColumn;
|
81
|
import org.eclipse.swt.widgets.TreeItem;
|
82
|
import org.eclipse.ui.IActionBars;
|
83
|
import org.eclipse.ui.IMemento;
|
84
|
import org.eclipse.ui.ISharedImages;
|
85
|
import org.eclipse.ui.IViewSite;
|
86
|
import org.eclipse.ui.IWorkbenchActionConstants;
|
87
|
import org.eclipse.ui.IWorkbenchPage;
|
88
|
import org.eclipse.ui.PartInitException;
|
89
|
import org.eclipse.ui.PlatformUI;
|
90
|
import org.eclipse.ui.part.ViewPart;
|
91
|
|
92
|
public class LogView extends ViewPart implements ILogListener {
|
93
|
public static final String P_LOG_WARNING = "warning"; //$NON-NLS-1$
|
94
|
public static final String P_LOG_ERROR = "error"; //$NON-NLS-1$
|
95
|
public static final String P_LOG_INFO = "info"; //$NON-NLS-1$
|
96
|
public static final String P_LOG_LIMIT = "limit"; //$NON-NLS-1$
|
97
|
public static final String P_USE_LIMIT = "useLimit"; //$NON-NLS-1$
|
98
|
public static final String P_SHOW_ALL_SESSIONS = "allSessions"; //$NON-NLS-1$
|
99
|
private static final String P_COLUMN_1 = "column2"; //$NON-NLS-1$
|
100
|
private static final String P_COLUMN_2 = "column3"; //$NON-NLS-1$
|
101
|
private static final String P_COLUMN_3 = "column4"; //$NON-NLS-1$
|
102
|
public static final String P_ACTIVATE = "activate"; //$NON-NLS-1$
|
103
|
public static final String P_ORDER_TYPE = "orderType"; //$NON-NLS-1$
|
104
|
public static final String P_ORDER_VALUE = "orderValue"; //$NON-NLS-1$
|
105
|
|
106
|
private int MESSAGE_ORDER;
|
107
|
private int PLUGIN_ORDER;
|
108
|
private int DATE_ORDER;
|
109
|
|
110
|
public final static byte MESSAGE = 0x0;
|
111
|
public final static byte PLUGIN = 0x1;
|
112
|
public final static byte DATE = 0x2;
|
113
|
public static int ASCENDING = 1;
|
114
|
public static int DESCENDING = -1;
|
115
|
|
116
|
private ArrayList fLogs;
|
117
|
|
118
|
// private Clipboard fClipboard;
|
119
|
|
120
|
// private IMemento fMemento;
|
121
|
private File fInputFile;
|
122
|
private String fDirectory;
|
123
|
|
124
|
private Comparator fComparator;
|
125
|
|
126
|
// hover text
|
127
|
private boolean fCanOpenTextShell;
|
128
|
private Text fTextLabel;
|
129
|
private Shell fTextShell;
|
130
|
|
131
|
private boolean fFirstEvent = true;
|
132
|
|
133
|
private TreeColumn fColumn1;
|
134
|
private TreeColumn fColumn2;
|
135
|
private TreeColumn fColumn3;
|
136
|
|
137
|
private Tree fTree;
|
138
|
private TreeViewer fTreeViewer;
|
139
|
private LogViewLabelProvider fLabelProvider;
|
140
|
|
141
|
private Action fPropertiesAction;
|
142
|
private Action fDeleteLogAction;
|
143
|
private Action fReadLogAction;
|
144
|
// private Action fCopyAction;
|
145
|
private Action fActivateViewAction;
|
146
|
private Action fOpenLogAction;
|
147
|
private Action fExportAction;
|
148
|
|
149
|
public LogView() {
|
150
|
fLogs = new ArrayList();
|
151
|
fInputFile = Platform.getLogFileLocation().toFile();
|
152
|
}
|
153
|
|
154
|
public void createPartControl(Composite parent) {
|
155
|
readLogFile();
|
156
|
createViewer(parent);
|
157
|
createActions();
|
158
|
// fClipboard = new Clipboard(fTree.getDisplay());
|
159
|
fTree.setToolTipText(""); //$NON-NLS-1$
|
160
|
getSite().setSelectionProvider(fTreeViewer);
|
161
|
initializeViewerSorter();
|
162
|
|
163
|
makeHoverShell();
|
164
|
|
165
|
Platform.addLogListener(this);
|
166
|
// PlatformUI.getWorkbench().getHelpSystem().setHelp(fTree, IHelpContextIds.LOG_VIEW);
|
167
|
}
|
168
|
|
169
|
private void createActions() {
|
170
|
IActionBars bars = getViewSite().getActionBars();
|
171
|
|
172
|
// fCopyAction = createCopyAction();
|
173
|
// bars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction);
|
174
|
|
175
|
IToolBarManager toolBarManager = bars.getToolBarManager();
|
176
|
|
177
|
fExportAction = createExportAction();
|
178
|
toolBarManager.add(fExportAction);
|
179
|
|
180
|
final Action importLogAction = createImportLogAction();
|
181
|
toolBarManager.add(importLogAction);
|
182
|
|
183
|
toolBarManager.add(new Separator());
|
184
|
|
185
|
final Action clearAction = createClearAction();
|
186
|
toolBarManager.add(clearAction);
|
187
|
|
188
|
fDeleteLogAction = createDeleteLogAction();
|
189
|
toolBarManager.add(fDeleteLogAction);
|
190
|
|
191
|
fOpenLogAction = createOpenLogAction();
|
192
|
toolBarManager.add(fOpenLogAction);
|
193
|
|
194
|
fReadLogAction = createReadLogAction();
|
195
|
toolBarManager.add(fReadLogAction);
|
196
|
|
197
|
toolBarManager.add(new Separator());
|
198
|
|
199
|
IMenuManager mgr = bars.getMenuManager();
|
200
|
mgr.add(createFilterAction());
|
201
|
mgr.add(new Separator());
|
202
|
|
203
|
fActivateViewAction = createActivateViewAction();
|
204
|
mgr.add(fActivateViewAction);
|
205
|
|
206
|
createPropertiesAction();
|
207
|
|
208
|
MenuManager popupMenuManager = new MenuManager("#PopupMenu"); //$NON-NLS-1$
|
209
|
IMenuListener listener = new IMenuListener() {
|
210
|
public void menuAboutToShow(IMenuManager manager) {
|
211
|
// manager.add(fCopyAction);
|
212
|
manager.add(new Separator());
|
213
|
manager.add(clearAction);
|
214
|
manager.add(fDeleteLogAction);
|
215
|
manager.add(fOpenLogAction);
|
216
|
manager.add(fReadLogAction);
|
217
|
manager.add(new Separator());
|
218
|
manager.add(fExportAction);
|
219
|
manager.add(importLogAction);
|
220
|
manager.add(new Separator());
|
221
|
((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator);
|
222
|
manager.add(fPropertiesAction);
|
223
|
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
224
|
}
|
225
|
};
|
226
|
popupMenuManager.addMenuListener(listener);
|
227
|
popupMenuManager.setRemoveAllWhenShown(true);
|
228
|
getSite().registerContextMenu(popupMenuManager, getSite().getSelectionProvider());
|
229
|
Menu menu = popupMenuManager.createContextMenu(fTree);
|
230
|
fTree.setMenu(menu);
|
231
|
}
|
232
|
|
233
|
private Action createActivateViewAction() {
|
234
|
Action action = new Action(PDERuntimeMessages.get().LogView_activate) { //
|
235
|
public void run() {
|
236
|
// fMemento.putString(P_ACTIVATE, isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
|
237
|
}
|
238
|
};
|
239
|
// action.setChecked(fMemento.getString(P_ACTIVATE).equals("true")); //$NON-NLS-1$
|
240
|
return action;
|
241
|
}
|
242
|
|
243
|
private Action createClearAction() {
|
244
|
Action action = new Action(PDERuntimeMessages.get().LogView_clear) {
|
245
|
public void run() {
|
246
|
handleClear();
|
247
|
}
|
248
|
};
|
249
|
action.setImageDescriptor(PDERuntimePluginImages.DESC_CLEAR);
|
250
|
action.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_CLEAR_DISABLED);
|
251
|
action.setToolTipText(PDERuntimeMessages.get().LogView_clear_tooltip);
|
252
|
action.setText(PDERuntimeMessages.get().LogView_clear);
|
253
|
return action;
|
254
|
}
|
255
|
|
256
|
private Action createCopyAction() {
|
257
|
Action action = new Action(PDERuntimeMessages.get().LogView_copy) {
|
258
|
public void run() {
|
259
|
copyToClipboard(fTreeViewer.getSelection());
|
260
|
}
|
261
|
};
|
262
|
action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
263
|
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
|
264
|
return action;
|
265
|
}
|
266
|
|
267
|
private Action createDeleteLogAction() {
|
268
|
Action action = new Action(PDERuntimeMessages.get().LogView_delete) {
|
269
|
public void run() {
|
270
|
doDeleteLog();
|
271
|
}
|
272
|
};
|
273
|
action.setToolTipText(PDERuntimeMessages.get().LogView_delete_tooltip);
|
274
|
action.setImageDescriptor(PDERuntimePluginImages.DESC_REMOVE_LOG);
|
275
|
action.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_REMOVE_LOG_DISABLED);
|
276
|
action.setEnabled(fInputFile.exists() && fInputFile.equals(Platform.getLogFileLocation().toFile()));
|
277
|
return action;
|
278
|
}
|
279
|
|
280
|
private Action createExportAction() {
|
281
|
Action action = new Action(PDERuntimeMessages.get().LogView_export) {
|
282
|
public void run() {
|
283
|
handleExport();
|
284
|
}
|
285
|
};
|
286
|
action.setToolTipText(PDERuntimeMessages.get().LogView_export_tooltip);
|
287
|
action.setImageDescriptor(PDERuntimePluginImages.DESC_EXPORT);
|
288
|
action.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_EXPORT_DISABLED);
|
289
|
action.setEnabled(fInputFile.exists());
|
290
|
return action;
|
291
|
}
|
292
|
|
293
|
private Action createFilterAction() {
|
294
|
Action action = new Action(PDERuntimeMessages.get().LogView_filter) {
|
295
|
public void run() {
|
296
|
handleFilter();
|
297
|
}
|
298
|
};
|
299
|
action.setToolTipText(PDERuntimeMessages.get().LogView_filter);
|
300
|
action.setImageDescriptor(PDERuntimePluginImages.DESC_FILTER);
|
301
|
action.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_FILTER_DISABLED);
|
302
|
return action;
|
303
|
}
|
304
|
|
305
|
private Action createImportLogAction() {
|
306
|
Action action = new Action(PDERuntimeMessages.get().LogView_import) {
|
307
|
public void run() {
|
308
|
handleImport();
|
309
|
}
|
310
|
};
|
311
|
action.setToolTipText(PDERuntimeMessages.get().LogView_import_tooltip);
|
312
|
action.setImageDescriptor(PDERuntimePluginImages.DESC_IMPORT);
|
313
|
action.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_IMPORT_DISABLED);
|
314
|
return action;
|
315
|
}
|
316
|
|
317
|
private Action createOpenLogAction() {
|
318
|
Action action = null;
|
319
|
try {
|
320
|
// check to see if org.eclipse.ui.ide is available
|
321
|
Class.forName("org.eclipse.ui.ide.IDE"); //$NON-NLS-1$
|
322
|
// check to see if org.eclipse.core.filesystem is available
|
323
|
Class.forName("org.eclipse.core.filesystem.IFileStore"); //$NON-NLS-1$
|
324
|
action = new OpenIDELogFileAction(this);
|
325
|
} catch (ClassNotFoundException e) {
|
326
|
action = new Action() {
|
327
|
public void run() {
|
328
|
if (fInputFile.exists()) {
|
329
|
Job job = getOpenLogFileJob();
|
330
|
job.setUser(false);
|
331
|
job.setPriority(Job.SHORT);
|
332
|
job.schedule();
|
333
|
}
|
334
|
}
|
335
|
};
|
336
|
}
|
337
|
action.setText(PDERuntimeMessages.get().LogView_view_currentLog);
|
338
|
action.setImageDescriptor(PDERuntimePluginImages.DESC_OPEN_LOG);
|
339
|
action.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_OPEN_LOG_DISABLED);
|
340
|
action.setEnabled(fInputFile.exists());
|
341
|
action.setToolTipText(PDERuntimeMessages.get().LogView_view_currentLog_tooltip);
|
342
|
return action;
|
343
|
}
|
344
|
|
345
|
private void createPropertiesAction() {
|
346
|
fPropertiesAction = new EventDetailsDialogAction(fTree.getShell(), fTreeViewer);
|
347
|
fPropertiesAction.setImageDescriptor(PDERuntimePluginImages.DESC_PROPERTIES);
|
348
|
fPropertiesAction.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_PROPERTIES_DISABLED);
|
349
|
fPropertiesAction.setToolTipText(PDERuntimeMessages.get().LogView_properties_tooltip);
|
350
|
fPropertiesAction.setEnabled(false);
|
351
|
}
|
352
|
|
353
|
private Action createReadLogAction() {
|
354
|
Action action = new Action(PDERuntimeMessages.get().LogView_readLog_restore) {
|
355
|
public void run() {
|
356
|
fInputFile = Platform.getLogFileLocation().toFile();
|
357
|
reloadLog();
|
358
|
}
|
359
|
};
|
360
|
action.setToolTipText(PDERuntimeMessages.get().LogView_readLog_restore_tooltip);
|
361
|
action.setImageDescriptor(PDERuntimePluginImages.DESC_READ_LOG);
|
362
|
action.setDisabledImageDescriptor(PDERuntimePluginImages.DESC_READ_LOG_DISABLED);
|
363
|
return action;
|
364
|
}
|
365
|
|
366
|
private void createViewer(Composite parent) {
|
367
|
fTreeViewer = new TreeViewer(parent, SWT.FULL_SELECTION);
|
368
|
fTree = fTreeViewer.getTree();
|
369
|
fTree.setLinesVisible(true);
|
370
|
createColumns(fTree);
|
371
|
fTreeViewer.setContentProvider(new LogViewContentProvider(this));
|
372
|
fTreeViewer.setLabelProvider(fLabelProvider = new LogViewLabelProvider());
|
373
|
fLabelProvider.connect(this);
|
374
|
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
375
|
public void selectionChanged(SelectionChangedEvent e) {
|
376
|
handleSelectionChanged(e.getSelection());
|
377
|
if (fPropertiesAction.isEnabled())
|
378
|
((EventDetailsDialogAction) fPropertiesAction).resetSelection();
|
379
|
}
|
380
|
});
|
381
|
fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
|
382
|
public void doubleClick(DoubleClickEvent event) {
|
383
|
((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator);
|
384
|
fPropertiesAction.run();
|
385
|
}
|
386
|
});
|
387
|
fTreeViewer.setInput(this);
|
388
|
addMouseListeners();
|
389
|
}
|
390
|
|
391
|
private void createColumns(Tree tree) {
|
392
|
fColumn1 = new TreeColumn(tree, SWT.LEFT);
|
393
|
fColumn1.setText(PDERuntimeMessages.get().LogView_column_message);
|
394
|
// fColumn1.setWidth(fMemento.getInteger(P_COLUMN_1).intValue());
|
395
|
fColumn1.setWidth(300);
|
396
|
fColumn1.addSelectionListener(new SelectionAdapter() {
|
397
|
public void widgetSelected(SelectionEvent e) {
|
398
|
MESSAGE_ORDER *= -1;
|
399
|
ViewerComparator comparator = getViewerComparator(MESSAGE);
|
400
|
fTreeViewer.setComparator(comparator);
|
401
|
boolean isComparatorSet =
|
402
|
((EventDetailsDialogAction) fPropertiesAction).resetSelection(MESSAGE, MESSAGE_ORDER);
|
403
|
setComparator(MESSAGE);
|
404
|
if (!isComparatorSet)
|
405
|
((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator);
|
406
|
// fMemento.putInteger(P_ORDER_VALUE, MESSAGE_ORDER);
|
407
|
// fMemento.putInteger(P_ORDER_TYPE, MESSAGE);
|
408
|
setColumnSorting(fColumn1, MESSAGE_ORDER);
|
409
|
}
|
410
|
});
|
411
|
|
412
|
fColumn2 = new TreeColumn(tree, SWT.LEFT);
|
413
|
fColumn2.setText(PDERuntimeMessages.get().LogView_column_plugin);
|
414
|
// fColumn2.setWidth(fMemento.getInteger(P_COLUMN_2).intValue());
|
415
|
fColumn2.setWidth(150);
|
416
|
fColumn2.addSelectionListener(new SelectionAdapter() {
|
417
|
public void widgetSelected(SelectionEvent e) {
|
418
|
PLUGIN_ORDER *= -1;
|
419
|
ViewerComparator comparator = getViewerComparator(PLUGIN);
|
420
|
fTreeViewer.setComparator(comparator);
|
421
|
boolean isComparatorSet =
|
422
|
((EventDetailsDialogAction) fPropertiesAction).resetSelection(PLUGIN, PLUGIN_ORDER);
|
423
|
setComparator(PLUGIN);
|
424
|
if (!isComparatorSet)
|
425
|
((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator);
|
426
|
// fMemento.putInteger(P_ORDER_VALUE, PLUGIN_ORDER);
|
427
|
// fMemento.putInteger(P_ORDER_TYPE, PLUGIN);
|
428
|
setColumnSorting(fColumn2, PLUGIN_ORDER);
|
429
|
}
|
430
|
});
|
431
|
|
432
|
fColumn3 = new TreeColumn(tree, SWT.LEFT);
|
433
|
fColumn3.setText(PDERuntimeMessages.get().LogView_column_date);
|
434
|
// fColumn3.setWidth(fMemento.getInteger(P_COLUMN_3).intValue());
|
435
|
fColumn3.setWidth(150);
|
436
|
fColumn3.addSelectionListener(new SelectionAdapter() {
|
437
|
public void widgetSelected(SelectionEvent e) {
|
438
|
DATE_ORDER *= -1;
|
439
|
ViewerComparator comparator = getViewerComparator(DATE);
|
440
|
fTreeViewer.setComparator(comparator);
|
441
|
setComparator(DATE);
|
442
|
((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator);
|
443
|
// fMemento.putInteger(P_ORDER_VALUE, DATE_ORDER);
|
444
|
// fMemento.putInteger(P_ORDER_TYPE, DATE);
|
445
|
setColumnSorting(fColumn3, DATE_ORDER);
|
446
|
}
|
447
|
});
|
448
|
|
449
|
tree.setHeaderVisible(true);
|
450
|
}
|
451
|
|
452
|
private void initializeViewerSorter() {
|
453
|
// byte orderType = fMemento.getInteger(P_ORDER_TYPE).byteValue();
|
454
|
byte orderType = DATE;
|
455
|
ViewerComparator comparator = getViewerComparator(orderType);
|
456
|
fTreeViewer.setComparator(comparator);
|
457
|
// if (orderType == MESSAGE )
|
458
|
// setColumnSorting(fColumn1, MESSAGE_ORDER);
|
459
|
// else if (orderType == PLUGIN)
|
460
|
// setColumnSorting(fColumn2, PLUGIN_ORDER);
|
461
|
// else if (orderType == DATE)
|
462
|
setColumnSorting(fColumn3, DATE_ORDER);
|
463
|
}
|
464
|
|
465
|
private void setColumnSorting(TreeColumn column, int order) {
|
466
|
fTree.setSortColumn(column);
|
467
|
fTree.setSortDirection(order == ASCENDING ? SWT.UP : SWT.DOWN);
|
468
|
}
|
469
|
|
470
|
public void dispose() {
|
471
|
writeSettings();
|
472
|
Platform.removeLogListener(this);
|
473
|
// fClipboard.dispose();
|
474
|
if (fTextShell != null)
|
475
|
fTextShell.dispose();
|
476
|
LogReader.reset();
|
477
|
fLabelProvider.disconnect(this);
|
478
|
super.dispose();
|
479
|
}
|
480
|
|
481
|
|
482
|
private void handleImport() {
|
483
|
// FileDialog dialog = new FileDialog(getViewSite().getShell());
|
484
|
// dialog.setFilterExtensions(new String[] { "*.log" }); //$NON-NLS-1$
|
485
|
// if (fDirectory != null)
|
486
|
// dialog.setFilterPath(fDirectory);
|
487
|
// handleImportPath(dialog.open());
|
488
|
}
|
489
|
|
490
|
public void handleImportPath(String path) {
|
491
|
if (path != null && new Path(path).toFile().exists()) {
|
492
|
fInputFile = new Path(path).toFile();
|
493
|
fDirectory = fInputFile.getParent();
|
494
|
IRunnableWithProgress op = new IRunnableWithProgress() {
|
495
|
public void run(IProgressMonitor monitor)
|
496
|
throws InvocationTargetException, InterruptedException {
|
497
|
monitor.beginTask(PDERuntimeMessages.get().LogView_operation_importing, IProgressMonitor.UNKNOWN);
|
498
|
readLogFile();
|
499
|
}
|
500
|
};
|
501
|
ProgressMonitorDialog pmd = new ProgressMonitorDialog(getViewSite().getShell());
|
502
|
try {
|
503
|
pmd.run(true, true, op);
|
504
|
} catch (InvocationTargetException e) {
|
505
|
} catch (InterruptedException e) {
|
506
|
} finally {
|
507
|
fReadLogAction.setText(PDERuntimeMessages.get().LogView_readLog_reload);
|
508
|
fReadLogAction.setToolTipText(PDERuntimeMessages.get().LogView_readLog_reload);
|
509
|
asyncRefresh(false);
|
510
|
resetDialogButtons();
|
511
|
}
|
512
|
}
|
513
|
}
|
514
|
|
515
|
private void handleExport() {
|
516
|
// FileDialog dialog = new FileDialog(getViewSite().getShell(), SWT.SAVE);
|
517
|
// dialog.setFilterExtensions(new String[] { "*.log" }); //$NON-NLS-1$
|
518
|
// if (fDirectory != null)
|
519
|
// dialog.setFilterPath(fDirectory);
|
520
|
// String path = dialog.open();
|
521
|
// if (path != null) {
|
522
|
// if (path.indexOf('.') == -1 && !path.endsWith(".log")) //$NON-NLS-1$
|
523
|
// path += ".log"; //$NON-NLS-1$
|
524
|
// File outputFile = new Path(path).toFile();
|
525
|
// fDirectory = outputFile.getParent();
|
526
|
// if (outputFile.exists()) {
|
527
|
// String message = NLS.bind(PDERuntimeMessages.LogView_confirmOverwrite_message, outputFile.toString());
|
528
|
// if (!MessageDialog.openQuestion(getViewSite().getShell(), PDERuntimeMessages.LogView_exportLog, message))
|
529
|
// return;
|
530
|
// }
|
531
|
// copy(fInputFile, outputFile);
|
532
|
// }
|
533
|
}
|
534
|
|
535
|
private void copy(File inputFile, File outputFile) {
|
536
|
BufferedReader reader = null;
|
537
|
BufferedWriter writer = null;
|
538
|
try {
|
539
|
reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), "UTF-8")); //$NON-NLS-1$
|
540
|
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); //$NON-NLS-1$
|
541
|
while (reader.ready()) {
|
542
|
writer.write(reader.readLine());
|
543
|
writer.write(System.getProperty("line.separator")); //$NON-NLS-1$
|
544
|
}
|
545
|
} catch (IOException e) {
|
546
|
} finally {
|
547
|
try {
|
548
|
if (reader != null)
|
549
|
reader.close();
|
550
|
if (writer != null)
|
551
|
writer.close();
|
552
|
} catch (IOException e1) {
|
553
|
}
|
554
|
}
|
555
|
}
|
556
|
|
557
|
private void handleFilter() {
|
558
|
FilterDialog dialog = new FilterDialog(PDERuntimePlugin.getActiveWorkbenchShell(), null);
|
559
|
// FilterDialog dialog = new FilterDialog(PDERuntimePlugin.getActiveWorkbenchShell(), fMemento);
|
560
|
dialog.create();
|
561
|
dialog.getShell().setText(PDERuntimeMessages.get().LogView_FilterDialog_title);
|
562
|
if (dialog.open() == Window.OK)
|
563
|
reloadLog();
|
564
|
}
|
565
|
|
566
|
private void doDeleteLog() {
|
567
|
String title = PDERuntimeMessages.get().LogView_confirmDelete_title;
|
568
|
String message = PDERuntimeMessages.get().LogView_confirmDelete_message;
|
569
|
if (!MessageDialog.openConfirm(fTree.getShell(), title, message))
|
570
|
return;
|
571
|
if (fInputFile.delete() || fLogs.size() > 0) {
|
572
|
fLogs.clear();
|
573
|
asyncRefresh(false);
|
574
|
resetDialogButtons();
|
575
|
}
|
576
|
}
|
577
|
|
578
|
public void fillContextMenu(IMenuManager manager) {
|
579
|
}
|
580
|
|
581
|
public LogEntry[] getLogs() {
|
582
|
return (LogEntry[]) fLogs.toArray(new LogEntry[fLogs.size()]);
|
583
|
}
|
584
|
|
585
|
protected void handleClear() {
|
586
|
BusyIndicator.showWhile(fTree.getDisplay(),
|
587
|
new Runnable() {
|
588
|
public void run() {
|
589
|
fLogs.clear();
|
590
|
asyncRefresh(false);
|
591
|
resetDialogButtons();
|
592
|
}
|
593
|
});
|
594
|
}
|
595
|
|
596
|
protected void reloadLog() {
|
597
|
IRunnableWithProgress op = new IRunnableWithProgress() {
|
598
|
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
599
|
monitor.beginTask(PDERuntimeMessages.get().LogView_operation_reloading, IProgressMonitor.UNKNOWN);
|
600
|
readLogFile();
|
601
|
}
|
602
|
};
|
603
|
ProgressMonitorDialog pmd = new ProgressMonitorDialog(getViewSite().getShell());
|
604
|
try {
|
605
|
pmd.run(true, true, op);
|
606
|
} catch (InvocationTargetException e) {
|
607
|
} catch (InterruptedException e) {
|
608
|
} finally {
|
609
|
fReadLogAction.setText(PDERuntimeMessages.get().LogView_readLog_restore);
|
610
|
fReadLogAction.setToolTipText(PDERuntimeMessages.get().LogView_readLog_restore);
|
611
|
asyncRefresh(false);
|
612
|
resetDialogButtons();
|
613
|
}
|
614
|
}
|
615
|
|
616
|
private void readLogFile() {
|
617
|
fLogs.clear();
|
618
|
if (!fInputFile.exists())
|
619
|
return;
|
620
|
LogReader.parseLogFile(fInputFile, fLogs, null);
|
621
|
// LogReader.parseLogFile(fInputFile, fLogs, fMemento);
|
622
|
}
|
623
|
|
624
|
public void logging(IStatus status, String plugin) {
|
625
|
if (!fInputFile.equals(Platform.getLogFileLocation().toFile()))
|
626
|
return;
|
627
|
if (fFirstEvent) {
|
628
|
readLogFile();
|
629
|
asyncRefresh();
|
630
|
fFirstEvent = false;
|
631
|
} else {
|
632
|
pushStatus(status);
|
633
|
}
|
634
|
}
|
635
|
|
636
|
private void pushStatus(IStatus status) {
|
637
|
LogEntry entry = new LogEntry(status);
|
638
|
LogReader.addEntry(entry, fLogs, null, true);
|
639
|
// LogReader.addEntry(entry, fLogs, fMemento, true);
|
640
|
asyncRefresh();
|
641
|
}
|
642
|
|
643
|
private void asyncRefresh() {
|
644
|
asyncRefresh(true);
|
645
|
}
|
646
|
|
647
|
private void asyncRefresh(final boolean activate) {
|
648
|
if (fTree.isDisposed())
|
649
|
return;
|
650
|
Display display = fTree.getDisplay();
|
651
|
final ViewPart view = this;
|
652
|
if (display != null) {
|
653
|
display.asyncExec(new Runnable() {
|
654
|
public void run() {
|
655
|
if (!fTree.isDisposed()) {
|
656
|
fTreeViewer.refresh();
|
657
|
fDeleteLogAction.setEnabled(fInputFile.exists()
|
658
|
&& fInputFile.equals(Platform.getLogFileLocation().toFile()));
|
659
|
fOpenLogAction.setEnabled(fInputFile.exists());
|
660
|
fExportAction.setEnabled(fInputFile.exists());
|
661
|
if (activate && fActivateViewAction.isChecked()) {
|
662
|
IWorkbenchPage page = PDERuntimePlugin.getActivePage();
|
663
|
if (page != null)
|
664
|
page.bringToTop(view);
|
665
|
}
|
666
|
}
|
667
|
}
|
668
|
});
|
669
|
}
|
670
|
}
|
671
|
|
672
|
public void setFocus() {
|
673
|
if (fTree != null && !fTree.isDisposed())
|
674
|
fTree.setFocus();
|
675
|
}
|
676
|
|
677
|
private void handleSelectionChanged(ISelection selection) {
|
678
|
updateStatus(selection);
|
679
|
// fCopyAction.setEnabled(!selection.isEmpty());
|
680
|
fPropertiesAction.setEnabled(!selection.isEmpty());
|
681
|
}
|
682
|
|
683
|
private void updateStatus(ISelection selection) {
|
684
|
IStatusLineManager status = getViewSite().getActionBars().getStatusLineManager();
|
685
|
if (selection.isEmpty())
|
686
|
status.setMessage(null);
|
687
|
else {
|
688
|
LogEntry entry = (LogEntry) ((IStructuredSelection) selection).getFirstElement();
|
689
|
status.setMessage(((LogViewLabelProvider) fTreeViewer.getLabelProvider()).getColumnText(entry, 0));
|
690
|
}
|
691
|
}
|
692
|
|
693
|
private void copyToClipboard(ISelection selection) {
|
694
|
StringWriter writer = new StringWriter();
|
695
|
PrintWriter pwriter = new PrintWriter(writer);
|
696
|
if (selection.isEmpty())
|
697
|
return;
|
698
|
LogEntry entry = (LogEntry) ((IStructuredSelection) selection).getFirstElement();
|
699
|
entry.write(pwriter);
|
700
|
pwriter.flush();
|
701
|
String textVersion = writer.toString();
|
702
|
try {
|
703
|
pwriter.close();
|
704
|
writer.close();
|
705
|
} catch (IOException e) {
|
706
|
}
|
707
|
// if (textVersion.trim().length() > 0) {
|
708
|
// //set the clipboard contents
|
709
|
// fClipboard.setContents(
|
710
|
// new Object[] { textVersion },
|
711
|
// new Transfer[] { TextTransfer.getInstance() });
|
712
|
// }
|
713
|
}
|
714
|
|
715
|
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
716
|
super.init(site, memento);
|
717
|
// if (memento == null)
|
718
|
// this.fMemento = XMLMemento.createWriteRoot("LOGVIEW"); //$NON-NLS-1$
|
719
|
// else
|
720
|
// this.fMemento = memento;
|
721
|
// readSettings();
|
722
|
|
723
|
// initialize column ordering
|
724
|
// final byte type = this.fMemento.getInteger(P_ORDER_TYPE).byteValue();
|
725
|
// switch (type){
|
726
|
// case DATE:
|
727
|
// DATE_ORDER = this.fMemento.getInteger(P_ORDER_VALUE).intValue();
|
728
|
// MESSAGE_ORDER = DESCENDING;
|
729
|
// PLUGIN_ORDER = DESCENDING;
|
730
|
// break;
|
731
|
// case MESSAGE:
|
732
|
// MESSAGE_ORDER = this.fMemento.getInteger(P_ORDER_VALUE).intValue();
|
733
|
// DATE_ORDER = DESCENDING;
|
734
|
// PLUGIN_ORDER = DESCENDING;
|
735
|
// break;
|
736
|
// case PLUGIN:
|
737
|
// PLUGIN_ORDER = this.fMemento.getInteger(P_ORDER_VALUE).intValue();
|
738
|
// MESSAGE_ORDER = DESCENDING;
|
739
|
// DATE_ORDER = DESCENDING;
|
740
|
// break;
|
741
|
// default:
|
742
|
DATE_ORDER = DESCENDING;
|
743
|
MESSAGE_ORDER = DESCENDING;
|
744
|
PLUGIN_ORDER = DESCENDING;
|
745
|
// }
|
746
|
// setComparator(fMemento.getInteger(P_ORDER_TYPE).byteValue());
|
747
|
setComparator(DATE);
|
748
|
}
|
749
|
|
750
|
private void initializeMemento() {
|
751
|
// if (fMemento.getString(P_USE_LIMIT) == null)
|
752
|
// fMemento.putString(P_USE_LIMIT, "true"); //$NON-NLS-1$
|
753
|
// if (fMemento.getInteger(P_LOG_LIMIT) == null)
|
754
|
// fMemento.putInteger(P_LOG_LIMIT, 50);
|
755
|
// if (fMemento.getString(P_LOG_INFO) == null)
|
756
|
// fMemento.putString(P_LOG_INFO, "true"); //$NON-NLS-1$
|
757
|
// if (fMemento.getString(P_LOG_WARNING) == null)
|
758
|
// fMemento.putString(P_LOG_WARNING, "true"); //$NON-NLS-1$
|
759
|
// if (fMemento.getString(P_LOG_ERROR) == null)
|
760
|
// fMemento.putString(P_LOG_ERROR, "true"); //$NON-NLS-1$
|
761
|
// if (fMemento.getString(P_SHOW_ALL_SESSIONS) == null)
|
762
|
// fMemento.putString(P_SHOW_ALL_SESSIONS, "true"); //$NON-NLS-1$
|
763
|
// Integer width = fMemento.getInteger(P_COLUMN_1);
|
764
|
// if (width == null || width.intValue() == 0)
|
765
|
// fMemento.putInteger(P_COLUMN_1, 300);
|
766
|
// width = fMemento.getInteger(P_COLUMN_2);
|
767
|
// if (width == null || width.intValue() == 0)
|
768
|
// fMemento.putInteger(P_COLUMN_2, 150);
|
769
|
// width = fMemento.getInteger(P_COLUMN_3);
|
770
|
// if (width == null || width.intValue() == 0)
|
771
|
// fMemento.putInteger(P_COLUMN_3, 150);
|
772
|
// if (fMemento.getString(P_ACTIVATE) == null)
|
773
|
// fMemento.putString(P_ACTIVATE, "true"); //$NON-NLS-1$
|
774
|
//
|
775
|
// fMemento.putInteger(P_ORDER_VALUE, DESCENDING);
|
776
|
// fMemento.putInteger(P_ORDER_TYPE, DATE);
|
777
|
}
|
778
|
|
779
|
public void saveState(IMemento memento) {
|
780
|
// if (this.fMemento == null || memento == null)
|
781
|
// return;
|
782
|
// this.fMemento.putInteger(P_COLUMN_1, fColumn1.getWidth());
|
783
|
// this.fMemento.putInteger(P_COLUMN_2, fColumn2.getWidth());
|
784
|
// this.fMemento.putInteger(P_COLUMN_3, fColumn3.getWidth());
|
785
|
// this.fMemento.putString(P_ACTIVATE,
|
786
|
// fActivateViewAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
|
787
|
// memento.putMemento(this.fMemento);
|
788
|
// writeSettings();
|
789
|
}
|
790
|
|
791
|
private void addMouseListeners() {
|
792
|
// Listener tableListener = new Listener() {
|
793
|
// public void handleEvent(Event e) {
|
794
|
// switch (e.type) {
|
795
|
// case SWT.MouseMove:
|
796
|
// onMouseMove(e);
|
797
|
// break;
|
798
|
// case SWT.MouseHover:
|
799
|
// onMouseHover(e);
|
800
|
// break;
|
801
|
// case SWT.MouseDown:
|
802
|
// onMouseDown(e);
|
803
|
// break;
|
804
|
// }
|
805
|
// }
|
806
|
// };
|
807
|
// int[] tableEvents = new int[] { SWT.MouseDown, SWT.MouseMove, SWT.MouseHover };
|
808
|
// for (int i = 0; i < tableEvents.length; i++) {
|
809
|
// fTree.addListener(tableEvents[i], tableListener);
|
810
|
// }
|
811
|
}
|
812
|
|
813
|
private void makeHoverShell() {
|
814
|
fTextShell = new Shell(fTree.getShell(), SWT.NO_FOCUS | SWT.ON_TOP /*| SWT.TOOL*/);
|
815
|
Display display = fTextShell.getDisplay();
|
816
|
fTextShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
|
817
|
GridLayout layout = new GridLayout(1, false);
|
818
|
int border = ((fTree.getShell().getStyle() & SWT.NO_TRIM) == 0) ? 0 : 1;
|
819
|
layout.marginHeight = border;
|
820
|
layout.marginWidth = border;
|
821
|
fTextShell.setLayout(layout);
|
822
|
fTextShell.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
823
|
Composite shellComposite = new Composite(fTextShell, SWT.NONE);
|
824
|
layout = new GridLayout();
|
825
|
layout.marginHeight = 0;
|
826
|
layout.marginWidth = 0;
|
827
|
shellComposite.setLayout(layout);
|
828
|
shellComposite.setLayoutData(
|
829
|
new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING));
|
830
|
fTextLabel = new Text(shellComposite, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY);
|
831
|
GridData gd = new GridData(GridData.FILL_BOTH);
|
832
|
gd.widthHint = 100;
|
833
|
gd.grabExcessHorizontalSpace = true;
|
834
|
fTextLabel.setLayoutData(gd);
|
835
|
Color c = fTree.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
|
836
|
fTextLabel.setBackground(c);
|
837
|
c = fTree.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
|
838
|
fTextLabel.setForeground(c);
|
839
|
fTextLabel.setEditable(false);
|
840
|
fTextShell.addDisposeListener(new DisposeListener() {
|
841
|
public void widgetDisposed(DisposeEvent e) {
|
842
|
onTextShellDispose(e);
|
843
|
}
|
844
|
});
|
845
|
}
|
846
|
|
847
|
void onTextShellDispose(DisposeEvent e) {
|
848
|
fCanOpenTextShell = true;
|
849
|
setFocus();
|
850
|
}
|
851
|
|
852
|
void onMouseDown(Event e) {
|
853
|
if (fTextShell != null && !fTextShell.isDisposed() && !fTextShell.isFocusControl()) {
|
854
|
fTextShell.setVisible(false);
|
855
|
fCanOpenTextShell = true;
|
856
|
}
|
857
|
}
|
858
|
|
859
|
void onMouseHover(Event e) {
|
860
|
if (!fCanOpenTextShell)
|
861
|
return;
|
862
|
fCanOpenTextShell = false;
|
863
|
Point point = new Point(e.x, e.y);
|
864
|
TreeItem item = fTree.getItem(point);
|
865
|
if (item == null)
|
866
|
return;
|
867
|
String message = ((LogEntry) item.getData()).getStack();
|
868
|
if (message == null)
|
869
|
return;
|
870
|
|
871
|
fTextLabel.setText(message);
|
872
|
Rectangle bounds = fTree.getDisplay().getBounds();
|
873
|
// Point cursorPoint = fTree.getDisplay().getCursorLocation();
|
874
|
int x = point.x;
|
875
|
int y = point.y + 25;
|
876
|
int width = fTree.getColumn(0).getWidth();
|
877
|
int height = 125;
|
878
|
// if (cursorPoint.x + width > bounds.width)
|
879
|
// x -= width;
|
880
|
// if (cursorPoint.y + height + 25 > bounds.height)
|
881
|
// y -= height + 27;
|
882
|
|
883
|
fTextShell.setLocation(fTree.toDisplay(x, y));
|
884
|
fTextShell.setSize(width, height);
|
885
|
fTextShell.setVisible(true);
|
886
|
}
|
887
|
|
888
|
void onMouseMove(Event e) {
|
889
|
if (fTextShell != null && !fTextShell.isDisposed() && fTextShell.isVisible())
|
890
|
fTextShell.setVisible(false);
|
891
|
|
892
|
Point point = new Point(e.x, e.y);
|
893
|
TreeItem item = fTree.getItem(point);
|
894
|
if (item == null)
|
895
|
return;
|
896
|
Image image= item.getImage();
|
897
|
LogEntry entry = (LogEntry)item.getData();
|
898
|
int parentCount = getNumberOfParents(entry);
|
899
|
int startRange = 20 + Math.max(image.getBounds().width + 2, 7 + 2)*parentCount;
|
900
|
int endRange = startRange + 16;
|
901
|
fCanOpenTextShell = e.x >= startRange && e.x <= endRange;
|
902
|
}
|
903
|
|
904
|
private int getNumberOfParents(LogEntry entry){
|
905
|
LogEntry parent = (LogEntry)entry.getParent(entry);
|
906
|
if (parent ==null)
|
907
|
return 0;
|
908
|
return 1 + getNumberOfParents(parent);
|
909
|
}
|
910
|
|
911
|
public Comparator getComparator() {
|
912
|
return fComparator;
|
913
|
}
|
914
|
|
915
|
private void setComparator(byte sortType) {
|
916
|
if (sortType == DATE) {
|
917
|
fComparator = new Comparator() {
|
918
|
public int compare(Object e1, Object e2) {
|
919
|
long date1 = ((LogEntry) e1).getDate().getTime();
|
920
|
long date2 = ((LogEntry) e2).getDate().getTime();
|
921
|
if (date1 == date2) {
|
922
|
int result = fLogs.indexOf(e2) - fLogs.indexOf(e1);
|
923
|
if (DATE_ORDER == DESCENDING)
|
924
|
result *= DESCENDING;
|
925
|
return result;
|
926
|
}
|
927
|
if (DATE_ORDER == DESCENDING)
|
928
|
return date1 > date2 ? DESCENDING : ASCENDING;
|
929
|
return date1 < date2 ? DESCENDING : ASCENDING;
|
930
|
}
|
931
|
};
|
932
|
} else if (sortType == PLUGIN) {
|
933
|
fComparator = new Comparator() {
|
934
|
public int compare(Object e1, Object e2) {
|
935
|
LogEntry entry1 = (LogEntry) e1;
|
936
|
LogEntry entry2 = (LogEntry) e2;
|
937
|
return getDefaultComparator().compare(entry1.getPluginId(), entry2.getPluginId()) * PLUGIN_ORDER;
|
938
|
}
|
939
|
};
|
940
|
} else {
|
941
|
fComparator = new Comparator() {
|
942
|
public int compare(Object e1, Object e2) {
|
943
|
LogEntry entry1 = (LogEntry) e1;
|
944
|
LogEntry entry2 = (LogEntry) e2;
|
945
|
return getDefaultComparator().compare(entry1.getMessage(), entry2.getMessage()) * MESSAGE_ORDER;
|
946
|
}
|
947
|
};
|
948
|
}
|
949
|
}
|
950
|
|
951
|
private Comparator getDefaultComparator() {
|
952
|
return Policy.getComparator();
|
953
|
}
|
954
|
|
955
|
private ViewerComparator getViewerComparator(byte sortType) {
|
956
|
if (sortType == PLUGIN) {
|
957
|
return new ViewerComparator() {
|
958
|
public int compare(Viewer viewer, Object e1, Object e2) {
|
959
|
LogEntry entry1 = (LogEntry) e1;
|
960
|
LogEntry entry2 = (LogEntry) e2;
|
961
|
return getComparator().compare(entry1.getPluginId(), entry2.getPluginId()) * PLUGIN_ORDER;
|
962
|
}
|
963
|
};
|
964
|
} else if (sortType == MESSAGE) {
|
965
|
return new ViewerComparator() {
|
966
|
public int compare(Viewer viewer, Object e1, Object e2) {
|
967
|
LogEntry entry1 = (LogEntry) e1;
|
968
|
LogEntry entry2 = (LogEntry) e2;
|
969
|
return getComparator().compare(entry1.getMessage(), entry2.getMessage()) * MESSAGE_ORDER;
|
970
|
}
|
971
|
};
|
972
|
} else {
|
973
|
return new ViewerComparator() {
|
974
|
public int compare(Viewer viewer, Object e1, Object e2) {
|
975
|
long date1 = ((LogEntry) e1).getDate().getTime();
|
976
|
long date2 = ((LogEntry) e2).getDate().getTime();
|
977
|
if (date1 == date2) {
|
978
|
int result = fLogs.indexOf(e2) - fLogs.indexOf(e1);
|
979
|
if (DATE_ORDER == DESCENDING)
|
980
|
result *= DESCENDING;
|
981
|
return result;
|
982
|
}
|
983
|
if (DATE_ORDER == DESCENDING)
|
984
|
return date1 > date2 ? DESCENDING : ASCENDING;
|
985
|
return date1 < date2 ? DESCENDING : ASCENDING;
|
986
|
}
|
987
|
};
|
988
|
}
|
989
|
}
|
990
|
|
991
|
private void resetDialogButtons() {
|
992
|
((EventDetailsDialogAction) fPropertiesAction).resetDialogButtons();
|
993
|
}
|
994
|
|
995
|
/**
|
996
|
* Returns the filter dialog settings object used to maintain
|
997
|
* state between filter dialogs
|
998
|
* @return the dialog settings to be used
|
999
|
*/
|
1000
|
private IDialogSettings getLogSettings() {
|
1001
|
IDialogSettings settings= PDERuntimePlugin.getDefault().getDialogSettings();
|
1002
|
return settings.getSection(getClass().getName());
|
1003
|
}
|
1004
|
|
1005
|
/**
|
1006
|
* Returns the plugin preferences used to maintain
|
1007
|
* state of log view
|
1008
|
* @return the plugin preferences
|
1009
|
*/
|
1010
|
private Preferences getLogPreferences(){
|
1011
|
return PDERuntimePlugin.getDefault().getPluginPreferences();
|
1012
|
}
|
1013
|
|
1014
|
private void readSettings(){
|
1015
|
IDialogSettings s = getLogSettings();
|
1016
|
Preferences p = getLogPreferences();
|
1017
|
if (s == null || p == null){
|
1018
|
initializeMemento();
|
1019
|
return;
|
1020
|
}
|
1021
|
try {
|
1022
|
// fMemento.putString(P_USE_LIMIT, s.getBoolean(P_USE_LIMIT) ? "true":"false"); //$NON-NLS-1$ //$NON-NLS-2$
|
1023
|
// fMemento.putString(P_LOG_INFO, s.getBoolean(P_LOG_INFO) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
|
1024
|
// fMemento.putString(P_LOG_WARNING, s.getBoolean(P_LOG_WARNING) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
|
1025
|
// fMemento.putString(P_LOG_ERROR, s.getBoolean(P_LOG_ERROR) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
|
1026
|
// fMemento.putString(P_SHOW_ALL_SESSIONS, s.getBoolean(P_SHOW_ALL_SESSIONS) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
|
1027
|
// fMemento.putInteger(P_LOG_LIMIT, s.getInt(P_LOG_LIMIT));
|
1028
|
// fMemento.putInteger(P_COLUMN_1, p.getInt(P_COLUMN_1) > 0 ? p.getInt(P_COLUMN_1) : 300);
|
1029
|
// fMemento.putInteger(P_COLUMN_2, p.getInt(P_COLUMN_2) > 0 ? p.getInt(P_COLUMN_2) : 150);
|
1030
|
// fMemento.putInteger(P_COLUMN_3, p.getInt(P_COLUMN_3) > 0 ? p.getInt(P_COLUMN_3) : 150);
|
1031
|
// fMemento.putString(P_ACTIVATE, p.getBoolean(P_ACTIVATE) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
|
1032
|
// int order = p.getInt(P_ORDER_VALUE);
|
1033
|
// fMemento.putInteger(P_ORDER_VALUE, order == 0 ? DESCENDING : order);
|
1034
|
// fMemento.putInteger(P_ORDER_TYPE, p.getInt(P_ORDER_TYPE));
|
1035
|
} catch (NumberFormatException e) {
|
1036
|
// fMemento.putInteger(P_LOG_LIMIT, 50);
|
1037
|
// fMemento.putInteger(P_COLUMN_1, 300);
|
1038
|
// fMemento.putInteger(P_COLUMN_2, 150);
|
1039
|
// fMemento.putInteger(P_COLUMN_3, 150);
|
1040
|
// fMemento.putInteger(P_ORDER_TYPE, DATE);
|
1041
|
// fMemento.putInteger(P_ORDER_VALUE, DESCENDING);
|
1042
|
}
|
1043
|
}
|
1044
|
|
1045
|
private void writeSettings(){
|
1046
|
writeViewSettings();
|
1047
|
writeFilterSettings();
|
1048
|
}
|
1049
|
|
1050
|
private void writeFilterSettings(){
|
1051
|
IDialogSettings settings = getLogSettings();
|
1052
|
if (settings == null)
|
1053
|
settings = PDERuntimePlugin.getDefault().getDialogSettings().addNewSection(getClass().getName());
|
1054
|
// settings.put(P_USE_LIMIT, fMemento.getString(P_USE_LIMIT).equals("true")); //$NON-NLS-1$
|
1055
|
// settings.put(P_LOG_LIMIT, fMemento.getInteger(P_LOG_LIMIT).intValue());
|
1056
|
// settings.put(P_LOG_INFO, fMemento.getString(P_LOG_INFO).equals("true")); //$NON-NLS-1$
|
1057
|
// settings.put(P_LOG_WARNING, fMemento.getString(P_LOG_WARNING).equals("true")); //$NON-NLS-1$
|
1058
|
// settings.put(P_LOG_ERROR, fMemento.getString(P_LOG_ERROR).equals("true")); //$NON-NLS-1$
|
1059
|
// settings.put(P_SHOW_ALL_SESSIONS, fMemento.getString(P_SHOW_ALL_SESSIONS).equals("true")); //$NON-NLS-1$
|
1060
|
}
|
1061
|
|
1062
|
private void writeViewSettings(){
|
1063
|
Preferences preferences = getLogPreferences();
|
1064
|
// preferences.setValue(P_COLUMN_1, fMemento.getInteger(P_COLUMN_1).intValue());
|
1065
|
// preferences.setValue(P_COLUMN_2, fMemento.getInteger(P_COLUMN_2).intValue());
|
1066
|
// preferences.setValue(P_COLUMN_3, fMemento.getInteger(P_COLUMN_3).intValue());
|
1067
|
// preferences.setValue(P_ACTIVATE, fMemento.getString(P_ACTIVATE).equals("true")); //$NON-NLS-1$
|
1068
|
// int order = fMemento.getInteger(P_ORDER_VALUE).intValue();
|
1069
|
// preferences.setValue(P_ORDER_VALUE, order == 0 ? DESCENDING : order);
|
1070
|
// preferences.setValue(P_ORDER_TYPE, fMemento.getInteger(P_ORDER_TYPE).intValue());
|
1071
|
}
|
1072
|
|
1073
|
public void sortByDateDescending() {
|
1074
|
setColumnSorting(fColumn3, DESCENDING);
|
1075
|
}
|
1076
|
|
1077
|
protected Job getOpenLogFileJob() {
|
1078
|
final Shell shell = getViewSite().getShell();
|
1079
|
return new Job(PDERuntimeMessages.get().OpenLogDialog_message) {
|
1080
|
protected IStatus run(IProgressMonitor monitor) {
|
1081
|
boolean failed = false;
|
1082
|
if (fInputFile.length() <= LogReader.MAX_FILE_LENGTH) {
|
1083
|
// failed = !Program.launch(fInputFile.getAbsolutePath());
|
1084
|
// if (failed) {
|
1085
|
// Program p = Program.findProgram(".txt"); //$NON-NLS-1$
|
1086
|
// if (p != null) {
|
1087
|
// p.execute(fInputFile.getAbsolutePath());
|
1088
|
// return Status.OK_STATUS;
|
1089
|
// }
|
1090
|
// }
|
1091
|
}
|
1092
|
if (failed) {
|
1093
|
final OpenLogDialog openDialog = new OpenLogDialog(shell, fInputFile);
|
1094
|
Display.getDefault().asyncExec(new Runnable() {
|
1095
|
public void run() {
|
1096
|
openDialog.create();
|
1097
|
openDialog.open();
|
1098
|
}
|
1099
|
});
|
1100
|
}
|
1101
|
return Status.OK_STATUS;
|
1102
|
}
|
1103
|
};
|
1104
|
}
|
1105
|
|
1106
|
protected File getLogFile() {
|
1107
|
return fInputFile;
|
1108
|
}
|
1109
|
}
|