Author: jflesch
Date: 2006-07-22 03:30:49 +0000 (Sat, 22 Jul 2006)
New Revision: 9709

Modified:
   trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
   trunk/apps/Thaw/src/thaw/core/Core.java
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
Log:
Make configuration changes safer

Modified: trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/ConfigWindow.java     2006-07-22 03:08:37 UTC 
(rev 9708)
+++ trunk/apps/Thaw/src/thaw/core/ConfigWindow.java     2006-07-22 03:30:49 UTC 
(rev 9709)
@@ -10,6 +10,7 @@
 import javax.swing.JButton;
 import java.util.Observable;
 import java.awt.GridLayout;
+import javax.swing.JOptionPane;

 import thaw.i18n.I18n;

@@ -128,6 +129,19 @@
         * Called when apply button is pressed.
         */
        public void actionPerformed(ActionEvent e) {
+               if(e.getSource() == okButton) {
+                       int ret = 
JOptionPane.showOptionDialog((java.awt.Component)null,
+                                                                      
I18n.getMessage("thaw.warning.isWritingSoApplyLater"),
+                                                                      
I18n.getMessage("thaw.warning.title"),
+                                                                      
JOptionPane.YES_NO_OPTION, 
+                                                                      
JOptionPane.WARNING_MESSAGE,
+                                                                      
(javax.swing.Icon)null,
+                                                                      
(java.lang.Object[])null,
+                                                                      
(java.lang.Object)null);
+                       if(ret == JOptionPane.CLOSED_OPTION || ret > 0)
+                               return;
+               }
+
                if(e.getSource() == okButton
                   || e.getSource() == cancelButton) {


Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-22 03:08:37 UTC (rev 
9708)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-22 03:30:49 UTC (rev 
9709)
@@ -125,7 +125,8 @@

        /**
         * Init the connection to the node.
-        * If a connection is already established, it will disconnect, so this 
function could be call safely later.
+        * If a connection is already established, it will disconnect, so 
+        * if you called canDisconnect() before, then this function can be 
called safely.
         */
        public boolean initNodeConnection() {
                if(getMainWindow() != null)
@@ -136,8 +137,7 @@
                                queueManager.stopScheduler();

                        if(connection != null && connection.isConnected()) {
-                               connection.deleteObserver(this);
-                               connection.disconnect();
+                               disconnect();
                        }

                        connection = new 
FCPConnection(config.getValue("nodeAddress"),
@@ -292,13 +292,32 @@


        /**
+        * Makes things nicely ... :)
+        */
+       public void disconnect() {
+               Logger.info(this, "Disconnecting");
+               connection.deleteObserver(this);
+               connection.disconnect();
+
+               Logger.info(this, "Saving queue state");
+               QueueKeeper.saveQueue(queueManager, "thaw.queue.xml");
+       }
+
+       /**
+        * Check if the connection can be interrupted safely.
+        */
+       public boolean canDisconnect() {
+               return !connection.isWriting();
+       }
+
+       /**
         * End of the world.
         * @param force if true, doesn't check if FCPConnection.isWritting().
         * @see exit()
         */
        public void exit(boolean force) {
                if(!force) {
-                       if(connection.isWriting()) {
+                       if(!canDisconnect()) {
                                int ret = 
JOptionPane.showOptionDialog((java.awt.Component)null,
                                                                       
I18n.getMessage("thaw.warning.isWriting"),
                                                                       
I18n.getMessage("thaw.warning.title"),
@@ -319,13 +338,8 @@
                Logger.info(this, "Stopping plugins ...");
                pluginManager.stopPlugins();

-               Logger.info(this, "Disconnecting ...");
-               connection.deleteObserver(this);
-               connection.disconnect();
+               disconnect();

-               Logger.info(this, "Saving queue state ...");
-               QueueKeeper.saveQueue(queueManager, "thaw.queue.xml");
-
                Logger.info(this, "Saving configuration ...");
                if(!config.saveConfig()) {
                        Logger.error(this, "Config was not saved correctly !");
@@ -342,7 +356,7 @@

                if(o == connection && !connection.isConnected()) {
                        new WarningWindow(this, "We have been disconnected");
-                       connection.deleteObserver(this);
+                       disconnect();
                }
        }


Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-07-22 03:08:37 UTC 
(rev 9708)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-07-22 03:30:49 UTC 
(rev 9709)
@@ -135,4 +135,5 @@

 ## Warnings
 thaw.warning.title=Warning
-thaw.warning.isWriting=Warning ! Thaw is writing data. It would be better to 
quit when thaw will finish. Are you sure you want to quit ?
+thaw.warning.isWriting=Warning ! Thaw is writing data. It would be better to 
quit when thaw will finish. Are you sure that you want to quit ?
+thaw.warning.isWritingSoApplyLater=Warning ! Thaw is exchanging data with the 
node and settings changes makes Thaw disconnect/reconnect. Are you sure that 
you want to change them now ?

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2006-07-22 03:08:37 UTC 
(rev 9708)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2006-07-22 03:30:49 UTC 
(rev 9709)
@@ -135,3 +135,4 @@
 ## Warnings
 thaw.warning.title=Avertissement
 thaw.warning.isWriting=Attention ! Thaw est entrain d'?crire des informations. 
Il serait pr?f?rable de quitter une fois ces envois finis. Etes-vous s?r de 
vouloir quitter ?
+thaw.warning.isWritingSoApplyLater=Attention ! Thaw est entrain d'?changer des 
informations avec la node, et changer des param?tres d?connectes/reconnecte 
Thaw. Etes-vous s?r de vous vouloir les changer maintenant ?


Reply via email to