KARAF-1784 Provide additional actions for blueprint-enabled bundles
Signed-off-by: Lukasz Dywicki <luke@code-house.org>
git-svn-id: https://svn.apache.org/repos/asf/karaf/webconsole/trunk@1379103 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/main/java/org/apache/karaf/webconsole/core/panel/SingleLinkPanel.java b/core/src/main/java/org/apache/karaf/webconsole/core/panel/SingleLinkPanel.java
new file mode 100644
index 0000000..c405e60
--- /dev/null
+++ b/core/src/main/java/org/apache/karaf/webconsole/core/panel/SingleLinkPanel.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.webconsole.core.panel;
+
+import org.apache.wicket.markup.html.panel.Panel;
+
+/**
+ * Simple panel with one link inside.
+ */
+public class SingleLinkPanel extends Panel {
+
+ private static final long serialVersionUID = 1L;
+
+ public SingleLinkPanel(String id) {
+ super(id);
+ }
+
+}
diff --git a/core/src/main/java/org/apache/karaf/webconsole/core/util/LinkUtils.java b/core/src/main/java/org/apache/karaf/webconsole/core/util/LinkUtils.java
index f88b0ce..6291b1a 100644
--- a/core/src/main/java/org/apache/karaf/webconsole/core/util/LinkUtils.java
+++ b/core/src/main/java/org/apache/karaf/webconsole/core/util/LinkUtils.java
@@ -22,6 +22,7 @@
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.protocol.http.RequestUtils;
import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
/**
* Utility class to create links.
@@ -39,9 +40,25 @@
* @param page Page class to link.
* @return Bookmarkable link.
*/
- @SuppressWarnings({"rawtypes", "unchecked"})
public static <T extends Page> Link<Page> createPageLink(String linkId, String labelId, String label, Class<T> page) {
- Link link = new BookmarkablePageLink<T>(linkId, page);
+ return createPageLink(linkId, labelId, label, page, new PageParameters());
+ }
+
+ /**
+ * Creates bookmarkable page link with given page class and parameters.
+ *
+ * @param <T> Type of page.
+ *
+ * @param linkId Link element id.
+ * @param labelId Inner link element label.
+ * @param label Text label.
+ * @param page Page class to link.
+ * @param params Page parameters.
+ * @return Bookmarkable link.
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static <T extends Page> Link<Page> createPageLink(String linkId, String labelId, String label, Class<T> page, PageParameters params) {
+ Link link = new BookmarkablePageLink<T>(linkId, page, params);
link.add(new Label(labelId, label));
return link;
}
diff --git a/core/src/main/resources/org/apache/karaf/webconsole/core/panel/SingleLinkPanel.html b/core/src/main/resources/org/apache/karaf/webconsole/core/panel/SingleLinkPanel.html
new file mode 100644
index 0000000..6623e0f
--- /dev/null
+++ b/core/src/main/resources/org/apache/karaf/webconsole/core/panel/SingleLinkPanel.html
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<wicket:panel xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
+ <a wicket:id="link">
+ <span wicket:id="label" />
+ </a>
+ <wicket:child />
+</wicket:panel>
\ No newline at end of file
diff --git a/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/bundle/BlueprintActionPanel.java b/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/bundle/BlueprintActionPanel.java
new file mode 100644
index 0000000..56a78f6
--- /dev/null
+++ b/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/bundle/BlueprintActionPanel.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.webconsole.osgi.blueprint.bundle;
+
+import org.apache.karaf.webconsole.core.panel.SingleLinkPanel;
+import org.apache.karaf.webconsole.core.util.LinkUtils;
+import org.apache.karaf.webconsole.osgi.blueprint.IBlueprintBundleStateTracker;
+import org.apache.karaf.webconsole.osgi.blueprint.details.DetailsPage;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.ops4j.pax.wicket.api.PaxWicketBean;
+import org.osgi.framework.Bundle;
+
+public class BlueprintActionPanel extends SingleLinkPanel {
+
+ private static final long serialVersionUID = 1L;
+
+ @PaxWicketBean(name = "tracker")
+ private IBlueprintBundleStateTracker tracker;
+
+ public BlueprintActionPanel(String componentId, IModel<Bundle> model) {
+ super(componentId);
+ setDefaultModel(model);
+
+ Bundle bundle = model.getObject();
+ if (tracker.getState(model.getObject()) == null) {
+ setVisible(false);
+ return;
+ }
+
+ PageParameters params = new PageParameters();
+ params.add("bundleId", bundle.getBundleId());
+ add(LinkUtils.createPageLink("link", "label", "Manage blueprint", DetailsPage.class, params));
+ }
+
+}
diff --git a/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/bundle/BlueprintActionProvider.java b/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/bundle/BlueprintActionProvider.java
index bc26b77..11349dd 100644
--- a/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/bundle/BlueprintActionProvider.java
+++ b/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/bundle/BlueprintActionProvider.java
@@ -16,13 +16,9 @@
*/
package org.apache.karaf.webconsole.osgi.blueprint.bundle;
-import org.apache.karaf.webconsole.osgi.blueprint.IBlueprintBundleStateTracker;
-import org.apache.karaf.webconsole.osgi.blueprint.details.DetailsPage;
+import org.apache.karaf.webconsole.osgi.core.shared.BundleModel;
import org.apache.karaf.webconsole.osgi.core.spi.IActionProvider;
import org.apache.wicket.Component;
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
-import org.apache.wicket.model.Model;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.osgi.framework.Bundle;
/**
@@ -30,18 +26,8 @@
*/
public class BlueprintActionProvider implements IActionProvider {
- private IBlueprintBundleStateTracker tracker;
-
- public BlueprintActionProvider(IBlueprintBundleStateTracker tracker) {
- this.tracker = tracker;
- }
-
- public Component create(String componentId, Bundle model) {
- PageParameters params = new PageParameters();
- params.add("bundleId", model.getBundleId());
- BookmarkablePageLink link = new BookmarkablePageLink(componentId, DetailsPage.class, params);
- link.setModel(Model.of("Blueprint"));
- return link;
+ public Component create(String componentId, Bundle bundle) {
+ return new BlueprintActionPanel(componentId, new BundleModel(bundle));
}
}
diff --git a/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/details/DetailsPage.java b/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/details/DetailsPage.java
index 28d5bc9..cd97bd5 100644
--- a/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/details/DetailsPage.java
+++ b/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/details/DetailsPage.java
@@ -46,8 +46,8 @@
IModel<List<ComponentMetadata>> model = new MetadataModel(context, params.get("bundleId").toInt());
add(new ListView<ComponentMetadata>("components", model) {
+
@Override
- @SuppressWarnings("unchecked")
protected void populateItem(ListItem<ComponentMetadata> item) {
ComponentMetadata metadata = item.getModelObject();
item.add(new Label("componentId", metadata.getId()));