01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: /**
24: * ListModel for the TestCaseLog
25: *
26: * @author ole.matzura
27: */
28:
29: public class TestCaseLogModel extends AbstractListModel {
30: private List<Object> items = new ArrayList<Object>();
31: private List<SoftReference<TestStepResult>> results = new ArrayList<SoftReference<TestStepResult>>();
32: private int stepCount;
33:
34: public void addText(String msg) {
35: synchronized (this ) {
36: items.add(msg);
37: results.add(null);
38: fireIntervalAdded(this , items.size() - 1, items.size() - 1);
39: }
40: }
41:
42: public void addTestStepResult(TestStepResult result) {
43: synchronized (this ) {
44: stepCount++;
45:
46: int size = items.size();
47: items.add("Step " + stepCount + " ["
48: + result.getTestStep().getName() + "] "
49: + result.getStatus() + ": took "
50: + result.getTimeTaken() + " ms");
51: SoftReference<TestStepResult> ref = new SoftReference<TestStepResult>(
52: result);
53: results.add(ref);
54: for (String msg : result.getMessages()) {
55: items.add("-> " + msg);
56: results.add(ref);
57: }
58:
59: fireIntervalAdded(this , size, items.size() - 1);
60: }
61: }
62:
63: public void clear() {
64: synchronized (this ) {
65: int sz = getSize();
66: items.clear();
67: results.clear();
68: stepCount = 0;
69: fireIntervalRemoved(this , 0, sz);
70: }
71: }
72:
73: public int getSize() {
74: synchronized (this ) {
75: return items.size();
76: }
77: }
78:
79: public Object getElementAt(int arg0) {
80: try {
81: return items.get(arg0);
82: } catch (Throwable e) {
83: return null;
84: }
85: }
86:
87: public TestStepResult getResultAt(int index) {
88: if (index >= results.size())
89: return null;
90:
91: SoftReference<TestStepResult> result = results.get(index);
92: return result == null ? null : result.get();
93: }
94: }
|