KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > errors > ErrorServerConfigOptions


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.serverconfig.errors;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.net.*;
24 import java.rmi.*;
25
26 import javax.swing.*;
27 import javax.xml.rpc.*;
28
29 import org.openharmonise.him.*;
30 import org.openharmonise.him.configuration.*;
31 import org.openharmonise.him.harmonise.*;
32 import org.openharmonise.him.serverconfig.*;
33 import org.openharmonise.vfs.servers.ServerList;
34
35
36 /**
37  * Panel for configuring the error options of a Harmonise Information
38  * Server.
39  *
40  * @author Matthew Large
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class ErrorServerConfigOptions
45     extends AbstractServerConfigOptions
46     implements LayoutManager, ActionListener, ApplyChangesListener, KeyListener {
47         
48     /**
49      * Description.
50      */

51     private JTextArea m_descriptionTextArea = null;
52         
53     /**
54      * E-mail errors option label.
55      */

56     private JLabel m_emailErrorsLabel = null;
57     
58     /**
59      * E-mail errors option drop down.
60      */

61     private JComboBox m_emailErrorsCombo = null;
62     
63     /**
64      * true if the e-mail errors option has changed.
65      */

66     private boolean m_bEmailErrorsChanged = false;
67         
68     /**
69      * Errors e-mail address option label.
70      */

71     private JLabel m_errorEmailAddressLabel = null;
72     
73     /**
74      * Errors e-mail address option text field.
75      */

76     private JTextField m_errorEmailAddressTextField = null;
77     
78     /**
79      * true if the errors e-mail address option has changed.
80      */

81     private boolean m_bEmailAddressChanged = false;
82         
83     /**
84      * Redirect on errors option label.
85      */

86     private JLabel m_errorRedirectLabel = null;
87     
88     /**
89      * Redirect on errors option drop down.
90      */

91     private JComboBox m_errorRedirectCombo = null;
92     
93     /**
94      * true if the redirect on errors option has changed.
95      */

96     private boolean m_bErrorRedirectChanged = false;
97     
98     /**
99      * Error redirect address option label.
100      */

101     private JLabel m_errorRedirectAddressLabel = null;
102     
103     /**
104      * Error redirect address option text field.
105      */

106     private JTextField m_errorRedirectAddressTextField = null;
107     
108     /**
109      * true if the redirect address option has changed.
110      */

111     private boolean m_bRedirectAddressChanged = false;
112     
113     /**
114      * E-mail server address option label.
115      */

116     private JLabel m_emailServerAddressLabel = null;
117     
118     /**
119      * E-mail server address option text field.
120      */

121     private JTextField m_emailServerAddressTextField = null;
122     
123     /**
124      * true if the e-mail server address option has changed.
125      */

126     private boolean m_bEmailServerAddressChanged = false;
127         
128     /**
129      * Username for the current user.
130      */

131     private String JavaDoc m_sUsername = null;
132     
133     /**
134      * Password for the current user.
135      */

136     private String JavaDoc m_sPassword = null;
137
138     /**
139      * Constructs a new error configuration options panel.
140      *
141      */

142     public ErrorServerConfigOptions() {
143         super(null);
144         this.setup();
145     }
146
147     /**
148      * Constructs a new error configuration options panel.
149      *
150      * @param dialog configuration dialog that this panel will be in.
151      */

152     public ErrorServerConfigOptions(ServerConfigDialog dialog) {
153         super(dialog);
154         dialog.addApplyChangesListener(this);
155         this.setup();
156     }
157     
158     /**
159      * Initialises this component.
160      *
161      */

