View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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 synchronized void addText(String msg)
30  	{
31  		items.add(msg);
32  		results.add(null);
33  		fireIntervalAdded(this, items.size() - 1, items.size()-1 );
34  	}
35  
36  	public synchronized void addTestStepResult(TestStepResult result)
37  	{
38  		stepCount++;
39  
40  		items.add("Step " + stepCount + " [" + result.getTestStep().getName() + "] " + result.getStatus() + ": took " + result.getTimeTaken() + " ms");
41  		SoftReference<TestStepResult> ref = new SoftReference<TestStepResult>(result);
42  		results.add( ref);
43  		for (String msg : result.getMessages())
44  		{
45  			items.add("-> " + msg);
46  			results.add(ref);
47  		}
48  
49  		fireIntervalAdded(this, items.size() - 1, items.size()-1 );
50  	}
51  
52  	public synchronized void clear()
53  	{
54  		int sz = getSize();
55  		items.clear();
56  		results.clear();
57  		stepCount = 0;
58  		fireIntervalRemoved(this, 0, sz);
59  	}
60  
61  	public int getSize()
62  	{
63  		return items.size();
64  	}
65  
66  	public Object getElementAt(int arg0)
67  	{
68  		try
69  		{
70  			return items.get(arg0);
71  		}
72  		catch (Throwable e)
73  		{
74  			return null;
75  		}			
76  	}
77  
78  	public TestStepResult getResultAt(int index)
79  	{
80  		if( index >= results.size())
81  			return null;
82  		
83  		SoftReference<TestStepResult> result = results.get(index);
84  		return result == null ? null : result.get();
85  	}
86  }