KARAF-1793 Fix configuration edit form
authorŁukasz Dywicki <ldywicki@apache.org>
Wed, 5 Sep 2012 22:08:25 +0000 (22:08 +0000)
committerŁukasz Dywicki <ldywicki@apache.org>
Wed, 5 Sep 2012 22:08:25 +0000 (22:08 +0000)
Signed-off-by: Lukasz Dywicki <luke@code-house.org>
git-svn-id: https://svn.apache.org/repos/asf/karaf/webconsole/trunk@1381414 13f79535-47bb-0310-9956-ffa450edef68

core/src/main/java/org/apache/karaf/webconsole/core/form/LabelBorder.java
core/src/main/java/org/apache/karaf/webconsole/core/form/MapEditForm.java
core/src/main/java/org/apache/karaf/webconsole/core/util/DictionaryUtils.java
osgi/config/src/main/java/org/apache/karaf/webconsole/osgi/config/ConfigurationEditPage.java
osgi/config/src/main/java/org/apache/karaf/webconsole/osgi/config/ConfigurationProvider.java
osgi/config/src/main/java/org/apache/karaf/webconsole/osgi/config/model/ConfigurationModel.java

index 22ed228..1239935 100644 (file)
@@ -30,22 +30,27 @@ public class LabelBorder extends Border {
     private static final long serialVersionUID = 1L;
     private final FormComponent<?> component;
 
+    private Label help;
+
     public LabelBorder(String id, FormComponent<?> component) {
         super(id);
         this.component = component;
-        getBodyContainer().add(component);
 
-        add(new SimpleFormComponentLabel("label", component));
-        add(new Label("help", ""));
-        add(new ComponentFeedbackPanel("error", component));
+        add(component);
+
+        addToBorder(
+            new SimpleFormComponentLabel("label", component),
+            help = new Label("help", ""),
+            new ComponentFeedbackPanel("error", component)
+        );
     }
 
     public void setHelp(String message) {
-        addOrReplace(new Label("help", message));
+        help.setDefaultModelObject(message);
     }
 
     public void setHelp(IModel<?> message) {
-        addOrReplace(new Label("help", message));
+        help.setDefaultModel(message);
     }
 
     @Override
index 7f707ee..de8cb27 100644 (file)
@@ -44,16 +44,21 @@ public abstract class MapEditForm<K, V> extends Form<Map<K, V>> {
         RepeatingView repeatingView = new RepeatingView("entries");
 
         for (K key : model.getObject().keySet()) {
-            IModel<V> bind = model.bind("" + key);
+            IModel<V> bind = model.bind("[" + key + "]");
             repeatingView.add(populateItem(repeatingView.newChildId(), key, bind));
         }
         add(repeatingView);
     }
 
     protected Component populateItem(String componentId, K key, IModel<V> value) {
+        return new LabelBorder(componentId, createField(key, value));
+    }
+
+    private FormComponent<?> createField(K key, IModel<V> value) {
         FormComponent<V> field = new TextField<V>("value", value);
+        field.setType(String.class);
         field.setLabel(of(key.toString()));
-        LabelBorder border = new LabelBorder(componentId, field);
-        return border;
+        return field;
     }
+
 }
index 40e8529..50252ec 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Map;
 public abstract class DictionaryUtils {
 
     private DictionaryUtils() {
-        System.out.println("How you did that?");
+        // utility class, no public constructor
     }
 
     /**
index 05f6ba9..f53895e 100644 (file)
@@ -67,6 +67,9 @@ public class ConfigurationEditPage extends OsgiPage {
 
                 try {
                     Configuration configuration = new ConfigurationModel(pid, configurationAdmin).getObject();
+                    if (configuration.getBundleLocation() != null) {
+                        configuration.setBundleLocation(null);
+                    }
                     configuration.update(DictionaryUtils.dictionary(map));
 
                     Session.get().info("Configuration " + pid + " updated.");
index 4a1fff0..a6945f6 100644 (file)
@@ -38,15 +38,10 @@ public class ConfigurationProvider extends SortableDataProvider<Configuration> {
 
     public ConfigurationProvider(ConfigurationAdmin configurationAdmin) {
         this.configurationAdmin = configurationAdmin;
-        try {
-            this.configurations = configurationAdmin.listConfigurations(null);
-        } catch (Exception e) {
-            throw new ConfigurationNotFoundException(null, e);
-        }
     }
 
     public Iterator<? extends Configuration> iterator(int from, int count) {
-        return Arrays.asList(Arrays.copyOfRange(configurations, from, count)).iterator();
+        return Arrays.asList(Arrays.copyOfRange(getConfigurations(), from, from + count)).iterator();
     }
 
     public IModel<Configuration> model(Configuration object) {
@@ -54,9 +49,18 @@ public class ConfigurationProvider extends SortableDataProvider<Configuration> {
     }
 
     public int size() {
-        return configurations.length;
+        return getConfigurations().length;
     }
 
+    public Configuration[] getConfigurations() {
+        try {
+            configurations = configurationAdmin.listConfigurations(null);
+        } catch (Exception e) {
+            throw new ConfigurationNotFoundException(null, e);
+        }
+        return configurations;
+    }
+    
     @Override
     public void detach() {
         super.detach();
index 839ac93..e7f1307 100644 (file)
@@ -46,7 +46,7 @@ public class ConfigurationModel extends LoadableDetachableModel<Configuration> {
     @Override
     protected Configuration load() {
         try {
-            return configurationAdmin.getConfiguration(pid);
+            return configurationAdmin.getConfiguration(pid, null);
         } catch (IOException e) {
             throw new ConfigurationNotFoundException(pid, e);
         }