changeset 924:c739844c6d68

Skip registering the system ContextAction Reviewed-by: vanaltj, jerboaa, ebaron Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-December/004956.html
author Omair Majid <omajid@redhat.com>
date Mon, 21 Jan 2013 12:17:46 -0500
parents 3b9daf9ded8f
children 259c60624174
files client/core/src/main/java/com/redhat/thermostat/client/osgi/service/ContextAction.java client/core/src/main/java/com/redhat/thermostat/client/osgi/service/MenuAction.java client/core/src/main/java/com/redhat/thermostat/client/osgi/service/VMContextAction.java client/swing/src/main/java/com/redhat/thermostat/client/swing/MenuHelper.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/GUIClientCommand.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/osgi/ContextActionServiceProvider.java client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/GUIClientCommandTest.java killvm/client-swing/src/main/java/com/redhat/thermostat/killvm/client/internal/Activator.java
diffstat 8 files changed, 97 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/ContextAction.java	Mon Jan 21 16:33:51 2013 +0100
+++ b/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/ContextAction.java	Mon Jan 21 12:17:46 2013 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Red Hat, Inc.
+ * Copyright 2013 Red Hat, Inc.
  *
  * This file is part of Thermostat.
  *
@@ -36,31 +36,32 @@
 
 package com.redhat.thermostat.client.osgi.service;
 
-import com.redhat.thermostat.annotations.ExtensionPoint;
-
 /**
- * Marker service for context menu actions.
- * <br /><br />
- * 
- * Each specific subclass defines the selected entry points for the context
- * menus.
- * <br /><br />
+ * Parent interface for all context-sensitive actions.
+ * <p>
+ * {@code ContextAction}s are executed once the user selects the appropriate UI
+ * elements in the view and triggers the registered action.
+ * <p>
+ * The name of the action (as returned by {@link #getName()}) is likely to be
+ * user-visible and should be localized.
+ *
+ * <h2>Implementation Notes</h2>
+ * <p>
+ * The following information is specific to the current release and may change
+ * in a future release.
+ * <p>
+ * The swing client uses {@code ContextAction}s to mostly implement menus. Some
+ * of these menus are shown when a user right-clicks on a widget, but some are
+ * associated with a window.
  * 
- * Context actions are executed once the user select the appropriate UI elements
- * in the main framework view and trigger the registered action.
- * <br /><br />
- * 
- * An empty {@link ContextAction} is instantiated within the framework at
- * startup, so services implementing specific actions interfaces should track
- * for a {@link ContextAction} service to be active in the framework before
- * adding themselves.
- * <br /><br />
- * 
- * <strong>Exported entry point</strong>: com.redhat.thermostat.client.osgi.service.ContextAction
+ * @see MenuAction
+ * @see VMContextAction
  */
-@ExtensionPoint
 public interface ContextAction {
     
+    /** A user-visible name for this action */
     String getName();
+
+    /** A user-visible description for this action */
     String getDescription();
 }
--- a/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/MenuAction.java	Mon Jan 21 16:33:51 2013 +0100
+++ b/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/MenuAction.java	Mon Jan 21 12:17:46 2013 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Red Hat, Inc.
+ * Copyright 2013 Red Hat, Inc.
  *
  * This file is part of Thermostat.
  *
@@ -38,11 +38,21 @@
 import com.redhat.thermostat.annotations.ExtensionPoint;
 
 /**
- * Allows plugins to register menu items.
+ * {@code MenuAction}s are used to create top-level menu items in the main
+ * window.
  * <p>
- * To register a menu item for for the menu "File" in thermostat client window,
- * register a service that implements this class with the property
- * "parentMenu" set to "File".
+ * Plugins can register menu items by creating classes that implement this
+ * interface and registering them as OSGi services. To register a menu item for
+ * for the menu "File" in thermostat client window, register a service that
+ * returns <code> {"File", getName()}</code> from {@link #getPath()}.
+ *
+ * <h2>Implementation Notes</h2>
+ * <p>
+ * The following information is specific to the current release and may change
+ * in a future release.
+ * <p>
+ * The swing client uses {@code MenuActions}s to implement top-level menus in
+ * the main window only.
  */
 @ExtensionPoint
 public interface MenuAction extends ContextAction {
@@ -51,13 +61,23 @@
         CHECK,
         RADIO,
         STANDARD
-    };
+    }
+
+    /** The user-visible text displayed as the menu item. */
+    @Override
+    public String getName();
+
+    /** A user-visible description of what this {@code MenuAction} does. */
+    @Override
+    public String getDescription();
 
     /** Invoked when the user selects this menu item */
     void execute();
 
