1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface;
14
15 import java.awt.BorderLayout;
16 import java.awt.Color;
17 import java.awt.Component;
18 import java.awt.event.ActionEvent;
19 import java.awt.event.KeyEvent;
20
21 import javax.swing.AbstractAction;
22 import javax.swing.Action;
23 import javax.swing.BorderFactory;
24 import javax.swing.DefaultListModel;
25 import javax.swing.JButton;
26 import javax.swing.JDialog;
27 import javax.swing.JLabel;
28 import javax.swing.JList;
29 import javax.swing.JOptionPane;
30 import javax.swing.JPanel;
31 import javax.swing.JScrollPane;
32 import javax.swing.KeyStroke;
33 import javax.swing.ListSelectionModel;
34 import javax.swing.ScrollPaneConstants;
35
36 import com.eviware.soapui.SoapUI;
37 import com.eviware.soapui.impl.wsdl.WsdlInterface;
38 import com.jgoodies.forms.builder.ButtonBarBuilder;
39
40 /***
41 * Edits the service endpoints for a WsdlInterface
42 *
43 * @author Ole.Matzura
44 */
45
46 public class InterfaceEndpointsAction extends AbstractAction
47 {
48 private JDialog dialog;
49 private JList list;
50 private WsdlInterface iface;
51 private DefaultListModel listModel;
52
53 public InterfaceEndpointsAction( WsdlInterface iface )
54 {
55 super( "Service Endpoints" );
56 putValue( Action.SHORT_DESCRIPTION, "Manage service endpoints available for this interface" );
57 this.iface = iface;
58 }
59
60 public KeyStroke getAccelerator()
61 {
62 return KeyStroke.getKeyStroke( KeyEvent.VK_E, KeyEvent.CTRL_MASK );
63 }
64
65 private void buildDialog()
66 {
67 dialog = new JDialog( SoapUI.getInstance().getFrame() );
68 dialog.setTitle("Interface Service Endpoints" );
69
70 JPanel contentPanel = new JPanel( new BorderLayout() );
71 listModel = new DefaultListModel();
72 list = new JList( listModel );
73 list.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
74 list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
75 JScrollPane scrollPane = new JScrollPane( list );
76
77 scrollPane.setBorder( BorderFactory.createCompoundBorder(
78 BorderFactory.createEmptyBorder( 0, 3, 0, 3 ), BorderFactory.createLineBorder( Color.GRAY )));
79
80 scrollPane.setVerticalScrollBarPolicy( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );
81
82 contentPanel.add( scrollPane, BorderLayout.CENTER );
83 contentPanel.add( createButtons(), BorderLayout.SOUTH );
84 JLabel label = new JLabel( "Edit available service endpoints for this interface in list below" );
85 label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
86 contentPanel.add( label, BorderLayout.NORTH );
87
88 dialog.setContentPane( contentPanel );
89 dialog.setSize(400, 300);
90
91 dialog.setModal( true );
92 }
93
94 public void actionPerformed(ActionEvent e)
95 {
96 if( dialog == null )
97 buildDialog();
98
99 listModel.clear();
100
101 String[] endpoints = iface.getEndpoints();
102 for( int c = 0; c < endpoints.length; c++ )
103 {
104 listModel.addElement( endpoints[c] );
105 }
106
107 SoapUI.centerDialog( dialog );
108 dialog.setVisible( true );
109 }
110
111 private Component createButtons()
112 {
113 ButtonBarBuilder builder = ButtonBarBuilder.createLeftToRightBuilder();
114 builder.addFixed( new JButton( new AddAction() ));
115 builder.addRelatedGap();
116 builder.addFixed( new JButton( new EditAction() ));
117 builder.addRelatedGap();
118 builder.addFixed( new JButton( new DeleteAction() ));
119 builder.addGlue();
120 builder.addFixed( new JButton( new OkAction() ));
121 builder.addRelatedGap();
122 builder.addFixed( new JButton( new CancelAction() ));
123 builder.getPanel().setBorder( BorderFactory.createEmptyBorder(5, 5, 5, 5));
124 return builder.getPanel();
125 }
126
127 private class AddAction extends AbstractAction
128 {
129 public AddAction()
130 {
131 super( "Add" );
132 }
133
134 public void actionPerformed(ActionEvent e)
135 {
136 String endpoint = JOptionPane.showInputDialog( dialog, "Enter new endpoint address", list.getSelectedValue() );
137 if( endpoint == null ) return;
138
139 listModel.addElement( endpoint );
140 }
141 }
142
143 private class EditAction extends AbstractAction
144 {
145 public EditAction()
146 {
147 super( "Edit" );
148 }
149
150 public void actionPerformed(ActionEvent e)
151 {
152 int selectedIndex = list.getSelectedIndex();
153 if( selectedIndex == -1 ) return;
154 String endpoint = (String) listModel.getElementAt( selectedIndex );
155 endpoint = JOptionPane.showInputDialog( dialog, "Edit endpoint address", endpoint );
156 if( endpoint == null ) return;
157
158 listModel.setElementAt( endpoint, selectedIndex );
159 }
160 }
161
162 private class DeleteAction extends AbstractAction
163 {
164 public DeleteAction()
165 {
166 super( "Delete" );
167 }
168
169 public void actionPerformed(ActionEvent e )
170 {
171 int index = list.getSelectedIndex();
172 if( index != -1)
173 listModel.removeElementAt( index );
174 }
175 }
176
177 private class OkAction extends AbstractAction
178 {
179 public OkAction()
180 {
181 super( "OK" );
182 }
183
184 public void actionPerformed(ActionEvent e)
185 {
186 iface.clearEndpoints();
187 for( int c = 0; c < listModel.getSize(); c++ )
188 {
189 iface.addEndpoint( (String) listModel.getElementAt( c ));
190 }
191
192 dialog.setVisible( false );
193 }
194 }
195
196 private class CancelAction extends AbstractAction
197 {
198 public CancelAction()
199 {
200 super( "Cancel" );
201 }
202
203 public void actionPerformed(ActionEvent e)
204 {
205 dialog.setVisible( false );
206 }
207 }
208
209 }