1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.request.support;
14
15 import java.beans.PropertyChangeEvent;
16 import java.beans.PropertyChangeListener;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.Set;
20
21 import javax.swing.ComboBoxModel;
22 import javax.swing.event.ListDataEvent;
23 import javax.swing.event.ListDataListener;
24
25 import com.eviware.soapui.impl.wsdl.WsdlInterface;
26 import com.eviware.soapui.impl.wsdl.WsdlRequest;
27
28 /***
29 * ComboBox model for a request endpoint
30 *
31 * @author Ole.Matzura
32 */
33
34 public class EndpointsComboBoxModel implements ComboBoxModel, PropertyChangeListener
35 {
36 private Set<ListDataListener> listeners = new HashSet<ListDataListener>();
37 private String[] endpoints;
38 private WsdlRequest request;
39
40 public EndpointsComboBoxModel( WsdlRequest request )
41 {
42 this.request = request;
43 initEndpoints();
44 request.addPropertyChangeListener( this );
45 request.getOperation().getInterface().addPropertyChangeListener( this );
46 }
47
48 public void setSelectedItem(Object anItem)
49 {
50 request.setEndpoint( (String)anItem );
51 notifyContentsChanged();
52 }
53
54 public void refresh()
55 {
56 initEndpoints();
57 notifyContentsChanged();
58 }
59
60 private void initEndpoints()
61 {
62 endpoints = request.getOperation().getInterface().getEndpoints();
63 }
64
65 private void notifyContentsChanged()
66 {
67 Iterator<ListDataListener> iterator = listeners.iterator();
68 ListDataEvent e = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, getSize() );
69 while( iterator.hasNext() )
70 {
71 iterator.next().contentsChanged( e );
72 }
73 }
74
75 public Object getSelectedItem()
76 {
77 String endpoint = request.getEndpoint();
78 return endpoint == null ? "- no endpoint set -" : endpoint;
79 }
80
81 public int getSize()
82 {
83 return endpoints.length;
84 }
85
86 public Object getElementAt(int index)
87 {
88 return endpoints[index];
89 }
90
91 public void addListDataListener(ListDataListener l)
92 {
93 listeners.add( l );
94 }
95
96 public void removeListDataListener(ListDataListener l)
97 {
98 listeners.remove( l );
99 }
100
101 public void propertyChange(PropertyChangeEvent evt)
102 {
103 String propertyName = evt.getPropertyName();
104
105 if( propertyName.equals( WsdlRequest.ENDPOINT_PROPERTY ) )
106 {
107 notifyContentsChanged();
108 }
109 else if( propertyName.equals( WsdlInterface.ENDPOINT_PROPERTY ) )
110 {
111 refresh();
112 }
113 }
114
115 public void release()
116 {
117 request.removePropertyChangeListener( this );
118 request.getOperation().getInterface().removePropertyChangeListener( this );
119 }
120 }