Source Code Cross Referenced for LogView.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » runtime » logview » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.runtime.logview 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*******************************************************************************
0002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
0003:         * All rights reserved. This program and the accompanying materials
0004:         * are made available under the terms of the Eclipse Public License v1.0
0005:         * which accompanies this distribution, and is available at
0006:         * http://www.eclipse.org/legal/epl-v10.html
0007:         *
0008:         * Contributors:
0009:         *     IBM Corporation - initial API and implementation
0010:         *******************************************************************************/package org.eclipse.pde.internal.runtime.logview;
0011:
0012:        import java.io.BufferedReader;
0013:        import java.io.BufferedWriter;
0014:        import java.io.File;
0015:        import java.io.FileInputStream;
0016:        import java.io.FileOutputStream;
0017:        import java.io.IOException;
0018:        import java.io.InputStreamReader;
0019:        import java.io.OutputStreamWriter;
0020:        import java.io.PrintWriter;
0021:        import java.io.StringWriter;
0022:        import java.lang.reflect.InvocationTargetException;
0023:        import java.util.ArrayList;
0024:        import java.util.Comparator;
0025:
0026:        import org.eclipse.core.runtime.ILogListener;
0027:        import org.eclipse.core.runtime.IProgressMonitor;
0028:        import org.eclipse.core.runtime.IStatus;
0029:        import org.eclipse.core.runtime.Path;
0030:        import org.eclipse.core.runtime.Platform;
0031:        import org.eclipse.core.runtime.Preferences;
0032:        import org.eclipse.core.runtime.Status;
0033:        import org.eclipse.core.runtime.jobs.Job;
0034:        import org.eclipse.jface.action.Action;
0035:        import org.eclipse.jface.action.IMenuListener;
0036:        import org.eclipse.jface.action.IMenuManager;
0037:        import org.eclipse.jface.action.IStatusLineManager;
0038:        import org.eclipse.jface.action.IToolBarManager;
0039:        import org.eclipse.jface.action.MenuManager;
0040:        import org.eclipse.jface.action.Separator;
0041:        import org.eclipse.jface.dialogs.IDialogSettings;
0042:        import org.eclipse.jface.dialogs.MessageDialog;
0043:        import org.eclipse.jface.dialogs.ProgressMonitorDialog;
0044:        import org.eclipse.jface.operation.IRunnableWithProgress;
0045:        import org.eclipse.jface.util.Policy;
0046:        import org.eclipse.jface.viewers.DoubleClickEvent;
0047:        import org.eclipse.jface.viewers.IDoubleClickListener;
0048:        import org.eclipse.jface.viewers.ISelection;
0049:        import org.eclipse.jface.viewers.ISelectionChangedListener;
0050:        import org.eclipse.jface.viewers.IStructuredSelection;
0051:        import org.eclipse.jface.viewers.SelectionChangedEvent;
0052:        import org.eclipse.jface.viewers.TreeViewer;
0053:        import org.eclipse.jface.viewers.Viewer;
0054:        import org.eclipse.jface.viewers.ViewerComparator;
0055:        import org.eclipse.jface.window.Window;
0056:        import org.eclipse.osgi.util.NLS;
0057:        import org.eclipse.pde.internal.runtime.IHelpContextIds;
0058:        import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
0059:        import org.eclipse.pde.internal.runtime.PDERuntimePlugin;
0060:        import org.eclipse.pde.internal.runtime.PDERuntimePluginImages;
0061:        import org.eclipse.swt.SWT;
0062:        import org.eclipse.swt.custom.BusyIndicator;
0063:        import org.eclipse.swt.dnd.Clipboard;
0064:        import org.eclipse.swt.dnd.TextTransfer;
0065:        import org.eclipse.swt.dnd.Transfer;
0066:        import org.eclipse.swt.events.DisposeEvent;
0067:        import org.eclipse.swt.events.DisposeListener;
0068:        import org.eclipse.swt.events.SelectionAdapter;
0069:        import org.eclipse.swt.events.SelectionEvent;
0070:        import org.eclipse.swt.graphics.Color;
0071:        import org.eclipse.swt.graphics.Image;
0072:        import org.eclipse.swt.graphics.Point;
0073:        import org.eclipse.swt.graphics.Rectangle;
0074:        import org.eclipse.swt.layout.GridData;
0075:        import org.eclipse.swt.layout.GridLayout;
0076:        import org.eclipse.swt.program.Program;
0077:        import org.eclipse.swt.widgets.Composite;
0078:        import org.eclipse.swt.widgets.Display;
0079:        import org.eclipse.swt.widgets.Event;
0080:        import org.eclipse.swt.widgets.FileDialog;
0081:        import org.eclipse.swt.widgets.Listener;
0082:        import org.eclipse.swt.widgets.Menu;
0083:        import org.eclipse.swt.widgets.Shell;
0084:        import org.eclipse.swt.widgets.Text;
0085:        import org.eclipse.swt.widgets.Tree;
0086:        import org.eclipse.swt.widgets.TreeColumn;
0087:        import org.eclipse.swt.widgets.TreeItem;
0088:        import org.eclipse.ui.IActionBars;
0089:        import org.eclipse.ui.IMemento;
0090:        import org.eclipse.ui.ISharedImages;
0091:        import org.eclipse.ui.IViewSite;
0092:        import org.eclipse.ui.IWorkbenchActionConstants;
0093:        import org.eclipse.ui.IWorkbenchPage;
0094:        import org.eclipse.ui.PartInitException;
0095:        import org.eclipse.ui.PlatformUI;
0096:        import org.eclipse.ui.XMLMemento;
0097:        import org.eclipse.ui.actions.ActionFactory;
0098:        import org.eclipse.ui.part.ViewPart;
0099:
0100:        public class LogView extends ViewPart implements  ILogListener {
0101:            public static final String P_LOG_WARNING = "warning"; //$NON-NLS-1$
0102:            public static final String P_LOG_ERROR = "error"; //$NON-NLS-1$
0103:            public static final String P_LOG_INFO = "info"; //$NON-NLS-1$
0104:            public static final String P_LOG_LIMIT = "limit"; //$NON-NLS-1$
0105:            public static final String P_USE_LIMIT = "useLimit"; //$NON-NLS-1$
0106:            public static final String P_SHOW_ALL_SESSIONS = "allSessions"; //$NON-NLS-1$
0107:            private static final String P_COLUMN_1 = "column2"; //$NON-NLS-1$
0108:            private static final String P_COLUMN_2 = "column3"; //$NON-NLS-1$
0109:            private static final String P_COLUMN_3 = "column4"; //$NON-NLS-1$
0110:            public static final String P_ACTIVATE = "activate"; //$NON-NLS-1$
0111:            public static final String P_ORDER_TYPE = "orderType"; //$NON-NLS-1$
0112:            public static final String P_ORDER_VALUE = "orderValue"; //$NON-NLS-1$
0113:
0114:            private int MESSAGE_ORDER;
0115:            private int PLUGIN_ORDER;
0116:            private int DATE_ORDER;
0117:
0118:            public final static byte MESSAGE = 0x0;
0119:            public final static byte PLUGIN = 0x1;
0120:            public final static byte DATE = 0x2;
0121:            public static int ASCENDING = 1;
0122:            public static int DESCENDING = -1;
0123:
0124:            private ArrayList fLogs;
0125:
0126:            private Clipboard fClipboard;
0127:
0128:            private IMemento fMemento;
0129:            private File fInputFile;
0130:            private String fDirectory;
0131:
0132:            private Comparator fComparator;
0133:
0134:            // hover text
0135:            private boolean fCanOpenTextShell;
0136:            private Text fTextLabel;
0137:            private Shell fTextShell;
0138:
0139:            private boolean fFirstEvent = true;
0140:
0141:            private TreeColumn fColumn1;
0142:            private TreeColumn fColumn2;
0143:            private TreeColumn fColumn3;
0144:
0145:            private Tree fTree;
0146:            private TreeViewer fTreeViewer;
0147:            private LogViewLabelProvider fLabelProvider;
0148:
0149:            private Action fPropertiesAction;
0150:            private Action fDeleteLogAction;
0151:            private Action fReadLogAction;
0152:            private Action fCopyAction;
0153:            private Action fActivateViewAction;
0154:            private Action fOpenLogAction;
0155:            private Action fExportAction;
0156:
0157:            public LogView() {
0158:                fLogs = new ArrayList();
0159:                fInputFile = Platform.getLogFileLocation().toFile();
0160:            }
0161:
0162:            public void createPartControl(Composite parent) {
0163:                readLogFile();
0164:                createViewer(parent);
0165:                createActions();
0166:                fClipboard = new Clipboard(fTree.getDisplay());
0167:                fTree.setToolTipText(""); //$NON-NLS-1$
0168:                getSite().setSelectionProvider(fTreeViewer);
0169:                initializeViewerSorter();
0170:
0171:                makeHoverShell();
0172:
0173:                Platform.addLogListener(this );
0174:                PlatformUI.getWorkbench().getHelpSystem().setHelp(fTree,
0175:                        IHelpContextIds.LOG_VIEW);
0176:            }
0177:
0178:            private void createActions() {
0179:                IActionBars bars = getViewSite().getActionBars();
0180:
0181:                fCopyAction = createCopyAction();
0182:                bars.setGlobalActionHandler(ActionFactory.COPY.getId(),
0183:                        fCopyAction);
0184:
0185:                IToolBarManager toolBarManager = bars.getToolBarManager();
0186:
0187:                fExportAction = createExportAction();
0188:                toolBarManager.add(fExportAction);
0189:
0190:                final Action importLogAction = createImportLogAction();
0191:                toolBarManager.add(importLogAction);
0192:
0193:                toolBarManager.add(new Separator());
0194:
0195:                final Action clearAction = createClearAction();
0196:                toolBarManager.add(clearAction);
0197:
0198:                fDeleteLogAction = createDeleteLogAction();
0199:                toolBarManager.add(fDeleteLogAction);
0200:
0201:                fOpenLogAction = createOpenLogAction();
0202:                toolBarManager.add(fOpenLogAction);
0203:
0204:                fReadLogAction = createReadLogAction();
0205:                toolBarManager.add(fReadLogAction);
0206:
0207:                toolBarManager.add(new Separator());
0208:
0209:                IMenuManager mgr = bars.getMenuManager();
0210:                mgr.add(createFilterAction());
0211:                mgr.add(new Separator());
0212:
0213:                fActivateViewAction = createActivateViewAction();
0214:                mgr.add(fActivateViewAction);
0215:
0216:                createPropertiesAction();
0217:
0218:                MenuManager popupMenuManager = new MenuManager("#PopupMenu"); //$NON-NLS-1$
0219:                IMenuListener listener = new IMenuListener() {
0220:                    public void menuAboutToShow(IMenuManager manager) {
0221:                        manager.add(fCopyAction);
0222:                        manager.add(new Separator());
0223:                        manager.add(clearAction);
0224:                        manager.add(fDeleteLogAction);
0225:                        manager.add(fOpenLogAction);
0226:                        manager.add(fReadLogAction);
0227:                        manager.add(new Separator());
0228:                        manager.add(fExportAction);
0229:                        manager.add(importLogAction);
0230:                        manager.add(new Separator());
0231:                        ((EventDetailsDialogAction) fPropertiesAction)
0232:                                .setComparator(fComparator);
0233:                        manager.add(fPropertiesAction);
0234:                        manager.add(new Separator(
0235:                                IWorkbenchActionConstants.MB_ADDITIONS));
0236:                    }
0237:                };
0238:                popupMenuManager.addMenuListener(listener);
0239:                popupMenuManager.setRemoveAllWhenShown(true);
0240:                getSite().registerContextMenu(popupMenuManager,
0241:                        getSite().getSelectionProvider());
0242:                Menu menu = popupMenuManager.createContextMenu(fTree);
0243:                fTree.setMenu(menu);
0244:            }
0245:
0246:            private Action createActivateViewAction() {
0247:                Action action = new Action(PDERuntimeMessages.LogView_activate) { //       	
0248:                    public void run() {
0249:                        fMemento.putString(P_ACTIVATE,
0250:                                isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
0251:                    }
0252:                };
0253:                action
0254:                        .setChecked(fMemento.getString(P_ACTIVATE).equals(
0255:                                "true")); //$NON-NLS-1$
0256:                return action;
0257:            }
0258:
0259:            private Action createClearAction() {
0260:                Action action = new Action(PDERuntimeMessages.LogView_clear) {
0261:                    public void run() {
0262:                        handleClear();
0263:                    }
0264:                };
0265:                action.setImageDescriptor(PDERuntimePluginImages.DESC_CLEAR);
0266:                action
0267:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_CLEAR_DISABLED);
0268:                action.setToolTipText(PDERuntimeMessages.LogView_clear_tooltip);
0269:                action.setText(PDERuntimeMessages.LogView_clear);
0270:                return action;
0271:            }
0272:
0273:            private Action createCopyAction() {
0274:                Action action = new Action(PDERuntimeMessages.LogView_copy) {
0275:                    public void run() {
0276:                        copyToClipboard(fTreeViewer.getSelection());
0277:                    }
0278:                };
0279:                action.setImageDescriptor(PlatformUI.getWorkbench()
0280:                        .getSharedImages().getImageDescriptor(
0281:                                ISharedImages.IMG_TOOL_COPY));
0282:                return action;
0283:            }
0284:
0285:            private Action createDeleteLogAction() {
0286:                Action action = new Action(PDERuntimeMessages.LogView_delete) {
0287:                    public void run() {
0288:                        doDeleteLog();
0289:                    }
0290:                };
0291:                action
0292:                        .setToolTipText(PDERuntimeMessages.LogView_delete_tooltip);
0293:                action
0294:                        .setImageDescriptor(PDERuntimePluginImages.DESC_REMOVE_LOG);
0295:                action
0296:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_REMOVE_LOG_DISABLED);
0297:                action.setEnabled(fInputFile.exists()
0298:                        && fInputFile.equals(Platform.getLogFileLocation()
0299:                                .toFile()));
0300:                return action;
0301:            }
0302:
0303:            private Action createExportAction() {
0304:                Action action = new Action(PDERuntimeMessages.LogView_export) {
0305:                    public void run() {
0306:                        handleExport();
0307:                    }
0308:                };
0309:                action
0310:                        .setToolTipText(PDERuntimeMessages.LogView_export_tooltip);
0311:                action.setImageDescriptor(PDERuntimePluginImages.DESC_EXPORT);
0312:                action
0313:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_EXPORT_DISABLED);
0314:                action.setEnabled(fInputFile.exists());
0315:                return action;
0316:            }
0317:
0318:            private Action createFilterAction() {
0319:                Action action = new Action(PDERuntimeMessages.LogView_filter) {
0320:                    public void run() {
0321:                        handleFilter();
0322:                    }
0323:                };
0324:                action.setToolTipText(PDERuntimeMessages.LogView_filter);
0325:                action.setImageDescriptor(PDERuntimePluginImages.DESC_FILTER);
0326:                action
0327:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_FILTER_DISABLED);
0328:                return action;
0329:            }
0330:
0331:            private Action createImportLogAction() {
0332:                Action action = new Action(PDERuntimeMessages.LogView_import) {
0333:                    public void run() {
0334:                        handleImport();
0335:                    }
0336:                };
0337:                action
0338:                        .setToolTipText(PDERuntimeMessages.LogView_import_tooltip);
0339:                action.setImageDescriptor(PDERuntimePluginImages.DESC_IMPORT);
0340:                action
0341:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_IMPORT_DISABLED);
0342:                return action;
0343:            }
0344:
0345:            private Action createOpenLogAction() {
0346:                Action action = null;
0347:                try {
0348:                    // check to see if org.eclipse.ui.ide is available
0349:                    Class.forName("org.eclipse.ui.ide.IDE"); //$NON-NLS-1$
0350:                    // check to see if org.eclipse.core.filesystem is available
0351:                    Class.forName("org.eclipse.core.filesystem.IFileStore"); //$NON-NLS-1$
0352:                    action = new OpenIDELogFileAction(this );
0353:                } catch (ClassNotFoundException e) {
0354:                    action = new Action() {
0355:                        public void run() {
0356:                            if (fInputFile.exists()) {
0357:                                Job job = getOpenLogFileJob();
0358:                                job.setUser(false);
0359:                                job.setPriority(Job.SHORT);
0360:                                job.schedule();
0361:                            }
0362:                        }
0363:                    };
0364:                }
0365:                action.setText(PDERuntimeMessages.LogView_view_currentLog);
0366:                action.setImageDescriptor(PDERuntimePluginImages.DESC_OPEN_LOG);
0367:                action
0368:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_OPEN_LOG_DISABLED);
0369:                action.setEnabled(fInputFile.exists());
0370:                action
0371:                        .setToolTipText(PDERuntimeMessages.LogView_view_currentLog_tooltip);
0372:                return action;
0373:            }
0374:
0375:            private void createPropertiesAction() {
0376:                fPropertiesAction = new EventDetailsDialogAction(fTree
0377:                        .getShell(), fTreeViewer);
0378:                fPropertiesAction
0379:                        .setImageDescriptor(PDERuntimePluginImages.DESC_PROPERTIES);
0380:                fPropertiesAction
0381:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_PROPERTIES_DISABLED);
0382:                fPropertiesAction
0383:                        .setToolTipText(PDERuntimeMessages.LogView_properties_tooltip);
0384:                fPropertiesAction.setEnabled(false);
0385:            }
0386:
0387:            private Action createReadLogAction() {
0388:                Action action = new Action(
0389:                        PDERuntimeMessages.LogView_readLog_restore) {
0390:                    public void run() {
0391:                        fInputFile = Platform.getLogFileLocation().toFile();
0392:                        reloadLog();
0393:                    }
0394:                };
0395:                action
0396:                        .setToolTipText(PDERuntimeMessages.LogView_readLog_restore_tooltip);
0397:                action.setImageDescriptor(PDERuntimePluginImages.DESC_READ_LOG);
0398:                action
0399:                        .setDisabledImageDescriptor(PDERuntimePluginImages.DESC_READ_LOG_DISABLED);
0400:                return action;
0401:            }
0402:
0403:            private void createViewer(Composite parent) {
0404:                fTreeViewer = new TreeViewer(parent, SWT.FULL_SELECTION);
0405:                fTree = fTreeViewer.getTree();
0406:                fTree.setLinesVisible(true);
0407:                createColumns(fTree);
0408:                fTreeViewer
0409:                        .setContentProvider(new LogViewContentProvider(this ));
0410:                fTreeViewer
0411:                        .setLabelProvider(fLabelProvider = new LogViewLabelProvider());
0412:                fLabelProvider.connect(this );
0413:                fTreeViewer
0414:                        .addSelectionChangedListener(new ISelectionChangedListener() {
0415:                            public void selectionChanged(SelectionChangedEvent e) {
0416:                                handleSelectionChanged(e.getSelection());
0417:                                if (fPropertiesAction.isEnabled())
0418:                                    ((EventDetailsDialogAction) fPropertiesAction)
0419:                                            .resetSelection();
0420:                            }
0421:                        });
0422:                fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
0423:                    public void doubleClick(DoubleClickEvent event) {
0424:                        ((EventDetailsDialogAction) fPropertiesAction)
0425:                                .setComparator(fComparator);
0426:                        fPropertiesAction.run();
0427:                    }
0428:                });
0429:                fTreeViewer.setInput(this );
0430:                addMouseListeners();
0431:            }
0432:
0433:            private void createColumns(Tree tree) {
0434:                fColumn1 = new TreeColumn(tree, SWT.LEFT);
0435:                fColumn1.setText(PDERuntimeMessages.LogView_column_message);
0436:                fColumn1.setWidth(fMemento.getInteger(P_COLUMN_1).intValue());
0437:                fColumn1.addSelectionListener(new SelectionAdapter() {
0438:                    public void widgetSelected(SelectionEvent e) {
0439:                        MESSAGE_ORDER *= -1;
0440:                        ViewerComparator comparator = getViewerComparator(MESSAGE);
0441:                        fTreeViewer.setComparator(comparator);
0442:                        boolean isComparatorSet = ((EventDetailsDialogAction) fPropertiesAction)
0443:                                .resetSelection(MESSAGE, MESSAGE_ORDER);
0444:                        setComparator(MESSAGE);
0445:                        if (!isComparatorSet)
0446:                            ((EventDetailsDialogAction) fPropertiesAction)
0447:                                    .setComparator(fComparator);
0448:                        fMemento.putInteger(P_ORDER_VALUE, MESSAGE_ORDER);
0449:                        fMemento.putInteger(P_ORDER_TYPE, MESSAGE);
0450:                        setColumnSorting(fColumn1, MESSAGE_ORDER);
0451:                    }
0452:                });
0453:
0454:                fColumn2 = new TreeColumn(tree, SWT.LEFT);
0455:                fColumn2.setText(PDERuntimeMessages.LogView_column_plugin);
0456:                fColumn2.setWidth(fMemento.getInteger(P_COLUMN_2).intValue());
0457:                fColumn2.addSelectionListener(new SelectionAdapter() {
0458:                    public void widgetSelected(SelectionEvent e) {
0459:                        PLUGIN_ORDER *= -1;
0460:                        ViewerComparator comparator = getViewerComparator(PLUGIN);
0461:                        fTreeViewer.setComparator(comparator);
0462:                        boolean isComparatorSet = ((EventDetailsDialogAction) fPropertiesAction)
0463:                                .resetSelection(PLUGIN, PLUGIN_ORDER);
0464:                        setComparator(PLUGIN);
0465:                        if (!isComparatorSet)
0466:                            ((EventDetailsDialogAction) fPropertiesAction)
0467:                                    .setComparator(fComparator);
0468:                        fMemento.putInteger(P_ORDER_VALUE, PLUGIN_ORDER);
0469:                        fMemento.putInteger(P_ORDER_TYPE, PLUGIN);
0470:                        setColumnSorting(fColumn2, PLUGIN_ORDER);
0471:                    }
0472:                });
0473:
0474:                fColumn3 = new TreeColumn(tree, SWT.LEFT);
0475:                fColumn3.setText(PDERuntimeMessages.LogView_column_date);
0476:                fColumn3.setWidth(fMemento.getInteger(P_COLUMN_3).intValue());
0477:                fColumn3.addSelectionListener(new SelectionAdapter() {
0478:                    public void widgetSelected(SelectionEvent e) {
0479:                        DATE_ORDER *= -1;
0480:                        ViewerComparator comparator = getViewerComparator(DATE);
0481:                        fTreeViewer.setComparator(comparator);
0482:                        setComparator(DATE);
0483:                        ((EventDetailsDialogAction) fPropertiesAction)
0484:                                .setComparator(fComparator);
0485:                        fMemento.putInteger(P_ORDER_VALUE, DATE_ORDER);
0486:                        fMemento.putInteger(P_ORDER_TYPE, DATE);
0487:                        setColumnSorting(fColumn3, DATE_ORDER);
0488:                    }
0489:                });
0490:
0491:                tree.setHeaderVisible(true);
0492:            }
0493:
0494:            private void initializeViewerSorter() {
0495:                byte orderType = fMemento.getInteger(P_ORDER_TYPE).byteValue();
0496:                ViewerComparator comparator = getViewerComparator(orderType);
0497:                fTreeViewer.setComparator(comparator);
0498:                if (orderType == MESSAGE)
0499:                    setColumnSorting(fColumn1, MESSAGE_ORDER);
0500:                else if (orderType == PLUGIN)
0501:                    setColumnSorting(fColumn2, PLUGIN_ORDER);
0502:                else if (orderType == DATE)
0503:                    setColumnSorting(fColumn3, DATE_ORDER);
0504:            }
0505:
0506:            private void setColumnSorting(TreeColumn column, int order) {
0507:                fTree.setSortColumn(column);
0508:                fTree.setSortDirection(order == ASCENDING ? SWT.UP : SWT.DOWN);
0509:            }
0510:
0511:            public void dispose() {
0512:                writeSettings();
0513:                Platform.removeLogListener(this );
0514:                fClipboard.dispose();
0515:                if (fTextShell != null)
0516:                    fTextShell.dispose();
0517:                LogReader.reset();
0518:                fLabelProvider.disconnect(this );
0519:                super .dispose();
0520:            }
0521:
0522:            private void handleImport() {
0523:                FileDialog dialog = new FileDialog(getViewSite().getShell());
0524:                dialog.setFilterExtensions(new String[] { "*.log" }); //$NON-NLS-1$
0525:                if (fDirectory != null)
0526:                    dialog.setFilterPath(fDirectory);
0527:                handleImportPath(dialog.open());
0528:            }
0529:
0530:            public void handleImportPath(String path) {
0531:                if (path != null && new Path(path).toFile().exists()) {
0532:                    fInputFile = new Path(path).toFile();
0533:                    fDirectory = fInputFile.getParent();
0534:                    IRunnableWithProgress op = new IRunnableWithProgress() {
0535:                        public void run(IProgressMonitor monitor)
0536:                                throws InvocationTargetException,
0537:                                InterruptedException {
0538:                            monitor
0539:                                    .beginTask(
0540:                                            PDERuntimeMessages.LogView_operation_importing,
0541:                                            IProgressMonitor.UNKNOWN);
0542:                            readLogFile();
0543:                        }
0544:                    };
0545:                    ProgressMonitorDialog pmd = new ProgressMonitorDialog(
0546:                            getViewSite().getShell());
0547:                    try {
0548:                        pmd.run(true, true, op);
0549:                    } catch (InvocationTargetException e) {
0550:                    } catch (InterruptedException e) {
0551:                    } finally {
0552:                        fReadLogAction
0553:                                .setText(PDERuntimeMessages.LogView_readLog_reload);
0554:                        fReadLogAction
0555:                                .setToolTipText(PDERuntimeMessages.LogView_readLog_reload);
0556:                        asyncRefresh(false);
0557:                        resetDialogButtons();
0558:                    }
0559:                }
0560:            }
0561:
0562:            private void handleExport() {
0563:                FileDialog dialog = new FileDialog(getViewSite().getShell(),
0564:                        SWT.SAVE);
0565:                dialog.setFilterExtensions(new String[] { "*.log" }); //$NON-NLS-1$
0566:                if (fDirectory != null)
0567:                    dialog.setFilterPath(fDirectory);
0568:                String path = dialog.open();
0569:                if (path != null) {
0570:                    if (path.indexOf('.') == -1 && !path.endsWith(".log")) //$NON-NLS-1$
0571:                        path += ".log"; //$NON-NLS-1$
0572:                    File outputFile = new Path(path).toFile();
0573:                    fDirectory = outputFile.getParent();
0574:                    if (outputFile.exists()) {
0575:                        String message = NLS
0576:                                .bind(
0577:                                        PDERuntimeMessages.LogView_confirmOverwrite_message,
0578:                                        outputFile.toString());
0579:                        if (!MessageDialog.openQuestion(getViewSite()
0580:                                .getShell(),
0581:                                PDERuntimeMessages.LogView_exportLog, message))
0582:                            return;
0583:                    }
0584:                    copy(fInputFile, outputFile);
0585:                }
0586:            }
0587:
0588:            private void copy(File inputFile, File outputFile) {
0589:                BufferedReader reader = null;
0590:                BufferedWriter writer = null;
0591:                try {
0592:                    reader = new BufferedReader(new InputStreamReader(
0593:                            new FileInputStream(inputFile), "UTF-8")); //$NON-NLS-1$
0594:                    writer = new BufferedWriter(new OutputStreamWriter(
0595:                            new FileOutputStream(outputFile), "UTF-8")); //$NON-NLS-1$
0596:                    while (reader.ready()) {
0597:                        writer.write(reader.readLine());
0598:                        writer.write(System.getProperty("line.separator")); //$NON-NLS-1$
0599:                    }
0600:                } catch (IOException e) {
0601:                } finally {
0602:                    try {
0603:                        if (reader != null)
0604:                            reader.close();
0605:                        if (writer != null)
0606:                            writer.close();
0607:                    } catch (IOException e1) {
0608:                    }
0609:                }
0610:            }
0611:
0612:            private void handleFilter() {
0613:                FilterDialog dialog = new FilterDialog(PDERuntimePlugin
0614:                        .getActiveWorkbenchShell(), fMemento);
0615:                dialog.create();
0616:                dialog.getShell().setText(
0617:                        PDERuntimeMessages.LogView_FilterDialog_title);
0618:                if (dialog.open() == Window.OK)
0619:                    reloadLog();
0620:            }
0621:
0622:            private void doDeleteLog() {
0623:                String title = PDERuntimeMessages.LogView_confirmDelete_title;
0624:                String message = PDERuntimeMessages.LogView_confirmDelete_message;
0625:                if (!MessageDialog
0626:                        .openConfirm(fTree.getShell(), title, message))
0627:                    return;
0628:                if (fInputFile.delete() || fLogs.size() > 0) {
0629:                    fLogs.clear();
0630:                    asyncRefresh(false);
0631:                    resetDialogButtons();
0632:                }
0633:            }
0634:
0635:            public void fillContextMenu(IMenuManager manager) {
0636:            }
0637:
0638:            public LogEntry[] getLogs() {
0639:                return (LogEntry[]) fLogs.toArray(new LogEntry[fLogs.size()]);
0640:            }
0641:
0642:            protected void handleClear() {
0643:                BusyIndicator.showWhile(fTree.getDisplay(), new Runnable() {
0644:                    public void run() {
0645:                        fLogs.clear();
0646:                        asyncRefresh(false);
0647:                        resetDialogButtons();
0648:                    }
0649:                });
0650:            }
0651:
0652:            protected void reloadLog() {
0653:                IRunnableWithProgress op = new IRunnableWithProgress() {
0654:                    public void run(IProgressMonitor monitor)
0655:                            throws InvocationTargetException,
0656:                            InterruptedException {
0657:                        monitor.beginTask(
0658:                                PDERuntimeMessages.LogView_operation_reloading,
0659:                                IProgressMonitor.UNKNOWN);
0660:                        readLogFile();
0661:                    }
0662:                };
0663:                ProgressMonitorDialog pmd = new ProgressMonitorDialog(
0664:                        getViewSite().getShell());
0665:                try {
0666:                    pmd.run(true, true, op);
0667:                } catch (InvocationTargetException e) {
0668:                } catch (InterruptedException e) {
0669:                } finally {
0670:                    fReadLogAction
0671:                            .setText(PDERuntimeMessages.LogView_readLog_restore);
0672:                    fReadLogAction
0673:                            .setToolTipText(PDERuntimeMessages.LogView_readLog_restore);
0674:                    asyncRefresh(false);
0675:                    resetDialogButtons();
0676:                }
0677:            }
0678:
0679:            private void readLogFile() {
0680:                fLogs.clear();
0681:                if (!fInputFile.exists())
0682:                    return;
0683:                LogReader.parseLogFile(fInputFile, fLogs, fMemento);
0684:            }
0685:
0686:            public void logging(IStatus status, String plugin) {
0687:                if (!fInputFile.equals(Platform.getLogFileLocation().toFile()))
0688:                    return;
0689:                if (fFirstEvent) {
0690:                    readLogFile();
0691:                    asyncRefresh();
0692:                    fFirstEvent = false;
0693:                } else {
0694:                    pushStatus(status);
0695:                }
0696:            }
0697:
0698:            private void pushStatus(IStatus status) {
0699:                LogEntry entry = new LogEntry(status);
0700:                LogReader.addEntry(entry, fLogs, fMemento, true);
0701:                asyncRefresh();
0702:            }
0703:
0704:            private void asyncRefresh() {
0705:                asyncRefresh(true);
0706:            }
0707:
0708:            private void asyncRefresh(final boolean activate) {
0709:                if (fTree.isDisposed())
0710:                    return;
0711:                Display display = fTree.getDisplay();
0712:                final ViewPart view = this ;
0713:                if (display != null) {
0714:                    display.asyncExec(new Runnable() {
0715:                        public void run() {
0716:                            if (!fTree.isDisposed()) {
0717:                                fTreeViewer.refresh();
0718:                                fDeleteLogAction
0719:                                        .setEnabled(fInputFile.exists()
0720:                                                && fInputFile.equals(Platform
0721:                                                        .getLogFileLocation()
0722:                                                        .toFile()));
0723:                                fOpenLogAction.setEnabled(fInputFile.exists());
0724:                                fExportAction.setEnabled(fInputFile.exists());
0725:                                if (activate && fActivateViewAction.isChecked()) {
0726:                                    IWorkbenchPage page = PDERuntimePlugin
0727:                                            .getActivePage();
0728:                                    if (page != null)
0729:                                        page.bringToTop(view);
0730:                                }
0731:                            }
0732:                        }
0733:                    });
0734:                }
0735:            }
0736:
0737:            public void setFocus() {
0738:                if (fTree != null && !fTree.isDisposed())
0739:                    fTree.setFocus();
0740:            }
0741:
0742:            private void handleSelectionChanged(ISelection selection) {
0743:                updateStatus(selection);
0744:                fCopyAction.setEnabled(!selection.isEmpty());
0745:                fPropertiesAction.setEnabled(!selection.isEmpty());
0746:            }
0747:
0748:            private void updateStatus(ISelection selection) {
0749:                IStatusLineManager status = getViewSite().getActionBars()
0750:                        .getStatusLineManager();
0751:                if (selection.isEmpty())
0752:                    status.setMessage(null);
0753:                else {
0754:                    LogEntry entry = (LogEntry) ((IStructuredSelection) selection)
0755:                            .getFirstElement();
0756:                    status.setMessage(((LogViewLabelProvider) fTreeViewer
0757:                            .getLabelProvider()).getColumnText(entry, 0));
0758:                }
0759:            }
0760:
0761:            private void copyToClipboard(ISelection selection) {
0762:                StringWriter writer = new StringWriter();
0763:                PrintWriter pwriter = new PrintWriter(writer);
0764:                if (selection.isEmpty())
0765:                    return;
0766:                LogEntry entry = (LogEntry) ((IStructuredSelection) selection)
0767:                        .getFirstElement();
0768:                entry.write(pwriter);
0769:                pwriter.flush();
0770:                String textVersion = writer.toString();
0771:                try {
0772:                    pwriter.close();
0773:                    writer.close();
0774:                } catch (IOException e) {
0775:                }
0776:                if (textVersion.trim().length() > 0) {
0777:                    // set the clipboard contents
0778:                    fClipboard.setContents(new Object[] { textVersion },
0779:                            new Transfer[] { TextTransfer.getInstance() });
0780:                }
0781:            }
0782:
0783:            public void init(IViewSite site, IMemento memento)
0784:                    throws PartInitException {
0785:                super .init(site, memento);
0786:                if (memento == null)
0787:                    this .fMemento = XMLMemento.createWriteRoot("LOGVIEW"); //$NON-NLS-1$
0788:                else
0789:                    this .fMemento = memento;
0790:                readSettings();
0791:
0792:                // initialize column ordering 
0793:                final byte type = this .fMemento.getInteger(P_ORDER_TYPE)
0794:                        .byteValue();
0795:                switch (type) {
0796:                case DATE:
0797:                    DATE_ORDER = this .fMemento.getInteger(P_ORDER_VALUE)
0798:                            .intValue();
0799:                    MESSAGE_ORDER = DESCENDING;
0800:                    PLUGIN_ORDER = DESCENDING;
0801:                    break;
0802:                case MESSAGE:
0803:                    MESSAGE_ORDER = this .fMemento.getInteger(P_ORDER_VALUE)
0804:                            .intValue();
0805:                    DATE_ORDER = DESCENDING;
0806:                    PLUGIN_ORDER = DESCENDING;
0807:                    break;
0808:                case PLUGIN:
0809:                    PLUGIN_ORDER = this .fMemento.getInteger(P_ORDER_VALUE)
0810:                            .intValue();
0811:                    MESSAGE_ORDER = DESCENDING;
0812:                    DATE_ORDER = DESCENDING;
0813:                    break;
0814:                default:
0815:                    DATE_ORDER = DESCENDING;
0816:                    MESSAGE_ORDER = DESCENDING;
0817:                    PLUGIN_ORDER = DESCENDING;
0818:                }
0819:                setComparator(fMemento.getInteger(P_ORDER_TYPE).byteValue());
0820:            }
0821:
0822:            private void initializeMemento() {
0823:                if (fMemento.getString(P_USE_LIMIT) == null)
0824:                    fMemento.putString(P_USE_LIMIT, "true"); //$NON-NLS-1$
0825:                if (fMemento.getInteger(P_LOG_LIMIT) == null)
0826:                    fMemento.putInteger(P_LOG_LIMIT, 50);
0827:                if (fMemento.getString(P_LOG_INFO) == null)
0828:                    fMemento.putString(P_LOG_INFO, "true"); //$NON-NLS-1$
0829:                if (fMemento.getString(P_LOG_WARNING) == null)
0830:                    fMemento.putString(P_LOG_WARNING, "true"); //$NON-NLS-1$
0831:                if (fMemento.getString(P_LOG_ERROR) == null)
0832:                    fMemento.putString(P_LOG_ERROR, "true"); //$NON-NLS-1$
0833:                if (fMemento.getString(P_SHOW_ALL_SESSIONS) == null)
0834:                    fMemento.putString(P_SHOW_ALL_SESSIONS, "true"); //$NON-NLS-1$
0835:                Integer width = fMemento.getInteger(P_COLUMN_1);
0836:                if (width == null || width.intValue() == 0)
0837:                    fMemento.putInteger(P_COLUMN_1, 300);
0838:                width = fMemento.getInteger(P_COLUMN_2);
0839:                if (width == null || width.intValue() == 0)
0840:                    fMemento.putInteger(P_COLUMN_2, 150);
0841:                width = fMemento.getInteger(P_COLUMN_3);
0842:                if (width == null || width.intValue() == 0)
0843:                    fMemento.putInteger(P_COLUMN_3, 150);
0844:                if (fMemento.getString(P_ACTIVATE) == null)
0845:                    fMemento.putString(P_ACTIVATE, "true"); //$NON-NLS-1$
0846:
0847:                fMemento.putInteger(P_ORDER_VALUE, DESCENDING);
0848:                fMemento.putInteger(P_ORDER_TYPE, DATE);
0849:            }
0850:
0851:            public void saveState(IMemento memento) {
0852:                if (this .fMemento == null || memento == null)
0853:                    return;
0854:                this .fMemento.putInteger(P_COLUMN_1, fColumn1.getWidth());
0855:                this .fMemento.putInteger(P_COLUMN_2, fColumn2.getWidth());
0856:                this .fMemento.putInteger(P_COLUMN_3, fColumn3.getWidth());
0857:                this .fMemento.putString(P_ACTIVATE, fActivateViewAction
0858:                        .isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
0859:                memento.putMemento(this .fMemento);
0860:                writeSettings();
0861:            }
0862:
0863:            private void addMouseListeners() {
0864:                Listener tableListener = new Listener() {
0865:                    public void handleEvent(Event e) {
0866:                        switch (e.type) {
0867:                        case SWT.MouseMove:
0868:                            onMouseMove(e);
0869:                            break;
0870:                        case SWT.MouseHover:
0871:                            onMouseHover(e);
0872:                            break;
0873:                        case SWT.MouseDown:
0874:                            onMouseDown(e);
0875:                            break;
0876:                        }
0877:                    }
0878:                };
0879:                int[] tableEvents = new int[] { SWT.MouseDown, SWT.MouseMove,
0880:                        SWT.MouseHover };
0881:                for (int i = 0; i < tableEvents.length; i++) {
0882:                    fTree.addListener(tableEvents[i], tableListener);
0883:                }
0884:            }
0885:
0886:            private void makeHoverShell() {
0887:                fTextShell = new Shell(fTree.getShell(), SWT.NO_FOCUS
0888:                        | SWT.ON_TOP | SWT.TOOL);
0889:                Display display = fTextShell.getDisplay();
0890:                fTextShell.setBackground(display
0891:                        .getSystemColor(SWT.COLOR_INFO_BACKGROUND));
0892:                GridLayout layout = new GridLayout(1, false);
0893:                int border = ((fTree.getShell().getStyle() & SWT.NO_TRIM) == 0) ? 0
0894:                        : 1;
0895:                layout.marginHeight = border;
0896:                layout.marginWidth = border;
0897:                fTextShell.setLayout(layout);
0898:                fTextShell
0899:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
0900:                Composite shellComposite = new Composite(fTextShell, SWT.NONE);
0901:                layout = new GridLayout();
0902:                layout.marginHeight = 0;
0903:                layout.marginWidth = 0;
0904:                shellComposite.setLayout(layout);
0905:                shellComposite.setLayoutData(new GridData(GridData.FILL_BOTH
0906:                        | GridData.VERTICAL_ALIGN_BEGINNING));
0907:                fTextLabel = new Text(shellComposite, SWT.WRAP | SWT.MULTI
0908:                        | SWT.READ_ONLY);
0909:                GridData gd = new GridData(GridData.FILL_BOTH);
0910:                gd.widthHint = 100;
0911:                gd.grabExcessHorizontalSpace = true;
0912:                fTextLabel.setLayoutData(gd);
0913:                Color c = fTree.getDisplay().getSystemColor(
0914:                        SWT.COLOR_INFO_BACKGROUND);
0915:                fTextLabel.setBackground(c);
0916:                c = fTree.getDisplay()
0917:                        .getSystemColor(SWT.COLOR_INFO_FOREGROUND);
0918:                fTextLabel.setForeground(c);
0919:                fTextLabel.setEditable(false);
0920:                fTextShell.addDisposeListener(new DisposeListener() {
0921:                    public void widgetDisposed(DisposeEvent e) {
0922:                        onTextShellDispose(e);
0923:                    }
0924:                });
0925:            }
0926:
0927:            void onTextShellDispose(DisposeEvent e) {
0928:                fCanOpenTextShell = true;
0929:                setFocus();
0930:            }
0931:
0932:            void onMouseDown(Event e) {
0933:                if (fTextShell != null && !fTextShell.isDisposed()
0934:                        && !fTextShell.isFocusControl()) {
0935:                    fTextShell.setVisible(false);
0936:                    fCanOpenTextShell = true;
0937:                }
0938:            }
0939:
0940:            void onMouseHover(Event e) {
0941:                if (!fCanOpenTextShell || fTextShell == null
0942:                        || fTextShell.isDisposed())
0943:                    return;
0944:                fCanOpenTextShell = false;
0945:                Point point = new Point(e.x, e.y);
0946:                TreeItem item = fTree.getItem(point);
0947:                if (item == null)
0948:                    return;
0949:                String message = ((LogEntry) item.getData()).getStack();
0950:                if (message == null)
0951:                    return;
0952:
0953:                fTextLabel.setText(message);
0954:                Rectangle bounds = fTree.getDisplay().getBounds();
0955:                Point cursorPoint = fTree.getDisplay().getCursorLocation();
0956:                int x = point.x;
0957:                int y = point.y + 25;
0958:                int width = fTree.getColumn(0).getWidth();
0959:                int height = 125;
0960:                if (cursorPoint.x + width > bounds.width)
0961:                    x -= width;
0962:                if (cursorPoint.y + height + 25 > bounds.height)
0963:                    y -= height + 27;
0964:
0965:                fTextShell.setLocation(fTree.toDisplay(x, y));
0966:                fTextShell.setSize(width, height);
0967:                fTextShell.setVisible(true);
0968:            }
0969:
0970:            void onMouseMove(Event e) {
0971:                if (fTextShell != null && !fTextShell.isDisposed()
0972:                        && fTextShell.isVisible())
0973:                    fTextShell.setVisible(false);
0974:
0975:                Point point = new Point(e.x, e.y);
0976:                TreeItem item = fTree.getItem(point);
0977:                if (item == null)
0978:                    return;
0979:                Image image = item.getImage();
0980:                LogEntry entry = (LogEntry) item.getData();
0981:                int parentCount = getNumberOfParents(entry);
0982:                int startRange = 20
0983:                        + Math.max(image.getBounds().width + 2, 7 + 2)
0984:                        * parentCount;
0985:                int endRange = startRange + 16;
0986:                fCanOpenTextShell = e.x >= startRange && e.x <= endRange;
0987:            }
0988:
0989:            private int getNumberOfParents(LogEntry entry) {
0990:                LogEntry parent = (LogEntry) entry.getParent(entry);
0991:                if (parent == null)
0992:                    return 0;
0993:                return 1 + getNumberOfParents(parent);
0994:            }
0995:
0996:            public Comparator getComparator() {
0997:                return fComparator;
0998:            }
0999:
1000:            private void setComparator(byte sortType) {
1001:                if (sortType == DATE) {
1002:                    fComparator = new Comparator() {
1003:                        public int compare(Object e1, Object e2) {
1004:                            long date1 = ((LogEntry) e1).getDate().getTime();
1005:                            long date2 = ((LogEntry) e2).getDate().getTime();
1006:                            if (date1 == date2) {
1007:                                int result = fLogs.indexOf(e2)
1008:                                        - fLogs.indexOf(e1);
1009:                                if (DATE_ORDER == DESCENDING)
1010:                                    result *= DESCENDING;
1011:                                return result;
1012:                            }
1013:                            if (DATE_ORDER == DESCENDING)
1014:                                return date1 > date2 ? DESCENDING : ASCENDING;
1015:                            return date1 < date2 ? DESCENDING : ASCENDING;
1016:                        }
1017:                    };
1018:                } else if (sortType == PLUGIN) {
1019:                    fComparator = new Comparator() {
1020:                        public int compare(Object e1, Object e2) {
1021:                            LogEntry entry1 = (LogEntry) e1;
1022:                            LogEntry entry2 = (LogEntry) e2;
1023:                            return getDefaultComparator().compare(
1024:                                    entry1.getPluginId(), entry2.getPluginId())
1025:                                    * PLUGIN_ORDER;
1026:                        }
1027:                    };
1028:                } else {
1029:                    fComparator = new Comparator() {
1030:                        public int compare(Object e1, Object e2) {
1031:                            LogEntry entry1 = (LogEntry) e1;
1032:                            LogEntry entry2 = (LogEntry) e2;
1033:                            return getDefaultComparator().compare(
1034:                                    entry1.getMessage(), entry2.getMessage())
1035:                                    * MESSAGE_ORDER;
1036:                        }
1037:                    };
1038:                }
1039:            }
1040:
1041:            private Comparator getDefaultComparator() {
1042:                return Policy.getComparator();
1043:            }
1044:
1045:            private ViewerComparator getViewerComparator(byte sortType) {
1046:                if (sortType == PLUGIN) {
1047:                    return new ViewerComparator() {
1048:                        public int compare(Viewer viewer, Object e1, Object e2) {
1049:                            LogEntry entry1 = (LogEntry) e1;
1050:                            LogEntry entry2 = (LogEntry) e2;
1051:                            return getComparator().compare(
1052:                                    entry1.getPluginId(), entry2.getPluginId())
1053:                                    * PLUGIN_ORDER;
1054:                        }
1055:                    };
1056:                } else if (sortType == MESSAGE) {
1057:                    return new ViewerComparator() {
1058:                        public int compare(Viewer viewer, Object e1, Object e2) {
1059:                            LogEntry entry1 = (LogEntry) e1;
1060:                            LogEntry entry2 = (LogEntry) e2;
1061:                            return getComparator().compare(entry1.getMessage(),
1062:                                    entry2.getMessage())
1063:                                    * MESSAGE_ORDER;
1064:                        }
1065:                    };
1066:                } else {
1067:                    return new ViewerComparator() {
1068:                        public int compare(Viewer viewer, Object e1, Object e2) {
1069:                            long date1 = ((LogEntry) e1).getDate().getTime();
1070:                            long date2 = ((LogEntry) e2).getDate().getTime();
1071:                            if (date1 == date2) {
1072:                                int result = fLogs.indexOf(e2)
1073:                                        - fLogs.indexOf(e1);
1074:                                if (DATE_ORDER == DESCENDING)
1075:                                    result *= DESCENDING;
1076:                                return result;
1077:                            }
1078:                            if (DATE_ORDER == DESCENDING)
1079:                                return date1 > date2 ? DESCENDING : ASCENDING;
1080:                            return date1 < date2 ? DESCENDING : ASCENDING;
1081:                        }
1082:                    };
1083:                }
1084:            }
1085:
1086:            private void resetDialogButtons() {
1087:                ((EventDetailsDialogAction) fPropertiesAction)
1088:                        .resetDialogButtons();
1089:            }
1090:
1091:            /**
1092:             * Returns the filter dialog settings object used to maintain
1093:             * state between filter dialogs
1094:             * @return the dialog settings to be used
1095:             */
1096:            private IDialogSettings getLogSettings() {
1097:                IDialogSettings settings = PDERuntimePlugin.getDefault()
1098:                        .getDialogSettings();
1099:                return settings.getSection(getClass().getName());
1100:            }
1101:
1102:            /**
1103:             * Returns the plugin preferences used to maintain
1104:             * state of log view
1105:             * @return the plugin preferences
1106:             */
1107:            private Preferences getLogPreferences() {
1108:                return PDERuntimePlugin.getDefault().getPluginPreferences();
1109:            }
1110:
1111:            private void readSettings() {
1112:                IDialogSettings s = getLogSettings();
1113:                Preferences p = getLogPreferences();
1114:                if (s == null || p == null) {
1115:                    initializeMemento();
1116:                    return;
1117:                }
1118:                try {
1119:                    fMemento.putString(P_USE_LIMIT,
1120:                            s.getBoolean(P_USE_LIMIT) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
1121:                    fMemento.putString(P_LOG_INFO,
1122:                            s.getBoolean(P_LOG_INFO) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
1123:                    fMemento.putString(P_LOG_WARNING, s
1124:                            .getBoolean(P_LOG_WARNING) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
1125:                    fMemento.putString(P_LOG_ERROR,
1126:                            s.getBoolean(P_LOG_ERROR) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
1127:                    fMemento
1128:                            .putString(
1129:                                    P_SHOW_ALL_SESSIONS,
1130:                                    s.getBoolean(P_SHOW_ALL_SESSIONS) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
1131:                    fMemento.putInteger(P_LOG_LIMIT, s.getInt(P_LOG_LIMIT));
1132:                    fMemento.putInteger(P_COLUMN_1,
1133:                            p.getInt(P_COLUMN_1) > 0 ? p.getInt(P_COLUMN_1)
1134:                                    : 300);
1135:                    fMemento.putInteger(P_COLUMN_2,
1136:                            p.getInt(P_COLUMN_2) > 0 ? p.getInt(P_COLUMN_2)
1137:                                    : 150);
1138:                    fMemento.putInteger(P_COLUMN_3,
1139:                            p.getInt(P_COLUMN_3) > 0 ? p.getInt(P_COLUMN_3)
1140:                                    : 150);
1141:                    fMemento.putString(P_ACTIVATE,
1142:                            p.getBoolean(P_ACTIVATE) ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
1143:                    int order = p.getInt(P_ORDER_VALUE);
1144:                    fMemento.putInteger(P_ORDER_VALUE, order == 0 ? DESCENDING
1145:                            : order);
1146:                    fMemento.putInteger(P_ORDER_TYPE, p.getInt(P_ORDER_TYPE));
1147:                } catch (NumberFormatException e) {
1148:                    fMemento.putInteger(P_LOG_LIMIT, 50);
1149:                    fMemento.putInteger(P_COLUMN_1, 300);
1150:                    fMemento.putInteger(P_COLUMN_2, 150);
1151:                    fMemento.putInteger(P_COLUMN_3, 150);
1152:                    fMemento.putInteger(P_ORDER_TYPE, DATE);
1153:                    fMemento.putInteger(P_ORDER_VALUE, DESCENDING);
1154:                }
1155:            }
1156:
1157:            private void writeSettings() {
1158:                writeViewSettings();
1159:                writeFilterSettings();
1160:            }
1161:
1162:            private void writeFilterSettings() {
1163:                IDialogSettings settings = getLogSettings();
1164:                if (settings == null)
1165:                    settings = PDERuntimePlugin.getDefault()
1166:                            .getDialogSettings().addNewSection(
1167:                                    getClass().getName());
1168:                settings.put(P_USE_LIMIT, fMemento.getString(P_USE_LIMIT)
1169:                        .equals("true")); //$NON-NLS-1$
1170:                settings.put(P_LOG_LIMIT, fMemento.getInteger(P_LOG_LIMIT)
1171:                        .intValue());
1172:                settings.put(P_LOG_INFO, fMemento.getString(P_LOG_INFO).equals(
1173:                        "true")); //$NON-NLS-1$
1174:                settings.put(P_LOG_WARNING, fMemento.getString(P_LOG_WARNING)
1175:                        .equals("true")); //$NON-NLS-1$
1176:                settings.put(P_LOG_ERROR, fMemento.getString(P_LOG_ERROR)
1177:                        .equals("true")); //$NON-NLS-1$
1178:                settings.put(P_SHOW_ALL_SESSIONS, fMemento.getString(
1179:                        P_SHOW_ALL_SESSIONS).equals("true")); //$NON-NLS-1$
1180:            }
1181:
1182:            private void writeViewSettings() {
1183:                Preferences preferences = getLogPreferences();
1184:                preferences.setValue(P_COLUMN_1, fMemento
1185:                        .getInteger(P_COLUMN_1).intValue());
1186:                preferences.setValue(P_COLUMN_2, fMemento
1187:                        .getInteger(P_COLUMN_2).intValue());
1188:                preferences.setValue(P_COLUMN_3, fMemento
1189:                        .getInteger(P_COLUMN_3).intValue());
1190:                preferences.setValue(P_ACTIVATE, fMemento.getString(P_ACTIVATE)
1191:                        .equals("true")); //$NON-NLS-1$
1192:                int order = fMemento.getInteger(P_ORDER_VALUE).intValue();
1193:                preferences.setValue(P_ORDER_VALUE, order == 0 ? DESCENDING
1194:                        : order);
1195:                preferences.setValue(P_ORDER_TYPE, fMemento.getInteger(
1196:                        P_ORDER_TYPE).intValue());
1197:            }
1198:
1199:            public void sortByDateDescending() {
1200:                setColumnSorting(fColumn3, DESCENDING);
1201:            }
1202:
1203:            protected Job getOpenLogFileJob() {
1204:                final Shell shell = getViewSite().getShell();
1205:                return new Job(PDERuntimeMessages.OpenLogDialog_message) {
1206:                    protected IStatus run(IProgressMonitor monitor) {
1207:                        boolean failed = false;
1208:                        if (fInputFile.length() <= LogReader.MAX_FILE_LENGTH) {
1209:                            failed = !Program.launch(fInputFile
1210:                                    .getAbsolutePath());
1211:                            if (failed) {
1212:                                Program p = Program.findProgram(".txt"); //$NON-NLS-1$
1213:                                if (p != null) {
1214:                                    p.execute(fInputFile.getAbsolutePath());
1215:                                    return Status.OK_STATUS;
1216:                                }
1217:                            }
1218:                        }
1219:                        if (failed) {
1220:                            final OpenLogDialog openDialog = new OpenLogDialog(
1221:                                    shell, fInputFile);
1222:                            Display.getDefault().asyncExec(new Runnable() {
1223:                                public void run() {
1224:                                    openDialog.create();
1225:                                    openDialog.open();
1226:                                }
1227:                            });
1228:                        }
1229:                        return Status.OK_STATUS;
1230:                    }
1231:                };
1232:            }
1233:
1234:            protected File getLogFile() {
1235:                return fInputFile;
1236:            }
1237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.