1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support.editor.support;
14
15 import java.beans.PropertyChangeListener;
16 import java.beans.PropertyChangeSupport;
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import javax.swing.JComponent;
21
22 import com.eviware.soapui.support.editor.Editor;
23 import com.eviware.soapui.support.editor.EditorDocument;
24 import com.eviware.soapui.support.editor.EditorLocation;
25 import com.eviware.soapui.support.editor.EditorLocationListener;
26 import com.eviware.soapui.support.editor.EditorView;
27
28 /***
29 * Abstract base-class to be extended by XmlViews
30 *
31 * @author ole.matzura
32 */
33
34 public abstract class AbstractEditorView<T extends EditorDocument> implements EditorView<T>
35 {
36 private String title;
37 private boolean isActive;
38 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this );
39 private T xmlDocument;
40 private Set<EditorLocationListener<T>> listeners = new HashSet<EditorLocationListener<T>>();
41 private Editor<T> editor;
42 private JComponent component;
43 private final String viewId;
44
45 public AbstractEditorView(String title, Editor<T> editor, String viewId)
46 {
47 super();
48 this.title = title;
49 this.editor = editor;
50 this.viewId = viewId;
51 }
52
53 protected PropertyChangeSupport getPropertyChangeSupport()
54 {
55 return propertyChangeSupport;
56 }
57
58
59 public JComponent getComponent()
60 {
61 if( component == null )
62 component = buildUI();
63
64 return component;
65 }
66
67
68 public String getViewId()
69 {
70 return viewId;
71 }
72
73 public void requestFocus()
74 {
75 if( component != null )
76 component.requestFocusInWindow();
77 }
78
79 public abstract JComponent buildUI();
80
81 public boolean activate(EditorLocation<T> location)
82 {
83 isActive = true;
84 return true;
85 }
86
87 public boolean deactivate()
88 {
89 isActive = false;
90 return true;
91 }
92
93 public boolean isActive()
94 {
95 return isActive;
96 }
97
98 public String getTitle()
99 {
100 return title;
101 }
102
103 public void setTitle( String title )
104 {
105 String oldTitle = this.title;
106 this.title = title;
107
108 propertyChangeSupport.firePropertyChange( TITLE_PROPERTY, oldTitle, title );
109 }
110
111 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
112 {
113 propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
114 }
115
116 public void addPropertyChangeListener(PropertyChangeListener listener)
117 {
118 propertyChangeSupport.addPropertyChangeListener( listener );
119 }
120
121 public void removePropertyChangeListener(PropertyChangeListener listener)
122 {
123 propertyChangeSupport.removePropertyChangeListener( listener );
124 }
125
126 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
127 {
128 propertyChangeSupport.removePropertyChangeListener( propertyName, listener );
129 }
130
131 public T getDocument()
132 {
133 return xmlDocument;
134 }
135
136 public void setDocument(T xmlDocument)
137 {
138 this.xmlDocument = xmlDocument;
139 }
140
141 public void release()
142 {
143 if( this.xmlDocument != null )
144 {
145 this.xmlDocument = null;
146 }
147 }
148
149 public void addLocationListener(EditorLocationListener<T> listener)
150 {
151 listeners.add( listener );
152 }
153
154 public void removeLocationListener(EditorLocationListener<T> listener)
155 {
156 listeners.remove( listener );
157 }
158
159 public void fireLocationChanged( EditorLocation<T> location )
160 {
161 for( EditorLocationListener<T> listener : listeners )
162 listener.locationChanged( location );
163 }
164
165 public EditorLocation<T> getEditorLocation()
166 {
167 return null;
168 }
169
170 public void setLocation(EditorLocation<T> location)
171 {
172 }
173
174 public void locationChanged(EditorLocation<T> location)
175 {
176 }
177
178
179 public Editor<T> getEditor()
180 {
181 return editor;
182 }
183
184 public void setEditable(boolean enabled)
185 {
186 }
187 }