KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.vfs.servers.ServerList;
33
34
35 /**
36  * Panel for configuring the development options of a Harmonise Information
37  * Server.
38  *
39  * @author Matthew Large
40  * @version $Revision: 1.1 $
41  *
42  */

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

50         private JTextArea m_descriptionTextArea = null;
51         
52         /**
53          * Show XML option label.
54          */

55         private JLabel m_showXMLLabel = null;
56         
57         /**
58          * Show XML option drop down.
59          */

60         private JComboBox m_showXMLCombo = null;
61         
62         /**
63          * true if the show XML option has changed.
64          */

65         private boolean m_bShowXMLChanged = false;
66         
67         /**
68          * Admin utils username option label.
69          */

70         private JLabel m_adminUtilsUsernameLabel = null;
71         
72         /**
73          * Admin utils username option text field.
74          */

75         private JTextField m_adminUtilsUsernameTextField = null;
76         
77         /**
78          * Admin utils password option label.
79          */

80         private JLabel m_adminUtilsPasswordLabel = null;
81         
82         /**
83          * Admin utils password option text field.
84          */

85         private JPasswordField m_adminUtilsPasswordField = null;
86         
87         /**
88          * true if either the admin utils username or password option has changed.
89          */

90         private boolean m_badminUtilsPasswordChanged = false;
91         
92         /**
93          * Username for the current user.
94          */

95         private String JavaDoc m_sUsername = null;
96         
97         /**
98          * Password for the current user.
99          */

100         private String JavaDoc m_sPassword = null;
101
102         
103         public DevelopmentServerConfigOptions() {
104             super(null);
105             this.setup();
106         }
107
108         /**
109          * Constructs a new development server configuration options panel.
110          *
111          * @param dialog configuration dialog that this panel will be in.
112          */

113         public DevelopmentServerConfigOptions(ServerConfigDialog dialog) {
114             super(dialog);
115             dialog.addApplyChangesListener(this);
116             this.setup();
117         }
118     
119         /**
120          * Initialises this component.
121          *
122          */

123         private void setup() {
124             this.setLayout(this);
125             
126             this.m_sUsername = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUsername();
127             this.m_sPassword = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getPassword();
128
129             String JavaDoc fontName = "Dialog";
130             int fontSize = 11;
131             Font font = new Font(fontName, Font.PLAIN, fontSize);
132             
133             this.m_descriptionTextArea = new JTextArea("Set up access to the development utilities.");
134             this.m_descriptionTextArea.setEditable(false);
135             this.m_descriptionTextArea.setBorder(BorderFactory.createEmptyBorder());
136             this.m_descriptionTextArea.setWrapStyleWord(true);
137             this.m_descriptionTextArea.setLineWrap(true);
138             this.m_descriptionTextArea.setOpaque(false);
139             this.add(m_descriptionTextArea);
140         
141             ConfigSettingsClient service = new ConfigSettingsClient();
142             URL url = null;
143             try {
144                 URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
145                 String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
146                 url = new URL(sURL);
147                 
148             } catch (MalformedURLException e) {
149                 e.printStackTrace();
150             }
151         
152             ConfigProperty configProp = null;
153         
154             try {
155                 configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "ALLOW_SHOWXML");
156             } catch (RemoteException e) {
157                 e.printStackTrace();
158             } catch (ServiceException e) {
159                 e.printStackTrace();
160             }
161         
162             this.m_showXMLLabel = new JLabel("Allow \"Show XML\"?");
163             this.m_showXMLLabel.setFont(font);
164             this.add(m_showXMLLabel);
165         
166             this.m_showXMLCombo = new JComboBox(new String JavaDoc[]{"TRUE", "FALSE"});
167             this.m_showXMLCombo.setFont(font);
168             this.m_showXMLCombo.setActionCommand("SHOWXML");
169             if(configProp.getValue()!=null && configProp.getValue().equalsIgnoreCase("TRUE")) {
170                 this.m_showXMLCombo.setSelectedItem("TRUE");
171             } else {
172                 this.m_showXMLCombo.setSelectedItem("FALSE");
173             }
174             this.add(m_showXMLCombo);
175             this.m_showXMLCombo.addActionListener(this);
176         
177             try {
178                 configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "UTIL_USERS_PWD");
179             } catch (RemoteException e) {
180
181             } catch (ServiceException e) {
182                 e.printStackTrace();
183             }
184             
185             String JavaDoc sName = "";
186             String JavaDoc sPassword = "";
187             if(configProp.getValue()!=null && configProp.getValue().indexOf(":")>-1) {
188                 sName = configProp.getValue().substring(0, configProp.getValue().indexOf(":"));
189                 sPassword = configProp.getValue().substring(configProp.getValue().indexOf(":")+1);
190             } else {
191                 sName = "admin";
192                 sPassword = "admin";
193             }
194         
195             m_adminUtilsUsernameLabel = new JLabel("Utilities login (username)");
196             this.m_adminUtilsUsernameLabel.setFont(font);
197             this.add(this.m_adminUtilsUsernameLabel);
198             m_adminUtilsUsernameTextField = new JTextField(sName);
199             this.m_adminUtilsUsernameTextField.addKeyListener(this);
200             this.m_adminUtilsUsernameTextField.setFont(font);
201             this.add(this.m_adminUtilsUsernameTextField);
202         
203             m_adminUtilsPasswordLabel = new JLabel("Utilities login (password)");
204             this.m_adminUtilsPasswordLabel.setFont(font);
205             this.add(this.m_adminUtilsPasswordLabel);
206             m_adminUtilsPasswordField = new JPasswordField(sPassword);
207             this.m_adminUtilsPasswordField.addKeyListener(this);
208             this.m_adminUtilsPasswordField.setFont(font);
209             this.add(this.m_adminUtilsPasswordField);
210
211         
212         }
213
214         /* (non-Javadoc)
215          * @see java.awt.Component#getPreferredSize()
216          */

