KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > ServerConfigDialog


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;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.util.*;
24
25 import javax.swing.*;
26
27 import org.openharmonise.him.configuration.*;
28 import org.openharmonise.him.context.StateHandler;
29 import org.openharmonise.him.serverconfig.cache.*;
30 import org.openharmonise.him.serverconfig.errors.*;
31 import org.openharmonise.him.serverconfig.permissions.*;
32 import org.openharmonise.him.serverconfig.security.*;
33 import org.openharmonise.him.window.messages.*;
34 import org.openharmonise.vfs.context.*;
35 import org.openharmonise.vfs.gui.*;
36
37
38 /**
39  * Dialog for setting configuration options on a Harmonise
40  * Information Server.
41  *
42  * @author Matthew Large
43  * @version $Revision: 1.1 $
44  *
45  */

46 public class ServerConfigDialog extends JDialog implements LayoutManager, ActionListener, ContextListener {
47
48     /**
49      * List of {@link ApplyChangesListener} listeners.
50      */

51     private ArrayList m_listeners = new ArrayList();
52
53     /**
54      * Options tabs.
55      */

56     private JTabbedPane m_tabs = null;
57     
58     /**
59      * OK button.
60      */

61     private JButton m_buttonOK = null;
62     
63     /**
64      * Cancel button.
65      */

66     private JButton m_buttonCancel = null;
67     
68     /**
69      * Apply changes button.
70      */

71     private JButton m_buttonApply = null;
72
73     /**
74      * Constructs a new server configuration dialog.
75      *
76      * @param arg0 frame this dialog is associated to.
77      * @param arg1 title for this dialog.
78      * @throws java.awt.HeadlessException thrown when called in an environment that does not support a keyboard, display, or mouse.
79      */

80     public ServerConfigDialog(Frame arg0, String JavaDoc arg1)
81         throws HeadlessException {
82         super(arg0, arg1, true);
83         this.setup();
84     }
85     
86     /**
87      * Initialises this component.
88      *
89      */

90     private void setup() {
91         ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this);
92             
93             this.setResizable(false);
94             
95         StateHandler.getInstance().addWait("SERVER-PROP-OPEN", "Contacting server...");
96         try {
97             this.getContentPane().setLayout(this);
98         
99             this.setSize(400,500);
100             int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2;
101             int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2;
102         
103             this.setLocation(x, y);
104
105             String JavaDoc fontName = "Dialog";
106             int fontSize = 11;
107             Font font = new Font(fontName, Font.PLAIN, fontSize);
108             this.getContentPane().setBackground(new Color(224,224,224));
109         
110             this.m_buttonOK = new JButton("OK");
111             this.m_buttonOK.setActionCommand("OK");
112             this.m_buttonOK.addActionListener(this);
113             this.m_buttonOK.setFont(font);
114             this.getContentPane().add(this.m_buttonOK);
115
116             this.m_buttonCancel = new JButton("Cancel");
117             this.m_buttonCancel.setActionCommand("CANCEL");
118             this.m_buttonCancel.addActionListener(this);
119             this.m_buttonCancel.setFont(font);
120             this.getContentPane().add(this.m_buttonCancel);
121
122             this.m_buttonApply = new JButton("Apply");
123             this.m_buttonApply.setActionCommand("APPLY");
124             this.m_buttonApply.addActionListener(this);
125             this.m_buttonApply.setFont(font);
126             this.getContentPane().add(this.m_buttonApply);
127         
128             this.m_tabs = new JTabbedPane();
129             this.m_tabs.setFont(font);
130         
131             SecurityServerConfigOptions securityOptions = new SecurityServerConfigOptions(this);
132         
133             this.m_tabs.addTab("Password Policy", securityOptions);
134         
135             ErrorServerConfigOptions errorOptions = new ErrorServerConfigOptions(this);
136         
137             this.m_tabs.addTab("Errors", errorOptions);
138         
139             DevelopmentServerConfigOptions developmentOptions = new DevelopmentServerConfigOptions(this);
140         
141             this.m_tabs.addTab("Development Utilities", developmentOptions);
142         
143             CacheServerConfigOptions cacheOptions = new CacheServerConfigOptions(this);
144             JScrollPane scroller = new JScrollPane(cacheOptions, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
145         
146             this.m_tabs.addTab("Caches", scroller);
147         
148             PermissionsServerConfigOptions permissionsOptions = new PermissionsServerConfigOptions(this);
149             this.m_tabs.addTab("Permissions", permissionsOptions);
150         
151             this.getContentPane().add(this.m_tabs);
152             this.m_buttonApply.setEnabled(false);
153         } catch (Exception JavaDoc e) {
154             e.printStackTrace(System.err);
155         } finally {
156             StateHandler.getInstance().removeWait("SERVER-PROP-OPEN");
157         }
158         
159     }
160
161     /* (non-Javadoc)
162      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
163      */

164     public void layoutContainer(Container arg0) {
165         this.m_tabs.setSize(this.getSize().width-10, 430);
166         this.m_tabs.setLocation(0, 0);
167         
168         this.m_buttonOK.setSize(70, 20);
169         this.m_buttonOK.setLocation(150, 440);
170         
171         this.m_buttonCancel.setSize(70, 20);
172         this.m_buttonCancel.setLocation(230, 440);
173         
174         this.m_buttonApply.setSize(70, 20);
175         this.m_buttonApply.setLocation(310, 440);
176     }
177
178     /* (non-Javadoc)
179      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
180      */

181     public void actionPerformed(ActionEvent ae) {
182         if(ae.getActionCommand().equals("OK")) {
183             StateHandler.getInstance().addWait(this, "SERVER-PROP-OK");
184             if(this.fireApplyChanges()){
185                 MessageHandler.getInstance().fireMessageEvent("Changes saved to the Harmonise server.", MessageHandler.TYPE_CONFIRM);
186             } else {
187                 MessageHandler.getInstance().fireMessageEvent("There was a problem saving the changes to the Harmonise server.", MessageHandler.TYPE_ERROR);
188             }
189             ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this);
190             this.hide();
191             StateHandler.getInstance().removeWait(this, "SERVER-PROP-OK");
192         } else if(ae.getActionCommand().equals("CANCEL")) {
193             this.fireDiscardChanges();
194             ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this);
195             this.hide();
196         } else if(ae.getActionCommand().equals("APPLY")) {
197             StateHandler.getInstance().addWait(this, "SERVER-PROP-APPLY");
198                 this.m_buttonApply.setEnabled(false);
199                 if(fireApplyChanges()){
200                     MessageHandler.getInstance().fireMessageEvent("Changes saved to the Harmonise server.", MessageHandler.TYPE_CONFIRM);
201                 } else {
202                     MessageHandler.getInstance().fireMessageEvent("There was a problem saving the changes to the Harmonise server.", MessageHandler.TYPE_ERROR);
203                 }
204                 StateHandler.getInstance().removeWait(this, "SERVER-PROP-APPLY");
205         }
206     }
207     
208     /**
209      * Adds an {@link ApplyChangesListener} listener.
210      *
211      * @param listener Listener to add.
212      */

