1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.request.components.editor.support;
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 public abstract class AbstractEditorView implements XmlEditorView, PropertyChangeListener
28 {
29 private String title;
30 private boolean isActive;
31 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this );
32 private XmlDocument xmlDocument;
33 private boolean xmlChanged;
34 private Set<XmlLocationListener> listeners = new HashSet<XmlLocationListener>();
35 private XmlEditor editor;
36
37 public AbstractEditorView(String title)
38 {
39 super();
40 this.title = title;
41 xmlChanged = true;
42 }
43
44 public boolean activate(XmlLocation location)
45 {
46 isActive = true;
47 if( xmlChanged )
48 {
49 setXml( xmlDocument == null ? null : xmlDocument.getXml() );
50 }
51
52 return true;
53 }
54
55 public boolean deactivate()
56 {
57 isActive = false;
58 xmlChanged = false;
59
60 return true;
61 }
62
63 public boolean isActive()
64 {
65 return isActive;
66 }
67
68 public String getTitle()
69 {
70 return title;
71 }
72
73 public void setTitle( String title )
74 {
75 String oldTitle = this.title;
76 this.title = title;
77
78 propertyChangeSupport.firePropertyChange( TITLE_PROPERTY, oldTitle, title );
79 }
80
81 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
82 {
83 propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
84 }
85
86 public void addPropertyChangeListener(PropertyChangeListener listener)
87 {
88 propertyChangeSupport.addPropertyChangeListener( listener );
89 }
90
91 public void removePropertyChangeListener(PropertyChangeListener listener)
92 {
93 propertyChangeSupport.removePropertyChangeListener( listener );
94 }
95
96 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
97 {
98 propertyChangeSupport.removePropertyChangeListener( propertyName, listener );
99 }
100
101 public XmlDocument getXmlDocument()
102 {
103 return xmlDocument;
104 }
105
106 public void setXmlDocument(XmlDocument xmlDocument)
107 {
108 if( this.xmlDocument != null )
109 {
110 this.xmlDocument.removePropertyChangeListener( XmlDocument.XML_PROPERTY, this );
111 }
112
113 this.xmlDocument = xmlDocument;
114
115 if( xmlDocument != null )
116 {
117 this.xmlDocument.addPropertyChangeListener( XmlDocument.XML_PROPERTY, this );
118
119 setXml( xmlDocument.getXml() );
120 }
121 else
122 {
123 setXml( null );
124 }
125 }
126
127 public void propertyChange(PropertyChangeEvent evt)
128 {
129 if( isActive() )
130 setXml( (String) evt.getNewValue() );
131 else
132 xmlChanged = true;
133 }
134
135 protected abstract void setXml( String xml );
136
137 public void release()
138 {
139 if( this.xmlDocument != null )
140 {
141 this.xmlDocument.removePropertyChangeListener( XmlDocument.XML_PROPERTY, this );
142 }
143 }
144
145 public void addLocationListener(XmlLocationListener listener)
146 {
147 listeners.add( listener );
148 }
149
150 public void removeLocationListener(XmlLocationListener listener)
151 {
152 listeners.remove( listener );
153 }
154
155 public void fireLocationChanged( XmlLocation location )
156 {
157 for( XmlLocationListener listener : listeners )
158 listener.locationChanged( location );
159 }
160
161 public XmlLocation getLocation()
162 {
163 return null;
164 }
165
166 public void setLocation(XmlLocation location)
167 {
168 }
169
170 public void locationChanged(XmlLocation location)
171 {
172 }
173
174 public void init( XmlEditor editor )
175 {
176 this.editor = editor;
177 }
178
179 public XmlEditor getEditor()
180 {
181 return editor;
182 }
183
184 public void requestFocus()
185 {
186 }
187 }