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.panels.request.components.editor.inspectors.wss;
14  
15  import java.awt.BorderLayout;
16  import java.awt.Component;
17  import java.util.Vector;
18  
19  import javax.swing.AbstractListModel;
20  import javax.swing.JComponent;
21  import javax.swing.JList;
22  import javax.swing.JPanel;
23  import javax.swing.JScrollPane;
24  
25  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlLocation;
26  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.AbstractXmlInspector;
27  import com.eviware.soapui.support.UISupport;
28  
29  public abstract class AbstractWssInspector extends AbstractXmlInspector
30  {
31  	private JPanel mainPanel;
32  	private JList resultList;
33  
34  	protected AbstractWssInspector()
35  	{
36  		super( "WSS", "Displays WS-Security information for this response", true, WssInspectorFactory.INSPECTOR_ID );
37  	}
38  
39  	@Override
40  	public void release()
41  	{
42  		super.release();
43  	}
44  
45  	public void locationChanged( XmlLocation location )
46  	{
47  	}
48  
49  	public JComponent getComponent()
50  	{
51  		if( mainPanel == null )
52  		{
53  			mainPanel = new JPanel( new BorderLayout() );
54  			mainPanel.add( buildContent(), BorderLayout.CENTER );
55  
56  			UISupport.addTitledBorder( mainPanel, "WS-Security processing results" );
57  			
58  			update();
59  		}
60  
61  		return mainPanel;
62  	}
63  
64  	private Component buildContent()
65  	{
66  		resultList = new JList( new ResultVectorListModel( getWssResults() ));
67  		return new JScrollPane( resultList );
68  	}
69  
70  	public abstract Vector getWssResults();
71  
72  	public void update()
73  	{
74  		resultList.setModel( new ResultVectorListModel( getWssResults() ) );
75  		int size = resultList.getModel().getSize();
76  		setTitle( "WSS (" + size + ")" );
77  		setEnabled( size > 0 );
78  	}
79  	
80  	private static class ResultVectorListModel extends AbstractListModel
81  	{
82  		private final Vector result;
83  
84  		public ResultVectorListModel( Vector result )
85  		{
86  			this.result = result;
87  		}
88  
89  		public Object getElementAt( int index )
90  		{
91  			return result == null ? null : result.get( index );
92  		}
93  
94  		public int getSize()
95  		{
96  			return result == null ? 0 : result.size();
97  		}
98  	}
99  }