217         public Dimension getPreferredSize() {
218             return new Dimension(this.getParent().getSize().width-50, 100);
219         }
220
221         /* (non-Javadoc)
222          * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
223          */

224         public void layoutContainer(Container arg0) {
225             
226             int nHeight = 20;
227             
228             this.m_descriptionTextArea.setSize(350, 20);
229             this.m_descriptionTextArea.setLocation(20, nHeight);
230             nHeight = nHeight + this.m_descriptionTextArea.getSize().height + 20;
231         
232             this.m_showXMLLabel.setSize(this.m_showXMLLabel.getPreferredSize());
233             this.m_showXMLLabel.setLocation(20, nHeight);
234             this.m_showXMLCombo.setSize(100, 20);
235             this.m_showXMLCombo.setLocation(250, nHeight);
236             nHeight = nHeight + this.m_showXMLLabel.getSize().height + 20;
237         
238             this.m_adminUtilsUsernameLabel.setSize(this.m_adminUtilsUsernameLabel.getPreferredSize());
239             this.m_adminUtilsUsernameLabel.setLocation(20, nHeight);
240             this.m_adminUtilsUsernameTextField.setSize(100, 20);
241             this.m_adminUtilsUsernameTextField.setLocation(250, nHeight);
242             nHeight = nHeight + this.m_adminUtilsUsernameLabel.getSize().height + 20;
243         
244             this.m_adminUtilsPasswordLabel.setSize(this.m_adminUtilsPasswordLabel.getPreferredSize());
245             this.m_adminUtilsPasswordLabel.setLocation(20, nHeight);
246             this.m_adminUtilsPasswordField.setSize(100, 20);
247             this.m_adminUtilsPasswordField.setLocation(250, nHeight);
248             nHeight = nHeight + this.m_adminUtilsPasswordLabel.getSize().height + 20;
249         }
250
251         /* (non-Javadoc)
252          * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
253          */

254         public Dimension minimumLayoutSize(Container arg0) {
255             return null;
256         }
257
258         /* (non-Javadoc)
259          * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
260          */

261         public Dimension preferredLayoutSize(Container arg0) {
262             return null;
263         }
264
265         /* (non-Javadoc)
266          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
267          */

268         public void actionPerformed(ActionEvent ae) {
269             if(ae.getActionCommand().equals("SHOWXML")) {
270                 this.m_bShowXMLChanged = true;
271             }
272             this.fireChangesMade();
273         }
274
275         /* (non-Javadoc)
276          * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
277          */

278         public void keyReleased(KeyEvent ke) {
279             if(ke.getSource()==this.m_adminUtilsUsernameTextField) {
280                 this.m_badminUtilsPasswordChanged = true;
281             } else if(ke.getSource()==this.m_adminUtilsPasswordField) {
282                 this.m_badminUtilsPasswordChanged = true;
283             }
284             this.fireChangesMade();
285         }
286
287         /* (non-Javadoc)
288          * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
289          */

290         public boolean applyChanges() {
291             boolean bOk = true;
292             ConfigSettingsClient service = new ConfigSettingsClient();
293             URL url = null;
294             try {
295                 URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
296                 String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
297                 url = new URL(sURL);
298                 
299             } catch (MalformedURLException e) {
300                 e.printStackTrace();
301             }
302         
303             try {
304                 if(this.m_bShowXMLChanged) {
305                     ConfigProperty configProp = new ConfigProperty("ALLOW_SHOWXML", (String JavaDoc) this.m_showXMLCombo.getSelectedItem());
306                     service.setProperty(url, m_sUsername, m_sPassword, configProp);
307                     this.m_bShowXMLChanged=false;
308                 }
309                 if(this.m_badminUtilsPasswordChanged) {
310                     String JavaDoc sValue = this.m_adminUtilsUsernameTextField.getText() + ":" + new String JavaDoc(this.m_adminUtilsPasswordField.getPassword());
311                     ConfigProperty configProp = new ConfigProperty("UTIL_USER_PWD", sValue);
312                     service.setProperty(url, m_sUsername, m_sPassword, configProp);
313                     this.m_badminUtilsPasswordChanged=false;
314                 }
315             } catch (RemoteException e) {
316                 e.printStackTrace();
317                 bOk = false;
318             } catch (ServiceException e) {
319                 e.printStackTrace();
320                 bOk = false;
321             }
322             return bOk;
323         }
324
325         /* (non-Javadoc)
326          * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
327          */

328         public void removeLayoutComponent(Component arg0) {
329         }
330
331         /* (non-Javadoc)
332          * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
333          */

334         public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
335         }
336
337         /* (non-Javadoc)
338          * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
339          */

340         public void keyPressed(KeyEvent arg0) {
341         }
342
343         /* (non-Javadoc)
344          * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
345          */

346         public void keyTyped(KeyEvent arg0) {
347         }
348
349         /* (non-Javadoc)
350          * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
351          */

352         public void discardChanges() {
353         }
354
355     }
356
Popular Tags