View Javadoc

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