213     public void addApplyChangesListener(ApplyChangesListener listener) {
214         this.m_listeners.add(listener);
215     }
216     
217     /**
218      * Removes an {@link ApplyChangesListener} listener.
219      *
220      * @param listener Listener to remove.
221      */

222     public void removeApplyChangesListener(ApplyChangesListener listener) {
223         this.m_listeners.remove(listener);
224     }
225     
226     /**
227      * Informs all {@link ApplyChangesListener} listeners that
228      * they should apply their changes.
229      *
230      * @return true if all changes were applied successfully.
231      */

232     private boolean fireApplyChanges() {
233         boolean bOk = true;
234         Iterator itor = this.m_listeners.iterator();
235         while (itor.hasNext()) {
236             ApplyChangesListener listener = (ApplyChangesListener) itor.next();
237             if(listener.applyChanges()==false){
238                 bOk = false;
239             }
240         }
241         return bOk;
242     }
243     
244     /**
245      * Informs all {@link ApplyChangesListener} listeners that
246      * they should discard their changes.
247      *
248      */

249     private void fireDiscardChanges() {
250         Iterator itor = this.m_listeners.iterator();
251         while (itor.hasNext()) {
252             ApplyChangesListener listener = (ApplyChangesListener) itor.next();
253             listener.discardChanges();
254         }
255     }
256     
257     /**
258      * Enables the apply button.
259      *
260      */

