View Javadoc

1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  SoapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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.actions.project;
14  
15  import java.awt.event.ActionEvent;
16  
17  import javax.swing.AbstractAction;
18  import javax.swing.Action;
19  import javax.swing.JFileChooser;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.impl.wsdl.WsdlProject;
23  import com.eviware.soapui.model.iface.Interface;
24  import com.eviware.soapui.support.ExtensionFileFilter;
25  
26  /***
27   * Adds a WsdlInterface to a WsdlProject from a wsdl file
28   * 
29   * @author Ole.Matzura
30   */
31  
32  public class AddInterfaceActionFromFile extends AbstractAction
33  {
34     private JFileChooser chooser;
35  	private final WsdlProject project;
36  
37     public AddInterfaceActionFromFile( WsdlProject project ) 
38     {
39        super( "Add WSDL from file" );
40  		this.project = project;
41        putValue( Action.SHORT_DESCRIPTION, "Adds all interfaces in a specified local WSDL file to the current project" );
42     }
43     
44     public JFileChooser getChooser()
45     {
46        if( chooser == null )
47        {
48           chooser = new JFileChooser();
49           chooser.setDialogTitle("Select WSDL file");
50           chooser.setAcceptAllFileFilterUsed( true );
51           chooser.setFileFilter( new ExtensionFileFilter( ".wsdl", "WSDL Files (*.wsdl)"));
52        }
53        
54        return chooser;
55     }
56     
57     public void actionPerformed(ActionEvent e)
58  	{
59        JFileChooser chooser = getChooser();
60        if( chooser.showOpenDialog( SoapUI.getInstance().getFrame() ) != JFileChooser.APPROVE_OPTION ) return;
61        String url = chooser.getSelectedFile().getAbsolutePath();
62        if( url == null ) return;
63        
64        Interface[] ifaces = project.importWsdl( "file:" + url );
65        if( ifaces.length > 0 )
66           SoapUI.getInstance().selectModelItem( ifaces[0] );
67     }
68  }