1 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 46 public class ServerConfigDialog extends JDialog implements LayoutManager, ActionListener, ContextListener { 47 48 51 private ArrayList m_listeners = new ArrayList(); 52 53 56 private JTabbedPane m_tabs = null; 57 58 61 private JButton m_buttonOK = null; 62 63 66 private JButton m_buttonCancel = null; 67 68 71 private JButton m_buttonApply = null; 72 73 80 public ServerConfigDialog(Frame arg0, String arg1) 81 throws HeadlessException { 82 super(arg0, arg1, true); 83 this.setup(); 84 } 85 86 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 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 e) { 154 e.printStackTrace(System.err); 155 } finally { 156 StateHandler.getInstance().removeWait("SERVER-PROP-OPEN"); 157 } 158 159 } 160 161 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 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 213 public void addApplyChangesListener(ApplyChangesListener listener) { 214 this.m_listeners.add(listener); 215 } 216 217 222 public void removeApplyChangesListener(ApplyChangesListener listener) { 223 this.m_listeners.remove(listener); 224 } 225 226 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 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 261 public void changesMade() { 262 this.m_buttonApply.setEnabled(true); 263 } 264 265 268 private ServerConfigDialog() throws HeadlessException { 269 super(); 270 } 271 272 276 private ServerConfigDialog(Dialog arg0) throws HeadlessException { 277 super(arg0); 278 } 279 280 285 private ServerConfigDialog(Dialog arg0, boolean arg1) 286 throws HeadlessException { 287 super(arg0, arg1); 288 } 289 290 294 private ServerConfigDialog(Frame arg0) throws HeadlessException { 295 super(arg0); 296 } 297 298 303 private ServerConfigDialog(Frame arg0, boolean arg1) 304 throws HeadlessException { 305 super(arg0, arg1); 306 } 307 308 314 private ServerConfigDialog(Dialog arg0, String arg1, boolean arg2) 315 throws HeadlessException { 316 super(arg0, arg1, arg2); 317 } 318 319 324 private ServerConfigDialog(Dialog arg0, String arg1) 325 throws HeadlessException { 326 super(arg0, arg1); 327 } 328 329 335 private ServerConfigDialog(Frame arg0, String arg1, boolean arg2) 336 throws HeadlessException { 337 super(arg0, arg1, arg2); 338 } 339 340 347 private ServerConfigDialog( 348 Dialog arg0, 349 String arg1, 350 boolean arg2, 351 GraphicsConfiguration arg3) 352 throws HeadlessException { 353 super(arg0, arg1, arg2, arg3); 354 } 355 356 362 private ServerConfigDialog( 363 Frame arg0, 364 String arg1, 365 boolean arg2, 366 GraphicsConfiguration arg3) { 367 super(arg0, arg1, arg2, arg3); 368 } 369 370 373 public void removeLayoutComponent(Component arg0) { 374 } 375 376 379 public void addLayoutComponent(String arg0, Component arg1) { 380 } 381 382 385 public Dimension minimumLayoutSize(Container arg0) { 386 return this.getSize(); 387 } 388 389 392 public Dimension preferredLayoutSize(Container arg0) { 393 return this.getSize(); 394 } 395 396 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
|