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.support.resolver;
14  
15  import com.eviware.soapui.impl.wsdl.WsdlProject;
16  import com.eviware.soapui.impl.wsdl.actions.project.SimpleDialog;
17  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
18  import com.eviware.soapui.model.iface.Interface;
19  import com.eviware.soapui.model.iface.Operation;
20  import com.eviware.soapui.support.components.SimpleForm;
21  import com.eviware.soapui.support.resolver.ResolveContext.Resolver;
22  import com.eviware.soapui.support.swing.ModelItemListCellRenderer;
23  
24  import javax.swing.*;
25  import java.awt.*;
26  import java.awt.event.ActionEvent;
27  import java.awt.event.ActionListener;
28  
29  public abstract class ChangeOperationResolver implements Resolver
30  {
31     private boolean resolved = false;
32     private WsdlProject project;
33     private Operation selectedOperation;
34     private String operationType;
35  
36     public ChangeOperationResolver( WsdlTestStep testStep, String operationType )
37     {
38        this.project = testStep.getTestCase().getTestSuite().getProject();
39  
40        this.operationType = operationType;
41     }
42  
43     public String getResolvedPath()
44     {
45        return "";
46     }
47  
48     public boolean isResolved()
49     {
50        return resolved;
51     }
52  
53     public boolean resolve()
54     {
55        PropertyChangeDialog pDialog = new PropertyChangeDialog( "Resolve " + operationType );
56        pDialog.setVisible( true );
57        resolved = update();
58        return resolved;
59     }
60  
61     public abstract boolean update();
62  
63     protected abstract Interface[] getInterfaces( WsdlProject project );
64  
65     public String getDescription()
66     {
67        return "Resolve: Select another " + operationType;
68     }
69  
70     @Override
71     public String toString()
72     {
73        return getDescription();
74     }
75  
76     @SuppressWarnings( "serial" )
77     private class PropertyChangeDialog extends SimpleDialog
78     {
79        private JComboBox sourceStepCombo;
80        private JComboBox propertiesCombo;
81  
82        public PropertyChangeDialog( String title )
83        {
84           super( title, getDescription(), null );
85        }
86  
87        protected Component buildContent()
88        {
89           SimpleForm form = new SimpleForm();
90  
91           form.addSpace( 5 );
92           Interface[] ifaces = getInterfaces( project );
93           DefaultComboBoxModel sourceStepComboModel = new DefaultComboBoxModel();
94           sourceStepCombo = form.appendComboBox( "Interfaces", sourceStepComboModel, "Target Interface" );
95           sourceStepCombo.setRenderer( new ModelItemListCellRenderer() );
96           for( Interface element : ifaces )
97              sourceStepComboModel.addElement( element );
98  
99           propertiesCombo = form.appendComboBox( operationType,
100                  ( (Interface) sourceStepCombo.getSelectedItem() ).getOperationList().toArray(), "Target " + operationType );
101          propertiesCombo.setRenderer( new ModelItemListCellRenderer() );
102 
103          sourceStepCombo.addActionListener( new ActionListener()
104          {
105             public void actionPerformed( ActionEvent e )
106             {
107                Interface iface = project.getInterfaceByName( ( (Interface) sourceStepCombo.getSelectedItem() ).getName() );
108                propertiesCombo.removeAllItems();
109                if( iface != null )
110                {
111                   propertiesCombo.setEnabled( true );
112                   for( Operation op : iface.getOperationList() )
113                      propertiesCombo.addItem( op );
114                }
115                else
116                {
117                   propertiesCombo.setEnabled( false );
118                }
119             }
120          } );
121 
122          form.addSpace( 5 );
123          return form.getPanel();
124       }
125 
126       protected boolean handleOk()
127       {
128          selectedOperation = (Operation) propertiesCombo.getSelectedItem();
129          return true;
130       }
131    }
132 
133    public Operation getSelectedOperation()
134    {
135       return selectedOperation;
136    }
137 
138 }