261     public void changesMade() {
262         this.m_buttonApply.setEnabled(true);
263     }
264     
265     /**
266      * @throws java.awt.HeadlessException
267      */

268     private ServerConfigDialog() throws HeadlessException {
269         super();
270     }
271
272     /**
273      * @param arg0
274      * @throws java.awt.HeadlessException
275      */

276     private ServerConfigDialog(Dialog arg0) throws HeadlessException {
277         super(arg0);
278     }
279
280     /**
281      * @param arg0
282      * @param arg1
283      * @throws java.awt.HeadlessException
284      */

285     private ServerConfigDialog(Dialog arg0, boolean arg1)
286         throws HeadlessException {
287         super(arg0, arg1);
288     }
289
290     /**
291      * @param arg0
292      * @throws java.awt.HeadlessException
293      */

294     private ServerConfigDialog(Frame arg0) throws HeadlessException {
295         super(arg0);
296     }
297
298     /**
299      * @param arg0
300      * @param arg1
301      * @throws java.awt.HeadlessException
302      */

303     private ServerConfigDialog(Frame arg0, boolean arg1)
304         throws HeadlessException {
305         super(arg0, arg1);
306     }
307
308     /**
309      * @param arg0
310      * @param arg1
311      * @param arg2
312      * @throws java.awt.HeadlessException
313      */

314     private ServerConfigDialog(Dialog arg0, String JavaDoc arg1, boolean arg2)
315         throws HeadlessException {
316         super(arg0, arg1, arg2);
317     }
318
319     /**
320      * @param arg0
321      * @param arg1
322      * @throws java.awt.HeadlessException
323      */

324     private ServerConfigDialog(Dialog arg0, String JavaDoc arg1)
325         throws HeadlessException {
326         super(arg0, arg1);
327     }
328
329     /**
330      * @param arg0
331      * @param arg1
332      * @param arg2
333      * @throws java.awt.HeadlessException
334      */

335     private ServerConfigDialog(Frame arg0, String JavaDoc arg1, boolean arg2)
336         throws HeadlessException {
337         super(arg0, arg1, arg2);
338     }
339
340     /**
341      * @param arg0
342      * @param arg1
343      * @param arg2
344      * @param arg3
345      * @throws java.awt.HeadlessException
346      */

347     private ServerConfigDialog(
348         Dialog arg0,
349         String JavaDoc arg1,
350         boolean arg2,
351         GraphicsConfiguration arg3)
352         throws HeadlessException {
353         super(arg0, arg1, arg2, arg3);
354     }
355
356     /**
357      * @param arg0
358      * @param arg1
359      * @param arg2
360      * @param arg3
361      */

362     private ServerConfigDialog(
363         Frame arg0,
364         String JavaDoc arg1,
365         boolean arg2,
366         GraphicsConfiguration arg3) {
367         super(arg0, arg1, arg2, arg3);
368     }
369
370     /* (non-Javadoc)
371      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
372      */

373     public void removeLayoutComponent(Component arg0) {
374     }
375
376     /* (non-Javadoc)
377      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
378      */

379     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
380     }
381
382     /* (non-Javadoc)
383      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
384      */

385     public Dimension minimumLayoutSize(Container arg0) {
386         return this.getSize();
387     }
388
389     /* (non-Javadoc)
390      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
391      */

392     public Dimension preferredLayoutSize(Container arg0) {
393         return this.getSize();
394     }
395
396     /* (non-Javadoc)
397      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
398      */

399     public void contextMessage(ContextEvent ce) {
400         if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) {
401             this.toFront();
402         }
403     }
404
405 }
406
Popular Tags