+    /** The type of the menu (radio, check, standard) */
     Type getType();
 
     /** The path to the menu action. The last element must equal getName() */
     String[] getPath();
+
 }
--- a/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/VMContextAction.java	Mon Jan 21 16:33:51 2013 +0100
+++ b/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/VMContextAction.java	Mon Jan 21 12:17:46 2013 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Red Hat, Inc.
+ * Copyright 2013 Red Hat, Inc.
  *
  * This file is part of Thermostat.
  *
@@ -41,12 +41,53 @@
 import com.redhat.thermostat.common.dao.VmRef;
 
 /**
- * A context action for VMs
+ * {@code VMContextAction}s provide actions that are associated with Java
+ * Virtual Machines and can be invoked by users. The exact position and
+ * appearance of these {@code VMContextAction}s varies based on the client
+ * implementation.
+ * <p>
+ * Plugins can register implementation of this interface as OSGi services to
+ * provide additional {@code VMContextAction}s.
+ * <p>
+ * <h2>Implementation Note</h2>
+ * <p>
+ * The following information is specific to the current release and may change
+ * in a future release.
+ * <p>
+ * The swing client uses instances of this class to provide menu items in the
+ * Host/VM tree. The menu is shown when a user right-clicks a VM in the Host/VM
+ * tree. A menu item for every {@link VMContextAction} is added, if the
+ * {@code Filter} matches, to this menu. Selecting a menu item invokes the
+ * corresponding {@code VMContextAction}.
  */
 @ExtensionPoint
 public interface VMContextAction extends ContextAction {
 
-    void execute(VmRef referece);
+    /**
+     * A user-visible name for this {@code VMContextAction}. Should be
+     * localized.
+     */
+    @Override
+    public String getName();
 
+    /**
+     * A user-visible description for {@code VMContextAction}. Should be
+     * localized.
+     */
+    @Override
+    public String getDescription();
+
+    /**
+     * Invoked when the user selects this context item
+     *
+     * @param reference specifies the vm that this context action was invoked
+     * on.
+     */
+    void execute(VmRef reference);
+
+    /**
+     * The {@link Filter} returned by this method is used to select what VMs
+     * this {@code VMContextAction} is applicable to.
+     */
     Filter<VmRef> getFilter();
 }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/MenuHelper.java	Mon Jan 21 16:33:51 2013 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/MenuHelper.java	Mon Jan 21 12:17:46 2013 -0500
