KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > ui > FailureTableDisplay


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

11 /**
12  *
13  */

14 package org.eclipse.jdt.internal.junit.ui;
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.DisposeEvent;
18 import org.eclipse.swt.events.DisposeListener;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.Table;
21 import org.eclipse.swt.widgets.TableItem;
22
23 public class FailureTableDisplay implements ITraceDisplay {
24     private final Table fTable;
25
26     private final Image fExceptionIcon = TestRunnerViewPart
27             .createImage("obj16/exc_catch.gif"); //$NON-NLS-1$
28

29     private final Image fStackIcon = TestRunnerViewPart
30             .createImage("obj16/stkfrm_obj.gif"); //$NON-NLS-1$
31

32     public FailureTableDisplay(Table table) {
33         fTable = table;
34         fTable.getParent().addDisposeListener(new DisposeListener() {
35             public void widgetDisposed(DisposeEvent e) {
36                 disposeIcons();
37             }
38         });
39     }
40
41     public void addTraceLine(int lineType, String JavaDoc label) {
42         TableItem tableItem = newTableItem();
43         switch (lineType) {
44         case TextualTrace.LINE_TYPE_EXCEPTION:
45             tableItem.setImage(fExceptionIcon);
46             break;
47         case TextualTrace.LINE_TYPE_STACKFRAME:
48             tableItem.setImage(fStackIcon);
49             break;
50         case TextualTrace.LINE_TYPE_NORMAL:
51         default:
52             break;
53         }
54         tableItem.setText(label);
55     }
56
57     public Image getExceptionIcon() {
58         return fExceptionIcon;
59     }
60
61     public Image getStackIcon() {
62         return fStackIcon;
63     }
64
65     public Table getTable() {
66         return fTable;
67     }
68
69     private void disposeIcons() {
70         if (fExceptionIcon != null && !fExceptionIcon.isDisposed())
71             fExceptionIcon.dispose();
72         if (fStackIcon != null && !fStackIcon.isDisposed())
73             fStackIcon.dispose();
74     }
75
76     TableItem newTableItem() {
77         return new TableItem(fTable, SWT.NONE);
78     }
79 }
80
Popular Tags