KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > runtime > logview > EventDetailsDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.runtime.logview;
12
13 import java.io.IOException JavaDoc;
14 import java.io.PrintWriter JavaDoc;
15 import java.io.StringWriter JavaDoc;
16 import java.util.Arrays JavaDoc;
17 import java.util.Comparator JavaDoc;
18 import java.util.Date JavaDoc;
19
20 import org.eclipse.core.runtime.IAdaptable;
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.dialogs.IDialogConstants;
23 import org.eclipse.jface.dialogs.IDialogSettings;
24 import org.eclipse.jface.dialogs.TrayDialog;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.ISelectionProvider;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28 import org.eclipse.jface.viewers.StructuredSelection;
29 import org.eclipse.jface.viewers.TreeViewer;
30 import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
31 import org.eclipse.pde.internal.runtime.PDERuntimePlugin;
32 import org.eclipse.pde.internal.runtime.PDERuntimePluginImages;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.custom.SashForm;
35 import org.eclipse.swt.dnd.Clipboard;
36 import org.eclipse.swt.dnd.TextTransfer;
37 import org.eclipse.swt.dnd.Transfer;
38 import org.eclipse.swt.graphics.Image;
39 import org.eclipse.swt.graphics.Point;
40 import org.eclipse.swt.layout.GridData;
41 import org.eclipse.swt.layout.GridLayout;
42 import org.eclipse.swt.widgets.Button;
43 import org.eclipse.swt.widgets.Composite;
44 import org.eclipse.swt.widgets.Control;
45 import org.eclipse.swt.widgets.Label;
46 import org.eclipse.swt.widgets.Shell;
47 import org.eclipse.swt.widgets.Text;
48 import org.eclipse.ui.ISharedImages;
49 import org.eclipse.ui.PlatformUI;
50
51 import com.ibm.icu.text.Collator;
52 import com.ibm.icu.text.DateFormat;
53 import com.ibm.icu.text.SimpleDateFormat;
54
55 public class EventDetailsDialog extends TrayDialog {
56     private LogEntry entry, parentEntry;
57     private LogViewLabelProvider labelProvider;
58     private static int COPY_ID = 22;
59     private TreeViewer provider;
60     private int elementNum, totalElementCount;
61     private LogEntry[] entryChildren;
62     private int childIndex = 0;
63     private boolean isOpen;
64     private boolean isLastChild;
65     private boolean isAtEndOfLog;
66     
67     private Label dateLabel;
68     private Label severityImageLabel;
69     private Label severityLabel;
70     private Text msgText;
71     private Text stackTraceText;
72     private Text sessionDataText;
73     private Clipboard clipboard;
74     private Button copyButton;
75     private Button backButton;
76     private Button nextButton;
77     private Image imgNextEnabled;
78     private Image imgPrevEnabled;
79     private Image imgCopyEnabled;
80     private SashForm sashForm;
81     
82     // sorting
83
private Comparator JavaDoc comparator = null;
84     private Collator collator;
85     
86     // location configuration
87
private Point dialogLocation;
88     private Point dialogSize;
89     private int[] sashWeights;
90     
91     /**
92      *
93      * @param parentShell shell in which dialog is displayed
94      * @param selection entry initially selected and to be displayed
95      * @param provider viewer
96      * @param comparator comparator used to order all entries
97      */

98     protected EventDetailsDialog(Shell parentShell, IAdaptable selection, ISelectionProvider provider, Comparator JavaDoc comparator) {
99         super(parentShell);
100         this.provider = (TreeViewer) provider;
101         labelProvider = (LogViewLabelProvider)this.provider.getLabelProvider();
102         labelProvider.connect(this);
103         this.entry = (LogEntry)selection;
104         this.comparator = comparator;
105         setShellStyle(SWT.MODELESS | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.CLOSE | SWT.BORDER | SWT.TITLE);
106         clipboard = new Clipboard(parentShell.getDisplay());
107         initialize();
108         createImages();
109         collator = Collator.getInstance();
110         readConfiguration();
111         isLastChild = false;
112         isAtEndOfLog = false;
113     }
114
115     private void initialize() {
116         elementNum = getParentElementNum();
117         resetTotalElementCount();
118         parentEntry = (LogEntry) entry.getParent(entry);
119         if (isChild(entry)){
120             setEntryChildren(parentEntry);
121             resetChildIndex();
122         }
123         isLastChild = false;
124         isAtEndOfLog = false;
125     }
126     
127     private void resetChildIndex() {
128         for (int i = 0; i < entryChildren.length; i++) {
129             if (equal(entryChildren[i].getMessage(), entry.getMessage())
130                     && equal(entryChildren[i].getDate(), entry.getDate())
131                     && equal(entryChildren[i].getPluginId(), entry
132                             .getPluginId())
133                     && entryChildren[i].getSeverity() == entry.getSeverity()
134                     && equal(entryChildren[i].getSeverityText(), entry
135                             .getSeverityText())) {
136                 childIndex = i;
137                 break;
138             }
139         }
140     }
141     
142     private boolean equal(String JavaDoc str1, String JavaDoc str2) {
143         if (str1 == null) {
144             return str1 == str2;
145         }
146         return str1.equals(str2);
147     }
148     
149     private boolean equal(Date JavaDoc d1, Date JavaDoc d2) {
150         if (d1 == null)
151             return d1 == d2;
152         return d1.equals(d2);
153     }
154     
155     private void createImages(){
156         imgCopyEnabled =
157             PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY).createImage(
158                 true);
159         //imgNextDisabled. = PDERuntimePluginImages.DESC_NEXT_EVENT_DISABLED.createImage(true);
160
//imgPrevDisabled = PDERuntimePluginImages.DESC_PREV_EVENT_DISABLED.createImage(true);
161
imgPrevEnabled = PDERuntimePluginImages.DESC_PREV_EVENT.createImage(true);
162         imgNextEnabled = PDERuntimePluginImages.DESC_NEXT_EVENT.createImage(true);
163     }
164
165     private boolean isChild(LogEntry entry) {
166         return entry.getParent(entry) != null;
167     }
168     
169     public boolean isOpen(){
170         return isOpen;
171     }
172
173     public int open(){
174         isOpen = true;
175         if (sashWeights == null){
176             int width = getSashForm().getClientArea().width;
177             if (width - 100 > 0)
178                 width -= 100;
179             else
180                 width = width/2;
181             sashWeights = new int[]{width, getSashForm().getClientArea().width-width};
182         }
183         getSashForm().setWeights(sashWeights);
184         return super.open();
185     }
186     
187     public boolean close() {
188         storeSettings();
189         isOpen = false;
190         imgCopyEnabled.dispose();
191         imgNextEnabled.dispose();
192         imgPrevEnabled.dispose();
193         labelProvider.disconnect(this);
194         return super.close();
195     }
196
197     public void create() {
198         super.create();
199         
200         // dialog location
201
if (dialogLocation != null)
202             getShell().setLocation(dialogLocation);
203         
204         // dialog size
205
if (dialogSize != null)
206             getShell().setSize(dialogSize);
207         else
208             getShell().setSize(500,550);
209                 
210         applyDialogFont(buttonBar);
211         getButton(IDialogConstants.OK_ID).setFocus();
212     }
213
214     protected void buttonPressed(int buttonId) {
215         if (IDialogConstants.OK_ID == buttonId)
216             okPressed();
217         else if (IDialogConstants.CANCEL_ID == buttonId)
218             cancelPressed();
219         else if (IDialogConstants.BACK_ID == buttonId)
220             backPressed();
221         else if (IDialogConstants.NEXT_ID == buttonId)
222             nextPressed();
223         else if (COPY_ID == buttonId)
224             copyPressed();
225     }
226
227     protected void backPressed() {
228         if (isChild(entry)) {
229             if (childIndex > 0) {
230                 if (isLastChild){
231                     setEntryChildren(parentEntry);
232                     isLastChild = false;
233                 }
234                 childIndex--;
235                 entry = entryChildren[childIndex];
236             } else
237                 entry = parentEntry;
238         } else {
239             if (elementNum - 1 >= 0)
240                 elementNum -= 1;
241             entry = entryChildren[elementNum];
242         }
243         setEntrySelectionInTable();
244     }
245
246     protected void nextPressed() {
247         if (isChild(entry) && childIndex < entryChildren.length-1) {
248             childIndex++;
249             entry = entryChildren[childIndex];
250             isLastChild = childIndex == entryChildren.length - 1;
251         } else if (isChild(entry) && isLastChild && !isAtEndOfLog){
252             findNextSelectedChild(entry);
253         } else if (elementNum + 1 < totalElementCount){
254             if (isLastChild){
255                 setEntryChildren();
256                 isLastChild = false;
257             }
258             elementNum += 1;
259             entry = entryChildren[elementNum];
260         } else { // at end of list but can branch into child elements - bug 58083
261
setEntryChildren(entry);
262             entry = entryChildren[0];
263             isAtEndOfLog = entryChildren.length == 0;
264             isLastChild = entryChildren.length == 0;
265         }
266         setEntrySelectionInTable();
267     }
268
269     protected void copyPressed() {
270         StringWriter JavaDoc writer = new StringWriter JavaDoc();
271         PrintWriter JavaDoc pwriter = new PrintWriter JavaDoc(writer);
272
273         entry.write(pwriter);
274         pwriter.flush();
275         String JavaDoc textVersion = writer.toString();
276         try {
277             pwriter.close();
278             writer.close();
279         } catch (IOException JavaDoc e) {
280         }
281         // set the clipboard contents
282
clipboard.setContents(new Object JavaDoc[] { textVersion }, new Transfer[] { TextTransfer.getInstance()});
283     }
284
285     public void setComparator(Comparator JavaDoc comparator){
286         this.comparator = comparator;
287         updateProperties();
288     }
289     private void setComparator(byte sortType, final int sortOrder){
290         if (sortType == LogView.DATE){
291             comparator = new Comparator JavaDoc(){
292                 public int compare(Object JavaDoc e1, Object JavaDoc e2) {
293                     Date JavaDoc date1 = ((LogEntry) e1).getDate();
294                     Date JavaDoc date2 = ((LogEntry) e2).getDate();
295                     if (sortOrder == LogView.ASCENDING)
296                         return date1.getTime() < date2.getTime() ? LogView.DESCENDING : LogView.ASCENDING;
297                     return date1.getTime() > date2.getTime() ? LogView.DESCENDING : LogView.ASCENDING;
298                 }
299             };
300         } else if (sortType == LogView.PLUGIN){
301             comparator = new Comparator JavaDoc(){
302                 public int compare(Object JavaDoc e1, Object JavaDoc e2) {
303                     LogEntry entry1 = (LogEntry)e1;
304                     LogEntry entry2 = (LogEntry)e2;
305                     return collator.compare(entry1.getPluginId(), entry2.getPluginId()) * sortOrder;
306                 }
307             };
308         } else {
309             comparator = new Comparator JavaDoc(){
310                 public int compare(Object JavaDoc e1, Object JavaDoc e2) {
311                     LogEntry entry1 = (LogEntry)e1;
312                     LogEntry entry2 = (LogEntry)e2;
313                     return collator.compare(entry1.getMessage(), entry2.getMessage()) * sortOrder;
314                 }
315             };
316         }
317     }
318     
319     public void resetSelection(IAdaptable selectedEntry, byte sortType, int sortOrder){
320         setComparator(sortType, sortOrder);
321         resetSelection(selectedEntry);
322     }
323     
324     public void resetSelection(IAdaptable selectedEntry){
325         if (entry.equals(selectedEntry) &&
326                 elementNum == getParentElementNum()){
327             updateProperties();
328             return;
329         }
330         entry = (LogEntry)selectedEntry;
331         initialize();
332         updateProperties();
333     }
334     
335     public void resetButtons(){
336         backButton.setEnabled(false);
337         nextButton.setEnabled(false);
338     }
339     
340     private void setEntrySelectionInTable(){
341         ISelection selection = new StructuredSelection(entry);
342         provider.setSelection(selection);
343     }
344     
345     public void updateProperties() {
346         if (isChild(entry)){
347             parentEntry = (LogEntry) entry.getParent(entry);
348             setEntryChildren(parentEntry);
349             resetChildIndex();
350             if (childIndex == entryChildren.length - 1)
351                 isLastChild = true;
352         }
353
354         resetTotalElementCount();
355         
356         Date JavaDoc date = entry.getDate();
357         String JavaDoc strDate = null;
358         if (date != null) {
359             DateFormat formatter = new SimpleDateFormat(LogEntry.F_DATE_FORMAT);
360             strDate = formatter.format(date);
361         }
362         dateLabel.setText(strDate != null ? strDate : ""); //$NON-NLS-1$
363
severityImageLabel.setImage(labelProvider.getColumnImage(entry, 0));
364         severityLabel.setText(entry.getSeverityText());
365         msgText.setText(entry.getMessage() != null ? entry.getMessage() : ""); //$NON-NLS-1$
366
String JavaDoc stack = entry.getStack();
367         if (stack != null) {
368             stackTraceText.setText(stack);
369         } else {
370             stackTraceText.setText(PDERuntimeMessages.EventDetailsDialog_noStack);
371         }
372         LogSession session = entry.getSession();
373         if (session != null && session.getSessionData() != null)
374             sessionDataText.setText(session.getSessionData());
375
376         updateButtons();
377     }
378     
379     private void updateButtons(){
380         boolean isAtEnd = elementNum == totalElementCount - 1;
381         if (isChild(entry)){
382             backButton.setEnabled(true);
383             nextButton.setEnabled(nextChildExists(entry, parentEntry, entryChildren) || !isLastChild || !isAtEnd || entry.hasChildren());
384         } else {
385             backButton.setEnabled(elementNum != 0);
386             nextButton.setEnabled(!isAtEnd || entry.hasChildren());
387         }
388     }
389     
390     private void findNextSelectedChild(LogEntry originalEntry){
391         if (isChild (parentEntry)){
392             // we're at the end of the child list; find next parent
393
// to select. If the parent is a child at the end of the child
394
// list, find its next parent entry to select, etc.
395

396             entry = parentEntry;
397             setEntryChildren((LogEntry)parentEntry.getParent(parentEntry));
398             parentEntry = (LogEntry)parentEntry.getParent(parentEntry);
399             resetChildIndex();
400             isLastChild = childIndex == entryChildren.length-1;
401             if (isLastChild){
402                 findNextSelectedChild(originalEntry);
403             } else {
404                 nextPressed();
405             }
406         } else {
407             entry = originalEntry;
408             isAtEndOfLog = true;
409             nextPressed();
410         }
411     }
412     
413     private boolean nextChildExists(LogEntry originalEntry, LogEntry originalParent, LogEntry[] originalEntries){
414         if (isChild (parentEntry)){
415             // we're at the end of the child list; find next parent
416
// to select. If the parent is a child at the end of the child
417
// list, find its next parent entry to select, etc.
418

419             entry = parentEntry;
420             setEntryChildren((LogEntry)parentEntry.getParent(parentEntry));
421             parentEntry = (LogEntry)parentEntry.getParent(parentEntry);
422             resetChildIndex();
423             if (childIndex == entryChildren.length-1){
424                 nextChildExists(originalEntry, originalParent, originalEntries);
425             } else {
426                 entry = originalEntry;
427                 parentEntry = originalParent;
428                 entryChildren = originalEntries;
429                 resetChildIndex();
430                 return true;
431             }
432         }
433         entry = originalEntry;
434         parentEntry = originalParent;
435         entryChildren = originalEntries;
436         resetChildIndex();
437         return false;
438         
439     }
440     private void setEntryChildren(){
441         Object JavaDoc[] children = ((LogViewContentProvider)provider.getContentProvider()).getElements(null);
442
443         if (comparator != null)
444             Arrays.sort(children, comparator);
445         entryChildren = new LogEntry[children.length];
446         
447         System.arraycopy(children,0,entryChildren,0,children.length);
448     }
449     
450     private void resetTotalElementCount(){
451         totalElementCount = provider.getTree().getItemCount();
452     }
453     
454     private void setEntryChildren(LogEntry parent){
455         if (parent == null){
456             setEntryChildren();
457             return;
458         }
459         Object JavaDoc[] children = parent.getChildren(parent);
460         if (comparator != null)
461             Arrays.sort(children, comparator);
462         entryChildren = new LogEntry[children.length];
463         
464         System.arraycopy(children,0,entryChildren,0,children.length);
465     }
466
467     private int getParentElementNum(){
468         LogEntry itemEntry = (LogEntry)((IStructuredSelection)provider.getSelection()).getFirstElement();
469         itemEntry = getRootEntry(itemEntry);
470         
471         setEntryChildren();
472         for (int i = 0; i<provider.getTree().getItemCount(); i++){
473             try {
474                 LogEntry littleEntry = entryChildren[i];
475                 if (itemEntry.equals(littleEntry)){
476                     return i;
477                 }
478             } catch (Exception JavaDoc e){
479                 
480             }
481         }
482         return 0;
483     }
484     
485     private LogEntry getRootEntry(LogEntry entry){
486         if (!isChild(entry))
487             return entry;
488         return getRootEntry((LogEntry)entry.getParent(entry));
489     }
490     
491     public SashForm getSashForm(){
492         return sashForm;
493     }
494     
495     protected Control createDialogArea(Composite parent) {
496         Composite container = new Composite(parent, SWT.NONE);
497         GridLayout layout = new GridLayout();
498         layout.numColumns = 1;
499         container.setLayout(layout);
500         GridData gd = new GridData(GridData.FILL_BOTH);
501         container.setLayoutData(gd);
502
503         createDetailsSection(container);
504         createSashForm(container);
505         createStackSection(getSashForm());
506         createSessionSection(getSashForm());
507
508         updateProperties();
509         Dialog.applyDialogFont(container);
510         return container;
511     }
512
513     private void createSashForm(Composite parent){
514         sashForm = new SashForm(parent, SWT.VERTICAL);
515         GridLayout layout = new GridLayout();
516         layout.marginHeight = layout.marginWidth = 0;
517         sashForm.setLayout(layout);
518         sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
519     }
520     
521     private void createToolbarButtonBar(Composite parent) {
522         Composite comp = new Composite(parent, SWT.NONE);
523         GridLayout layout = new GridLayout();
524         layout.marginWidth = layout.marginHeight = 0;
525         layout.numColumns = 1;
526         comp.setLayout(layout);
527         comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
528
529         Composite container = new Composite(comp, SWT.NONE);
530         layout = new GridLayout();
531         layout.marginWidth = 0;
532         layout.marginHeight = 10;
533         layout.numColumns = 1;
534         container.setLayout(layout);
535         container.setLayoutData(new GridData(GridData.FILL_BOTH));
536
537         backButton = createButton(container, IDialogConstants.BACK_ID, "", false); //$NON-NLS-1$
538
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
539         gd.horizontalSpan = 3;
540         gd.verticalSpan = 1;
541         backButton.setLayoutData(gd);
542         backButton.setToolTipText(PDERuntimeMessages.EventDetailsDialog_previous);
543         backButton.setImage(imgPrevEnabled);
544         
545         nextButton = createButton(container, IDialogConstants.NEXT_ID, "", false); //$NON-NLS-1$
546
gd = new GridData();
547         gd.horizontalSpan = 3;
548         gd.verticalSpan = 1;
549         nextButton.setLayoutData(gd);
550         nextButton.setToolTipText(PDERuntimeMessages.EventDetailsDialog_next);
551         nextButton.setImage(imgNextEnabled);
552         
553         copyButton = createButton(container, COPY_ID, "", false); //$NON-NLS-1$
554
gd = new GridData();
555         gd.horizontalSpan = 3;
556         gd.verticalSpan = 1;
557         copyButton.setLayoutData(gd);
558         copyButton.setImage(imgCopyEnabled);
559         copyButton.setToolTipText(PDERuntimeMessages.EventDetailsDialog_copy);
560     }
561
562     protected void createButtonsForButtonBar(Composite parent) {
563         // create OK button only by default
564
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
565     }
566
567     private void createDetailsSection(Composite parent) {
568         Composite container = new Composite(parent, SWT.NONE);
569         GridLayout layout = new GridLayout();
570         layout.numColumns = 2;
571         container.setLayout(layout);
572         container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
573
574         createTextSection(container);
575         createToolbarButtonBar(container);
576     }
577
578     private void createTextSection(Composite parent) {
579         Composite textContainer = new Composite(parent, SWT.NONE);
580         GridLayout layout = new GridLayout();
581         layout.numColumns = 3;
582         layout.marginHeight = layout.marginWidth = 0;
583         textContainer.setLayout(layout);
584         textContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
585
586         Label label = new Label(textContainer, SWT.NONE);
587         label.setText(PDERuntimeMessages.EventDetailsDialog_date);
588         dateLabel = new Label(textContainer, SWT.NULL);
589         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
590         gd.horizontalSpan = 2;
591         dateLabel.setLayoutData(gd);
592
593         label = new Label(textContainer, SWT.NONE);
594         label.setText(PDERuntimeMessages.EventDetailsDialog_severity);
595         severityImageLabel = new Label(textContainer, SWT.NULL);
596         severityLabel = new Label(textContainer, SWT.NULL);
597         gd = new GridData(GridData.FILL_HORIZONTAL);
598         severityLabel.setLayoutData(gd);
599
600         label = new Label(textContainer, SWT.NONE);
601         label.setText(PDERuntimeMessages.EventDetailsDialog_message);
602         gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
603         label.setLayoutData(gd);
604         msgText = new Text(textContainer, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
605         msgText.setEditable(false);
606         gd = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING | GridData.GRAB_VERTICAL);
607         gd.horizontalSpan = 2;
608         gd.heightHint = 44;
609         gd.grabExcessVerticalSpace = true;
610         msgText.setLayoutData(gd);
611     }
612
613     private void createStackSection(Composite parent) {
614         Composite container = new Composite(parent, SWT.NONE);
615         GridLayout layout = new GridLayout();
616         layout.marginHeight = 0;
617         layout.marginWidth = 6;
618         container.setLayout(layout);
619         GridData gd = new GridData(GridData.FILL_BOTH);
620         gd.heightHint = 100;
621         container.setLayoutData(gd);
622
623         Label label = new Label(container, SWT.NULL);
624         label.setText(PDERuntimeMessages.EventDetailsDialog_exception);
625         gd = new GridData(GridData.FILL_HORIZONTAL);
626         gd.horizontalSpan = 3;
627         label.setLayoutData(gd);
628
629         stackTraceText = new Text(container, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
630         gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
631         gd.grabExcessHorizontalSpace = true;
632         stackTraceText.setLayoutData(gd);
633         stackTraceText.setEditable(false);
634     }
635
636     private void createSessionSection(Composite parent) {
637         Composite container = new Composite(parent, SWT.NONE);
638         GridLayout layout = new GridLayout();
639         layout.marginHeight = 0;
640         layout.marginWidth = 6;
641         container.setLayout(layout);
642         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
643         gd.heightHint = 100;
644         container.setLayoutData(gd);
645
646         Label line = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
647         gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
648         gd.widthHint = 1;
649         line.setLayoutData(gd);
650         
651         Label label = new Label(container, SWT.NONE);
652         label.setText(PDERuntimeMessages.EventDetailsDialog_session);
653         gd = new GridData(GridData.FILL_HORIZONTAL);
654         label.setLayoutData(gd);
655         sessionDataText = new Text(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL );
656         gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
657         gd.grabExcessHorizontalSpace = true;
658         sessionDataText.setLayoutData(gd);
659         sessionDataText.setEditable(false);
660     }
661     
662     //--------------- configuration handling --------------
663

664     /**
665      * Stores the current state in the dialog settings.
666      * @since 2.0
667      */

668     private void storeSettings() {
669         writeConfiguration();
670     }
671     /**
672      * Returns the dialog settings object used to share state
673      * between several event detail dialogs.
674      *
675      * @return the dialog settings to be used
676      */

677     private IDialogSettings getDialogSettings() {
678         IDialogSettings settings= PDERuntimePlugin.getDefault().getDialogSettings();
679         IDialogSettings dialogSettings = settings.getSection(getClass().getName());
680         if (dialogSettings == null)
681             dialogSettings = settings.addNewSection(getClass().getName());
682         return dialogSettings;
683     }
684
685     /**
686      * Initializes itself from the dialog settings with the same state
687      * as at the previous invocation.
688      */

689     private void readConfiguration() {
690         IDialogSettings s= getDialogSettings();
691         try {
692             int x= s.getInt("x"); //$NON-NLS-1$
693
int y= s.getInt("y"); //$NON-NLS-1$
694
dialogLocation= new Point(x, y);
695             
696             x = s.getInt("width"); //$NON-NLS-1$
697
y = s.getInt("height"); //$NON-NLS-1$
698
dialogSize = new Point(x,y);
699             
700             sashWeights = new int[2];
701             sashWeights[0] = s.getInt("sashWidth1"); //$NON-NLS-1$
702
sashWeights[1] = s.getInt("sashWidth2"); //$NON-NLS-1$
703

704         } catch (NumberFormatException JavaDoc e) {
705             dialogLocation= null;
706             dialogSize = null;
707             sashWeights = null;
708         }
709     }
710     
711     private void writeConfiguration(){
712         IDialogSettings s = getDialogSettings();
713         Point location = getShell().getLocation();
714         s.put("x", location.x); //$NON-NLS-1$
715
s.put("y", location.y); //$NON-NLS-1$
716

717         Point size = getShell().getSize();
718         s.put("width", size.x); //$NON-NLS-1$
719
s.put("height", size.y); //$NON-NLS-1$
720

721         sashWeights = getSashForm().getWeights();
722         s.put("sashWidth1", sashWeights[0]); //$NON-NLS-1$
723
s.put("sashWidth2", sashWeights[1]); //$NON-NLS-1$
724
}
725 }
726
Popular Tags