1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.request.components.editor.views;
14
15 import java.beans.PropertyChangeEvent;
16 import java.beans.PropertyChangeListener;
17 import java.beans.PropertyChangeSupport;
18 import java.util.HashSet;
19 import java.util.Set;
20
21 import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlDocument;
22 import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlEditor;
23 import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlEditorView;
24 import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlLocation;
25 import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlLocationListener;
26
27 /***
28 * Abstract base-class to be extended by XmlViews
29 *
30 * @author ole.matzura
31 */
32
33 public abstract class AbstractEditorView implements XmlEditorView, PropertyChangeListener
34 {
35 private String title;
36 private boolean isActive;
37 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this );
38 private XmlDocument xmlDocument;
39 private boolean xmlChanged;
40 private Set<XmlLocationListener> listeners = new HashSet<XmlLocationListener>();
41 private XmlEditor editor;
42
43 public AbstractEditorView(String title, XmlEditor xmlEditor)
44 {
45 super();
46 this.title = title;
47 editor = xmlEditor;
48 xmlChanged = false;
49 }
50
51 protected PropertyChangeSupport getPropertyChangeSupport()
52 {
53 return propertyChangeSupport;
54 }
55
56 public boolean activate(XmlLocation location)
57 {
58 isActive = true;
59 if( xmlChanged )
60 {
61 setXml( xmlDocument == null ? null : xmlDocument.getXml() );
62 xmlChanged = false;
63 }
64
65 return true;
66 }
67
68 public boolean isXmlChanged()
69 {
70 return xmlChanged;
71 }
72
73 public boolean deactivate()
74 {
75 isActive = false;
76 xmlChanged = false;
77
78 return true;
79 }
80
81 public boolean isActive()
82 {
83 return isActive;
84 }
85
86 public String getTitle()
87 {
88 return title;
89 }
90
91 public void setTitle( String title )
92 {
93 String oldTitle = this.title;
94 this.title = title;
95
96 propertyChangeSupport.firePropertyChange( TITLE_PROPERTY, oldTitle, title );
97 }
98
99 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
100 {
101 propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
102 }
103
104 public void addPropertyChangeListener(PropertyChangeListener listener)
105 {
106 propertyChangeSupport.addPropertyChangeListener( listener );
107 }
108
109 public void removePropertyChangeListener(PropertyChangeListener listener)
110 {
111 propertyChangeSupport.removePropertyChangeListener( listener );
112 }
113
114 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
115 {
116 propertyChangeSupport.removePropertyChangeListener( propertyName, listener );
117 }
118
119 public XmlDocument getXmlDocument()
120 {
121 return xmlDocument;
122 }
123
124 public void setXmlDocument(XmlDocument xmlDocument)
125 {
126 if( this.xmlDocument != null )
127 {
128 this.xmlDocument.removePropertyChangeListener( XmlDocument.XML_PROPERTY, this );
129 }
130
131 this.xmlDocument = xmlDocument;
132
133 if( xmlDocument != null )
134 {
135 this.xmlDocument.addPropertyChangeListener( XmlDocument.XML_PROPERTY, this );
136 setXml( xmlDocument.getXml() );
137 }
138 else
139 {
140 setXml( null );
141 }
142
143 xmlChanged = false;
144 }
145
146 public void propertyChange(PropertyChangeEvent evt)
147 {
148 if( isActive() )
149 setXml( (String) evt.getNewValue() );
150 else
151 xmlChanged = true;
152 }
153
154 protected abstract void setXml( String xml );
155
156 public void release()
157 {
158 if( this.xmlDocument != null )
159 {
160 this.xmlDocument.removePropertyChangeListener( XmlDocument.XML_PROPERTY, this );
161 this.xmlDocument = null;
162 }
163 }
164
165 public void addLocationListener(XmlLocationListener listener)
166 {
167 listeners.add( listener );
168 }
169
170 public void removeLocationListener(XmlLocationListener listener)
171 {
172 listeners.remove( listener );
173 }
174
175 public void fireLocationChanged( XmlLocation location )
176 {
177 for( XmlLocationListener listener : listeners )
178 listener.locationChanged( location );
179 }
180
181 public XmlLocation getLocation()
182 {
183 return null;
184 }
185
186 public void setLocation(XmlLocation location)
187 {
188 }
189
190 public void locationChanged(XmlLocation location)
191 {
192 }
193
194 public void syncUpdates()
195 {
196 if( !isActive() && xmlChanged )
197 {
198 setXml( xmlDocument == null ? null : xmlDocument.getXml() );
199 xmlChanged = false;
200 }
201 }
202
203 public XmlEditor getEditor()
204 {
205 return editor;
206 }
207
208 public void requestFocus()
209 {
210 }
211 }