162     private void setup() {
163         this.setLayout(this);
164             
165         this.m_sUsername = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUsername();
166         this.m_sPassword = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getPassword();
167
168         String JavaDoc fontName = "Dialog";
169         int fontSize = 11;
170         Font font = new Font(fontName, Font.PLAIN, fontSize);
171             
172         this.m_descriptionTextArea = new JTextArea("Use the list below to configure how the server deals with error reports.");
173         this.m_descriptionTextArea.setEditable(false);
174         this.m_descriptionTextArea.setBorder(BorderFactory.createEmptyBorder());
175         this.m_descriptionTextArea.setWrapStyleWord(true);
176         this.m_descriptionTextArea.setLineWrap(true);
177         this.m_descriptionTextArea.setOpaque(false);
178         this.add(m_descriptionTextArea);
179         
180         ConfigSettingsClient service = new ConfigSettingsClient();
181         URL url = null;
182         try {
183             URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
184             String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
185             url = new URL(sURL);
186             
187         } catch (MalformedURLException e) {
188             e.printStackTrace();
189         }
190         
191         String JavaDoc sValue = null;
192         
193         try {
194             ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "EMAIL_ERRORS");
195             sValue = configProp.getValue();
196             if(sValue==null) {
197                 sValue = "default";
198             }
199         } catch (RemoteException e) {
200             e.printStackTrace();
201         } catch (ServiceException e) {
202             e.printStackTrace();
203         }
204         
205         this.m_emailErrorsLabel = new JLabel("E-mail Errors?");
206         this.m_emailErrorsLabel.setFont(font);
207         this.add(m_emailErrorsLabel);
208         
209         this.m_emailErrorsCombo = new JComboBox(new String JavaDoc[]{"TRUE", "FALSE"});
210         this.m_emailErrorsCombo.setFont(font);
211         this.m_emailErrorsCombo.setActionCommand("MAILERRORS");
212         if(sValue.equalsIgnoreCase("TRUE")) {
213             this.m_emailErrorsCombo.setSelectedItem("TRUE");
214         } else {
215             this.m_emailErrorsCombo.setSelectedItem("FALSE");
216         }
217         this.add(m_emailErrorsCombo);
218         this.m_emailErrorsCombo.addActionListener(this);
219         
220         try {
221             ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "ERROR_EMAIL_ADDRESS");
222             sValue = configProp.getValue();
223             if(sValue==null) {
224                 sValue = "default";
225             }
226         } catch (RemoteException e) {
227             e.printStackTrace();
228         } catch (ServiceException e) {
229             e.printStackTrace();
230         }
231         
232         m_errorEmailAddressLabel = new JLabel("Error E-mail Address");
233         this.m_errorEmailAddressLabel.setFont(font);
234         this.add(this.m_errorEmailAddressLabel);
235         m_errorEmailAddressTextField = new JTextField(sValue);
236         this.m_errorEmailAddressTextField.addKeyListener(this);
237         this.m_errorEmailAddressTextField.setFont(font);
238         this.add(this.m_errorEmailAddressTextField);
239         
240         try {
241             ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "REDIRECT_ON_ERROR");
242             sValue = configProp.getValue();
243             if(sValue==null) {
244                 sValue = "default";
245             }
246         } catch (RemoteException e) {
247             e.printStackTrace();
248         } catch (ServiceException e) {
249             e.printStackTrace();
250         }
251         
252         this.m_errorRedirectLabel = new JLabel("Redirect on Error?");
253         this.m_errorRedirectLabel.setFont(font);
254         this.add(m_errorRedirectLabel);
255         
256         this.m_errorRedirectCombo = new JComboBox(new String JavaDoc[]{"TRUE", "FALSE"});
257         this.m_errorRedirectCombo.setFont(font);
258         this.m_errorRedirectCombo.setActionCommand("REDIRECT");
259         if(sValue.equalsIgnoreCase("TRUE")) {
260             this.m_errorRedirectCombo.setSelectedItem("TRUE");
261         } else {
262             this.m_errorRedirectCombo.setSelectedItem("FALSE");
263         }
264         this.add(m_errorRedirectCombo);
265         this.m_errorRedirectCombo.addActionListener(this);
266         
267         try {
268             ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "ERROR_REDIRECT_URL");
269             sValue = configProp.getValue();
270             if(sValue==null) {
271                 sValue = "default";
272             }
273         } catch (RemoteException e) {
274             e.printStackTrace();
275         } catch (ServiceException e) {
276             e.printStackTrace();
277         }
278         
279         m_errorRedirectAddressLabel = new JLabel("Error Redirect URL");
280         this.m_errorRedirectAddressLabel.setFont(font);
281         this.add(this.m_errorRedirectAddressLabel);
282         m_errorRedirectAddressTextField = new JTextField(sValue);
283         this.m_errorRedirectAddressTextField.addKeyListener(this);
284         this.m_errorRedirectAddressTextField.setFont(font);
285         this.add(this.m_errorRedirectAddressTextField);
286         
287         try {
288             ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "EMAIL_HOST");
289             sValue = configProp.getValue();
290             if(sValue==null) {
291                 sValue = "default";
292             }
293         } catch (RemoteException e) {
294             e.printStackTrace();
295         } catch (ServiceException e) {
296             e.printStackTrace();
297         }
298         
299         m_emailServerAddressLabel = new JLabel("E-mail Server Address");
300         this.m_emailServerAddressLabel.setFont(font);
301         this.add(this.m_emailServerAddressLabel);
302         m_emailServerAddressTextField = new JTextField(sValue);
303         this.m_emailServerAddressTextField.addKeyListener(this);
304         this.m_emailServerAddressTextField.setFont(font);
305         this.add(this.m_emailServerAddressTextField);
306         
307     }
308
309     /* (non-Javadoc)
310      * @see java.awt.Component#getPreferredSize()
311      */

