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 public JComponent getComponent()
59 {
60 if( component == null )
61 component = buildUI();
62
63 return component;
64 }
65
66 public String getViewId()
67 {
68 return viewId;
69 }
70
71 public void requestFocus()
72 {
73 if( component != null )
74 component.requestFocusInWindow();
75 }
76
77 public abstract JComponent buildUI();
78
79 public boolean activate( EditorLocation<T> location )
80 {
81 isActive = true;
82 return true;
83 }
84
85 public boolean deactivate()
86 {
87 isActive = false;
88 return true;
89 }
90
91 public boolean isActive()
92 {
93 return isActive;
94 }
95
96 public String getTitle()
97 {
98 return title;
99 }
100
101 public void setTitle( String title )
102 {
103 String oldTitle = this.title;
104 this.title = title;
105
106 propertyChangeSupport.firePropertyChange( TITLE_PROPERTY, oldTitle, title );
107 }
108
109 public void addPropertyChangeListener( String propertyName, PropertyChangeListener listener )
110 {
111 propertyChangeSupport.addPropertyChangeListener( propertyName, listener );
112 }
113
114 public void addPropertyChangeListener( PropertyChangeListener listener )
115 {
116 propertyChangeSupport.addPropertyChangeListener( listener );
117 }
118
119 public void removePropertyChangeListener( PropertyChangeListener listener )
120 {
121 propertyChangeSupport.removePropertyChangeListener( listener );
122 }
123
124 public void removePropertyChangeListener( String propertyName, PropertyChangeListener listener )
125 {
126 propertyChangeSupport.removePropertyChangeListener( propertyName, listener );
127 }
128
129 public T getDocument()
130 {
131 return xmlDocument;
132 }
133
134 public void setDocument( T xmlDocument )
135 {
136 this.xmlDocument = xmlDocument;
137 }
138
139 public void release()
140 {
141 if( this.xmlDocument != null )
142 {
143 this.xmlDocument = null;
144 }
145 }
146
147 public void addLocationListener( EditorLocationListener<T> listener )
148 {
149 listeners.add( listener );
150 }
151
152 public void removeLocationListener( EditorLocationListener<T> listener )
153 {
154 listeners.remove( listener );
155 }
156
157 public void fireLocationChanged( EditorLocation<T> location )
158 {
159 for( EditorLocationListener<T> listener : listeners )
160 listener.locationChanged( location );
161 }
162
163 public EditorLocation<T> getEditorLocation()
164 {
165 return null;
166 }
167
168 public void setLocation( EditorLocation<T> location )
169 {
170 }
171
172 public void locationChanged( EditorLocation<T> location )
173 {
174 }
175
176 public Editor<T> getEditor()
177 {
178 return editor;
179 }
180
181 public void setEditable( boolean enabled )
182 {
183 }
184 }