changeset 1313:987d175c2d74

Generify Filter review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-November/008695.html reviewed-by: omajid
author Mario Torre <neugens.limasoftware@gmail.com>
date Mon, 11 Nov 2013 11:06:04 +0100
parents 4ae82c4623a1
children 0a4e551bef62
files client/core/src/main/java/com/redhat/thermostat/client/core/vmlist/HostFilter.java client/core/src/main/java/com/redhat/thermostat/client/core/vmlist/VMFilter.java client/core/src/main/java/com/redhat/thermostat/client/ui/ReferenceFilter.java client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/LivingHostFilter.java client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/LivingVMFilter.java client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/internal/VMFilterActivator.java client/living-vm-filter/core/src/test/java/com/redhat/thermostat/client/filter/vm/core/internal/VMFilterActivatorTest.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/HostFilterRegistry.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/ReferenceFilterRegistry.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/RegistryFactory.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/VmFilterRegistry.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/FilterManager.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/HostTreeController.java client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImplTest.java client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/HostTreeControllerTest.java
diffstat 16 files changed, 222 insertions(+), 355 deletions(-) [+]
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/core/vmlist/HostFilter.java	Fri Nov 08 14:44:28 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright 2012, 2013 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.client.core.vmlist;
-
-import com.redhat.thermostat.annotations.ExtensionPoint;
-import com.redhat.thermostat.common.Filter;
-import com.redhat.thermostat.storage.core.HostRef;
-
-/**
- * Filter that controls if {@link HostRef}erences can be shown in the
- * reference tree of this Swing Client.
- */
-@ExtensionPoint
-public abstract class HostFilter extends Filter<HostRef>{
-}
--- a/client/core/src/main/java/com/redhat/thermostat/client/core/vmlist/VMFilter.java	Fri Nov 08 14:44:28 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright 2012, 2013 Red Hat, Inc.
- * 
- * This file is part of Thermostat.
- * 
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- * 
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- * 
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- * 
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.client.core.vmlist;
-
-import com.redhat.thermostat.annotations.ExtensionPoint;
-import com.redhat.thermostat.common.Filter;
-import com.redhat.thermostat.storage.core.VmRef;
-
-/**
- * Filter that controls if {@link VmRef}erences can be shown in the
- * reference tree of this Swing Client.
- */
-@ExtensionPoint
-public abstract class VMFilter extends Filter<VmRef> {
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/ReferenceFilter.java	Mon Nov 11 11:06:04 2013 +0100
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012, 2013 Red Hat, Inc.
+ * 
+ * This file is part of Thermostat.
+ * 
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ * 
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ * 
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ * 
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.client.ui;
+
+import com.redhat.thermostat.annotations.ExtensionPoint;
+import com.redhat.thermostat.common.Filter;
+import com.redhat.thermostat.storage.core.Ref;
+
+/**
+ * A specialization of the {@link Filter} interface that can filter
+ * {@link Ref}erences.
+ */
+@ExtensionPoint
+public abstract class ReferenceFilter extends Filter<Ref> {
+
+    /**
+     * Return <code>true</code> if the given filter applies to this reference.
+     */
+    public boolean applies(Ref reference) {
+        return true;
+    }
+}
--- a/client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/LivingHostFilter.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/LivingHostFilter.java	Mon Nov 11 11:06:04 2013 +0100
@@ -36,11 +36,12 @@
 
 package com.redhat.thermostat.client.filter.vm.core;
 
-import com.redhat.thermostat.client.core.vmlist.HostFilter;
+import com.redhat.thermostat.client.ui.ReferenceFilter;
 import com.redhat.thermostat.storage.core.HostRef;
+import com.redhat.thermostat.storage.core.Ref;
 import com.redhat.thermostat.storage.dao.HostInfoDAO;
 
-public class LivingHostFilter extends HostFilter {
+public class LivingHostFilter extends ReferenceFilter {
 
     volatile boolean filterActive = true;
     
@@ -51,10 +52,16 @@
     }
     
     @Override
-    public boolean matches(HostRef ref) {
+    public boolean applies(Ref reference) {
+        return (reference instanceof HostRef);
+    }
+    
+    @Override
+    public boolean matches(Ref ref) {
         if (!filterActive)
             return true;
-       return dao.isAlive(ref);
+        
+        return applies(ref) && dao.isAlive((HostRef) ref);
     }
 
     public void setActive(boolean active) {
--- a/client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/LivingVMFilter.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/LivingVMFilter.java	Mon Nov 11 11:06:04 2013 +0100
@@ -36,13 +36,14 @@
 
 package com.redhat.thermostat.client.filter.vm.core;
 
-import com.redhat.thermostat.client.core.vmlist.VMFilter;
+import com.redhat.thermostat.client.ui.ReferenceFilter;
+import com.redhat.thermostat.storage.core.Ref;
 import com.redhat.thermostat.storage.core.VmRef;
 import com.redhat.thermostat.storage.dao.HostInfoDAO;
 import com.redhat.thermostat.storage.dao.VmInfoDAO;
 import com.redhat.thermostat.storage.model.VmInfo;
 
-public class LivingVMFilter extends VMFilter {
+public class LivingVMFilter extends ReferenceFilter {
 
     volatile boolean filterActive = true;
     
@@ -55,15 +56,25 @@
     }
     
     @Override
-    public boolean matches(VmRef ref) {
-        if (!filterActive)
+    public boolean applies(Ref reference) {
+        return (reference instanceof VmRef);
+    }
+    
+    @Override
+    public boolean matches(Ref ref) {
+        if (!filterActive) {
             return true;
-
+        }
+        
+        if (!applies(ref)) {
+            return false;
+        }
+        
         // if the parent host if not alive, we don't want to hide this
         boolean match = true;
         
-        if (hostDao.isAlive(ref.getHostRef())) {
-            VmInfo vmInfo = vmDao.getVmInfo(ref);
+        if (hostDao.isAlive(((VmRef) ref).getHostRef())) {
+            VmInfo vmInfo = vmDao.getVmInfo((VmRef) ref);
             match = vmInfo.isAlive();
         }
 
--- a/client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/internal/VMFilterActivator.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/living-vm-filter/core/src/main/java/com/redhat/thermostat/client/filter/vm/core/internal/VMFilterActivator.java	Mon Nov 11 11:06:04 2013 +0100
@@ -46,11 +46,10 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
-import com.redhat.thermostat.client.core.vmlist.HostFilter;
-import com.redhat.thermostat.client.core.vmlist.VMFilter;
 import com.redhat.thermostat.client.filter.vm.core.LivingHostFilter;
 import com.redhat.thermostat.client.filter.vm.core.LivingVMFilter;
 import com.redhat.thermostat.client.ui.MenuAction;
+import com.redhat.thermostat.client.ui.ReferenceFilter;
 import com.redhat.thermostat.common.MultipleServiceTracker;
 import com.redhat.thermostat.storage.dao.HostInfoDAO;
 import com.redhat.thermostat.storage.dao.VmInfoDAO;
@@ -81,11 +80,11 @@
                 HostInfoDAO hostDao = (HostInfoDAO) services.get(HostInfoDAO.class.getName());
 
                 LivingHostFilter hostFilter = new LivingHostFilter(hostDao);
-                registration = context.registerService(HostFilter.class.getName(), hostFilter, null);
+                registration = context.registerService(ReferenceFilter.class.getName(), hostFilter, null);
                 registeredServices.add(registration);
 
                 LivingVMFilter vmFilter = new LivingVMFilter(vmDao, hostDao);
-                registration = context.registerService(VMFilter.class.getName(), vmFilter, null);
+                registration = context.registerService(ReferenceFilter.class.getName(), vmFilter, null);
                 registeredServices.add(registration);
 
                 LivingVMFilterMenuAction vmMenu = new LivingVMFilterMenuAction(vmFilter);
--- a/client/living-vm-filter/core/src/test/java/com/redhat/thermostat/client/filter/vm/core/internal/VMFilterActivatorTest.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/living-vm-filter/core/src/test/java/com/redhat/thermostat/client/filter/vm/core/internal/VMFilterActivatorTest.java	Mon Nov 11 11:06:04 2013 +0100
@@ -41,11 +41,10 @@
 
 import org.junit.Test;
 
-import com.redhat.thermostat.client.core.vmlist.HostFilter;
-import com.redhat.thermostat.client.core.vmlist.VMFilter;
 import com.redhat.thermostat.client.filter.vm.core.LivingHostFilter;
 import com.redhat.thermostat.client.filter.vm.core.LivingVMFilter;
 import com.redhat.thermostat.client.ui.MenuAction;
+import com.redhat.thermostat.client.ui.ReferenceFilter;
 import com.redhat.thermostat.storage.dao.HostInfoDAO;
 import com.redhat.thermostat.storage.dao.VmInfoDAO;
 import com.redhat.thermostat.testutils.StubBundleContext;
@@ -65,8 +64,8 @@
         ctx.registerService(HostInfoDAO.class, hostDao, null);
 
         assertTrue(ctx.isServiceRegistered(MenuAction.class.getName(), LivingVMFilterMenuAction.class));
-        assertTrue(ctx.isServiceRegistered(VMFilter.class.getName(), LivingVMFilter.class));
-        assertTrue(ctx.isServiceRegistered(HostFilter.class.getName(), LivingHostFilter.class));
+        assertTrue(ctx.isServiceRegistered(ReferenceFilter.class.getName(), LivingVMFilter.class));
+        assertTrue(ctx.isServiceRegistered(ReferenceFilter.class.getName(), LivingHostFilter.class));
     }
 
 }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/HostFilterRegistry.java	Fri Nov 08 14:44:28 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * Copyright 2012, 2013 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.client.swing.internal;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-
-import com.redhat.thermostat.client.core.vmlist.HostFilter;
-import com.redhat.thermostat.common.ThermostatExtensionRegistry;
-
-public class HostFilterRegistry extends ThermostatExtensionRegistry<HostFilter> {
-
-    private static final String FILTER = "(&(" + Constants.OBJECTCLASS + "=" +
-            HostFilter.class.getName() + "))";
-
-    public HostFilterRegistry(BundleContext context) throws InvalidSyntaxException {
-        super(context, FILTER, HostFilter.class);
-    }
-}
-
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImpl.java	Mon Nov 11 11:06:04 2013 +0100
@@ -169,8 +169,7 @@
     };
 
     private VmInformationControllerProvider vmInfoControllerProvider;
-    private VmFilterRegistry vmFilterRegistry;
-    private HostFilterRegistry hostFilterRegistry;
+    private ReferenceFilterRegistry filterRegistry;
     private FilterManager filterManager;
 
     private DecoratorRegistryController decoratorController;
@@ -191,8 +190,7 @@
         decoratorController = registryFactory.createDecoratorController();
 
         try {
-            vmFilterRegistry = registryFactory.createVmFilterRegistry();
-            hostFilterRegistry = registryFactory.createHostFilterRegistry();
+            filterRegistry = registryFactory.createFilterRegistry();
             
             menuRegistry = registryFactory.createMenuRegistry();
             vmInfoRegistry = registryFactory.createVMInformationRegistry();
@@ -371,8 +369,7 @@
         menuRegistry.start();
 
         HostTreeController hostTreeController = view.getHostTreeController();
-        filterManager = new FilterManager(vmFilterRegistry, hostFilterRegistry,
-                                          hostTreeController);
+        filterManager = new FilterManager(filterRegistry, hostTreeController);
 
         filterManager.start();
         
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/ReferenceFilterRegistry.java	Mon Nov 11 11:06:04 2013 +0100
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2012, 2013 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.client.swing.internal;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+
+import com.redhat.thermostat.client.ui.ReferenceFilter;
+import com.redhat.thermostat.common.ThermostatExtensionRegistry;
+
+public class ReferenceFilterRegistry extends ThermostatExtensionRegistry<ReferenceFilter> {
+
+    private static final String FILTER = "(&(" + Constants.OBJECTCLASS + "=" +
+            ReferenceFilter.class.getName() + "))";
+
+    public ReferenceFilterRegistry(BundleContext context) throws InvalidSyntaxException {
+        super(context, FILTER, ReferenceFilter.class);
+    }
+}
+
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/RegistryFactory.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/RegistryFactory.java	Mon Nov 11 11:06:04 2013 +0100
@@ -50,12 +50,8 @@
         this.context = context;
     }
 
-    HostFilterRegistry createHostFilterRegistry() throws InvalidSyntaxException {
-        return new HostFilterRegistry(context);
-    }
-
-    VmFilterRegistry createVmFilterRegistry() throws InvalidSyntaxException {
-        return new VmFilterRegistry(context);
+    ReferenceFilterRegistry createFilterRegistry() throws InvalidSyntaxException {
+        return new ReferenceFilterRegistry(context);
     }
     
     MenuRegistry createMenuRegistry() throws InvalidSyntaxException {
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/VmFilterRegistry.java	Fri Nov 08 14:44:28 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright 2012, 2013 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.client.swing.internal;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-
-import com.redhat.thermostat.client.core.vmlist.VMFilter;
-import com.redhat.thermostat.common.ThermostatExtensionRegistry;
-
-public class VmFilterRegistry extends ThermostatExtensionRegistry<VMFilter> {
-
-    private static final String FILTER = "(&(" + Constants.OBJECTCLASS + "=" +
-            VMFilter.class.getName() + "))";
-
-    public VmFilterRegistry(BundleContext context) throws InvalidSyntaxException {
-        super(context, FILTER, VMFilter.class);
-    }
-}
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/FilterManager.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/FilterManager.java	Mon Nov 11 11:06:04 2013 +0100
@@ -36,10 +36,8 @@
 
 package com.redhat.thermostat.client.swing.internal.vmlist.controller;
 
-import com.redhat.thermostat.client.core.vmlist.HostFilter;
-import com.redhat.thermostat.client.core.vmlist.VMFilter;
-import com.redhat.thermostat.client.swing.internal.HostFilterRegistry;
-import com.redhat.thermostat.client.swing.internal.VmFilterRegistry;
+import com.redhat.thermostat.client.swing.internal.ReferenceFilterRegistry;
+import com.redhat.thermostat.client.ui.ReferenceFilter;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.ThermostatExtensionRegistry;
@@ -47,57 +45,36 @@
 
 public class FilterManager {
     
-    private ActionListener<ThermostatExtensionRegistry.Action> hostFilterListener;
-    private ActionListener<ThermostatExtensionRegistry.Action> vmFilterListener;
+    private ActionListener<ThermostatExtensionRegistry.Action> filterListener;
 
-    private VmFilterRegistry vmFilterRegistry;
-    private HostFilterRegistry hostFilterRegistry;
+    private ReferenceFilterRegistry filterRegistry;
     
-    public FilterManager(VmFilterRegistry vmFilterRegistry,
-                         HostFilterRegistry hostFilterRegistry,
+    public FilterManager(ReferenceFilterRegistry filterRegistry,
                          final HostTreeController hostController)
     {
         
-        hostFilterListener = new ActionListener<ThermostatExtensionRegistry.Action>() {
+        filterListener = new ActionListener<ThermostatExtensionRegistry.Action>() {
             @Override
             public void actionPerformed(ActionEvent<Action> actionEvent) {
                 if (actionEvent.getActionId() == Action.SERVICE_ADDED){
-                    hostController.addHostFilter((HostFilter) actionEvent.getPayload());
+                    hostController.addFilter((ReferenceFilter) actionEvent.getPayload());
                 } else {
-                    hostController.removeHostFilter((HostFilter) actionEvent.getPayload());
-                }
-            }
-        };
-        vmFilterListener = new  ActionListener<ThermostatExtensionRegistry.Action>() {
-            @Override
-            public void actionPerformed(ActionEvent<Action> actionEvent) {
-                if (actionEvent.getActionId() == Action.SERVICE_ADDED){
-                    hostController.addVMFilter((VMFilter) actionEvent.getPayload());
-                } else {
-                    hostController.removeVMFilter((VMFilter) actionEvent.getPayload());
+                    hostController.removeFilter((ReferenceFilter) actionEvent.getPayload());
                 }
             }
         };
         
-        this.vmFilterRegistry = vmFilterRegistry;
-        this.hostFilterRegistry = hostFilterRegistry;
+        this.filterRegistry = filterRegistry;
     }
     
     public void start() {
-        hostFilterRegistry.addActionListener(hostFilterListener);
-        hostFilterRegistry.start();
-
-        vmFilterRegistry.addActionListener(vmFilterListener);
-        vmFilterRegistry.start();
+        filterRegistry.addActionListener(filterListener);
+        filterRegistry.start();
     }
     
     public void stop() {
-        hostFilterRegistry.removeActionListener(hostFilterListener);
-        hostFilterListener = null;
-        hostFilterRegistry.stop();
-
-        vmFilterRegistry.removeActionListener(vmFilterListener);
-        vmFilterListener = null;
-        vmFilterRegistry.stop();
+        filterRegistry.removeActionListener(filterListener);
+        filterListener = null;
+        filterRegistry.stop();
     }
 }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/HostTreeController.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/HostTreeController.java	Mon Nov 11 11:06:04 2013 +0100
@@ -41,9 +41,6 @@
 
 import javax.swing.SwingUtilities;
 
-import com.redhat.thermostat.client.core.vmlist.HostFilter;
-import com.redhat.thermostat.client.core.vmlist.VMFilter;
-
 import com.redhat.thermostat.client.swing.internal.accordion.Accordion;
 import com.redhat.thermostat.client.swing.internal.accordion.AccordionComponent;
 import com.redhat.thermostat.client.swing.internal.accordion.AccordionComponentEvent;
@@ -52,17 +49,14 @@
 import com.redhat.thermostat.client.swing.internal.accordion.AccordionModel;
 import com.redhat.thermostat.client.swing.internal.accordion.AccordionModelChangeListener;
 import com.redhat.thermostat.client.swing.internal.accordion.ItemSelectedEvent;
-
 import com.redhat.thermostat.client.swing.internal.vmlist.HostTreeComponentFactory;
 import com.redhat.thermostat.client.swing.internal.vmlist.ReferenceProvider;
-
+import com.redhat.thermostat.client.ui.ReferenceFilter;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.ActionNotifier;
-
 import com.redhat.thermostat.common.Filter;
 import com.redhat.thermostat.common.Filter.FilterEvent;
-
 import com.redhat.thermostat.storage.core.HostRef;
 import com.redhat.thermostat.storage.core.Ref;
 import com.redhat.thermostat.storage.core.VmRef;
@@ -78,8 +72,7 @@
     
     private final ActionNotifier<ReferenceSelection> referenceNotifier;
 
-    private CopyOnWriteArrayList<Filter<HostRef>> hostFilters;
-    private CopyOnWriteArrayList<Filter<VmRef>> vmFilters;
+    private CopyOnWriteArrayList<ReferenceFilter> filters;
     
     private FilterListener filterListener;
     
@@ -120,8 +113,7 @@
         
         filterListener = new FilterListener();
         
-        hostFilters = new CopyOnWriteArrayList<>();
-        vmFilters = new CopyOnWriteArrayList<>();
+        filters = new CopyOnWriteArrayList<>();
         
         fullModel = new AccordionModel<>();
         fullModel.addAccordionModelChangeListener(new AccordionModelProxy());
@@ -151,7 +143,7 @@
             @Override
             public void run() {
                 fullModel.addHeader(host);
-                if (filter(hostFilters, host)) {
+                if (filter(filters, host)) {
                     proxyModel.removeHeader(host);
                 }
             }
@@ -162,7 +154,7 @@
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
-                if (filter(hostFilters, host)) {
+                if (filter(filters, host)) {
                     proxyModel.removeHeader(host);
                 }
                 fireDecoratorChanged();
@@ -205,24 +197,26 @@
                 
                 // adding a vm may add an host, so we need to be sure
                 // the host is not filtered before checking the vm itself
-                if (filter(hostFilters, vm.getHostRef())) {
+                if (filter(filters, vm.getHostRef())) {
                     
                     // this will also remove all the vm, so we can skip the
                     // next filtering step
                     proxyModel.removeHeader(vm.getHostRef());
                     
                 } else
-                    if (filter(vmFilters, vm)) {
+                    if (filter(filters, vm)) {
                     proxyModel.removeComponent(vm.getHostRef(), vm);
                 }
             }
         });
     }
 
-    private <R> boolean filter(CopyOnWriteArrayList<Filter<R>> filters, R ref) {
-        for (Filter<R> filter : filters) {
-            if (!filter.matches(ref)) {
-                return true;
+    private boolean filter(CopyOnWriteArrayList<ReferenceFilter> filters, Ref ref) {
+        for (ReferenceFilter filter : filters) {
+            if (filter.applies(ref)) {
+                if (!filter.matches(ref)) {
+                    return true;
+                }
             }
         }
         return false;
@@ -275,7 +269,7 @@
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
-                if (filter(vmFilters, vm)) {
+                if (filter(filters, vm)) {
                     proxyModel.removeComponent(vm.getHostRef(), vm);
                 }
                 fireDecoratorChanged();
@@ -288,30 +282,6 @@
         decoratorManager.getMainLabelDecoratorListener().fireDecorationChanged();
         decoratorManager.getIconDecoratorListener().fireDecorationChanged();
     }
-            
-    public void addHostFilter(HostFilter filter) {
-        hostFilters.add(filter);
-        filter.addFilterEventListener(filterListener);
-        rebuildTree();
-    }
-
-    public void removeHostFilter(HostFilter filter) {
-        hostFilters.remove(filter);
-        filter.removeFilterEventListener(filterListener);
-        rebuildTree();
-    }
-
-    public void addVMFilter(VMFilter filter) {
-        vmFilters.add(filter);
-        filter.addFilterEventListener(filterListener);
-        rebuildTree();
-    }
-
-    public void removeVMFilter(VMFilter filter) {
-        vmFilters.remove(filter);
-        filter.removeFilterEventListener(filterListener);
-        rebuildTree();
-    }
     
     private synchronized void rebuildTree() {
         Ref selected = null;
@@ -328,7 +298,7 @@
         AccordionModel<RefPayload<HostRef>, RefPayload<VmRef>> _model = new AccordionModel<>();
         List<HostRef> hosts = fullModel.getHeaders();
         for (HostRef host : hosts) {
-            if (!filter(hostFilters, host)) {
+            if (!filter(filters, host)) {
                 
                 RefPayload<HostRef> hostPayload = new RefPayload<>(); 
                 hostPayload.reference = host;
@@ -337,7 +307,7 @@
                 _model.addHeader(hostPayload);
                 List<VmRef> vms = fullModel.getComponents(host);
                 for (VmRef vm : vms) {
-                    if (!filter(vmFilters, vm)) {
+                    if (!filter(filters, vm)) {
                         
                         RefPayload<VmRef> vmPayload = new RefPayload<>(); 
                         vmPayload.reference = vm;                        
@@ -387,4 +357,16 @@
     public DecoratorManager getDecoratorManager() {
         return decoratorManager;
     }
+
+    public void addFilter(ReferenceFilter filter) {
+        filters.add(filter);
+        filter.addFilterEventListener(filterListener);
+        rebuildTree();
+    }
+
+    public void removeFilter(ReferenceFilter filter) {
+        filters.remove(filter);
+        filter.removeFilterEventListener(filterListener);
+        rebuildTree();
+    }
 }
\ No newline at end of file
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImplTest.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/MainWindowControllerImplTest.java	Mon Nov 11 11:06:04 2013 +0100
@@ -98,8 +98,7 @@
     private HostInfoDAO mockHostsDAO;
     private VmInfoDAO mockVmsDAO;
 
-    private HostFilterRegistry hostFilterRegistry;
-    private VmFilterRegistry vmFilterRegistry;
+    private ReferenceFilterRegistry hostFilterRegistry;
 
     private VMInformationRegistry vmInfoRegistry;
     private MenuRegistry menus;
@@ -190,8 +189,7 @@
         when(view.getNotifier()).thenReturn(notifier);
         
         RegistryFactory registryFactory = mock(RegistryFactory.class);
-        hostFilterRegistry = mock(HostFilterRegistry.class);
-        vmFilterRegistry = mock(VmFilterRegistry.class);
+        hostFilterRegistry = mock(ReferenceFilterRegistry.class);
 
         vmInfoRegistry = mock(VMInformationRegistry.class);
         menus = mock(MenuRegistry.class);
@@ -200,17 +198,13 @@
         decoratorController = mock(DecoratorRegistryController.class);
         
         when(registryFactory.createMenuRegistry()).thenReturn(menus);
-        when(registryFactory.createHostFilterRegistry()).thenReturn(hostFilterRegistry);
-        when(registryFactory.createVmFilterRegistry()).thenReturn(vmFilterRegistry);
+        when(registryFactory.createFilterRegistry()).thenReturn(hostFilterRegistry);
         when(registryFactory.createVMInformationRegistry()).thenReturn(vmInfoRegistry);
         when(registryFactory.createDecoratorController()).thenReturn(decoratorController);
         
         ArgumentCaptor<ActionListener> grabHostFiltersListener = ArgumentCaptor.forClass(ActionListener.class);
         doNothing().when(hostFilterRegistry).addActionListener(grabHostFiltersListener.capture());
 
-        ArgumentCaptor<ActionListener> grabVmFiltersListener = ArgumentCaptor.forClass(ActionListener.class);
-        doNothing().when(vmFilterRegistry).addActionListener(grabVmFiltersListener.capture());
-        
         ArgumentCaptor<ActionListener> grabInfoRegistry = ArgumentCaptor.forClass(ActionListener.class);
         doNothing().when(vmInfoRegistry).addActionListener(grabInfoRegistry.capture());
 
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/HostTreeControllerTest.java	Fri Nov 08 14:44:28 2013 +0100
+++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/vmlist/controller/HostTreeControllerTest.java	Mon Nov 11 11:06:04 2013 +0100
@@ -40,7 +40,6 @@
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.verify;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
@@ -54,14 +53,14 @@
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import com.redhat.thermostat.client.core.vmlist.HostFilter;
-import com.redhat.thermostat.client.core.vmlist.VMFilter;
 import com.redhat.thermostat.client.swing.internal.accordion.Accordion;
 import com.redhat.thermostat.client.swing.internal.accordion.AccordionModel;
 import com.redhat.thermostat.client.swing.internal.vmlist.HostTreeComponentFactory;
 import com.redhat.thermostat.client.ui.ReferenceFieldIconDecorator;
 import com.redhat.thermostat.client.ui.ReferenceFieldLabelDecorator;
+import com.redhat.thermostat.client.ui.ReferenceFilter;
 import com.redhat.thermostat.storage.core.HostRef;
+import com.redhat.thermostat.storage.core.Ref;
 import com.redhat.thermostat.storage.core.VmRef;
 
 public class HostTreeControllerTest {
@@ -115,16 +114,22 @@
         }
     }
     
-    private abstract class TestHostFilter extends HostFilter {
+    private abstract class TestHostFilter extends ReferenceFilter {
         boolean filter;
         @Override
-        public final boolean matches(HostRef toMatch) {
+        public final boolean matches(Ref toMatch) {
+            
             if (!filter) return true;
             
             return matchesImpl(toMatch);
         }
         
-        protected abstract boolean matchesImpl(HostRef toMatch);
+        @Override
+        public boolean applies(Ref reference) {
+            return (reference instanceof HostRef);
+        }
+        
+        protected abstract boolean matchesImpl(Ref toMatch);
         
         public void toggle() {
             filter = !this.filter;
@@ -132,21 +137,15 @@
         }
     }
     
-    private abstract class TestVMFilter extends VMFilter {
+    private abstract class TestVMFilter extends TestHostFilter {
         boolean filter;
+        
         @Override
-        public final boolean matches(VmRef toMatch) {
-            if (!filter) return true;
-            
-            return matchesImpl(toMatch);
+        public boolean applies(Ref reference) {
+            return (reference instanceof VmRef);
         }
-        
-        protected abstract boolean matchesImpl(VmRef toMatch);
-        
-        public void toggle() {
-            filter = !this.filter;
-            notify(FilterEvent.FILTER_CHANGED);
-        }
+
+        protected abstract boolean matchesImpl(Ref toMatch);
     }
     
     @Test
@@ -175,14 +174,14 @@
         
         TestHostFilter filter1 = new TestHostFilter() {
             @Override
-            protected boolean matchesImpl(HostRef toMatch) {
+            protected boolean matchesImpl(Ref toMatch) {
                 return (toMatch.getName().equals("0"));
             }
         };
         // enable the filter first
         filter1.toggle();
         
-        controller.addHostFilter(filter1);
+        controller.addFilter(filter1);
         
         waitForSwing();
         
@@ -206,12 +205,12 @@
         // now on with vms, filter not enabled at first
         TestVMFilter filter2 = new TestVMFilter() {
             @Override
-            protected boolean matchesImpl(VmRef toMatch) {
+            protected boolean matchesImpl(Ref toMatch) {
                 return (toMatch.getName().equals("vm0"));
             }
         };
         
-        controller.addVMFilter(filter2);
+        controller.addFilter(filter2);
         
         waitForSwing();
         
@@ -249,6 +248,9 @@
         components  = proxyModel.getComponents(host1);
         assertTrue(components.isEmpty());
         
+        headers = proxyModel.getHeaders();
+        assertEquals(2, headers.size());
+        
         // now test if controller reacts to updates
         
         controller.updateVMStatus(vm0);
@@ -282,7 +284,7 @@
 
         TestHostFilter filter = new TestHostFilter() {
             @Override
-            protected boolean matchesImpl(HostRef toMatch) {
+            protected boolean matchesImpl(Ref toMatch) {
                 return (toMatch.getName().equals("0"));
             }
         };
@@ -296,7 +298,7 @@
         waitForSwing();
         
         // filter out host 0, then add the vms
-        controller.addHostFilter(filter);
+        controller.addFilter(filter);
         
         waitForSwing();