312     public Dimension getPreferredSize() {
313         return new Dimension(this.getParent().getSize().width-50, 100);
314     }
315
316     /* (non-Javadoc)
317      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
318      */

319     public void layoutContainer(Container arg0) {
320             
321         int nHeight = 20;
322             
323         this.m_descriptionTextArea.setSize(350, 20);
324         this.m_descriptionTextArea.setLocation(20, nHeight);
325         nHeight = nHeight + this.m_descriptionTextArea.getSize().height + 20;
326         
327         this.m_emailErrorsLabel.setSize(this.m_emailErrorsLabel.getPreferredSize());
328         this.m_emailErrorsLabel.setLocation(20, nHeight);
329         this.m_emailErrorsCombo.setSize(100, 20);
330         this.m_emailErrorsCombo.setLocation(250, nHeight);
331         nHeight = nHeight + this.m_emailErrorsLabel.getSize().height + 20;
332         
333         this.m_errorEmailAddressLabel.setSize(this.m_errorEmailAddressLabel.getPreferredSize());
334         this.m_errorEmailAddressLabel.setLocation(20, nHeight);
335         this.m_errorEmailAddressTextField.setSize(100, 20);
336         this.m_errorEmailAddressTextField.setLocation(250, nHeight);
337         nHeight = nHeight + this.m_errorEmailAddressLabel.getSize().height + 20;
338         
339         this.m_errorRedirectLabel.setSize(this.m_errorRedirectLabel.getPreferredSize());
340         this.m_errorRedirectLabel.setLocation(20, nHeight);
341         this.m_errorRedirectCombo.setSize(100, 20);
342         this.m_errorRedirectCombo.setLocation(250, nHeight);
343         nHeight = nHeight + this.m_errorRedirectLabel.getSize().height + 20;
344         
345         this.m_errorRedirectAddressLabel.setSize(this.m_errorRedirectAddressLabel.getPreferredSize());
346         this.m_errorRedirectAddressLabel.setLocation(20, nHeight);
347         this.m_errorRedirectAddressTextField.setSize(100, 20);
348         this.m_errorRedirectAddressTextField.setLocation(250, nHeight);
349         nHeight = nHeight + this.m_errorRedirectAddressLabel.getSize().height + 20;
350         
351         this.m_emailServerAddressLabel.setSize(this.m_emailServerAddressLabel.getPreferredSize());
352         this.m_emailServerAddressLabel.setLocation(20, nHeight);
353         this.m_emailServerAddressTextField.setSize(100, 20);
354         this.m_emailServerAddressTextField.setLocation(250, nHeight);
355         nHeight = nHeight + this.m_emailServerAddressLabel.getSize().height + 20;
356     }
357
358     /* (non-Javadoc)
359      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
360      */

