Author: jflesch
Date: 2007-09-03 22:34:34 +0000 (Mon, 03 Sep 2007)
New Revision: 14945

Modified:
   trunk/apps/Thaw/src/thaw/core/LibraryPlugin.java
   trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java
Log:
Make the indexWebGrapher plugin unregister from the hsqldb plugin correctly

Modified: trunk/apps/Thaw/src/thaw/core/LibraryPlugin.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/LibraryPlugin.java    2007-09-03 22:23:09 UTC 
(rev 14944)
+++ trunk/apps/Thaw/src/thaw/core/LibraryPlugin.java    2007-09-03 22:34:34 UTC 
(rev 14945)
@@ -1,5 +1,11 @@
 package thaw.core;

+import thaw.core.Logger;
+
+import java.util.Vector;
+import java.util.Iterator;
+
+
 /**
  * Plugins adding functionality for other plugins should extends this class.
  * Then plugins using these library plugins will be able to register them one 
by one.
@@ -7,24 +13,53 @@
  * realStop() is called when the last plugin has unregistered itself.
  */
 public abstract class LibraryPlugin implements Plugin {
-       private int nmbRegistered = 0;
+       private Vector registered = null;

        public abstract boolean run(Core core);
        public abstract boolean stop();

+
        public void registerChild(final Plugin child) {
-               nmbRegistered++;
+               if (registered == null)
+                       registered = new Vector();

-               if(nmbRegistered == 1)
+               if (registered.size() == 0)
                        realStart();
+
+               while (registered.remove(child)) {
+                       Logger.warning(this, "Plugin '"+
+                                      child.getClass().getName()+
+                                      "' was already registered to '"+
+                                      this.getClass().getName()+
+                                      "'");
+               }
+
+               registered.add(child);
        }


        public void unregisterChild(final Plugin child) {
-               nmbRegistered--;
+               if (registered == null) {
+                       Logger.warning(this, "Abnormal : 
'"+this.getClass().getName()+
+                                      "' is unregistering child plugin '"+
+                                      child.getClass().getName()+
+                                      "' but "+
+                                      "no plugin was registered ?!");
+                       registered = new Vector();
+               }

-               if(nmbRegistered == 0)
+               while (registered.remove(child)) { }
+
+               if(registered.size() == 0) {
                        realStop();
+               } else {
+                       Logger.debug(this, "unregisterChild() : Children still 
registered to "+
+                                    "'"+this.getClass().getName()+"' : ");
+                       for (Iterator it = registered.iterator();
+                            it.hasNext();) {
+                               Logger.debug(this, 
it.next().getClass().getName());
+                       }
+               }
        }

        public abstract void realStart();

Modified: trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java       2007-09-03 
22:23:09 UTC (rev 14944)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java       2007-09-03 
22:34:34 UTC (rev 14945)
@@ -131,6 +131,7 @@

        public boolean stop() {
                core.getMainWindow().removeTab(tabPanel);
+               db.unregisterChild(this);

                return true;
        }


Reply via email to