1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.xmlhammer.gui.preferences;
24
25 import javax.swing.JFrame;
26 import javax.swing.event.TreeSelectionListener;
27
28 import org.xmlhammer.gui.util.preferences.HelpEnabledPreferencesPage;
29 import org.xmlhammer.model.jaxp.Attributes;
30 import org.xmlhammer.model.jaxp.Features;
31 import org.xmlhammer.model.jaxp.JAXPDocumentBuilderFactory;
32 import org.xmlhammer.model.jaxp.JAXPSAXParserFactory;
33 import org.xmlhammer.model.jaxp.JAXPSchemaFactory;
34 import org.xmlhammer.model.jaxp.JAXPTransformerFactory;
35 import org.xmlhammer.model.jaxp.JAXPXPathFactory;
36 import org.xmlhammer.model.jaxp.Mappings;
37 import org.xmlhammer.model.jaxp.Properties;
38 import org.xmlhammer.model.jaxp.SchemaFactoryProperties;
39 import org.xmlhammer.model.jaxp.Settings;
40 import org.xmlhammer.model.preferences.Preferences;
41
42 /***
43 * Preferences dialog ...
44 *
45 * @version $Revision: 1.19 $, $Date: 2007/07/04 19:42:50 $
46 * @author Edwin Dankert <edankert@gmail.com>
47 */
48
49 public class PreferencesDialog extends JAXPPropertiesDialog implements TreeSelectionListener {
50
51 private static final long serialVersionUID = 3257006574768632372L;
52 protected ClasspathPanel classpathPanel = null;
53 protected CatalogsPanel catalogsPanel = null;
54 protected LookAndFeelPanel lookAndFeelPanel = null;
55 protected ExternalApplicationPreferencesPanel externalApplicationPanel = null;
56 protected ProxyPreferencesPanel proxyPanel = null;
57
58 /***
59 * @param parent the underlying frame.
60 * @param preferences the global preferences.
61 * @throws java.awt.HeadlessException
62 */
63 public PreferencesDialog(JFrame parent) {
64 super(parent, "Preferences");
65
66 add((HelpEnabledPreferencesPage)null, getCatalogsPanel());
67 add((HelpEnabledPreferencesPage)null, getSAXParserFactoryPreferencesPanel());
68 add(getSAXParserFactoryPreferencesPanel(), getSAXParserFactoryPropertiesPanel());
69 add(getSAXParserFactoryPreferencesPanel(), getSAXParserFactoryFeaturesPanel());
70 add((HelpEnabledPreferencesPage)null, getDocumentBuilderFactoryPreferencesPanel());
71 add(getDocumentBuilderFactoryPreferencesPanel(), getDocumentBuilderFactoryAttributesPanel());
72 add(getDocumentBuilderFactoryPreferencesPanel(), getDocumentBuilderFactoryFeaturesPanel());
73 add((HelpEnabledPreferencesPage)null, getTransformerFactoryPreferencesPanel());
74 add(getTransformerFactoryPreferencesPanel(), getTransformerFactoryAttributesPanel());
75 add(getTransformerFactoryPreferencesPanel(), getTransformerFactoryFeaturesPanel());
76 add((HelpEnabledPreferencesPage)null, getXPathFactoryPreferencesPanel());
77 add(getXPathFactoryPreferencesPanel(), getPrefixNamespaceMappingsPanel());
78 add(getXPathFactoryPreferencesPanel(), getXPathFactoryFeaturesPanel());
79 add((HelpEnabledPreferencesPage)null, getSchemaFactoryPreferencesPanel());
80 add(getSchemaFactoryPreferencesPanel(), getSchemaFactoryPropertiesPanel());
81 add(getSchemaFactoryPreferencesPanel(), getSchemaFactoryFeaturesPanel());
82 add((HelpEnabledPreferencesPage)null, getClasspathPanel());
83 add((HelpEnabledPreferencesPage)null, getExternalApplicationPreferencesPanel());
84 add((HelpEnabledPreferencesPage)null, getProxyPreferencesPanel());
85 add((HelpEnabledPreferencesPage)null, getLookAndFeelPanel());
86 }
87
88 /***
89 * @return whether the properties should be stored.
90 */
91 public int open() {
92 update();
93
94 return super.open();
95 }
96
97 private void update() {
98 getClasspathPanel().setClasspath(getPreferences().getClasspath());
99 getCatalogsPanel().setCatalogs(getPreferences().getCatalogs());
100 getLookAndFeelPanel().setLookAndFeel(getPreferences().getLaf());
101 getExternalApplicationPreferencesPanel().setExternalApplication(getPreferences().getExternalApplication());
102 getProxyPreferencesPanel().setProxy(getPreferences().getProxy());
103
104 Settings jaxpSettings = getPreferences().getJAXPSettings();
105
106 if ( jaxpSettings == null) {
107 jaxpSettings = new Settings();
108 }
109
110
111 getSAXParserFactoryPreferencesPanel().setJAXPSAXParserFactorySettings( jaxpSettings.getJAXPSAXParserFactory().getSettings());
112 getSAXParserFactoryPropertiesPanel().setProperties( jaxpSettings.getJAXPSAXParserFactory().getProperties().getProperty());
113 getSAXParserFactoryFeaturesPanel().setFeatures( jaxpSettings.getJAXPSAXParserFactory().getFeatures().getFeature());
114
115 getDocumentBuilderFactoryPreferencesPanel().setJAXPDocumentBuilderFactorySettings( jaxpSettings.getJAXPDocumentBuilderFactory().getSettings());
116 getDocumentBuilderFactoryAttributesPanel().setAttributes( jaxpSettings.getJAXPDocumentBuilderFactory().getAttributes().getAttribute());
117 getDocumentBuilderFactoryFeaturesPanel().setFeatures( jaxpSettings.getJAXPDocumentBuilderFactory().getFeatures().getFeature());
118
119 getXPathFactoryPreferencesPanel().setJAXPXPathFactorySettings( jaxpSettings.getJAXPXPathFactory().getSettings());
120 getPrefixNamespaceMappingsPanel().setMappings( jaxpSettings.getJAXPXPathFactory().getMappings().getMapping());
121 getXPathFactoryFeaturesPanel().setFeatures( jaxpSettings.getJAXPXPathFactory().getFeatures().getFeature());
122
123 getTransformerFactoryPreferencesPanel().setJAXPTransformerFactorySettings( jaxpSettings.getJAXPTransformerFactory().getSettings());
124 getTransformerFactoryAttributesPanel().setAttributes( jaxpSettings.getJAXPTransformerFactory().getAttributes().getAttribute());
125 getTransformerFactoryFeaturesPanel().setFeatures( jaxpSettings.getJAXPTransformerFactory().getFeatures().getFeature());
126
127 getSchemaFactoryPreferencesPanel().setJAXPSchemaFactorySettings( jaxpSettings.getJAXPSchemaFactory().getSettings());
128 getSchemaFactoryPreferencesPanel().setProperties( jaxpSettings.getJAXPSchemaFactory().getSchemaFactoryProperties().getSchemaFactoryProperty());
129 getSchemaFactoryPropertiesPanel().setProperties( jaxpSettings.getJAXPSchemaFactory().getProperties().getProperty());
130 getSchemaFactoryFeaturesPanel().setFeatures( jaxpSettings.getJAXPSchemaFactory().getFeatures().getFeature());
131 }
132
133 /***
134 * @param preferences the underlying preference which need to be updated.
135 */
136 public void update(Preferences preferences) {
137 getPreferences().setClasspath(getClasspathPanel().getClasspath());
138 getPreferences().setCatalogs(getCatalogsPanel().getCatalogs());
139 getPreferences().setLaf(getLookAndFeelPanel().getLookAndFeel());
140
141 preferences.setExternalApplication(getExternalApplicationPreferencesPanel().getExternalApplication());
142 preferences.setProxy(getProxyPreferencesPanel().getProxy());
143
144
145 Settings jaxpSettings = preferences.getJAXPSettings();
146 if ( jaxpSettings == null) {
147 jaxpSettings = new Settings();
148 }
149
150 JAXPSAXParserFactory saxFactory = new JAXPSAXParserFactory();
151
152 saxFactory.setSettings( getSAXParserFactoryPreferencesPanel().getJAXPSAXParserFactorySettings());
153
154 Properties properties = new Properties();
155 properties.getProperty().addAll( getSAXParserFactoryPropertiesPanel().getProperties());
156 saxFactory.setProperties( properties);
157
158 Features features = new Features();
159 features.getFeature().addAll( getSAXParserFactoryFeaturesPanel().getFeatures());
160 saxFactory.setFeatures( features);
161
162 jaxpSettings.setJAXPSAXParserFactory( saxFactory);
163
164 JAXPDocumentBuilderFactory domFactory = new JAXPDocumentBuilderFactory();
165
166 domFactory.setSettings( getDocumentBuilderFactoryPreferencesPanel().getJAXPDocumentBuilderFactorySettings());
167
168 Attributes attributes = new Attributes();
169 attributes.getAttribute().addAll( getDocumentBuilderFactoryAttributesPanel().getAttributes());
170 domFactory.setAttributes( attributes);
171
172 features = new Features();
173 features.getFeature().addAll( getDocumentBuilderFactoryFeaturesPanel().getFeatures());
174 domFactory.setFeatures( features);
175
176 jaxpSettings.setJAXPDocumentBuilderFactory( domFactory);
177
178 JAXPTransformerFactory traxFactory = new JAXPTransformerFactory();
179
180 traxFactory.setSettings( getTransformerFactoryPreferencesPanel().getJAXPTransfomerFactory());
181
182 attributes = new Attributes();
183 attributes.getAttribute().addAll( getTransformerFactoryAttributesPanel().getAttributes());
184 traxFactory.setAttributes( attributes);
185
186 features = new Features();
187 features.getFeature().addAll( getTransformerFactoryFeaturesPanel().getFeatures());
188 traxFactory.setFeatures( features);
189
190 jaxpSettings.setJAXPTransformerFactory( traxFactory);
191
192 JAXPXPathFactory xpathFactory = new JAXPXPathFactory();
193
194 xpathFactory.setSettings( getXPathFactoryPreferencesPanel().getJAXPXPathFactorySettings());
195
196 Mappings mappings = new Mappings();
197 mappings.getMapping().addAll( getPrefixNamespaceMappingsPanel().getMappings());
198 xpathFactory.setMappings( mappings);
199
200 features = new Features();
201 features.getFeature().addAll( getXPathFactoryFeaturesPanel().getFeatures());
202 xpathFactory.setFeatures( features);
203
204 jaxpSettings.setJAXPXPathFactory( xpathFactory);
205
206 JAXPSchemaFactory schemaFactory = new JAXPSchemaFactory();
207
208 schemaFactory.setSettings( getSchemaFactoryPreferencesPanel().getJAXPSchemaFactorySettings());
209
210 SchemaFactoryProperties schemaProperties = new SchemaFactoryProperties();
211 schemaProperties.getSchemaFactoryProperty().addAll( getSchemaFactoryPreferencesPanel().getProperties());
212 schemaFactory.setSchemaFactoryProperties( schemaProperties);
213
214 properties = new Properties();
215 properties.getProperty().addAll( getSchemaFactoryPropertiesPanel().getProperties());
216 schemaFactory.setProperties( properties);
217
218 features = new Features();
219 features.getFeature().addAll( getSchemaFactoryFeaturesPanel().getFeatures());
220 schemaFactory.setFeatures( features);
221
222 jaxpSettings.setJAXPSchemaFactory( schemaFactory);
223
224 preferences.setJAXPSettings( jaxpSettings);
225 }
226
227 protected ClasspathPanel getClasspathPanel() {
228 if ( classpathPanel == null) {
229 classpathPanel = new ClasspathPanel((JFrame)getParent(), "Class Path", "preferences.classpath");
230 }
231
232 return classpathPanel;
233 }
234
235 protected LookAndFeelPanel getLookAndFeelPanel() {
236 if ( lookAndFeelPanel == null) {
237 lookAndFeelPanel = new LookAndFeelPanel();
238 }
239
240 return lookAndFeelPanel;
241 }
242
243 protected CatalogsPanel getCatalogsPanel() {
244 if (catalogsPanel == null) {
245 catalogsPanel = new CatalogsPanel((JFrame)getParent(), "XML Catalogs", "preferences.catalogs");
246 }
247
248 return catalogsPanel;
249 }
250
251 protected ExternalApplicationPreferencesPanel getExternalApplicationPreferencesPanel() {
252 if (externalApplicationPanel == null) {
253 externalApplicationPanel = new ExternalApplicationPreferencesPanel();
254 }
255
256 return externalApplicationPanel;
257 }
258
259 protected ProxyPreferencesPanel getProxyPreferencesPanel() {
260 if (proxyPanel == null) {
261 proxyPanel = new ProxyPreferencesPanel();
262 }
263
264 return proxyPanel;
265 }
266 }