示例#1
0
  public OptionalEditor(PropertySheet.Item parameter) {

    if (!(parameter instanceof OptionalParameter)) throw new IllegalArgumentException();

    optionalParameter = (OptionalParameter<?>) parameter;
    embeddedParameter = optionalParameter.getEmbeddedParameter();

    // The checkbox
    checkBox = new CheckBox();

    setLeft(checkBox);

    // Add embedded editor
    try {
      Class<? extends PropertyEditor<?>> embeddedEditorClass =
          embeddedParameter.getPropertyEditorClass().get();
      embeddedEditor =
          embeddedEditorClass
              .getDeclaredConstructor(PropertySheet.Item.class)
              .newInstance(embeddedParameter);
      Node embeddedNode = embeddedEditor.getEditor();
      Boolean value = optionalParameter.getValue();
      if (value == null) value = false;
      embeddedNode.setDisable(!value);
      checkBox.setOnAction(
          e -> {
            embeddedNode.setDisable(!checkBox.isSelected());
          });

      setCenter(embeddedNode);
    } catch (Exception e) {
      throw (new IllegalStateException(e));
    }
  }
示例#2
0
 @SuppressWarnings("unchecked")
 @Override
 public void setValue(Boolean value) {
   if (value != null) {
     checkBox.setSelected(value);
     embeddedEditor.setValue(embeddedParameter.getValue());
   }
 }
示例#3
0
 @Override
 public Boolean getValue() {
   embeddedParameter.setValue(embeddedEditor.getValue());
   return checkBox.isSelected();
 }