View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.testcase;
14  
15  import java.lang.ref.SoftReference;
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import javax.swing.AbstractListModel;
20  
21  import com.eviware.soapui.model.testsuite.TestStepResult;
22  
23  public class TestCaseLogModel extends AbstractListModel
24  {
25  	private List<Object> items = new ArrayList<Object>();
26  	private List<SoftReference<TestStepResult>> results = new ArrayList<SoftReference<TestStepResult>>();
27  	private int stepCount;
28  
29  	public void addText(String msg)
30  	{
31  		synchronized( this )
32  		{
33  			items.add(msg);
34  			results.add(null);
35  			fireIntervalAdded(this, items.size() - 1, items.size()-1 );
36  		}
37  	}
38  
39  	public void addTestStepResult(TestStepResult result)
40  	{
41  		synchronized( this )
42  		{
43  			stepCount++;
44  	
45  			int size = items.size();
46  			items.add("Step " + stepCount + " [" + result.getTestStep().getName() + "] " + result.getStatus() + ": took " + result.getTimeTaken() + " ms");
47  			SoftReference<TestStepResult> ref = new SoftReference<TestStepResult>(result);
48  			results.add( ref);
49  			for (String msg : result.getMessages())
50  			{
51  				items.add("-> " + msg);
52  				results.add(ref);
53  			}
54  	
55  			fireIntervalAdded(this, size, items.size()-1 );
56  		}
57  	}
58  
59  	public void clear()
60  	{
61  		synchronized( this )
62  		{
63  			int sz = getSize();
64  			items.clear();
65  			results.clear();
66  			stepCount = 0;
67  			fireIntervalRemoved(this, 0, sz);
68  		}
69  	}
70  
71  	public int getSize()
72  	{
73  		synchronized( this )
74  		{
75  			return items.size();
76  		}
77  	}
78  
79  	public Object getElementAt(int arg0)
80  	{
81  		try
82  		{
83  			return items.get(arg0);
84  		}
85  		catch (Throwable e)
86  		{
87  			return null;
88  		}
89  	}
90  
91  	public TestStepResult getResultAt(int index)
92  	{
93  		if( index >= results.size())
94  			return null;
95  		
96  		SoftReference<TestStepResult> result = results.get(index);
97  		return result == null ? null : result.get();
98  	}
99  }