1 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 43 public class DevelopmentServerConfigOptions 44 extends AbstractServerConfigOptions 45 implements LayoutManager, ActionListener, ApplyChangesListener, KeyListener { 46 47 50 private JTextArea m_descriptionTextArea = null; 51 52 55 private JLabel m_showXMLLabel = null; 56 57 60 private JComboBox m_showXMLCombo = null; 61 62 65 private boolean m_bShowXMLChanged = false; 66 67 70 private JLabel m_adminUtilsUsernameLabel = null; 71 72 75 private JTextField m_adminUtilsUsernameTextField = null; 76 77 80 private JLabel m_adminUtilsPasswordLabel = null; 81 82 85 private JPasswordField m_adminUtilsPasswordField = null; 86 87 90 private boolean m_badminUtilsPasswordChanged = false; 91 92 95 private String m_sUsername = null; 96 97 100 private String m_sPassword = null; 101 102 103 public DevelopmentServerConfigOptions() { 104 super(null); 105 this.setup(); 106 } 107 108 113 public DevelopmentServerConfigOptions(ServerConfigDialog dialog) { 114 super(dialog); 115 dialog.addApplyChangesListener(this); 116 this.setup(); 117 } 118 119 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 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 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 []{"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 sName = ""; 186 String 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 217 public Dimension getPreferredSize() { 218 return new Dimension(this.getParent().getSize().width-50, 100); 219 } 220 221 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 254 public Dimension minimumLayoutSize(Container arg0) { 255 return null; 256 } 257 258 261 public Dimension preferredLayoutSize(Container arg0) { 262 return null; 263 } 264 265 268 public void actionPerformed(ActionEvent ae) { 269 if(ae.getActionCommand().equals("SHOWXML")) { 270 this.m_bShowXMLChanged = true; 271 } 272 this.fireChangesMade(); 273 } 274 275 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 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 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 ) 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 sValue = this.m_adminUtilsUsernameTextField.getText() + ":" + new String (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 328 public void removeLayoutComponent(Component arg0) { 329 } 330 331 334 public void addLayoutComponent(String arg0, Component arg1) { 335 } 336 337 340 public void keyPressed(KeyEvent arg0) { 341 } 342 343 346 public void keyTyped(KeyEvent arg0) { 347 } 348 349 352 public void discardChanges() { 353 } 354 355 } 356
| Popular Tags
|