FieldDropdown

public final class FieldDropdown extends Field

Adds a dropdown list to an Input.

Nested Class Summary

class FieldDropdown.Option An option for a block's dropdown field. 
class FieldDropdown.Options The list of all options for a FieldDropdown
interface FieldDropdown.OptionsObserver Interface to listen for changes that occur to an FieldDropdown.Options list. 

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

FieldDropdown(String name)
FieldDropdown(String name, FieldDropdown.Options options)

Public Method Summary

FieldDropdown
clone()
static FieldDropdown
fromJson(JSONObject json)
Loads a FieldDropdown from JSON.
List<String>
FieldDropdown.Options
String
int
String
String
boolean
setFromString(String text)
Sets the values of the field from a string.
void
setOptions(List<FieldDropdown.Option> optionList)
Sets the available options for this field.
void
setOptions(FieldDropdown.Options options)
Sets the FieldDropdown.Options instance for this field.
void
setSelectedIndex(int index)
Sets the current selected option.
void
setSelectedValue(String newValue)
Update the selection index to the first available option that has the given value.

Inherited Method Summary

Public Constructors

public FieldDropdown (String name)

Parameters
name

public FieldDropdown (String name, FieldDropdown.Options options)

Parameters
name
options

Public Methods

public FieldDropdown clone ()

Returns
  • A clone of this field, which shares the same options and is initialized to the same selected value.

public static FieldDropdown fromJson (JSONObject json)

Loads a FieldDropdown from JSON. This is usually used for the BlockFactory's prototype instances.

Parameters
json The JSON representing the object.
Returns
  • A new FieldDropdown instance.

public List<String> getDisplayNames ()

Returns
  • A list of all of the display names in order.

public FieldDropdown.Options getOptions ()

Returns
  • The list of options in this dropdown field.

public String getSelectedDisplayName ()

Returns
  • The display name of the currently selected option.

public int getSelectedIndex ()

Returns
  • The index of the currently selected option.

public String getSelectedValue ()

Returns
  • The value of the currently selected option.

public String getSerializedValue ()

Returns

public boolean setFromString (String text)

Sets the values of the field from a string.

This is used for setting values of all types of fields when loading a workspace from XML. It is also used, however, as the primary means of setting text fields (e.g., inputs, labels, dates).

There should be a concrete implementation for each field type.

Parameters
text The text value for this field from the XML.
Returns
  • True if the value was set, false otherwise.

public void setOptions (List<FieldDropdown.Option> optionList)

Sets the available options for this field.

Parameters
optionList A list of FieldDropdown.Options, to initialize a new FieldDropdown.Options list.

public void setOptions (FieldDropdown.Options options)

Sets the FieldDropdown.Options instance for this field.

Parameters
options An FieldDropdown.Options list, replacing the current options.

public void setSelectedIndex (int index)

Sets the current selected option.

Parameters
index The index to select.

public void setSelectedValue (String newValue)

Update the selection index to the first available option that has the given value. If there are no options the index will be set to -1. If the value given is empty or does not exist the index will be set to 0.

Parameters
newValue The value of the option to select.