diff --git a/core/src/main/java/org/apache/karaf/webconsole/core/behavior/RemoveAttributeBehavior.java b/core/src/main/java/org/apache/karaf/webconsole/core/behavior/RemoveAttributeBehavior.java new file mode 100644 index 0000000..84054d1 --- /dev/null +++ b/core/src/main/java/org/apache/karaf/webconsole/core/behavior/RemoveAttributeBehavior.java @@ -0,0 +1,40 @@ +/* + * 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.behavior; + +import org.apache.wicket.Component; +import org.apache.wicket.behavior.AbstractBehavior; +import org.apache.wicket.markup.ComponentTag; + +/** + * Simple behavior to remove some attributes from output markup. + */ +public class RemoveAttributeBehavior extends AbstractBehavior { + + private static final long serialVersionUID = 1L; + + private String attribute; + + public RemoveAttributeBehavior(String attribute) { + this.attribute = attribute; + } + + public void onComponentTag(Component component, ComponentTag tag) { + tag.getAttributes().remove(attribute); + } + +} diff --git a/core/src/main/java/org/apache/karaf/webconsole/core/form/LabelBorder.java b/core/src/main/java/org/apache/karaf/webconsole/core/form/LabelBorder.java index e56dfe7..22ed228 100644 --- a/core/src/main/java/org/apache/karaf/webconsole/core/form/LabelBorder.java +++ b/core/src/main/java/org/apache/karaf/webconsole/core/form/LabelBorder.java @@ -20,6 +20,8 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.border.Border; import org.apache.wicket.markup.html.form.FormComponent; +import org.apache.wicket.markup.html.form.SimpleFormComponentLabel; +import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; @@ -28,18 +30,14 @@ public class LabelBorder extends Border { private static final long serialVersionUID = 1L; private final FormComponent component; - public LabelBorder(String id, String fieldLabel, FormComponent component) { - this(id, Model.of(fieldLabel), component); - } - - public LabelBorder(String id, IModel fieldLabel, FormComponent component) { + public LabelBorder(String id, FormComponent component) { super(id); this.component = component; getBodyContainer().add(component); - add(new Label("label", fieldLabel).setRenderBodyOnly(true)); + add(new SimpleFormComponentLabel("label", component)); add(new Label("help", "")); - add(new Label("error", "")); + add(new ComponentFeedbackPanel("error", component)); } public void setHelp(String message) { @@ -55,7 +53,6 @@ protected void onBeforeRender() { super.onBeforeRender(); if (component.getFeedbackMessage() != null) { - addOrReplace(new Label("error", "" + component.getFeedbackMessage().getMessage())); add(new AttributeAppender("class", Model.of("error"), " ")); } } diff --git a/core/src/main/java/org/apache/karaf/webconsole/core/form/MapEditForm.java b/core/src/main/java/org/apache/karaf/webconsole/core/form/MapEditForm.java index 90568cf..7f707ee 100644 --- a/core/src/main/java/org/apache/karaf/webconsole/core/form/MapEditForm.java +++ b/core/src/main/java/org/apache/karaf/webconsole/core/form/MapEditForm.java @@ -16,6 +16,8 @@ */ package org.apache.karaf.webconsole.core.form; +import static org.apache.wicket.model.Model.of; + import java.util.Map; import org.apache.wicket.Component; @@ -48,13 +50,10 @@ public MapEditForm(String id, CompoundPropertyModel> model) { add(repeatingView); } - @SuppressWarnings("unchecked") protected Component populateItem(String componentId, K key, IModel value) { - FormComponent field = new TextField("value", value, (Class) value.getObject().getClass()); - LabelBorder border = new LabelBorder(componentId, ""+ key, field); -// border.add(new Label("label", "" + key)); -// border.add(); - border.setHelp("Value for " + key); + FormComponent field = new TextField("value", value); + field.setLabel(of(key.toString())); + LabelBorder border = new LabelBorder(componentId, field); return border; } } diff --git a/core/src/main/resources/org/apache/karaf/webconsole/core/form/LabelBorder.html b/core/src/main/resources/org/apache/karaf/webconsole/core/form/LabelBorder.html index 7ed52cb..62c8e6e 100644 --- a/core/src/main/resources/org/apache/karaf/webconsole/core/form/LabelBorder.html +++ b/core/src/main/resources/org/apache/karaf/webconsole/core/form/LabelBorder.html @@ -16,9 +16,7 @@ limitations under the License. --> - +
diff --git a/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePage.java b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePage.java new file mode 100644 index 0000000..e34d372 --- /dev/null +++ b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePage.java @@ -0,0 +1,46 @@ +/* + * 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.core.bundle.install; + +import static org.apache.wicket.model.Model.of; + +import org.apache.karaf.webconsole.osgi.core.bundle.list.BundlePage; +import org.apache.karaf.webconsole.osgi.core.shared.OsgiPage; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.model.IModel; +import org.ops4j.pax.wicket.api.PaxWicketMountPoint; + +/** + * Page with bundle installation form. + */ +@PaxWicketMountPoint(mountPoint = "/osgi/bundle/add") +public class InstallBundlePage extends OsgiPage { + + public InstallBundlePage() { + IModel model = of(new WicketInstallModel()); + + Form form = new Form("install", model); + form.add(new InstallBundlePanel("bundle", model)); + + form.add(new InstallBundleSubmitLink("confirm")); + form.add(new BookmarkablePageLink("cancel", BundlePage.class)); + + add(form); + } + +} diff --git a/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePanel.java b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePanel.java new file mode 100644 index 0000000..a5c6c69 --- /dev/null +++ b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePanel.java @@ -0,0 +1,90 @@ +/* + * 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.core.bundle.install; + +import static org.apache.wicket.model.Model.of; + +import org.apache.karaf.webconsole.core.behavior.RemoveAttributeBehavior; +import org.apache.karaf.webconsole.core.form.LabelBorder; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox; +import org.apache.wicket.behavior.SimpleAttributeModifier; +import org.apache.wicket.markup.html.form.CheckBox; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.RequiredTextField; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.form.upload.FileUploadField; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; + +/** + * Bundle installation form wrapper. + */ +public class InstallBundlePanel extends Panel { + + private static final long serialVersionUID = 1L; + private TextField location; + private CheckBox upload; + private FileUploadField file; + + public InstallBundlePanel(String id, IModel model) { + super(id); + + Form form = new Form("form", new CompoundPropertyModel(model)); + location = new RequiredTextField("location"); + location.setLabel(of("Bundle location")); + LabelBorder border = new LabelBorder("locationGroup", location); + form.add(border); + + upload = new AjaxCheckBox("upload") { + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + if (target != null) { + if (upload.getModelObject()) { + onChecked(); + } else { + onUnchecked(); + } + target.addComponent(file); + } + } + }; + upload.setLabel(of("Specify file to install")); + border = new LabelBorder("uploadGroup", upload); + form.add(border); + + file = new FileUploadField("file"); + file.setLabel(of("Bundle file")); + file.add(new SimpleAttributeModifier("disabled", "disabled")); + file.setOutputMarkupId(true); + border = new LabelBorder("fileGroup", file); + form.add(border); + + add(form); + } + + protected void onChecked() { + file.add(new RemoveAttributeBehavior("disabled")); + } + + protected void onUnchecked() { + file.add(new SimpleAttributeModifier("disabled", "disabled")); + } +} diff --git a/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundleSubmitLink.java b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundleSubmitLink.java new file mode 100644 index 0000000..e5285c8 --- /dev/null +++ b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundleSubmitLink.java @@ -0,0 +1,60 @@ +/* + * 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.core.bundle.install; + +import org.apache.karaf.webconsole.osgi.core.bundle.list.BundlePage; +import org.apache.wicket.RequestCycle; +import org.apache.wicket.Session; +import org.apache.wicket.markup.html.form.SubmitLink; +import org.ops4j.pax.wicket.api.PaxWicketBean; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Bundle installation link. Requires form with {@link WicketInstallModel}. + */ +public class InstallBundleSubmitLink extends SubmitLink { + private static final long serialVersionUID = 1L; + + @PaxWicketBean(name = "blueprintBundleContext") + private BundleContext context; + + private transient Logger logger = LoggerFactory.getLogger(InstallBundleSubmitLink.class); + + public InstallBundleSubmitLink(String id) { + super(id); + } + + @Override + public void onSubmit() { + WicketInstallModel modelObject = (WicketInstallModel) getForm().getModelObject(); + + try { + if (modelObject.isUpload()) { + context.installBundle(modelObject.getLocation(), modelObject.getInputStream()); + } else { + context.installBundle(modelObject.getLocation()); + } + Session.get().info("Bundle " + modelObject.getLocation() + " installed"); + RequestCycle.get().setResponsePage(BundlePage.class); + } catch (Exception e) { + logger.error("Error during installation", e); + Session.get().error("Can not install bundle " + e.getMessage()); + } + } +} diff --git a/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/WicketInstallModel.java b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/WicketInstallModel.java new file mode 100644 index 0000000..2c7e3e4 --- /dev/null +++ b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/install/WicketInstallModel.java @@ -0,0 +1,60 @@ +/* + * 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.core.bundle.install; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; + +import org.apache.wicket.markup.html.form.upload.FileUpload; + +/** + * Model for installation form. + */ +public class WicketInstallModel implements Serializable { + + private static final long serialVersionUID = 1L; + + private String location; + private boolean upload = false; + private FileUpload file; + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public boolean isUpload() { + return upload; + } + + public void setUpload(boolean upload) { + this.upload = upload; + } + + public void setFile(FileUpload file) { + this.file = file; + } + + public InputStream getInputStream() throws IOException { + return file.getInputStream(); + } + +} diff --git a/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.java b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.java index 589003c..ea31a27 100644 --- a/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.java +++ b/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.java @@ -22,17 +22,20 @@ import java.util.List; import org.apache.karaf.webconsole.core.table.PropertyColumnExt; +import org.apache.karaf.webconsole.osgi.core.bundle.install.InstallBundlePage; import org.apache.karaf.webconsole.osgi.core.shared.BundleDataProvider; import org.apache.karaf.webconsole.osgi.core.shared.OsgiPage; import org.apache.karaf.webconsole.osgi.core.shared.State; import org.apache.karaf.webconsole.osgi.core.spi.IActionProvider; import org.apache.karaf.webconsole.osgi.core.spi.IColumnProvider; import org.apache.karaf.webconsole.osgi.core.spi.IDecorationProvider; +import org.apache.wicket.Page; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable; import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; @@ -90,6 +93,8 @@ public void populateItem(Item> cellItem, final String com }); add(new DefaultDataTable("bundles", columns, new BundleDataProvider(context), 100)); + + add(new BookmarkablePageLink("install", InstallBundlePage.class)); } } diff --git a/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePage.html b/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePage.html new file mode 100644 index 0000000..507e6b6 --- /dev/null +++ b/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePage.html @@ -0,0 +1,30 @@ + + + +

Install bundle

+ +
+
+
+ +
+ + Cancel +
+
+
\ No newline at end of file diff --git a/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePanel.html b/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePanel.html new file mode 100644 index 0000000..aeaeb4f --- /dev/null +++ b/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/install/InstallBundlePanel.html @@ -0,0 +1,34 @@ + + + +
+
+ Install bundle + +
+ +
+
+ +
+
+ +
+
+
+
\ No newline at end of file diff --git a/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.html b/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.html index c8651f3..b982ead 100644 --- a/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.html +++ b/osgi/core/src/main/resources/org/apache/karaf/webconsole/osgi/core/bundle/list/BundlePage.html @@ -16,8 +16,19 @@ limitations under the License. --> -

Bundles

+
+

Bundles

- + + + +
+
+