001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.serverconfig.errors;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023: import java.net.*;
024: import java.rmi.*;
025:
026: import javax.swing.*;
027: import javax.xml.rpc.*;
028:
029: import org.openharmonise.him.*;
030: import org.openharmonise.him.configuration.*;
031: import org.openharmonise.him.harmonise.*;
032: import org.openharmonise.him.serverconfig.*;
033: import org.openharmonise.vfs.servers.ServerList;
034:
035: /**
036: * Panel for configuring the error options of a Harmonise Information
037: * Server.
038: *
039: * @author Matthew Large
040: * @version $Revision: 1.1 $
041: *
042: */
043: public class ErrorServerConfigOptions extends
044: AbstractServerConfigOptions implements LayoutManager,
045: ActionListener, ApplyChangesListener, KeyListener {
046:
047: /**
048: * Description.
049: */
050: private JTextArea m_descriptionTextArea = null;
051:
052: /**
053: * E-mail errors option label.
054: */
055: private JLabel m_emailErrorsLabel = null;
056:
057: /**
058: * E-mail errors option drop down.
059: */
060: private JComboBox m_emailErrorsCombo = null;
061:
062: /**
063: * true if the e-mail errors option has changed.
064: */
065: private boolean m_bEmailErrorsChanged = false;
066:
067: /**
068: * Errors e-mail address option label.
069: */
070: private JLabel m_errorEmailAddressLabel = null;
071:
072: /**
073: * Errors e-mail address option text field.
074: */
075: private JTextField m_errorEmailAddressTextField = null;
076:
077: /**
078: * true if the errors e-mail address option has changed.
079: */
080: private boolean m_bEmailAddressChanged = false;
081:
082: /**
083: * Redirect on errors option label.
084: */
085: private JLabel m_errorRedirectLabel = null;
086:
087: /**
088: * Redirect on errors option drop down.
089: */
090: private JComboBox m_errorRedirectCombo = null;
091:
092: /**
093: * true if the redirect on errors option has changed.
094: */
095: private boolean m_bErrorRedirectChanged = false;
096:
097: /**
098: * Error redirect address option label.
099: */
100: private JLabel m_errorRedirectAddressLabel = null;
101:
102: /**
103: * Error redirect address option text field.
104: */
105: private JTextField m_errorRedirectAddressTextField = null;
106:
107: /**
108: * true if the redirect address option has changed.
109: */
110: private boolean m_bRedirectAddressChanged = false;
111:
112: /**
113: * E-mail server address option label.
114: */
115: private JLabel m_emailServerAddressLabel = null;
116:
117: /**
118: * E-mail server address option text field.
119: */
120: private JTextField m_emailServerAddressTextField = null;
121:
122: /**
123: * true if the e-mail server address option has changed.
124: */
125: private boolean m_bEmailServerAddressChanged = false;
126:
127: /**
128: * Username for the current user.
129: */
130: private String m_sUsername = null;
131:
132: /**
133: * Password for the current user.
134: */
135: private String m_sPassword = null;
136:
137: /**
138: * Constructs a new error configuration options panel.
139: *
140: */
141: public ErrorServerConfigOptions() {
142: super (null);
143: this .setup();
144: }
145:
146: /**
147: * Constructs a new error configuration options panel.
148: *
149: * @param dialog configuration dialog that this panel will be in.
150: */
151: public ErrorServerConfigOptions(ServerConfigDialog dialog) {
152: super (dialog);
153: dialog.addApplyChangesListener(this );
154: this .setup();
155: }
156:
157: /**
158: * Initialises this component.
159: *
160: */
161: private void setup() {
162: this .setLayout(this );
163:
164: this .m_sUsername = ServerList.getInstance()
165: .getHarmoniseServer().getVFS().getAuthentication()
166: .getUsername();
167: this .m_sPassword = ServerList.getInstance()
168: .getHarmoniseServer().getVFS().getAuthentication()
169: .getPassword();
170:
171: String fontName = "Dialog";
172: int fontSize = 11;
173: Font font = new Font(fontName, Font.PLAIN, fontSize);
174:
175: this .m_descriptionTextArea = new JTextArea(
176: "Use the list below to configure how the server deals with error reports.");
177: this .m_descriptionTextArea.setEditable(false);
178: this .m_descriptionTextArea.setBorder(BorderFactory
179: .createEmptyBorder());
180: this .m_descriptionTextArea.setWrapStyleWord(true);
181: this .m_descriptionTextArea.setLineWrap(true);
182: this .m_descriptionTextArea.setOpaque(false);
183: this .add(m_descriptionTextArea);
184:
185: ConfigSettingsClient service = new ConfigSettingsClient();
186: URL url = null;
187: try {
188: URI uri = ServerList.getInstance().getHarmoniseServer()
189: .getURI();
190: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
191: + uri.getPort() + "/webdav/services/ConfigService";
192: url = new URL(sURL);
193:
194: } catch (MalformedURLException e) {
195: e.printStackTrace();
196: }
197:
198: String sValue = null;
199:
200: try {
201: ConfigProperty configProp = service.getProperty(url,
202: this .m_sUsername, this .m_sPassword, "EMAIL_ERRORS");
203: sValue = configProp.getValue();
204: if (sValue == null) {
205: sValue = "default";
206: }
207: } catch (RemoteException e) {
208: e.printStackTrace();
209: } catch (ServiceException e) {
210: e.printStackTrace();
211: }
212:
213: this .m_emailErrorsLabel = new JLabel("E-mail Errors?");
214: this .m_emailErrorsLabel.setFont(font);
215: this .add(m_emailErrorsLabel);
216:
217: this .m_emailErrorsCombo = new JComboBox(new String[] { "TRUE",
218: "FALSE" });
219: this .m_emailErrorsCombo.setFont(font);
220: this .m_emailErrorsCombo.setActionCommand("MAILERRORS");
221: if (sValue.equalsIgnoreCase("TRUE")) {
222: this .m_emailErrorsCombo.setSelectedItem("TRUE");
223: } else {
224: this .m_emailErrorsCombo.setSelectedItem("FALSE");
225: }
226: this .add(m_emailErrorsCombo);
227: this .m_emailErrorsCombo.addActionListener(this );
228:
229: try {
230: ConfigProperty configProp = service.getProperty(url,
231: this .m_sUsername, this .m_sPassword,
232: "ERROR_EMAIL_ADDRESS");
233: sValue = configProp.getValue();
234: if (sValue == null) {
235: sValue = "default";
236: }
237: } catch (RemoteException e) {
238: e.printStackTrace();
239: } catch (ServiceException e) {
240: e.printStackTrace();
241: }
242:
243: m_errorEmailAddressLabel = new JLabel("Error E-mail Address");
244: this .m_errorEmailAddressLabel.setFont(font);
245: this .add(this .m_errorEmailAddressLabel);
246: m_errorEmailAddressTextField = new JTextField(sValue);
247: this .m_errorEmailAddressTextField.addKeyListener(this );
248: this .m_errorEmailAddressTextField.setFont(font);
249: this .add(this .m_errorEmailAddressTextField);
250:
251: try {
252: ConfigProperty configProp = service.getProperty(url,
253: this .m_sUsername, this .m_sPassword,
254: "REDIRECT_ON_ERROR");
255: sValue = configProp.getValue();
256: if (sValue == null) {
257: sValue = "default";
258: }
259: } catch (RemoteException e) {
260: e.printStackTrace();
261: } catch (ServiceException e) {
262: e.printStackTrace();
263: }
264:
265: this .m_errorRedirectLabel = new JLabel("Redirect on Error?");
266: this .m_errorRedirectLabel.setFont(font);
267: this .add(m_errorRedirectLabel);
268:
269: this .m_errorRedirectCombo = new JComboBox(new String[] {
270: "TRUE", "FALSE" });
271: this .m_errorRedirectCombo.setFont(font);
272: this .m_errorRedirectCombo.setActionCommand("REDIRECT");
273: if (sValue.equalsIgnoreCase("TRUE")) {
274: this .m_errorRedirectCombo.setSelectedItem("TRUE");
275: } else {
276: this .m_errorRedirectCombo.setSelectedItem("FALSE");
277: }
278: this .add(m_errorRedirectCombo);
279: this .m_errorRedirectCombo.addActionListener(this );
280:
281: try {
282: ConfigProperty configProp = service.getProperty(url,
283: this .m_sUsername, this .m_sPassword,
284: "ERROR_REDIRECT_URL");
285: sValue = configProp.getValue();
286: if (sValue == null) {
287: sValue = "default";
288: }
289: } catch (RemoteException e) {
290: e.printStackTrace();
291: } catch (ServiceException e) {
292: e.printStackTrace();
293: }
294:
295: m_errorRedirectAddressLabel = new JLabel("Error Redirect URL");
296: this .m_errorRedirectAddressLabel.setFont(font);
297: this .add(this .m_errorRedirectAddressLabel);
298: m_errorRedirectAddressTextField = new JTextField(sValue);
299: this .m_errorRedirectAddressTextField.addKeyListener(this );
300: this .m_errorRedirectAddressTextField.setFont(font);
301: this .add(this .m_errorRedirectAddressTextField);
302:
303: try {
304: ConfigProperty configProp = service.getProperty(url,
305: this .m_sUsername, this .m_sPassword, "EMAIL_HOST");
306: sValue = configProp.getValue();
307: if (sValue == null) {
308: sValue = "default";
309: }
310: } catch (RemoteException e) {
311: e.printStackTrace();
312: } catch (ServiceException e) {
313: e.printStackTrace();
314: }
315:
316: m_emailServerAddressLabel = new JLabel("E-mail Server Address");
317: this .m_emailServerAddressLabel.setFont(font);
318: this .add(this .m_emailServerAddressLabel);
319: m_emailServerAddressTextField = new JTextField(sValue);
320: this .m_emailServerAddressTextField.addKeyListener(this );
321: this .m_emailServerAddressTextField.setFont(font);
322: this .add(this .m_emailServerAddressTextField);
323:
324: }
325:
326: /* (non-Javadoc)
327: * @see java.awt.Component#getPreferredSize()
328: */
329: public Dimension getPreferredSize() {
330: return new Dimension(this .getParent().getSize().width - 50, 100);
331: }
332:
333: /* (non-Javadoc)
334: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
335: */
336: public void layoutContainer(Container arg0) {
337:
338: int nHeight = 20;
339:
340: this .m_descriptionTextArea.setSize(350, 20);
341: this .m_descriptionTextArea.setLocation(20, nHeight);
342: nHeight = nHeight + this .m_descriptionTextArea.getSize().height
343: + 20;
344:
345: this .m_emailErrorsLabel.setSize(this .m_emailErrorsLabel
346: .getPreferredSize());
347: this .m_emailErrorsLabel.setLocation(20, nHeight);
348: this .m_emailErrorsCombo.setSize(100, 20);
349: this .m_emailErrorsCombo.setLocation(250, nHeight);
350: nHeight = nHeight + this .m_emailErrorsLabel.getSize().height
351: + 20;
352:
353: this .m_errorEmailAddressLabel
354: .setSize(this .m_errorEmailAddressLabel
355: .getPreferredSize());
356: this .m_errorEmailAddressLabel.setLocation(20, nHeight);
357: this .m_errorEmailAddressTextField.setSize(100, 20);
358: this .m_errorEmailAddressTextField.setLocation(250, nHeight);
359: nHeight = nHeight
360: + this .m_errorEmailAddressLabel.getSize().height + 20;
361:
362: this .m_errorRedirectLabel.setSize(this .m_errorRedirectLabel
363: .getPreferredSize());
364: this .m_errorRedirectLabel.setLocation(20, nHeight);
365: this .m_errorRedirectCombo.setSize(100, 20);
366: this .m_errorRedirectCombo.setLocation(250, nHeight);
367: nHeight = nHeight + this .m_errorRedirectLabel.getSize().height
368: + 20;
369:
370: this .m_errorRedirectAddressLabel
371: .setSize(this .m_errorRedirectAddressLabel
372: .getPreferredSize());
373: this .m_errorRedirectAddressLabel.setLocation(20, nHeight);
374: this .m_errorRedirectAddressTextField.setSize(100, 20);
375: this .m_errorRedirectAddressTextField.setLocation(250, nHeight);
376: nHeight = nHeight
377: + this .m_errorRedirectAddressLabel.getSize().height
378: + 20;
379:
380: this .m_emailServerAddressLabel
381: .setSize(this .m_emailServerAddressLabel
382: .getPreferredSize());
383: this .m_emailServerAddressLabel.setLocation(20, nHeight);
384: this .m_emailServerAddressTextField.setSize(100, 20);
385: this .m_emailServerAddressTextField.setLocation(250, nHeight);
386: nHeight = nHeight
387: + this .m_emailServerAddressLabel.getSize().height + 20;
388: }
389:
390: /* (non-Javadoc)
391: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
392: */
393: public Dimension minimumLayoutSize(Container arg0) {
394: return null;
395: }
396:
397: /* (non-Javadoc)
398: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
399: */
400: public Dimension preferredLayoutSize(Container arg0) {
401: return null;
402: }
403:
404: /* (non-Javadoc)
405: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
406: */
407: public void actionPerformed(ActionEvent ae) {
408: if (ae.getActionCommand().equals("MAILERRORS")) {
409: this .m_bEmailErrorsChanged = true;
410: } else if (ae.getActionCommand().equals("REDIRECT")) {
411: this .m_bErrorRedirectChanged = true;
412: }
413: this .fireChangesMade();
414: }
415:
416: /* (non-Javadoc)
417: * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
418: */
419: public void keyReleased(KeyEvent ke) {
420: if (ke.getSource() == this .m_errorEmailAddressTextField) {
421: this .m_bEmailAddressChanged = true;
422: }
423: if (ke.getSource() == this .m_errorRedirectAddressTextField) {
424: this .m_bRedirectAddressChanged = true;
425: }
426: if (ke.getSource() == this .m_emailServerAddressTextField) {
427: this .m_bEmailServerAddressChanged = true;
428: }
429: this .fireChangesMade();
430: }
431:
432: /* (non-Javadoc)
433: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
434: */
435: public boolean applyChanges() {
436: boolean bOk = true;
437: ConfigSettingsClient service = new ConfigSettingsClient();
438: URL url = null;
439: try {
440: URI uri = ServerList.getInstance().getHarmoniseServer()
441: .getURI();
442: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
443: + uri.getPort() + "/webdav/services/ConfigService";
444: url = new URL(sURL);
445:
446: } catch (MalformedURLException e) {
447: e.printStackTrace();
448: }
449: try {
450: if (this .m_bEmailErrorsChanged) {
451: service.setProperty(url, m_sUsername, m_sPassword,
452: new ConfigProperty("EMAIL_ERRORS",
453: (String) this .m_emailErrorsCombo
454: .getSelectedItem()));
455: this .m_bEmailErrorsChanged = false;
456: }
457: if (this .m_bEmailAddressChanged) {
458: service.setProperty(url, m_sUsername, m_sPassword,
459: new ConfigProperty("ERROR_EMAIL_ADDRESS",
460: this .m_errorEmailAddressTextField
461: .getText()));
462: this .m_bEmailAddressChanged = false;
463: }
464: if (this .m_bErrorRedirectChanged) {
465: service.setProperty(url, m_sUsername, m_sPassword,
466: new ConfigProperty("REDIRECT_ON_ERROR",
467: (String) this .m_errorRedirectCombo
468: .getSelectedItem()));
469: this .m_bErrorRedirectChanged = false;
470: }
471: if (this .m_bRedirectAddressChanged) {
472: service.setProperty(url, m_sUsername, m_sPassword,
473: new ConfigProperty("ERROR_REDIRECT_URL",
474: this .m_errorRedirectAddressTextField
475: .getText()));
476: this .m_bRedirectAddressChanged = false;
477: }
478: if (this .m_bEmailServerAddressChanged) {
479: service.setProperty(url, m_sUsername, m_sPassword,
480: new ConfigProperty("EMAIL_HOST",
481: this .m_emailServerAddressTextField
482: .getText()));
483: this .m_bEmailServerAddressChanged = false;
484: }
485: } catch (Exception e) {
486: e.printStackTrace();
487: bOk = false;
488: }
489: return bOk;
490: }
491:
492: /* (non-Javadoc)
493: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
494: */
495: public void removeLayoutComponent(Component arg0) {
496: }
497:
498: /* (non-Javadoc)
499: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
500: */
501: public void addLayoutComponent(String arg0, Component arg1) {
502: }
503:
504: /* (non-Javadoc)
505: * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
506: */
507: public void keyPressed(KeyEvent arg0) {
508: }
509:
510: /* (non-Javadoc)
511: * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
512: */
513: public void keyTyped(KeyEvent arg0) {
514: }
515:
516: /* (non-Javadoc)
517: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
518: */
519: public void discardChanges() {
520: }
521:
522: }
|