# HG changeset patch # User Omair Majid # Date 1393016342 18000 # Node ID 4dfa549ca00c932c25aaa8fb3651ed404917b6b4 # Parent 4356c844cff9d0222f7d37b76dab4620731c73c1 Add UI for editing arguments diff -r 4356c844cff9 -r 4dfa549ca00c TODO.md --- 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, diff -r 4356c844cff9 -r 4dfa549ca00c com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/Messages.java --- 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; diff -r 4356c844cff9 -r 4dfa549ca00c com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/CommandEditPage.java --- 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, ""); //$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); diff -r 4356c844cff9 -r 4dfa549ca00c com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/Converters.java --- /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 list = (List) 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 result = Arrays.asList(parts); + return result; + } + + } + +} diff -r 4356c844cff9 -r 4dfa549ca00c com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/messages.properties --- 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 diff -r 4356c844cff9 -r 4dfa549ca00c com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/package-info.java --- 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. + *

+ * The models in this package are used for two distinct purposes: + *

    + *
  1. For marshalling and unmarhalling to XML using JAXB
  2. + *
  3. For binding to the UI using JFace databinding
  4. + *
+ * 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,