package edu.colorado.csdms.wmt.client.data;

import java.util.Vector;

import com.google.gwt.core.client.JavaScriptObject;

/**
 * A GWT JavaScript overlay (JSO) type that describes a parameter for a WMT
 * component model, with "key", "name", "description" and "value" attributes.
 * Declares JSNI methods to access these attributes from a JSON and modify
 * them in memory.
 * <p>
 * For more on GWT JSO types, see <a href=
 * "http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsOverlay.html"
 * >DevGuideCodingBasicsOverlay</a> and <a
 * href="http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html"
 * >DevGuideCodingBasicsJSNI</a>.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class ParameterJSO extends JavaScriptObject {

  // Overlay types have protected, no-arg, constructors.
  protected ParameterJSO() {
  }

  /**
   * A JSNI method to access the "key" attribute of a ParameterJSO. This
   * attribute is always present, and is a string.
   */
  public final native String getKey() /*-{
		return this.key;
  }-*/;

  /**
   * A JSNI method to access the "name" attribute of a ParameterJSO. This
   * attribute is always present, and is a string.
   */
  public final native String getName() /*-{
		return this.name;
  }-*/;

  /**
   * A JSNI method to access the "description" attribute of a ParameterJSO. This
   * attribute is always present, and is a string.
   */
  public final native String getDescription() /*-{
		return this.description;
  }-*/;

  /**
   * A JSNI method to access the "visible" attribute of a ParameterJSO,
   * controlling whether the parameter is shown in the WMT Parameters panel. If
   * this attribute is not present, true is returned. Note that the return is a
   * JS boolean, not a J Boolean.
   */
  public final native boolean isVisible() /*-{
		return (typeof this.visible == 'undefined') ? true : this.visible;
  }-*/;

  /**
   * A JSNI method for setting the "visible" attribute of a ParameterJSO,
   * controlling whether the parameter is shown in the WMT Parameters panel.
   * 
   * @param visible JS boolean, true if visible
   */
  public final native void isVisible(boolean visible) /*-{
		this.visible = visible;
  }-*/;

  /**
   * A JSNI method for checking whether a ParameterJSO has a "group" attribute.
   * Note that the return is a JS boolean, not a J Boolean.
   */
  public final native boolean hasGroup() /*-{
		return 'group' in this;
  }-*/;

  /**
   * A JSNI method to get the "name" attribute of a group, a String. If the
   * group or the name doesn't exist, null is returned.
   */
  public final native String getGroupName() /*-{
		return this.group && this.group.name || null;
  }-*/;

  /**
   * A JSNI method to get the "leader" attribute of a group, a JS boolean. If
   * the group or the leader doesn't exist, false is returned.
   */
  public final native boolean isGroupLeader() /*-{
		return this.group && this.group.leader || false;
  }-*/;

  /**
   * A JSNI method to get the number of members in a group, a JS int. If the
   * group or the members atribute doesn't exist, 0 is returned.
   */
  public final native int nGroupMembers() /*-{
		return this.group && this.group.members || 0;
  }-*/;

  /**
   * JSNI method to get the "value" attribute of a ParameterJSO. This attribute
   * is a ValueJSO object. It's always present, but it may be empty.
   */
  public final native ValueJSO getValue() /*-{
		return this.value;
  }-*/;

  /**
   * A non-JSNI method for stringifying the attributes of a ParameterJSO. Must
   * be final.
   */
  public final Vector<String> toStringVector() {

    Vector<String> retVal = new Vector<String>();
    retVal.add("key: " + getKey());
    retVal.add("name: " + getName());
    retVal.add("description: " + getDescription());
    for (int i = 0; i < getValue().toStringVector().size(); i++) {
      retVal.add(getValue().toStringVector().get(i));
    }
    return retVal;
  }
}

@@ -3069,16 +3069,17 @@
 mbers at
+t
 ribute d
@@ -3209,32 +3209,1386 @@
  %7C%7C 0;%0A  %7D-*/;%0A%0A
+  /**%0A   * A JSNI method for checking whether a ParameterJSO has a %22selection%22%0A   * attribute. A JS boolean is returned.%0A   */%0A  public final native boolean hasSelection() /*-%7B%0A%09%09return 'selection' in this;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the %22name%22 attribute of a selection, a String. If the%0A   * selection or the name doesn't exist, null is returned.%0A   */%0A  public final native String getSelectionName() /*-%7B%0A%09%09return this.selection && this.selection.name %7C%7C null;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the %22selector%22 attribute of a group, a JS boolean. If%0A   * the selection or the leader doesn't exist, false is returned.%0A   */%0A  public final native boolean isSelector() /*-%7B%0A%09%09return this.selection && this.selection.selector %7C%7C false;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the number of members in a selection, a JS int. If the%0A   * selection or the members attribute doesn't exist, 0 is returned.%0A   */%0A  public final native int nSelectionMembers() /*-%7B%0A%09%09return this.selection && this.selection.selections %7C%7C 0;%0A  %7D-*/;%0A%0A  /**%0A   * A JSNI method to get the mapping of a choice in the selector to the%0A   * appropriate member in the selection. Both the input choice and the output%0A   * mapping are Strings.%0A   */%0A  public final native String getSelectionMapping(String choice) /*-%7B%0A%09%09return this.selection.mapping%5Bchoice%5D;%0A  %7D-*/;%0A%0A
   /**%0A   * JSNI 

Add access methods for the new 'selection' parameter data type