View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.support.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.support.UISupport;
26  import com.eviware.soapui.support.editor.EditorView;
27  import com.eviware.soapui.support.editor.inspectors.AbstractXmlInspector;
28  import com.eviware.soapui.support.editor.xml.XmlDocument;
29  import com.eviware.soapui.support.editor.xml.XmlLocation;
30  
31  public abstract class AbstractWssInspector extends AbstractXmlInspector
32  {
33  	private JPanel mainPanel;
34  	private JList resultList;
35  
36  	protected AbstractWssInspector()
37  	{
38  		super( "WSS", "Displays WS-Security information for this response", true, WssInspectorFactory.INSPECTOR_ID );
39  	}
40  
41  	@Override
42  	public void release()
43  	{
44  		super.release();
45  	}
46  
47  	public void locationChanged( XmlLocation location )
48  	{
49  	}
50  
51  	public JComponent getComponent()
52  	{
53  		if( mainPanel == null )
54  		{
55  			mainPanel = new JPanel( new BorderLayout() );
56  			mainPanel.add( buildContent(), BorderLayout.CENTER );
57  
58  			UISupport.addTitledBorder( mainPanel, "WS-Security processing results" );
59  
60  			update();
61  		}
62  
63  		return mainPanel;
64  	}
65  
66  	private Component buildContent()
67  	{
68  		resultList = new JList( new ResultVectorListModel( getWssResults() ) );
69  		return new JScrollPane( resultList );
70  	}
71  
72  	public abstract Vector<?> getWssResults();
73  
74  	public void update()
75  	{
76  		resultList.setModel( new ResultVectorListModel( getWssResults() ) );
77  		int size = resultList.getModel().getSize();
78  		setTitle( "WSS (" + size + ")" );
79  		setEnabled( size > 0 );
80  	}
81  
82  	private static class ResultVectorListModel extends AbstractListModel
83  	{
84  		private final Vector<?> result;
85  
86  		public ResultVectorListModel( Vector<?> result )
87  		{
88  			this.result = result;
89  		}
90  
91  		public Object getElementAt( int index )
92  		{
93  			return result == null ? null : result.get( index );
94  		}
95  
96  		public int getSize()
97  		{
98  			return result == null ? 0 : result.size();
99  		}
100 	}
101 
102 	@Override
103 	public boolean isEnabledFor( EditorView<XmlDocument> view )
104 	{
105 		return true;
106 	}
107 }