1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.message.ui;
14 import java.io.IOException;
15 import java.io.PrintWriter;
16 import java.io.StringWriter;
18 import java.net.URISyntaxException;
19 import java.text.Collator;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Comparator;
23 import java.util.Date;
24 import java.util.List;
25 import java.util.StringTokenizer;
27 import org.eclipse.core.runtime.IAdaptable;
28 import org.eclipse.jface.dialogs.Dialog;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.jface.dialogs.IDialogSettings;
31 import org.eclipse.jface.dialogs.TrayDialog;
32 import org.eclipse.jface.resource.JFaceResources;
33 import org.eclipse.jface.resource.LocalResourceManager;
34 import org.eclipse.jface.viewers.ISelection;
35 import org.eclipse.jface.viewers.ISelectionProvider;
36 import org.eclipse.jface.viewers.ITreeContentProvider;
37 import org.eclipse.jface.viewers.StructuredSelection;
38 import org.eclipse.jface.viewers.TreeViewer;
39 import org.eclipse.jface.window.Window;
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.browser.Browser;
42 import org.eclipse.swt.browser.LocationEvent;
43 import org.eclipse.swt.browser.LocationListener;
44 import org.eclipse.swt.custom.SashForm;
45 import org.eclipse.swt.dnd.Clipboard;
46 import org.eclipse.swt.dnd.TextTransfer;
47 import org.eclipse.swt.dnd.Transfer;
48 import org.eclipse.swt.events.SelectionAdapter;
49 import org.eclipse.swt.events.SelectionEvent;
50 import org.eclipse.swt.graphics.Point;
51 import org.eclipse.swt.layout.GridData;
52 import org.eclipse.swt.layout.GridLayout;
53 import org.eclipse.swt.widgets.Button;
54 import org.eclipse.swt.widgets.Composite;
55 import org.eclipse.swt.widgets.Control;
56 import org.eclipse.swt.widgets.Label;
57 import org.eclipse.swt.widgets.Shell;
58 import org.eclipse.swt.widgets.Text;
59 import org.eclipse.ui.IMemento;
60 import org.eclipse.ui.ISharedImages;
61 import org.eclipse.ui.PlatformUI;
62 import org.simantics.message.IMessageDataSchemeExtension;
63 import org.simantics.message.IMessageSchemeManager;
64 import org.simantics.message.MessageSchemeException;
65 import org.simantics.message.ReferenceSerializationException;
66 import org.simantics.utils.ui.ErrorLogger;
69 * Displays details about Log Entry.
70 * Event information is split in three sections: details, stack trace and session. Details
71 * contain event date, message and severity. Stack trace is displayed if an exception is bound
72 * to event. Stack trace entries can be filtered.
74 public class EventDetailsDialog extends TrayDialog {
76 public static final String FILTER_ENABLED = "detailsStackFilterEnabled"; //$NON-NLS-1$
77 public static final String FILTER_LIST = "detailsStackFilterList"; //$NON-NLS-1$
79 private IMemento memento;
81 private AbstractEntry entry;
82 private AbstractEntry parentEntry; // parent of the entry
83 private AbstractEntry[] entryChildren; // children of the entry
85 private LogViewLabelProvider labelProvider;
86 private TreeViewer provider;
88 private static int COPY_ID = 22;
90 private int childIndex = 0;
91 private boolean isOpen;
92 private boolean isLastChild;
93 private boolean isAtEndOfLog;
95 private Label dateLabel;
96 private Label severityImageLabel;
97 private Label severityLabel;
99 //private Text stackTraceText;
100 private Text sessionDataText;
101 private Clipboard clipboard;
102 private Button copyButton;
103 private Button backButton;
104 private Button nextButton;
105 private SashForm sashForm;
106 private Label detailsTextDescription;
107 private Browser detailsText;
110 private Comparator<Object> comparator = null;
113 // patterns for filtering stack traces
114 private String[] stackFilterPatterns = null;
116 // location configuration
117 private Point dialogLocation;
118 private Point dialogSize;
119 private int[] sashWeights;
120 private LocalResourceManager resourceManager;
124 * @param parentShell shell in which dialog is displayed
125 * @param selection entry initially selected and to be displayed
126 * @param provider viewer
127 * @param comparator comparator used to order all entries
129 protected EventDetailsDialog(Shell parentShell, IAdaptable selection, ISelectionProvider provider, Comparator<Object> comparator, IMemento memento) {
131 resourceManager = new LocalResourceManager(JFaceResources.getResources());
132 this.provider = (TreeViewer) provider;
133 labelProvider = (LogViewLabelProvider) this.provider.getLabelProvider();
134 labelProvider.connect(this);
135 this.entry = (AbstractEntry) selection;
136 this.comparator = comparator;
137 this.memento = memento;
138 setShellStyle(SWT.MODELESS | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.CLOSE | SWT.BORDER | SWT.TITLE);
139 clipboard = new Clipboard(parentShell.getDisplay());
141 collator = Collator.getInstance();
144 isAtEndOfLog = false;
145 stackFilterPatterns = getFilters();
148 private void initialize() {
149 parentEntry = (AbstractEntry) entry.getParent(entry);
150 if (isChild(entry)) {
151 setEntryChildren(parentEntry);
157 isAtEndOfLog = false;
160 private void resetChildIndex() {
161 if (entryChildren == null)
164 LogEntry thisEntry = (LogEntry) entry;
166 for (int i = 0; i < entryChildren.length; i++) {
167 if (entryChildren[i] instanceof LogEntry) {
169 LogEntry logEntry = (LogEntry) entryChildren[i];
171 if (logEntry == thisEntry) {
181 private boolean isChild(AbstractEntry entry) {
182 return entry.getParent(entry) != null;
185 public boolean isOpen() {
191 /*if (sashWeights == null)*/ {
192 int width = getSashForm().getClientArea().width;
197 sashWeights = new int[] {width, /*width/2,*/ getSashForm().getClientArea().width - width};
198 //System.out.println("guessed new sashWeights: " + Arrays.toString(sashWeights));
200 getSashForm().setWeights(sashWeights);
204 public boolean close() {
207 labelProvider.disconnect(this);
208 boolean result = super.close();
209 resourceManager.dispose();
213 public void create() {
217 if (dialogLocation != null)
218 getShell().setLocation(dialogLocation);
221 if (dialogSize != null)
222 getShell().setSize(dialogSize);
224 getShell().setSize(500, 550);
226 applyDialogFont(buttonBar);
227 getButton(IDialogConstants.OK_ID).setFocus();
230 protected void buttonPressed(int buttonId) {
231 if (IDialogConstants.OK_ID == buttonId)
233 else if (IDialogConstants.CANCEL_ID == buttonId)
235 else if (IDialogConstants.BACK_ID == buttonId)
237 else if (IDialogConstants.NEXT_ID == buttonId)
239 else if (COPY_ID == buttonId)
243 protected void backPressed() {
244 if (childIndex > 0) {
245 if (isLastChild && (isChild(entry))) {
246 setEntryChildren(parentEntry);
250 entry = entryChildren[childIndex];
252 if (parentEntry instanceof LogEntry) {
254 if (isChild(entry)) {
255 setEntryChildren((AbstractEntry) entry.getParent(entry));
262 setEntrySelectionInTable();
265 protected void nextPressed() {
266 if (childIndex < entryChildren.length - 1) {
268 entry = entryChildren[childIndex];
269 isLastChild = childIndex == entryChildren.length - 1;
270 } else if (isChild(entry) && isLastChild && !isAtEndOfLog) {
271 findNextSelectedChild(entry);
272 } else { // at end of list but can branch into child elements - bug 58083
273 setEntryChildren(entry);
274 entry = entryChildren[0];
275 isAtEndOfLog = entryChildren.length == 0;
276 isLastChild = entryChildren.length == 0;
278 setEntrySelectionInTable();
281 protected void copyPressed() {
282 StringWriter writer = new StringWriter();
283 PrintWriter pwriter = new PrintWriter(writer);
285 entry.write(pwriter);
287 String textVersion = writer.toString();
291 } catch (IOException e) { // do nothing
293 // set the clipboard contents
294 clipboard.setContents(new Object[] {textVersion}, new Transfer[] {TextTransfer.getInstance()});
297 public void setComparator(Comparator<Object> comparator) {
298 this.comparator = comparator;
302 private void setComparator(byte sortType, final int sortOrder) {
303 if (sortType == LogView.DATE) {
304 comparator = new Comparator<Object>() {
305 public int compare(Object e1, Object e2) {
306 Date date1 = ((LogEntry) e1).getDate();
307 Date date2 = ((LogEntry) e2).getDate();
308 if (sortOrder == LogView.ASCENDING)
309 return date1.getTime() < date2.getTime() ? LogView.DESCENDING : LogView.ASCENDING;
310 return date1.getTime() > date2.getTime() ? LogView.DESCENDING : LogView.ASCENDING;
313 } else if (sortType == LogView.PLUGIN) {
314 comparator = new Comparator<Object>() {
315 public int compare(Object e1, Object e2) {
316 LogEntry entry1 = (LogEntry) e1;
317 LogEntry entry2 = (LogEntry) e2;
318 return collator.compare(entry1.getPluginId(), entry2.getPluginId()) * sortOrder;
322 comparator = new Comparator<Object>() {
323 public int compare(Object e1, Object e2) {
324 LogEntry entry1 = (LogEntry) e1;
325 LogEntry entry2 = (LogEntry) e2;
326 return collator.compare(entry1.getMessage(), entry2.getMessage()) * sortOrder;
332 public void resetSelection(IAdaptable selectedEntry, byte sortType, int sortOrder) {
333 setComparator(sortType, sortOrder);
334 resetSelection(selectedEntry);
337 public void resetSelection(IAdaptable selectedEntry) {
338 if (entry.equals(selectedEntry)) {
342 if (selectedEntry instanceof AbstractEntry) {
343 entry = (AbstractEntry) selectedEntry;
349 public void resetButtons() {
350 backButton.setEnabled(false);
351 nextButton.setEnabled(false);
354 private void setEntrySelectionInTable() {
355 ISelection selection = new StructuredSelection(entry);
356 provider.setSelection(selection);
359 public void updateProperties() {
360 if (isChild(entry)) {
361 parentEntry = (AbstractEntry) entry.getParent(entry);
362 setEntryChildren(parentEntry);
364 if (childIndex == entryChildren.length - 1)
368 if (entry instanceof LogEntry) {
369 LogEntry logEntry = (LogEntry) entry;
371 String strDate = logEntry.getFormattedDate();
372 dateLabel.setText(strDate);
373 severityImageLabel.setImage(labelProvider.getColumnImage(entry, 0));
374 severityLabel.setText(logEntry.getSeverityText());
375 msgText.setText(logEntry.getMessage() != null ? logEntry.getMessage() : ""); //$NON-NLS-1$
377 String detailedDescription= logEntry.getDetailedDescription();
379 if (detailedDescription != null && !detailedDescription.trim().isEmpty()) {
380 detailsText.setText(detailedDescription);
381 detailsTextDescription.setText(Messages.EventDetailsDialog_detailedMessage);
383 String stack = logEntry.getStack();
386 stack = filterStack(stack);
387 detailsText.setText("<pre>" + stack + "</pre>"); //$NON-NLS-1$ //$NON-NLS-2$
388 detailsTextDescription.setText(Messages.EventDetailsDialog_exception);
390 detailsText.setText("<pre>" + Messages.EventDetailsDialog_noDetailedMessage + "</pre>"); //$NON-NLS-1$ //$NON-NLS-2$
394 LogSession logSession = logEntry.getSession();
395 String session = logSession != null ? logSession.getSessionData() : null;
396 if (session != null) {
397 sessionDataText.setText(session);
401 dateLabel.setText(""); //$NON-NLS-1$
402 severityImageLabel.setImage(null);
403 severityLabel.setText(""); //$NON-NLS-1$
404 msgText.setText(""); //$NON-NLS-1$
405 //stackTraceText.setText(""); //$NON-NLS-1$
406 sessionDataText.setText(""); //$NON-NLS-1$
410 //getSashForm().pack(true);
413 private void updateButtons() {
414 boolean isAtEnd = childIndex == entryChildren.length - 1;
415 if (isChild(entry)) {
416 boolean canGoToParent = (entry.getParent(entry) instanceof LogEntry);
417 backButton.setEnabled((childIndex > 0) || canGoToParent);
418 nextButton.setEnabled(nextChildExists(entry, parentEntry, entryChildren) || entry.hasChildren() || !isLastChild || !isAtEnd);
420 backButton.setEnabled(childIndex != 0);
421 nextButton.setEnabled(!isAtEnd || entry.hasChildren());
425 private void findNextSelectedChild(AbstractEntry originalEntry) {
426 if (isChild(parentEntry)) {
427 // we're at the end of the child list; find next parent
428 // to select. If the parent is a child at the end of the child
429 // list, find its next parent entry to select, etc.
432 setEntryChildren((AbstractEntry) parentEntry.getParent(parentEntry));
433 parentEntry = (AbstractEntry) parentEntry.getParent(parentEntry);
435 isLastChild = childIndex == entryChildren.length - 1;
437 findNextSelectedChild(originalEntry);
441 } else if (parentEntry instanceof LogEntry) {
445 isLastChild = childIndex == entryChildren.length - 1;
447 if (isChild(entry)) {
448 findNextSelectedChild(originalEntry);
450 entry = originalEntry;
458 entry = originalEntry;
464 private boolean nextChildExists(AbstractEntry originalEntry, AbstractEntry originalParent, AbstractEntry[] originalEntries) {
465 if (isChild(parentEntry)) {
466 // we're at the end of the child list; find next parent
467 // to select. If the parent is a child at the end of the child
468 // list, find its next parent entry to select, etc.
471 parentEntry = (AbstractEntry) entry.getParent(entry);
472 setEntryChildren(parentEntry);
474 if (childIndex == entryChildren.length - 1) {
475 return nextChildExists(originalEntry, originalParent, originalEntries);
477 entry = originalEntry;
478 parentEntry = originalParent;
479 entryChildren = originalEntries;
482 } else if (parentEntry instanceof LogEntry) {
487 if ((childIndex != -1) && (childIndex < entryChildren.length - 1)) {
488 entry = originalEntry;
489 parentEntry = originalParent;
490 entryChildren = originalEntries;
495 entry = originalEntry;
496 parentEntry = originalParent;
497 entryChildren = originalEntries;
504 * Sets entry children (Prev-Next navigable) to top-level elements
506 private void setEntryChildren() {
507 AbstractEntry[] children = getElements();
509 if (comparator != null)
510 Arrays.sort(children, comparator);
511 entryChildren = new AbstractEntry[children.length];
513 System.arraycopy(children, 0, entryChildren, 0, children.length);
517 * Sets entry children (Prev-Next navigable) to children of given entry
519 private void setEntryChildren(AbstractEntry entry) {
520 Object[] children = entry.getChildren(entry);
522 if (comparator != null)
523 Arrays.sort(children, comparator);
525 List<Object> result = new ArrayList<Object>();
526 for (int i = 0; i < children.length; i++) {
527 if (children[i] instanceof AbstractEntry) {
528 result.add(children[i]);
532 entryChildren = (AbstractEntry[]) result.toArray(new AbstractEntry[result.size()]);
535 public SashForm getSashForm() {
539 protected Control createDialogArea(Composite parent) {
540 Composite container = new Composite(parent, SWT.NONE);
541 GridLayout layout = new GridLayout();
542 layout.numColumns = 1;
543 container.setLayout(layout);
544 GridData gd = new GridData(GridData.FILL_BOTH);
545 container.setLayoutData(gd);
547 createDetailsSection(container);
548 createSashForm(container);
549 createDetailedMessageSection(getSashForm());
550 //createStackSection(getSashForm());
551 createSessionSection(getSashForm());
554 Dialog.applyDialogFont(container);
558 private void createSashForm(Composite parent) {
559 sashForm = new SashForm(parent, SWT.VERTICAL);
560 GridLayout layout = new GridLayout();
561 layout.marginHeight = layout.marginWidth = 0;
562 sashForm.setLayout(layout);
563 sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
566 private void createToolbarButtonBar(Composite parent) {
567 Composite comp = new Composite(parent, SWT.NONE);
568 GridLayout layout = new GridLayout();
569 layout.marginWidth = layout.marginHeight = 0;
570 //layout.numColumns = 1;
571 comp.setLayout(layout);
572 comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
573 ((GridData) comp.getLayoutData()).verticalAlignment = SWT.BOTTOM;
575 Composite container = new Composite(comp, SWT.NONE);
576 layout = new GridLayout();
577 layout.marginWidth = 0;
578 layout.marginHeight = 0;
579 container.setLayout(layout);
580 container.setLayoutData(new GridData(GridData.FILL_BOTH));
582 backButton = createButton(container, IDialogConstants.BACK_ID, "", false); //$NON-NLS-1$
583 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
584 backButton.setLayoutData(gd);
585 backButton.setToolTipText(Messages.EventDetailsDialog_previous);
586 backButton.setImage(SharedImages.getImage(SharedImages.DESC_PREV_EVENT));
588 copyButton = createButton(container, COPY_ID, "", false); //$NON-NLS-1$
590 copyButton.setLayoutData(gd);
591 copyButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
592 copyButton.setToolTipText(Messages.EventDetailsDialog_copy);
594 nextButton = createButton(container, IDialogConstants.NEXT_ID, "", false); //$NON-NLS-1$
596 nextButton.setLayoutData(gd);
597 nextButton.setToolTipText(Messages.EventDetailsDialog_next);
598 nextButton.setImage(SharedImages.getImage(SharedImages.DESC_NEXT_EVENT));
600 Button button = new Button(container, SWT.NONE);
601 button.setToolTipText(Messages.EventDetailsDialog_ShowFilterDialog);
602 button.setImage(SharedImages.getImage(SharedImages.DESC_FILTER));
604 gd.horizontalAlignment = SWT.RIGHT;
605 button.setLayoutData(gd);
606 button.addSelectionListener(new SelectionAdapter() {
607 public void widgetSelected(SelectionEvent e) {
608 FilterDialog dialog = new FilterDialog(getShell(), memento);
610 dialog.getShell().setText(Messages.EventDetailsDialog_FilterDialog);
611 if (dialog.open() == Window.OK)
612 // update filters and currently displayed stack trace
613 stackFilterPatterns = getFilters();
618 // set numColumns at the end, after all createButton() calls, which change this value
619 layout.numColumns = 2;
622 protected void createButtonsForButtonBar(Composite parent) {
623 // create OK button only by default
624 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
627 private void createDetailsSection(Composite parent) {
628 Composite container = new Composite(parent, SWT.NONE);
629 GridLayout layout = new GridLayout();
630 layout.marginWidth = layout.marginHeight = 0;
631 layout.numColumns = 2;
632 container.setLayout(layout);
633 container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
635 createTextSection(container);
636 createToolbarButtonBar(container);
639 private void createTextSection(Composite parent) {
640 Composite textContainer = new Composite(parent, SWT.NONE);
641 GridLayout layout = new GridLayout();
642 layout.numColumns = 3;
643 layout.marginHeight = layout.marginWidth = 0;
644 textContainer.setLayout(layout);
645 textContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
647 Label label = new Label(textContainer, SWT.NONE);
648 label.setText(Messages.EventDetailsDialog_date);
649 dateLabel = new Label(textContainer, SWT.NULL);
650 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
651 gd.horizontalSpan = 2;
652 dateLabel.setLayoutData(gd);
654 label = new Label(textContainer, SWT.NONE);
655 label.setText(Messages.EventDetailsDialog_severity);
656 severityImageLabel = new Label(textContainer, SWT.NULL);
657 severityLabel = new Label(textContainer, SWT.NULL);
658 gd = new GridData(GridData.FILL_HORIZONTAL);
659 severityLabel.setLayoutData(gd);
661 label = new Label(textContainer, SWT.NONE);
662 label.setText(Messages.EventDetailsDialog_message);
663 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
664 label.setLayoutData(gd);
665 msgText = new Text(textContainer, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
666 msgText.setEditable(false);
667 gd = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING | GridData.GRAB_VERTICAL);
668 gd.horizontalSpan = 2;
670 gd.grabExcessVerticalSpace = true;
671 msgText.setLayoutData(gd);
674 private void createDetailedMessageSection(Composite parent) {
675 Composite container = new Composite(parent, SWT.NONE);
676 GridLayout layout = new GridLayout(2, false);
677 layout.marginHeight = 0;
678 layout.marginWidth = 6;
679 container.setLayout(layout);
680 GridData gd = new GridData(GridData.FILL_BOTH);
682 container.setLayoutData(gd);
684 detailsTextDescription = new Label(container, SWT.NONE);
685 detailsTextDescription.setText(Messages.EventDetailsDialog_detailedMessage);
687 gd.verticalAlignment = SWT.BOTTOM;
688 gd.grabExcessHorizontalSpace = true;
689 detailsTextDescription.setLayoutData(gd);
691 /*final Composite messageDescriptorComposite = new Composite(container, SWT.BORDER);
692 //GridDataFactory.fillDefaults().grab(true, false).applyTo(messageDescriptorComposite);
693 TableWrapLayout layout2 = new TableWrapLayout();
694 layout2.bottomMargin = 0;
695 layout2.topMargin = 0;
696 layout2.leftMargin = 0;
697 layout2.rightMargin = 0;
698 messageDescriptorComposite.setLayout(layout2);
699 gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
700 gd.grabExcessHorizontalSpace = true;
701 gd.horizontalSpan = 2;
702 messageDescriptorComposite.setLayoutData(gd);*/
704 detailsText = new Browser(container, SWT.BORDER);
705 // detailsText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
706 gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
707 gd.grabExcessHorizontalSpace = true;
708 gd.grabExcessVerticalSpace = true;
709 gd.horizontalSpan = 2;
710 detailsText.setLayoutData(gd);
711 /*TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB);
712 detailsText.setLayoutData(data);*/
713 //TextColors.bindTo(resourceManager, detailsText);
714 /*detailsText.addHyperlinkListener(new IHyperlinkListener() {
716 public void linkActivated(HyperlinkEvent event) {
717 String s = (String) event.data;
718 //System.out.println("link activated: " + s);
720 URI uri = new URI(s);
721 String scheme = uri.getScheme();
722 String schemeSpecificPart = uri.getSchemeSpecificPart();
724 IMessageSchemeManager msm = org.simantics.message.internal.Activator.getDefault().getMessageSchemeManager();
725 IMessageDataSchemeExtension[] exts = msm.getByScheme(scheme);
727 for (IMessageDataSchemeExtension ext : exts) {
728 Object data = ext.getSerializer().deserialize(schemeSpecificPart);
729 ext.getHandler().perform(data);
732 } catch (URISyntaxException e) {
733 // TODO Auto-generated catch block
735 } catch (ReferenceSerializationException e) {
736 // TODO Auto-generated catch block
741 public void linkEntered(HyperlinkEvent e) {
742 //System.out.println("link entered: " + e.data);
745 public void linkExited(HyperlinkEvent e) {
746 //System.out.println("link exited: " + e.data);
750 /*messageDescriptorComposite.setContent(detailsText);
751 messageDescriptorComposite.setExpandVertical(true);
752 messageDescriptorComposite.setExpandHorizontal(true);
753 messageDescriptorComposite.addControlListener(new ControlAdapter() {
754 public void controlResized(ControlEvent e) {
755 Rectangle r = messageDescriptorComposite.getClientArea();
756 //System.out.println("scrolled composite resized: " + e + ", client area: " + r);
757 Point contentSize = detailsText.computeSize(r.width, SWT.DEFAULT);
758 //System.out.println("computed content size: " + contentSize);
759 messageDescriptorComposite.setMinSize(contentSize);
762 detailsText.addLocationListener(new LocationListener() {
764 public void changed(LocationEvent event) {
765 //System.out.println("changed: " + event);
768 public void changing(LocationEvent event) {
769 //System.out.println("changing: " + event);
770 String location = event.location;
771 if ("about:blank".equals(location)) { //$NON-NLS-1$
775 //System.out.println("link activated: " + location);
777 URI uri = new URI(location);
778 String scheme = uri.getScheme();
779 //String schemeSpecificPart = uri.getSchemeSpecificPart();
781 IMessageSchemeManager msm = org.simantics.message.internal.Activator.getDefault().getMessageSchemeManager();
782 IMessageDataSchemeExtension[] exts = msm.getByScheme(scheme);
784 for (IMessageDataSchemeExtension ext : exts) {
785 Object data = ext.getSerializer().deserialize(uri);
787 ext.getHandler().perform(data);
789 } catch (MessageSchemeException e) {
790 ErrorLogger.defaultLogError(e);
794 } catch (URISyntaxException e) {
795 // TODO Auto-generated catch block
797 } catch (ReferenceSerializationException e) {
798 // TODO Auto-generated catch block
806 /*private void createStackSection(Composite parent) {
807 Composite container = new Composite(parent, SWT.NONE);
808 GridLayout layout = new GridLayout(2, false);
809 layout.marginHeight = 0;
810 layout.marginWidth = 6;
811 container.setLayout(layout);
812 GridData gd = new GridData(GridData.FILL_BOTH);
814 container.setLayoutData(gd);
816 Label label = new Label(container, SWT.NONE);
817 label.setText(Messages.EventDetailsDialog_exception);
819 gd.verticalAlignment = SWT.BOTTOM;
820 label.setLayoutData(gd);
822 stackTraceText = new Text(container, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
823 gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
824 gd.grabExcessHorizontalSpace = true;
825 gd.horizontalSpan = 2;
826 stackTraceText.setLayoutData(gd);
827 stackTraceText.setEditable(false);
830 private void createSessionSection(Composite parent) {
831 Composite container = new Composite(parent, SWT.NONE);
832 GridLayout layout = new GridLayout();
833 layout.marginHeight = 0;
834 layout.marginWidth = 6;
835 container.setLayout(layout);
836 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
838 container.setLayoutData(gd);
840 Label line = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
841 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
843 line.setLayoutData(gd);
845 Label label = new Label(container, SWT.NONE);
846 label.setText(Messages.EventDetailsDialog_session);
847 gd = new GridData(GridData.FILL_HORIZONTAL);
848 label.setLayoutData(gd);
849 sessionDataText = new Text(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
850 gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
851 gd.grabExcessHorizontalSpace = true;
852 sessionDataText.setLayoutData(gd);
853 sessionDataText.setEditable(false);
857 * Loads filters from preferences.
858 * @return filters from preferences or empty array
862 private String[] getFilters() {
864 Boolean filterEnabled = memento.getBoolean(FILTER_ENABLED);
866 String filtersString = memento.getString(FILTER_LIST);
868 if ((filterEnabled == null) || (filterEnabled.booleanValue() == false) || filtersString == null) {
869 return new String[0];
872 StringTokenizer st = new StringTokenizer(filtersString, ";"); //$NON-NLS-1$
873 List<Object> filters = new ArrayList<Object>();
874 while (st.hasMoreElements()) {
875 String filter = st.nextToken();
879 return (String[]) filters.toArray(new String[filters.size()]);
883 * Filters stack trace.
884 * Every stack trace line is compared against all patterns.
885 * If line contains any of pattern strings, it's excluded from output.
887 * @returns filtered stack trace
890 private String filterStack(String stack) {
891 if (stackFilterPatterns.length == 0) {
895 StringTokenizer st = new StringTokenizer(stack, "\n"); //$NON-NLS-1$
896 StringBuffer result = new StringBuffer();
897 while (st.hasMoreTokens()) {
898 String stackElement = st.nextToken();
900 boolean filtered = false;
902 while ((!filtered) && (i < stackFilterPatterns.length)) {
903 filtered = stackElement.indexOf(stackFilterPatterns[i]) >= 0;
908 result.append(stackElement).append("\n"); //$NON-NLS-1$
912 return result.toString();
915 //--------------- configuration handling --------------
918 * Stores the current state in the dialog settings.
921 private void storeSettings() {
922 writeConfiguration();
926 * Returns the dialog settings object used to share state
927 * between several event detail dialogs.
929 * @return the dialog settings to be used
931 private IDialogSettings getDialogSettings() {
932 IDialogSettings settings = Activator.getDefault().getDialogSettings();
933 IDialogSettings dialogSettings = settings.getSection(getClass().getName());
934 if (dialogSettings == null)
935 dialogSettings = settings.addNewSection(getClass().getName());
936 return dialogSettings;
940 * Initializes itself from the dialog settings with the same state
941 * as at the previous invocation.
943 private void readConfiguration() {
944 IDialogSettings s = getDialogSettings();
946 int x = s.getInt("x"); //$NON-NLS-1$
947 int y = s.getInt("y"); //$NON-NLS-1$
948 dialogLocation = new Point(x, y);
950 x = s.getInt("width"); //$NON-NLS-1$
951 y = s.getInt("height"); //$NON-NLS-1$
952 dialogSize = new Point(x, y);
954 sashWeights = new int[3];
955 sashWeights[0] = s.getInt("sashWidth0"); //$NON-NLS-1$
956 sashWeights[1] = s.getInt("sashWidth1"); //$NON-NLS-1$
957 sashWeights[2] = s.getInt("sashWidth2"); //$NON-NLS-1$
959 } catch (NumberFormatException e) {
960 dialogLocation = null;
966 private void writeConfiguration() {
967 IDialogSettings s = getDialogSettings();
968 Point location = getShell().getLocation();
969 s.put("x", location.x); //$NON-NLS-1$
970 s.put("y", location.y); //$NON-NLS-1$
972 Point size = getShell().getSize();
973 s.put("width", size.x); //$NON-NLS-1$
974 s.put("height", size.y); //$NON-NLS-1$
976 sashWeights = getSashForm().getWeights();
977 s.put("sashWidth0", sashWeights[0]); //$NON-NLS-1$
978 s.put("sashWidth1", sashWeights[1]); //$NON-NLS-1$
979 //s.put("sashWidth2", sashWeights[2]); //$NON-NLS-1$
983 * Utility method to get all top level elements of the Log View
984 * @return top level elements of the Log View
986 private AbstractEntry[] getElements() {
987 return (AbstractEntry[]) ((ITreeContentProvider) provider.getContentProvider()).getElements(null);