@@ -215,8 +215,6 @@
     private static final class Menu {
         private Object swingDelegate;
 
-        public Menu() { /* no op */}
-
         public Menu(JMenuItem actual) {
             this.swingDelegate = actual;
         }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/GUIClientCommand.java	Mon Jan 21 16:33:51 2013 +0100
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/GUIClientCommand.java	Mon Jan 21 12:17:46 2013 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Red Hat, Inc.
+ * Copyright 2013 Red Hat, Inc.
  *
  * This file is part of Thermostat.
  *
@@ -36,36 +36,22 @@
 
 package com.redhat.thermostat.client.swing.internal;
 
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-
-import com.redhat.thermostat.client.osgi.service.ContextAction;
-import com.redhat.thermostat.client.swing.internal.osgi.ContextActionServiceProvider;
 import com.redhat.thermostat.common.cli.CommandContext;
 import com.redhat.thermostat.common.cli.CommandException;
 import com.redhat.thermostat.common.cli.SimpleCommand;
 
 public class GUIClientCommand extends SimpleCommand {
 
-    private BundleContext context;
     private Main clientMain;
 
     public GUIClientCommand(Main clientMain) {
-        this(clientMain, FrameworkUtil.getBundle(GUIClientCommand.class).getBundleContext());
-    }
-    
-    GUIClientCommand(Main clientMain, BundleContext context) {
-        this.context = context;
         this.clientMain = clientMain;
     }
-    
+
     @Override
     public void run(CommandContext ctx) throws CommandException {
-        context.registerService(ContextAction.class.getName(), new ContextActionServiceProvider(), null);
-        
         // this blocks, everything else needs to be done before
         clientMain.run();
-
     }
 
     @Override
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/osgi/ContextActionServiceProvider.java	Mon Jan 21 16:33:51 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright 2012 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.osgi;
-
-import com.redhat.thermostat.client.osgi.service.ContextAction;
-
-public class ContextActionServiceProvider implements ContextAction {
-  
-    @Override
-    public String getName() {
-        return "system context";
-    }
-
-    @Override
-    public String getDescription() {
-        return "system context";
-    }
-}
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/GUIClientCommandTest.java	Mon Jan 21 16:33:51 2013 +0100
+++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/GUIClientCommandTest.java	Mon Jan 21 12:17:46 2013 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Red Hat, Inc.
+ * Copyright 2013 Red Hat, Inc.
  *
  * This file is part of Thermostat.
  *
@@ -39,23 +39,15 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.util.Dictionary;
-
 import org.apache.commons.cli.Options;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.osgi.framework.BundleContext;
 
-import com.redhat.thermostat.client.osgi.service.ContextAction;
-import com.redhat.thermostat.common.ApplicationService;
 import com.redhat.thermostat.common.cli.CommandContext;
 import com.redhat.thermostat.common.cli.CommandContextFactory;
 import com.redhat.thermostat.common.cli.CommandException;
@@ -68,8 +60,7 @@
     @Before
     public void setUp() {
         clientMain = mock(Main.class);
-        BundleContext ctxt = mock(BundleContext.class);
-        cmd = new GUIClientCommand(clientMain, ctxt);
+        cmd = new GUIClientCommand(clientMain);
     }
 
     @After
@@ -80,17 +71,15 @@
 
     @Test
     public void testRun() throws CommandException {
-        BundleContext bCtx = mock(BundleContext.class);
         CommandContextFactory cmdCtxFactory = mock(CommandContextFactory.class);
 
         CommandContext cmdCtx = mock(CommandContext.class);
         when(cmdCtx.getCommandContextFactory()).thenReturn(cmdCtxFactory);
 
-        cmd = new GUIClientCommand(clientMain, bCtx);
+        cmd = new GUIClientCommand(clientMain);
         cmd.run(cmdCtx);
 
         verify(clientMain).run();
-        verify(bCtx).registerService(eq(ContextAction.class.getName()), isNotNull(), any(Dictionary.class));
     }
 
     @Test
--- a/killvm/client-swing/src/main/java/com/redhat/thermostat/killvm/client/internal/Activator.java	Mon Jan 21 16:33:51 2013 +0100
+++ b/killvm/client-swing/src/main/java/com/redhat/thermostat/killvm/client/internal/Activator.java	Mon Jan 21 12:17:46 2013 -0500
@@ -42,7 +42,6 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
-import com.redhat.thermostat.client.osgi.service.ContextAction;
 import com.redhat.thermostat.client.osgi.service.VMContextAction;
 import com.redhat.thermostat.common.MultipleServiceTracker;
 import com.redhat.thermostat.common.MultipleServiceTracker.Action;
@@ -59,7 +58,6 @@
         Class<?>[] serviceDeps = new Class<?>[] {
             AgentInfoDAO.class,
             VmInfoDAO.class,
-            ContextAction.class,
         };
 
         killVmActionTracker = new MultipleServiceTracker(context, serviceDeps, new Action() {