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.iface;
14  
15  import java.awt.BorderLayout;
16  import java.awt.Component;
17  import java.awt.Dimension;
18  import java.awt.event.ActionEvent;
19  import java.io.File;
20  import java.security.Provider;
21  import java.security.Security;
22  import java.util.List;
23  
24  import javax.swing.AbstractAction;
25  import javax.swing.DefaultCellEditor;
26  import javax.swing.JButton;
27  import javax.swing.JComboBox;
28  import javax.swing.JComponent;
29  import javax.swing.JPanel;
30  import javax.swing.JScrollPane;
31  import javax.swing.JSplitPane;
32  import javax.swing.JTabbedPane;
33  import javax.swing.event.ChangeEvent;
34  import javax.swing.event.ChangeListener;
35  import javax.swing.event.ListSelectionEvent;
36  import javax.swing.event.ListSelectionListener;
37  import javax.swing.table.AbstractTableModel;
38  
39  import org.jdesktop.swingx.JXTable;
40  
41  import com.eviware.soapui.SoapUI;
42  import com.eviware.soapui.impl.WorkspaceImpl;
43  import com.eviware.soapui.impl.wsdl.WsdlProject;
44  import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
45  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
46  import com.eviware.soapui.impl.wsdl.support.wss.IncomingWss;
47  import com.eviware.soapui.impl.wsdl.support.wss.OutgoingWss;
48  import com.eviware.soapui.impl.wsdl.support.wss.WssContainer;
49  import com.eviware.soapui.impl.wsdl.support.wss.WssContainerListener;
50  import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto;
51  import com.eviware.soapui.impl.wsdl.support.wss.WssEntry;
52  import com.eviware.soapui.impl.wsdl.support.wss.WssEntryRegistry;
53  import com.eviware.soapui.impl.wsdl.support.wss.crypto.KeyMaterialWssCrypto;
54  import com.eviware.soapui.impl.wsdl.support.wss.support.KeystoresComboBoxModel;
55  import com.eviware.soapui.model.support.ModelSupport;
56  import com.eviware.soapui.support.StringUtils;
57  import com.eviware.soapui.support.UISupport;
58  import com.eviware.soapui.support.components.JXToolBar;
59  import com.eviware.soapui.support.types.StringList;
60  
61  public class WSSTabPanel extends JPanel
62  {
63  	private JXTable cryptosTable;
64  	private RemoveCryptoAction removeCryptoAction;
65  	private RemoveIncomingWssAction removeIncomingWssAction;
66  	private JXTable incomingWssTable;
67  	private JComboBox incomingWssDecryptionCryptoComboBox;
68  	private JComboBox incomingWssSignatureCryptoComboBox;
69  	private JXTable outgoingWssTable;
70  	private RemoveOutgoingWssAction removeOutgoingWssAction;
71  //	private JPanel entriesConfigPanel;
72  	private JButton removeOutgoingEntryButton;
73  //	private JList entryList;
74  //	private WssEntriesListModel entriesModel;
75  	private WssEntry selectedEntry;
76  	private OutgoingWss selectedOutgoing;
77  	private JButton addOutgoingEntryButton;
78  	private final WssContainer wssContainer;
79  	private InternalWssContainerListener wssContainerListener;
80  	private JTabbedPane entriesTabs;
81  
82  	public WSSTabPanel( WssContainer wssContainer )
83  	{
84  		super( new BorderLayout() );
85  		this.wssContainer = wssContainer;
86  		
87  		wssContainerListener = new InternalWssContainerListener();
88  		wssContainer.addWssContainerListener( wssContainerListener );
89  
90  		buildUI();
91  	}
92  
93  	private void buildUI()
94  	{
95  		add( buildMainToolbar(), BorderLayout.NORTH );
96  		add( buildContent(), BorderLayout.CENTER );
97  	}
98  
99  	private JComponent buildContent()
100 	{
101 		JTabbedPane tabs = new JTabbedPane();
102 		tabs.addTab( "Outgoing Configurations", buildOutgoingConfigurationsTab() );
103 		tabs.addTab( "Incoming Configurations", buildIncomingConfigurationsTab() );
104 		tabs.addTab( "Keystores / Certificates", buildCryposTable() );
105 		
106 		tabs.setMinimumSize( new Dimension( 10, 10 ) );
107 		
108 		return UISupport.createTabPanel( tabs, true );
109 	}
110 
111 	private JPanel buildIncomingConfigurationsTab()
112 	{
113 		JPanel panel = new JPanel( new BorderLayout() );
114 		
115 		JPanel p = new JPanel( new BorderLayout() );
116 		p.add( buildIncomingWssToolbar(), BorderLayout.NORTH );
117 
118 		incomingWssTable = new JXTable( new IncomingWssTableModel() );
119 		incomingWssTable.setSortable( false );
120 		incomingWssTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
121 
122 			public void valueChanged( ListSelectionEvent e )
123 			{
124 				removeIncomingWssAction.setEnabled( incomingWssTable.getSelectedRow() != -1 );
125 			}} );
126 		
127 		incomingWssDecryptionCryptoComboBox = new JComboBox( new KeystoresComboBoxModel( wssContainer, null ));
128 		incomingWssTable.getColumn( 1 ).setCellEditor( new DefaultCellEditor( incomingWssDecryptionCryptoComboBox ) );
129 		
130 		incomingWssSignatureCryptoComboBox = new JComboBox( new KeystoresComboBoxModel( wssContainer, null ) );
131 		incomingWssTable.getColumn( 2 ).setCellEditor( new DefaultCellEditor( incomingWssSignatureCryptoComboBox ) );
132 		
133 		p.add( new JScrollPane( incomingWssTable ), BorderLayout.CENTER );
134 		panel.add( p, BorderLayout.CENTER );
135 		return panel;
136 	}
137 
138 	private JPanel buildOutgoingConfigurationsTab()
139 	{
140 		JPanel panel = new JPanel( new BorderLayout() );
141 		
142 		JPanel p = new JPanel( new BorderLayout() );
143 		p.add( buildOutgoingWssToolbar(), BorderLayout.NORTH );
144 
145 		outgoingWssTable = new JXTable( new OutgoingWssTableModel() );
146 		outgoingWssTable.setSortable( false );
147 		outgoingWssTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
148 
149 			public void valueChanged( ListSelectionEvent e )
150 			{
151 				int selectedRow = outgoingWssTable.getSelectedRow();
152 				selectedOutgoing = selectedRow == -1 ? null : wssContainer.getOutgoingWssAt( selectedRow );
153 				removeOutgoingWssAction.setEnabled( selectedRow != -1 );
154 				addOutgoingEntryButton.setEnabled( selectedRow != -1 );
155 //				entriesModel.setOutgoingWss( selectedOutgoing );
156 				
157 				entriesTabs.removeAll();
158 				if( selectedOutgoing != null )
159 				{
160 					for( WssEntry entry : selectedOutgoing.getEntries())
161 					{
162 						entriesTabs.addTab( entry.getLabel(), entry.getConfigurationPanel() );
163 					}
164 				}
165 				
166 				entriesTabs.getParent().setVisible( entriesTabs.getTabCount() > 0 );
167 			}} );
168 		
169 		JSplitPane split = UISupport.createVerticalSplit( new JScrollPane( outgoingWssTable ), buildOutgoingWssDetails() );
170 		split.setDividerLocation( 140 );
171 		p.add( split, BorderLayout.CENTER );
172 		panel.add( p, BorderLayout.CENTER );
173 		return panel;
174 	}
175 
176 	private Component buildOutgoingWssDetails()
177 	{
178 		JPanel panel = new JPanel( new BorderLayout() );
179 		panel.add( buildOutgoingEntriesToolbar(), BorderLayout.NORTH );
180 		panel.add( buildOutgoingEntryList(), BorderLayout.CENTER );
181 		
182 		entriesTabs.getParent().setVisible( false );
183 		
184 //		JSplitPane split = UISupport.createHorizontalSplit( buildOutgoingEntryList(), buildOutgoingEntryConfigPanel() );
185 //		split.setDividerLocation( 150 );
186 //
187 //		panel.add( split, BorderLayout.CENTER );
188 
189 		return panel;
190 	}
191 
192 //	private Component buildOutgoingEntryConfigPanel()
193 //	{
194 //		entriesConfigPanel = new JPanel( new BorderLayout() );
195 //		entriesConfigPanel.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) );
196 //		JScrollPane scrollPane = new JScrollPane( entriesConfigPanel );
197 //		scrollPane.setBorder( null );
198 //		return scrollPane;
199 //	}
200 
201 	private Component buildOutgoingEntryList()
202 	{
203 //		entriesModel = new WssEntriesListModel();
204 //		entryList = new JList( entriesModel );
205 //		entryList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
206 //		entryList.addListSelectionListener( new ListSelectionListener()
207 //		{
208 //			public void valueChanged( ListSelectionEvent e )
209 //			{
210 //				int index = entryList.getSelectedIndex();
211 //				setSelectedEntry( index == -1 ? null : ( ( WssEntry ) entriesModel.getElementAt( index ) ) );
212 //			}
213 //		} );
214 //		
215 		entriesTabs = new JTabbedPane();
216 		entriesTabs.addChangeListener( new ChangeListener() {
217 
218 			public void stateChanged( ChangeEvent e )
219 			{
220 				selectedEntry = entriesTabs.getSelectedIndex() == -1 ? null : 
221 					selectedOutgoing.getEntries().get( entriesTabs.getSelectedIndex() );
222 				removeOutgoingEntryButton.setEnabled( selectedEntry != null );
223 			}} );
224 		
225 		//return new JScrollPane( entryList );
226 		return UISupport.createTabPanel( entriesTabs, true );
227 	}
228 	
229 //	protected void setSelectedEntry( WssEntry entry )
230 //	{
231 //		this.selectedEntry = entry;
232 //		entriesConfigPanel.removeAll();
233 //
234 //		if( entry != null )
235 //		{
236 //			entriesConfigPanel.add( selectedEntry.getConfigurationPanel(), BorderLayout.CENTER );
237 //		}
238 //
239 //		removeOutgoingEntryButton.setEnabled( entry != null );
240 //
241 //		entriesConfigPanel.revalidate();
242 //		entriesConfigPanel.repaint();
243 //	}
244 	
245 	private Component buildOutgoingEntriesToolbar()
246 	{
247 		JXToolBar toolbar = UISupport.createSmallToolbar();
248 
249 		toolbar.addFixed( addOutgoingEntryButton = UISupport.createToolbarButton( new AddOutgoingEntryAction() ) );
250 		toolbar.addFixed( removeOutgoingEntryButton = UISupport.createToolbarButton( new RemoveOutgoingEntryAction(), false ) );
251 
252 		return toolbar;
253 	}
254 	
255 	private Component buildOutgoingWssToolbar()
256 	{
257 		JXToolBar toolbar = UISupport.createSmallToolbar();
258 		
259 		toolbar.addFixed( UISupport.createToolbarButton( new AddOutgoingWssAction() ));
260 		removeOutgoingWssAction = new RemoveOutgoingWssAction();
261 		toolbar.addFixed( UISupport.createToolbarButton( removeOutgoingWssAction ));
262 		toolbar.addGlue();
263 		toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.OUTGOINGWSS_HELP_URL)));
264 		
265 		return toolbar;
266 	}
267 
268 	private JPanel buildCryposTable()
269 	{
270 		JPanel panel = new JPanel( new BorderLayout() );
271 		JPanel p = new JPanel( new BorderLayout() );
272 		
273 		p.add( buildCryptosToolbar(), BorderLayout.NORTH );
274 
275 		cryptosTable = new JXTable( new CryptosTableModel() );
276 		cryptosTable.setSortable( false );
277 		cryptosTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
278 
279 			public void valueChanged( ListSelectionEvent e )
280 			{
281 				removeCryptoAction.setEnabled( cryptosTable.getSelectedRow() != -1 );
282 			}} );
283 		
284 		StringList providers = new StringList();
285 		providers.add( "<Default>" );
286 		for( Provider provider : Security.getProviders())
287 		{
288 			providers.add( provider.getName() );
289 		}
290 		
291 		JComboBox comboBox = new JComboBox( providers.toArray() );
292 		cryptosTable.getColumn( 5 ).setCellEditor( new DefaultCellEditor( comboBox ) );
293 		
294 		p.add( new JScrollPane( cryptosTable ), BorderLayout.CENTER );
295 		
296 		panel.add( p, BorderLayout.CENTER );
297 		return panel;
298 	}
299 
300 	private Component buildCryptosToolbar()
301 	{
302 		JXToolBar toolbar = UISupport.createSmallToolbar();
303 		
304 		toolbar.addFixed( UISupport.createToolbarButton( new AddCryptoAction() ));
305 		removeCryptoAction = new RemoveCryptoAction();
306 		toolbar.addFixed( UISupport.createToolbarButton( removeCryptoAction ));
307 		toolbar.addGlue();
308 		toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.CRYPTOSWSS_HELP_URL)));
309 		return toolbar;
310 	}
311 	
312 	private Component buildIncomingWssToolbar()
313 	{
314 		JXToolBar toolbar = UISupport.createSmallToolbar();
315 		
316 		toolbar.addFixed( UISupport.createToolbarButton( new AddIncomingWssAction() ));
317 		removeIncomingWssAction = new RemoveIncomingWssAction();
318 		toolbar.addFixed( UISupport.createToolbarButton( removeIncomingWssAction ));
319 		
320 		toolbar.addGlue();
321 		toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.INCOMINGWSS_HELP_URL)));
322 		
323 		return toolbar;
324 	}
325 
326 	private Component buildMainToolbar()
327 	{
328 		JXToolBar toolbar = UISupport.createSmallToolbar();
329 		toolbar.addFixed( UISupport.createToolbarButton( new ImportWssSettingsAction() ));
330 		toolbar.addGlue();
331 		toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.WSS_HELP_URL)));
332 		return toolbar;
333 	}
334 
335 	public void release()
336 	{
337 		wssContainer.removeWssContainerListener( wssContainerListener );
338 		
339 //		entriesModel.release();
340 		((IncomingWssTableModel)incomingWssTable.getModel()).release();
341 		((OutgoingWssTableModel)outgoingWssTable.getModel()).release();
342 		((CryptosTableModel)cryptosTable.getModel()).release();
343 		
344 		((KeystoresComboBoxModel)incomingWssDecryptionCryptoComboBox.getModel()).release();
345 		((KeystoresComboBoxModel)incomingWssSignatureCryptoComboBox.getModel()).release();
346 		
347 //		entriesConfigPanel.removeAll();
348 	}
349 
350 	public class CryptosTableModel extends AbstractTableModel 
351 	{
352 		private static final String DEFAULT_OPTION = "<Default>";
353 		private List<WssCrypto> cryptos;
354 
355 		public CryptosTableModel()
356 		{
357 			cryptos = wssContainer.getCryptoList();
358 		}
359 
360 		public void release()
361 		{
362 			cryptos = null;
363 		}
364 
365 		public int getColumnCount()
366 		{
367 			return 6;
368 		}
369 
370 		@Override
371 		public String getColumnName( int column )
372 		{
373 			switch( column )
374 			{
375 			case 0:
376 				return "Source";
377 			case 1:
378 				return "Status";
379 			case 2:
380 				return "Password";
381 			case 3:
382 				return "Default Alias";
383 			case 4:
384 				return "Alias Password";
385 			case 5:
386 				return "Crypto Provider";
387 			}
388 
389 			return null;
390 		}
391 
392 		public int getRowCount()
393 		{
394 			return cryptos == null ? null : cryptos.size();
395 		}
396 		
397 		@Override
398 		public boolean isCellEditable( int rowIndex, int columnIndex )
399 		{
400 			return columnIndex > 1;
401 		}
402 
403 		public Object getValueAt( int rowIndex, int columnIndex )
404 		{
405 			KeyMaterialWssCrypto crypto = ( KeyMaterialWssCrypto ) cryptos.get( rowIndex );
406 
407 			switch( columnIndex )
408 			{
409 			case 0:
410 				return crypto.getSource();
411 			case 1:
412 				return crypto.getStatus();
413 			case 2:
414 				return crypto.getPassword();
415 			case 3:
416 				return crypto.getDefaultAlias();
417 			case 4:
418 				return crypto.getAliasPassword();
419 			case 5:
420 				return StringUtils.hasContent( crypto.getCryptoProvider() ) ? crypto.getCryptoProvider() : DEFAULT_OPTION;
421 			}
422 
423 			return null;
424 		}
425 		
426 		@Override
427 		public void setValueAt( Object aValue, int rowIndex, int columnIndex )
428 		{
429 			KeyMaterialWssCrypto crypto = ( KeyMaterialWssCrypto ) cryptos.get( rowIndex );
430 			if( aValue == null || aValue.equals( DEFAULT_OPTION ) )
431 				aValue = "";
432 
433 			switch( columnIndex )
434 			{
435 			case 2:
436 				crypto.setPassword( aValue.toString() ); break;
437 			case 3:
438 				crypto.setDefaultAlias( aValue.toString() ); break;
439 			case 4:
440 				crypto.setAliasPassword( aValue.toString() ); break;
441 			case 5:
442 				crypto.setCryptoProvider( aValue.toString() ); break;
443 			}
444 		}
445 
446 		public void cryptoAdded( WssCrypto crypto )
447 		{
448 			cryptos.add( crypto );
449 			fireTableRowsInserted( cryptos.size()-1, cryptos.size()-1 );
450 		}
451 
452 		public void cryptoRemoved( WssCrypto crypto )
453 		{
454 			int ix = cryptos.indexOf( crypto );
455 			if( ix != -1 )
456 			{
457 				cryptos.remove( ix );
458 				fireTableRowsDeleted( ix, ix );
459 			}
460 		}
461 	}
462 
463 	private class AddCryptoAction extends AbstractAction
464 	{
465 		public AddCryptoAction()
466 		{
467 			putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ));
468 			putValue( SHORT_DESCRIPTION, "Adds a new crypto to this configuration" );
469 		}
470 
471 		public void actionPerformed( ActionEvent e )
472 		{
473 			File file = UISupport.getFileDialogs().open( this, "Select Key Material", null, null, null );
474 			if( file != null )
475 			{
476 				String password = UISupport.prompt( "Specify password for [" + file.getName() + "]", "Add Key Material", "" );
477 				wssContainer.addCrypto( file.getAbsolutePath(), password );
478 				cryptosTable.setRowSelectionInterval( cryptosTable.getRowCount()-1, cryptosTable.getRowCount()-1 );
479 			}
480 		}
481 	}
482 	
483 	private class RemoveCryptoAction extends AbstractAction
484 	{
485 		public RemoveCryptoAction()
486 		{
487 			putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ));
488 			putValue( SHORT_DESCRIPTION, "Removes the selected crypto from this configuration" );
489 			
490 			setEnabled( false );
491 		}
492 
493 		public void actionPerformed( ActionEvent e )
494 		{
495 			int row = cryptosTable.getSelectedRow();
496 			if( row == -1 )
497 				return;
498 			
499 			if( UISupport.confirm( "Removes selected crypto?", "Remove Crypto" ))
500 			{
501 				wssContainer.removeCryptoAt( row );
502 			}
503 		}
504 	}
505 	
506 	public class IncomingWssTableModel extends AbstractTableModel 
507 	{
508 		private List<IncomingWss> incomingWss;
509 
510 		public IncomingWssTableModel()
511 		{
512 			incomingWss = wssContainer.getIncomingWssList();
513 		}
514 
515 		public void release()
516 		{
517 			incomingWss = null;
518 		}
519 
520 		public int getColumnCount()
521 		{
522 			return 4;
523 		}
524 
525 		@Override
526 		public String getColumnName( int column )
527 		{
528 			switch( column )
529 			{
530 			case 0:
531 				return "Name";
532 			case 1:
533 				return "Decrypt Crypto";
534 			case 2:
535 				return "Signature Crypto";
536 			case 3:
537 				return "Password";
538 			}
539 
540 			return null;
541 		}
542 
543 		public int getRowCount()
544 		{
545 			return incomingWss == null ? 0 : incomingWss.size();
546 		}
547 		
548 		@Override
549 		public boolean isCellEditable( int rowIndex, int columnIndex )
550 		{
551 			return columnIndex > 0;
552 		}
553 
554 		public Object getValueAt( int rowIndex, int columnIndex )
555 		{
556 			IncomingWss incoming =  incomingWss.get( rowIndex );
557 
558 			switch( columnIndex )
559 			{
560 			case 0:
561 				return incoming.getName();
562 			case 1:
563 				return wssContainer.getCryptoByName( incoming.getDecryptCrypto() );
564 			case 2:
565 				return wssContainer.getCryptoByName( incoming.getSignatureCrypto() );
566 			case 3:
567 				return incoming.getDecryptPassword();
568 			}
569 
570 			return null;
571 		}
572 		
573 		@Override
574 		public void setValueAt( Object aValue, int rowIndex, int columnIndex )
575 		{
576 			IncomingWss incoming =  incomingWss.get( rowIndex );
577 
578 			switch( columnIndex )
579 			{
580 			case 1:
581 				incoming.setDecryptCrypto( aValue == null ? null : aValue.toString() ); break;
582 			case 2:
583 				incoming.setSignatureCrypto( aValue == null ? null : aValue.toString() ); break;
584 			case 3:
585 				incoming.setDecryptPassword( aValue == null ? null : aValue.toString() ); break;
586 			}
587 		}
588 
589 		public void incomingWssAdded( IncomingWss incoming )
590 		{
591 			incomingWss.add( incoming );
592 			fireTableRowsInserted( incomingWss.size()-1, incomingWss.size()-1 );
593 			
594 		}
595 
596 		public void incomingWssRemoved( IncomingWss incoming )
597 		{
598 			int ix = incomingWss.indexOf( incoming );
599 			if( ix != -1 )
600 			{
601 				incomingWss.remove( ix );
602 				fireTableRowsDeleted( ix, ix );
603 			}
604 		}
605 	}
606 
607 	private class AddIncomingWssAction extends AbstractAction
608 	{
609 		public AddIncomingWssAction()
610 		{
611 			putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ));
612 			putValue( SHORT_DESCRIPTION, "Adds a new Incoming WSS Configuration" );
613 		}
614 
615 		public void actionPerformed( ActionEvent e )
616 		{
617 			String name = UISupport.prompt( "Specify unique name for configuration", "New Incoming WSS Configuration", "" );
618 			if( StringUtils.hasContent( name ) && wssContainer.getIncomingByName( name ) == null )
619 			{
620 				wssContainer.addIncomingWss( name );
621 				incomingWssTable.setRowSelectionInterval( incomingWssTable.getRowCount()-1, incomingWssTable.getRowCount()-1 );
622 			}
623 		}
624 	}
625 	
626 	private class RemoveIncomingWssAction extends AbstractAction
627 	{
628 		public RemoveIncomingWssAction()
629 		{
630 			putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ));
631 			putValue( SHORT_DESCRIPTION, "Removes the selected Incoming WSS Configuration" );
632 			
633 			setEnabled( false );
634 		}
635 
636 		public void actionPerformed( ActionEvent e )
637 		{
638 			int row = incomingWssTable.getSelectedRow();
639 			if( row == -1 )
640 				return;
641 			
642 			if( UISupport.confirm( "Removes selected configuration?", "Remove Configuration" ))
643 			{
644 				wssContainer.removeIncomingWssAt( row );
645 			}
646 		}
647 	}
648 	
649 	public class OutgoingWssTableModel extends AbstractTableModel
650 	{
651 		private List<OutgoingWss> outgoingWss;
652 
653 		public OutgoingWssTableModel()
654 		{
655 			outgoingWss = wssContainer.getOutgoingWssList();
656 		}
657 
658 		public void release()
659 		{
660 			outgoingWss = null;
661 		}
662 
663 		public int getColumnCount()
664 		{
665 			return 3;
666 		}
667 
668 		@Override
669 		public String getColumnName( int column )
670 		{
671 			switch( column )
672 			{
673 			case 0:
674 				return "Name";
675 			case 1:
676 				return "Default Username/Alias";
677 			case 2:
678 				return "Default Password";
679 			}
680 
681 			return null;
682 		}
683 
684 		public int getRowCount()
685 		{
686 			return outgoingWss == null ? 0 : outgoingWss.size();
687 		}
688 		
689 		@Override
690 		public boolean isCellEditable( int rowIndex, int columnIndex )
691 		{
692 			return columnIndex > 0;
693 		}
694 
695 		public Object getValueAt( int rowIndex, int columnIndex )
696 		{
697 			OutgoingWss incoming =  outgoingWss.get( rowIndex );
698 
699 			switch( columnIndex )
700 			{
701 			case 0:
702 				return incoming.getName();
703 			case 1:
704 				return incoming.getUsername();
705 			case 2:
706 				return incoming.getPassword();
707 			}
708 
709 			return null;
710 		}
711 		
712 		@Override
713 		public void setValueAt( Object aValue, int rowIndex, int columnIndex )
714 		{
715 			OutgoingWss incoming =  outgoingWss.get( rowIndex );
716 
717 			switch( columnIndex )
718 			{
719 			case 1:
720 				incoming.setUsername( aValue == null ? null : aValue.toString() ); break;
721 			case 2:
722 				incoming.setPassword( aValue == null ? null : aValue.toString() ); break;
723 			}
724 		}
725 
726 		public void outgoingWssAdded( OutgoingWss outgoing )
727 		{
728 			outgoingWss.add( outgoing );
729 			fireTableRowsInserted( outgoingWss.size()-1, outgoingWss.size()-1 );
730 			
731 		}
732 
733 		public void outgoingWssRemoved( OutgoingWss outgoing )
734 		{
735 			int ix = outgoingWss.indexOf( outgoing );
736 			if( ix != -1 )
737 			{
738 				outgoingWss.remove( ix );
739 				fireTableRowsDeleted( ix, ix );
740 			}
741 		}
742 	}
743 
744 	private class AddOutgoingWssAction extends AbstractAction
745 	{
746 		public AddOutgoingWssAction()
747 		{
748 			putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ));
749 			putValue( SHORT_DESCRIPTION, "Adds a new Outgoing WSS Configuration" );
750 		}
751 
752 		public void actionPerformed( ActionEvent e )
753 		{
754 			String name = UISupport.prompt( "Specify unique name for configuration", "New Outgoing WSS Configuration", "" );
755 			if( StringUtils.hasContent( name ) && wssContainer.getOutgoingByName( name ) == null )
756 			{
757 				wssContainer.addOutgoingWss( name );
758 				outgoingWssTable.setRowSelectionInterval( outgoingWssTable.getRowCount()-1, outgoingWssTable.getRowCount()-1 );
759 			}
760 		}
761 	}
762 	
763 	private class RemoveOutgoingWssAction extends AbstractAction
764 	{
765 		public RemoveOutgoingWssAction()
766 		{
767 			putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ));
768 			putValue( SHORT_DESCRIPTION, "Removes the selected Outgoing WSS Configuration" );
769 			
770 			setEnabled( false );
771 		}
772 
773 		public void actionPerformed( ActionEvent e )
774 		{
775 			int row = outgoingWssTable.getSelectedRow();
776 			if( row == -1 )
777 				return;
778 			
779 			if( UISupport.confirm( "Removes selected configuration?", "Remove Configuration" ))
780 			{
781 				wssContainer.removeOutgoingWssAt( row );
782 			}
783 		}
784 	}
785 	
786 //	private class WssEntriesListModel extends AbstractListModel 
787 //	{
788 //		private List<WssEntry> entries = new ArrayList<WssEntry>();
789 //
790 //		public WssEntriesListModel()
791 //		{
792 //		}
793 //		
794 //		public void release()
795 //		{
796 //			entries.clear();
797 //		}
798 //
799 //		public void setOutgoingWss( OutgoingWss outgoingWss )
800 //		{
801 //			if( entries.size() > 0 )
802 //			{
803 //				int sz = entries.size();
804 //				entries.clear();
805 //				fireIntervalRemoved( this, 0, sz-1 );
806 //			}
807 //			
808 //			if( outgoingWss == null )
809 //				return;
810 //			
811 //			entries.addAll( outgoingWss.getEntries() );
812 //			
813 //			if( !entries.isEmpty())
814 //				fireIntervalAdded( this, 0, entries.size()-1 );
815 //		}
816 //
817 //		public Object getElementAt( int index )
818 //		{
819 //			return entries.get( index );
820 //		}
821 //
822 //		public int getSize()
823 //		{
824 //			return entries == null ? 0 : entries.size();
825 //		}
826 //
827 //		public void entryAdded( WssEntry entry )
828 //		{
829 //			entries.add( entry );
830 //			fireIntervalAdded( this, entries.size() - 1, entries.size() - 1 );
831 //		}
832 //
833 //		public void entryRemoved( WssEntry entry )
834 //		{
835 //			int ix = entries.indexOf( entry );
836 //			if( ix != -1 )
837 //			{
838 //				entries.remove( ix );
839 //				fireIntervalRemoved( this, ix, ix );
840 //			}
841 //		}
842 //	}
843 	
844 	public class AddOutgoingEntryAction extends AbstractAction
845 	{
846 		public AddOutgoingEntryAction()
847 		{
848 			putValue( SHORT_DESCRIPTION, "Adds a new WSS Entry" );
849 			putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ) );
850 			setEnabled( false );
851 		}
852 
853 		public void actionPerformed( ActionEvent e )
854 		{
855 			if( selectedOutgoing == null )
856 				return;
857 			
858 			String type = UISupport.prompt( "Select type of entry to add", "Add WSS Entry", WssEntryRegistry.get()
859 						.getTypes() );
860 			if( type != null )
861 			{
862 				WssEntry entry = selectedOutgoing.addEntry( type );
863 				entriesTabs.setSelectedComponent( entry.getConfigurationPanel() );
864 				
865 //				entriesTabs.addTab( entry.getLabel(), entry.getConfigurationPanel() );
866 //				entryList.setSelectedValue( entry, true );
867 			}
868 		}
869 	}
870 
871 	public class RemoveOutgoingEntryAction extends AbstractAction
872 	{
873 		public RemoveOutgoingEntryAction()
874 		{
875 			putValue( SHORT_DESCRIPTION, "Removes the selected WSS-Entry" );
876 			putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ) );
877 		}
878 
879 		public void actionPerformed( ActionEvent e )
880 		{
881 			if( selectedEntry == null )
882 				return;
883 
884 			if( UISupport.confirm( "Remove entry [" + selectedEntry.getLabel() + "]", "Remove WSS Entry" ) )
885 			{
886 				selectedOutgoing.removeEntry( selectedEntry );
887 			}
888 		}
889 	}
890 	
891 	private class InternalWssContainerListener implements WssContainerListener
892 	{
893 		public void cryptoAdded( WssCrypto crypto )
894 		{
895 			((CryptosTableModel)cryptosTable.getModel()).cryptoAdded( crypto );
896 		}
897 
898 		public void cryptoRemoved( WssCrypto crypto )
899 		{
900 			((CryptosTableModel)cryptosTable.getModel()).cryptoRemoved( crypto );
901 		}
902 
903 		public void incomingWssAdded( IncomingWss incomingWss )
904 		{
905 			((IncomingWssTableModel)incomingWssTable.getModel()).incomingWssAdded( incomingWss );
906 			
907 		}
908 
909 		public void incomingWssRemoved( IncomingWss incomingWss )
910 		{
911 			((IncomingWssTableModel)incomingWssTable.getModel()).incomingWssRemoved( incomingWss );
912 			
913 		}
914 
915 		public void outgoingWssAdded( OutgoingWss outgoingWss )
916 		{
917 			((OutgoingWssTableModel)outgoingWssTable.getModel()).outgoingWssAdded( outgoingWss );
918 		}
919 
920 		public void outgoingWssEntryAdded( WssEntry entry )
921 		{
922 			if( entry.getOutgoingWss() == selectedOutgoing )
923 			{
924 				entriesTabs.addTab( entry.getLabel(), entry.getConfigurationPanel() );
925 				entriesTabs.getParent().setVisible( true);
926 			}
927 //				entriesModel.entryAdded( entry );
928 		}
929 
930 		public void outgoingWssEntryRemoved( WssEntry entry )
931 		{
932 			if( entry.getOutgoingWss() == selectedOutgoing )
933 			{
934 				int ix = entriesTabs.indexOfComponent( entry.getConfigurationPanel() );
935 				if( ix != -1 )
936 					entriesTabs.remove( ix );
937 				
938 				entriesTabs.getParent().setVisible( entriesTabs.getTabCount() > 0 );
939 			}
940 //				entriesModel.entryRemoved( entry );
941 		}
942 
943 		public void outgoingWssRemoved( OutgoingWss outgoingWss )
944 		{
945 			((OutgoingWssTableModel)outgoingWssTable.getModel()).outgoingWssRemoved( outgoingWss );
946 		}
947 
948 		public void cryptoUpdated( WssCrypto crypto )
949 		{
950 		}
951 	}
952 	
953 	public class ImportWssSettingsAction extends AbstractAction
954 	{
955 		public ImportWssSettingsAction()
956 		{
957 			putValue( SHORT_DESCRIPTION, "Imports an existing WS-Security configuration from another project" );
958 			putValue( SMALL_ICON, UISupport.createImageIcon( "/load_properties.gif" ) );
959 		}
960 
961 		public void actionPerformed( ActionEvent e )
962 		{
963 			String[] names = ModelSupport.getNames( ((WorkspaceImpl)SoapUI.getWorkspace()).getOpenProjectList() );
964 			String projectName = UISupport.prompt( "Select project to import from", "Import WSS Settings", names );
965 			if( projectName != null )
966 			{
967 				WsdlProject prj = ( WsdlProject ) SoapUI.getWorkspace().getProjectByName( projectName );
968 				wssContainer.importConfig( prj.getWssContainer() );
969 			}
970 		}
971 	}
972 }