changeset 107:4dfa549ca00c

Add UI for editing arguments
author Omair Majid <omajid@redhat.com>
date Fri, 21 Feb 2014 15:59:02 -0500
parents 4356c844cff9
children fde496a78a98
files TODO.md com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Messages.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/CommandEditPage.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/Converters.java com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/messages.properties com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/package-info.java
diffstat 6 files changed, 90 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/TODO.md	Wed Feb 19 18:32:13 2014 -0500
+++ b/TODO.md	Fri Feb 21 15:59:02 2014 -0500
@@ -8,7 +8,7 @@
 
 - Fix up stale states
 
-- Implement support for options/arguments
+- Implement support for options
 
 - Modify the bundle loading dialog to be smarter. Offer auto-completion and
   automatically identify bundle names from all open projects and dependencies,
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Messages.java	Wed Feb 19 18:32:13 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Messages.java	Fri Feb 21 15:59:02 2014 -0500
@@ -9,6 +9,8 @@
     public static String BaseMasterDetailsBlock_add;
     public static String BaseMasterDetailsBlock_remove;
     public static String CommandEditPage_addButton;
+    public static String CommandEditPage_argumentsAndOptionsSectionTitle;
+    public static String CommandEditPage_argumentsLabel;
     public static String CommandEditPage_basicsSectionTitle;
     public static String CommandEditPage_bundlesToLoadsectionTitle;
     public static String CommandEditPage_cliCheckTitle;
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/CommandEditPage.java	Wed Feb 19 18:32:13 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/CommandEditPage.java	Fri Feb 21 15:59:02 2014 -0500
@@ -38,6 +38,8 @@
 
 import com.redhat.thermostat.tools.eclipse.plugin.BundleInformation;
 import com.redhat.thermostat.tools.eclipse.plugin.Messages;
+import com.redhat.thermostat.tools.eclipse.plugin.editor.Converters.ListToStringConverter;
+import com.redhat.thermostat.tools.eclipse.plugin.editor.Converters.StringToListConverter;
 import com.redhat.thermostat.tools.eclipse.plugin.model.Bundle;
 import com.redhat.thermostat.tools.eclipse.plugin.model.Command;
 import com.redhat.thermostat.tools.eclipse.plugin.model.Environments;
@@ -61,6 +63,7 @@
     private Text commandName;
     private Text commandUsage;
     private Text commandDescription;
+    private Text commandArguments;
     private Button cli;
     private Button shell;
 
@@ -203,7 +206,17 @@
     }
 
     private void createArgumentsAndOptionsSection(Composite sectionContents) {
-        // TODO Auto-generated method stub
+        Section argumentsAndOptions = toolkit.createSection(sectionContents, Section.TITLE_BAR);
+        argumentsAndOptions.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+        argumentsAndOptions.setText(Messages.CommandEditPage_argumentsAndOptionsSectionTitle);
+
+        Composite contents = toolkit.createComposite(argumentsAndOptions);
+        argumentsAndOptions.setClient(contents);
+        contents.setLayout(new GridLayout(2, false));
+
+        toolkit.createLabel(contents, Messages.CommandEditPage_argumentsLabel);
+        commandArguments = toolkit.createText(contents, "<arguments>"); //$NON-NLS-1$
+        commandArguments.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
     }
 
     private void createBundlesSection(final Composite sectionContents) {
@@ -268,6 +281,14 @@
         Binding descriptionBinding = bindingContext.bindValue(descriptionWidgetValue, descriptionModelValue, descriptionStrategy, null);
         ControlDecorationSupport.create(descriptionBinding, SWT.LEFT | SWT.TOP);
 
+        IObservableValue argumentsWidgetValue = WidgetProperties.text(SWT.Modify).observe(commandArguments);
+        IObservableValue argumentsModelValue = BeanProperties.value(Command.class, "arguments").observe(commandModel);
+        UpdateValueStrategy modelToWidgetStrategy = new UpdateValueStrategy();
+        modelToWidgetStrategy.setConverter(new Converters.ListToStringConverter());
+        UpdateValueStrategy widgetToModelStrategy = new UpdateValueStrategy();
+        widgetToModelStrategy.setConverter(new Converters.StringToListConverter());
+        bindingContext.bindValue(argumentsWidgetValue, argumentsModelValue, widgetToModelStrategy, modelToWidgetStrategy);
+
         IObservableValue environmentsModelValue = BeanProperties.value(Command.class, "environments").observe(commandModel); //$NON-NLS-1$
 
         IObservableValue cliWidgetValue = WidgetProperties.selection().observe(cli);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/Converters.java	Fri Feb 21 15:59:02 2014 -0500
@@ -0,0 +1,55 @@
+package com.redhat.thermostat.tools.eclipse.plugin.editor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.databinding.conversion.Converter;
+
+public class Converters {
+
+    public static class ListToStringConverter extends Converter {
+
+        public ListToStringConverter() {
+            super(List.class, String.class);
+        }
+
+        @Override
+        public Object convert(Object fromObject) {
+            if (!(fromObject instanceof List)) {
+                throw new AssertionError("Only List objects can be converted");
+            }
+            List<String> list = (List<String>) fromObject;
+
+            if (list.size() == 0) {
+                return "";
+            }
+
+            StringBuilder result = new StringBuilder();
+            for (String item : list) {
+                result.append(item).append(" ");
+            }
+            // return everything except the last " "
+            return result.substring(0, result.length() - 1);
+        }
+    }
+
+    public static class StringToListConverter extends Converter {
+
+        public StringToListConverter() {
+            super(String.class, List.class);
+        }
+
+        @Override
+        public Object convert(Object fromObject) {
+            if (!(fromObject instanceof String)) {
+                throw new AssertionError("Only string objects can be converted");
+            }
+            String from = (String) fromObject;
+            String[] parts = from.trim().split(" +");
+            List<String> result = Arrays.asList(parts);
+            return result;
+        }
+
+    }
+
+}
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/messages.properties	Wed Feb 19 18:32:13 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/messages.properties	Fri Feb 21 15:59:02 2014 -0500
@@ -1,6 +1,8 @@
 BaseMasterDetailsBlock_add=Add
 BaseMasterDetailsBlock_remove=Remove
 CommandEditPage_addButton=Add
+CommandEditPage_argumentsAndOptionsSectionTitle=Arguments and Options
+CommandEditPage_argumentsLabel=Arguments
 CommandEditPage_basicsSectionTitle=Basics
 CommandEditPage_bundlesToLoadsectionTitle=Bundles to load
 CommandEditPage_cliCheckTitle=CLI
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/package-info.java	Wed Feb 19 18:32:13 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/package-info.java	Fri Feb 21 15:59:02 2014 -0500
@@ -1,6 +1,14 @@
 /**
  * Contains model classes that represents XML elements of the
  * {@code thermostat-plugin.xml} file.
+ * <p>
+ * The models in this package are used for two distinct purposes:
+ * <ol>
+ * <li>For marshalling and unmarhalling to XML using JAXB</li>
+ * <li>For binding to the UI using JFace databinding</li>
+ * </ol>
+ * As a result of both these, some times the models are not built
+ * in the simplest way.
  */
 @javax.xml.bind.annotation.XmlSchema(
         namespace=SchemaConstants.SCHEMA_NAMESPACE,