361     public Dimension minimumLayoutSize(Container arg0) {
362         return null;
363     }
364
365     /* (non-Javadoc)
366      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
367      */

368     public Dimension preferredLayoutSize(Container arg0) {
369         return null;
370     }
371
372     /* (non-Javadoc)
373      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
374      */

375     public void actionPerformed(ActionEvent ae) {
376         if(ae.getActionCommand().equals("MAILERRORS")) {
377             this.m_bEmailErrorsChanged = true;
378         } else if(ae.getActionCommand().equals("REDIRECT")) {
379             this.m_bErrorRedirectChanged = true;
380         }
381         this.fireChangesMade();
382     }
383
384     /* (non-Javadoc)
385      * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
386      */

387     public void keyReleased(KeyEvent ke) {
388         if(ke.getSource()==this.m_errorEmailAddressTextField) {
389             this.m_bEmailAddressChanged = true;
390         }
391         if(ke.getSource()==this.m_errorRedirectAddressTextField) {
392             this.m_bRedirectAddressChanged = true;
393         }
394         if(ke.getSource()==this.m_emailServerAddressTextField) {
395             this.m_bEmailServerAddressChanged = true;
396         }
397         this.fireChangesMade();
398     }
399
400     /* (non-Javadoc)
401      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
402      */

403     public boolean applyChanges() {
404         boolean bOk = true;
405         ConfigSettingsClient service = new ConfigSettingsClient();
406         URL url = null;
407         try {
408             URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
409             String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
410             url = new URL(sURL);
411             
412         } catch (MalformedURLException e) {
413             e.printStackTrace();
414         }
415         try {
416             if(this.m_bEmailErrorsChanged) {
417                 service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("EMAIL_ERRORS", (String JavaDoc) this.m_emailErrorsCombo.getSelectedItem()));
418                 this.m_bEmailErrorsChanged=false;
419             }
420             if(this.m_bEmailAddressChanged) {
421                 service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("ERROR_EMAIL_ADDRESS", this.m_errorEmailAddressTextField.getText()));
422                 this.m_bEmailAddressChanged=false;
423             }
424             if(this.m_bErrorRedirectChanged) {
425                 service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("REDIRECT_ON_ERROR", (String JavaDoc) this.m_errorRedirectCombo.getSelectedItem()));
426                 this.m_bErrorRedirectChanged=false;
427             }
428             if(this.m_bRedirectAddressChanged) {
429                 service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("ERROR_REDIRECT_URL", this.m_errorRedirectAddressTextField.getText()));
430                 this.m_bRedirectAddressChanged=false;
431             }
432             if(this.m_bEmailServerAddressChanged) {
433                 service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("EMAIL_HOST", this.m_emailServerAddressTextField.getText()));
434                 this.m_bEmailServerAddressChanged=false;
435             }
436         } catch (Exception JavaDoc e) {
437             e.printStackTrace();
438             bOk = false;
439         }
440         return bOk;
441     }
442
443     /* (non-Javadoc)
444      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
445      */

446     public void removeLayoutComponent(Component arg0) {
447     }
448
449     /* (non-Javadoc)
450      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
451      */

452     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
453     }
454
455     /* (non-Javadoc)
456      * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
457      */

458     public void keyPressed(KeyEvent arg0) {
459     }
460
461     /* (non-Javadoc)
462      * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
463      */

464     public void keyTyped(KeyEvent arg0) {
465     }
466
467     /* (non-Javadoc)
468      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
469      */

470     public void discardChanges() {
471     }
472
473 }
474
Popular Tags