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)); } }
@SuppressWarnings("unchecked") @Override public void setValue(Boolean value) { if (value != null) { checkBox.setSelected(value); embeddedEditor.setValue(embeddedParameter.getValue()); } }
@Override public Boolean getValue() { embeddedParameter.setValue(embeddedEditor.getValue()); return checkBox.isSelected(); }