karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pie...@apache.org
Subject svn commit: r1164477 - in /karaf/sandbox/webconsole/trunk/osgi/src/main: java/org/apache/karaf/webconsole/osgi/internal/bundle/view/BundleActionsPanel.java resources/OSGI-INF/blueprint/osgi.xml
Date Fri, 02 Sep 2011 11:13:55 GMT
Author: pieber
Date: Fri Sep  2 11:13:54 2011
New Revision: 1164477

URL: http://svn.apache.org/viewvc?rev=1164477&view=rev
Log:
Extend BundleActionsPanel to support start/stop/refresh/uninstall operations

Modified:
    karaf/sandbox/webconsole/trunk/osgi/src/main/java/org/apache/karaf/webconsole/osgi/internal/bundle/view/BundleActionsPanel.java
    karaf/sandbox/webconsole/trunk/osgi/src/main/resources/OSGI-INF/blueprint/osgi.xml

Modified: karaf/sandbox/webconsole/trunk/osgi/src/main/java/org/apache/karaf/webconsole/osgi/internal/bundle/view/BundleActionsPanel.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/webconsole/trunk/osgi/src/main/java/org/apache/karaf/webconsole/osgi/internal/bundle/view/BundleActionsPanel.java?rev=1164477&r1=1164476&r2=1164477&view=diff
==============================================================================
--- karaf/sandbox/webconsole/trunk/osgi/src/main/java/org/apache/karaf/webconsole/osgi/internal/bundle/view/BundleActionsPanel.java
(original)
+++ karaf/sandbox/webconsole/trunk/osgi/src/main/java/org/apache/karaf/webconsole/osgi/internal/bundle/view/BundleActionsPanel.java
Fri Sep  2 11:13:54 2011
@@ -21,16 +21,26 @@ import java.util.List;
 
 import org.apache.karaf.webconsole.core.table.ActionsPanel;
 import org.apache.karaf.webconsole.osgi.bundle.IActionProvider;
+import org.apache.karaf.webconsole.osgi.internal.bundle.BundlesPage;
 import org.apache.karaf.webconsole.osgi.internal.bundle.DetailsPage;
+import org.apache.karaf.webconsole.osgi.internal.bundle.State;
 import org.apache.wicket.PageParameters;
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.Session;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
 import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.model.IModel;
+import org.ops4j.pax.wicket.api.PaxWicketBean;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 public class BundleActionsPanel extends ActionsPanel<Bundle> {
 
+    @PaxWicketBean(name = "packageAdmin")
+    private PackageAdmin admin;
+
     public BundleActionsPanel(String componentId, final IModel<Bundle> model, List<IActionProvider>
actionProviders) {
         super(componentId, model);
 
@@ -57,6 +67,95 @@ public class BundleActionsPanel extends 
 
         links.add(link);
 
+        switch (State.of(object.getState())) {
+        case ACTIVE:
+            links.add(createStopLink(id));
+            break;
+        case INSTALLED:
+        case RESOLVED:
+            links.add(createStartLink(id));
+        }
+
+        links.add(createRefreshLink(id));
+        links.add(createUninstallLink(id));
+
         return links;
     }
+
+    private Link createUninstallLink(String id) {
+        Link link = new Link(id) {
+            @Override
+            public void onClick() {
+                Bundle bundle = (Bundle) BundleActionsPanel.this.getDefaultModelObject();
+
+                try {
+                    bundle.uninstall();
+
+                    Session.get().info("Bundle " + bundle.getSymbolicName() + " uninstalled");
+                    RequestCycle.get().setResponsePage(BundlesPage.class);
+                } catch (BundleException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+            
+        };
+        link.add(new Label("label", "Uninstall"));
+        return link;
+    }
+
+    private Link createRefreshLink(String id) {
+        Link link = new Link(id) {
+            @Override
+            public void onClick() {
+                Bundle bundle = (Bundle) BundleActionsPanel.this.getDefaultModelObject();
+
+                admin.refreshPackages(new Bundle[] {bundle});
+                Session.get().info("Bundle " + bundle.getSymbolicName() + " refreshed");
+                RequestCycle.get().setResponsePage(BundlesPage.class);
+            }
+            
+        };
+        link.add(new Label("label", "Refresh"));
+        return link;
+    }
+
+    private Link createStartLink(String id) {
+        Link link = new Link(id) {
+            @Override
+            public void onClick() {
+                Bundle bundle = (Bundle) BundleActionsPanel.this.getDefaultModelObject();
+
+                try {
+                    bundle.start();
+                    Session.get().info("Bundle " + bundle.getSymbolicName() + " started");
+                    RequestCycle.get().setResponsePage(BundlesPage.class);
+                } catch (BundleException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+            
+        };
+        link.add(new Label("label", "Start"));
+        return link;
+    }
+
+    private Link createStopLink(String id) {
+        Link link = new Link(id) {
+            public void onClick() {
+                Bundle bundle = (Bundle) BundleActionsPanel.this.getDefaultModelObject();
+                try {
+                    bundle.stop();
+                    Session.get().info("Bundle " + bundle.getSymbolicName() + " stopped");
+                    RequestCycle.get().setResponsePage(BundlesPage.class);
+                } catch (BundleException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+        };
+        link.add(new Label("label", "Stop"));
+        return link;
+    }
 }

Modified: karaf/sandbox/webconsole/trunk/osgi/src/main/resources/OSGI-INF/blueprint/osgi.xml
URL: http://svn.apache.org/viewvc/karaf/sandbox/webconsole/trunk/osgi/src/main/resources/OSGI-INF/blueprint/osgi.xml?rev=1164477&r1=1164476&r2=1164477&view=diff
==============================================================================
--- karaf/sandbox/webconsole/trunk/osgi/src/main/resources/OSGI-INF/blueprint/osgi.xml (original)
+++ karaf/sandbox/webconsole/trunk/osgi/src/main/resources/OSGI-INF/blueprint/osgi.xml Fri
Sep  2 11:13:54 2011
@@ -46,6 +46,7 @@
 
     <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"
availability="optional" />
     <reference id="startLevel" interface="org.osgi.service.startlevel.StartLevel" />
+    <reference id="packageAdmin" interface="org.osgi.service.packageadmin.PackageAdmin"
/>
     <reference id="metaTypeService" interface="org.osgi.service.metatype.MetaTypeService"
/>
 
     <reference-list id="columnProviders" interface="org.apache.karaf.webconsole.osgi.bundle.IColumnProvider"
availability="optional" />



Mime
View raw message