コード例 #1
0
  private void updateModelValue() {
    if (property.get() == null || !(property.get() instanceof FromConfigurationPropertyValue)) {
      try {
        String defaultName = (String) choiceBox.getItems().get(0);
        Configuration defaultValue = Registery.get().getConfiguration(defaultName);
        property.set(new FromConfigurationPropertyValue(defaultValue));
      } catch (Exception ex) {
        Logger.getLogger(ConfigurationPropertyEditor.class.getName()).log(Level.SEVERE, null, ex);
      }
    }

    FromConfigurationPropertyValue fcpv = (FromConfigurationPropertyValue) property.get();

    if (fcpv != null
        && fcpv.getValue()
            != null) { // in case property is a dummy (came from collection property editor)
      Class implementor = fcpv.getValue().configuredType();
      String className = Registery.get().getRegisteredClassName(implementor);
      Property temp = property;
      property = null;
      choiceBox.getSelectionModel().select(className);
      property = temp;
      if (parentCollection != null && choiceBox.getItems().size() <= 1) {
        setText(className);
      }
      confEditor.setModel(fcpv.getValue(), readOnly, filter);
    } else {
      choiceBox.getSelectionModel().select("NULL");
    }
  }
コード例 #2
0
  public ConfigurationPropertyEditor(ConfigurationEditor parent, Property collection) {
    this.parent = parent;
    this.parentCollection = collection;

    getStyleClass().add("configuration-property-editor");

    selected = new SimpleBooleanProperty(false);

    skinProperty()
        .addListener(
            (sp, o, n) -> {
              Node node = FXUtils.getTitledPaneTitleRegion(this);

              if (node != null) {
                node.addEventFilter(MouseEvent.MOUSE_RELEASED, eh -> eh.consume());
                node.addEventFilter(
                    MouseEvent.MOUSE_PRESSED,
                    eh -> {
                      eh.consume();
                      if (!selected.get()) {
                        selected.set(true);
                      } else {
                        setExpanded(!isExpanded());
                      }
                    });
              }
            });

    selected.addListener(
        (p, ov, nv) -> {
          if (nv && parent != null) {
            parent.select(this);
          }
        });

    infoContainer = new Label("");
    confEditor = new ConfigurationEditorInternal(parent, this);

    implementorsBorderPane = new BorderPane();
    implementorsBorderPane.getStyleClass().add("implementors");

    Label label = new Label("type :");
    label.setPadding(new Insets(0, LABEL_MARGING, 0, 0));
    BorderPane.setAlignment(label, Pos.CENTER_LEFT);
    implementorsBorderPane.setLeft(label);

    choiceBox = new ChoiceBox<>();
    //        choiceBox.setMaxWidth(Double.MAX_VALUE);
    choiceBox
        .valueProperty()
        .addListener(
            (ObservableValue<? extends String> p, String ov, String nv) -> {
              try {
                if (property != null) {
                  Configuration value = null;
                  if (!nv.equals("NULL")) {
                    value = Registery.get().getConfiguration(nv);
                  }
                  property.set(value == null ? null : new FromConfigurationPropertyValue(value));
                  setRepresentativeName();
                  confEditor.setModel(value, readOnly, filter);
                }
              } catch (ClassNotFoundException ex) {
                Logger.getLogger(ConfigurationPropertyEditor.class.getName())
                    .log(Level.SEVERE, null, ex);
              }
            });
    BorderPane.setAlignment(choiceBox, Pos.CENTER_LEFT);
    implementorsBorderPane.setCenter(choiceBox);

    editorVBox = new VBox();
    editorVBox.getChildren().addAll(implementorsBorderPane, confEditor);
    setContent(editorVBox);

    setGraphic(infoContainer);
    setExpanded(false);
  }