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.impl.wsdl.support.wss.support;
14  
15  import java.util.ArrayList;
16  import java.util.List;
17  
18  import javax.swing.AbstractListModel;
19  import javax.swing.ComboBoxModel;
20  
21  import com.eviware.soapui.impl.wsdl.support.wss.IncomingWss;
22  import com.eviware.soapui.impl.wsdl.support.wss.OutgoingWss;
23  import com.eviware.soapui.impl.wsdl.support.wss.WssContainer;
24  import com.eviware.soapui.impl.wsdl.support.wss.WssContainerListener;
25  import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto;
26  import com.eviware.soapui.impl.wsdl.support.wss.WssEntry;
27  
28  public class KeystoresComboBoxModel extends AbstractListModel implements ComboBoxModel, WssContainerListener
29  {
30  	private List<WssCrypto> cryptos = new ArrayList<WssCrypto>();
31  	private WssCrypto selectedCrypto;
32  	private final WssContainer container;
33  
34  	public KeystoresComboBoxModel( WssContainer container, WssCrypto selectedCrypto )
35  	{
36  		this.container = container;
37  		this.selectedCrypto = selectedCrypto;
38  
39  		cryptos.addAll( container.getCryptoList() );
40  
41  		container.addWssContainerListener( this );
42  	}
43  
44  	public String getSelectedItem()
45  	{
46  		return selectedCrypto == null ? null : selectedCrypto.getLabel();
47  	}
48  
49  	public void setSelectedItem( Object anItem )
50  	{
51  		selectedCrypto = null;
52  
53  		for( WssCrypto crypto : cryptos )
54  			if( crypto.getLabel().equals( anItem ) )
55  				selectedCrypto = crypto;
56  	}
57  
58  	public Object getElementAt( int index )
59  	{
60  		return cryptos.get( index ).getLabel();
61  	}
62  
63  	public int getSize()
64  	{
65  		return cryptos == null ? 0 : cryptos.size();
66  	}
67  
68  	public void cryptoAdded( WssCrypto crypto )
69  	{
70  		cryptos.add( crypto );
71  		fireIntervalAdded( this, getSize() - 1, getSize() - 1 );
72  	}
73  
74  	public void cryptoRemoved( WssCrypto crypto )
75  	{
76  		int index = cryptos.indexOf( crypto );
77  		cryptos.remove( index );
78  		fireIntervalRemoved( this, index, index );
79  	}
80  
81  	public void incomingWssAdded( IncomingWss incomingWss )
82  	{
83  	}
84  
85  	public void incomingWssRemoved( IncomingWss incomingWss )
86  	{
87  	}
88  
89  	public void outgoingWssAdded( OutgoingWss outgoingWss )
90  	{
91  	}
92  
93  	public void outgoingWssEntryAdded( WssEntry entry )
94  	{
95  	}
96  
97  	public void outgoingWssEntryRemoved( WssEntry entry )
98  	{
99  	}
100 
101 	public void outgoingWssRemoved( OutgoingWss outgoingWss )
102 	{
103 	}
104 
105 	public void cryptoUpdated( WssCrypto crypto )
106 	{
107 	}
108 
109 	public void release()
110 	{
111 		container.removeWssContainerListener( this );
112 		cryptos = null;
113 		selectedCrypto = null;
114 	}
115 }