public void propertyChange (final @Nonnull PropertyChangeEvent event) { final String propertyName = event.getPropertyName(); if (PROP_VALUE.equals(propertyName)) { select(values, property.getValue(), spinner); } else if (PROP_ENABLED.equals(propertyName)) { spinner.setEnabled(property.isEnabled()); } // no PROP_VALID, a Spinner is always valid } });
public void onCheckedChanged (final @Nonnull CompoundButton buttonView, final boolean isChecked) { property.setValue(isChecked); } });
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void computeEnablements() { count.setEnabled(countType.getValue() != CountType.NOT_COUNTED); maxCount.setEnabled(countType.getValue() == CountType.RANGE); }
public static void bind (final @Nonnull List<RadioButton> radiobuttons, final @Nonnull FormProperty<?> prop) if (!prop.getType().isEnum()) throw new IllegalArgumentException("Only FormProperty<enum> can be bound to a spinner; instead was " + prop.getType()); final Enum<?>[] values = (Enum<?>[])prop.getType().getEnumConstants(); // FIXME: move to property.getValues() final FormProperty<Enum<?>> property = (FormProperty<Enum<?>>)prop; select(values, property.getValue(), radiobuttons); radioButton.setEnabled(property.isEnabled()); property.addPropertyChangeListener(new PropertyChangeListener() // FIXME: weak!
checkBox.setChecked(property.getValue()); checkBox.setEnabled(property.isEnabled()); property.addPropertyChangeListener(new PropertyChangeListener() // FIXME: weak!
private void showFeedback() { final int text = (model.getValue() != null) ? R.string.noteUpdated : R.string.noteErased; Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } }
boolean valid = true; if (countType.getValue() != CountType.NOT_COUNTED) lower = Integer.parseInt(count.getValue()); count.setValid(true); count.setValid(false); if (valid && countType.getValue() == CountType.RANGE) upper = Integer.parseInt(maxCount.getValue()); maxCount.setValid(true); maxCount.setValid(false); maxCount.setValid(false);
/******************************************************************************************************************* * * ******************************************************************************************************************/ public CountAndGenderFormModel() { computeEnablements(); countType.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange (final @Nonnull PropertyChangeEvent event) { computeEnablements(); } }); }
public static void bind (final @Nonnull Spinner spinner, final @Nonnull FormProperty<?> prop) if (!prop.getType().isEnum()) throw new IllegalArgumentException("Only FormProperty<enum> can be bound to a spinner; instead was " + prop.getType()); final Enum<?>[] values = (Enum<?>[])prop.getType().getEnumConstants(); // FIXME: move to property.getValues() final FormProperty<Enum<?>> property = (FormProperty<Enum<?>>)prop; select(values, property.getValue(), spinner); spinner.setEnabled(property.isEnabled()); property.addPropertyChangeListener(new PropertyChangeListener() // FIXME: weak!
editText.setText(property.getValue()); editText.setEnabled(property.isEnabled()); property.addPropertyChangeListener(new PropertyChangeListener() // FIXME: weak!
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull /* package */ static Cardinality getCardinality (final @Nonnull CountAndGenderFormModel model) { switch (model.getCountType().getValue()) { case NOT_COUNTED: return Cardinality.UNDEFINED; case EXACT: final int simpleCardinality = Integer.parseInt(model.getCount().getValue()); return Cardinality.valueOf(simpleCardinality); case APPROXIMATED: final int approxCardinality = Integer.parseInt(model.getCount().getValue()); return Cardinality.approxValueOf(approxCardinality); case RANGE: final int lower = Integer.parseInt(model.getCount().getValue()); final int upper = Integer.parseInt(model.getMaxCount().getValue()); return Cardinality.rangeOf(lower, upper); } throw new RuntimeException("Unexpected value: " + model.getCountType().getValue()); } }
model.getCountType().addPropertyChangeListener(focusRequestor);
public void propertyChange (final @Nonnull PropertyChangeEvent event) { final String propertyName = event.getPropertyName(); if (PROP_VALUE.equals(propertyName)) { checkBox.setChecked(property.getValue()); } else if (PROP_ENABLED.equals(propertyName)) { checkBox.setEnabled(property.isEnabled()); } // no PROP_VALID, a Checkbox is always valid } });
public void editNote() { final LayoutInflater inflater = LayoutInflater.from(context); final View view = inflater.inflate(R.layout.dialog_observation_note, null); final EditText etNote = (EditText)view.findViewById(R.id.etNote); etNote.setText(model.getValue()); new AlertDialog.Builder(context) .setIcon(android.R.drawable.ic_dialog_info) .setTitle(R.string.noteHeader) .setView(view) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick (final @Nonnull DialogInterface dialog, final int whichButton) { model.setValue(etNote.getText().toString().trim()); showFeedback(); } }) .setNegativeButton(android.R.string.no, null) .setNeutralButton(R.string.erase, new DialogInterface.OnClickListener() { public void onClick (final @Nonnull DialogInterface dialog, final int whichButton) { model.setValue(null); showFeedback(); } }) .create().show(); }
public void onNothingSelected (final @Nonnull AdapterView<?> parent) { property.setValue(null); } });
public void propertyChange (final @Nonnull PropertyChangeEvent event) { final String propertyName = event.getPropertyName(); if (PROP_VALUE.equals(propertyName)) { select(values, property.getValue(), radiobuttons); } else if (PROP_ENABLED.equals(propertyName)) { for (final RadioButton radioButton : radiobuttons) { radioButton.setEnabled(property.isEnabled()); } } // no PROP_VALID, RadioButtons are always valid } });
public void onClick (final @Nonnull DialogInterface dialog, final int whichButton) { model.setValue(etNote.getText().toString().trim()); showFeedback(); } })
public void propertyChange (final @Nonnull PropertyChangeEvent event) { final String propertyName = event.getPropertyName(); if (PROP_VALUE.equals(propertyName)) { final String value = property.getValue(); if (!editText.getText().toString().equals(value)) // avoid loops { editText.setText(value); } } else if (PROP_ENABLED.equals(propertyName)) { editText.setEnabled(property.isEnabled()); } if (PROP_VALID.equals(propertyName)) { // editText.setText(property.getValue()); } } });
public void onClick (final @Nonnull DialogInterface dialog, final int whichButton) { model.setValue(null); showFeedback(); } })