in kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/editors/StyleEditor.java [247:330]
private void initialize(EditorItemDelegate editor) {
this.editor = editor;
root = EditorUtils.loadFxml("StyleEditorItem.fxml", this);
// Add the AutoSuggest text field in the scene graph
propertySp.getChildren().add(super.getRoot());
propertyTf = super.getTextField();
EventHandler<ActionEvent> onActionListener = event -> {
// System.out.println("StyleItem : onActionListener");
if (getValue().equals(currentValue)) {
// no change
return;
}
if (!propertyTf.getText().isEmpty() && !valueTf.getText().isEmpty()) {
// System.out.println("StyleEditorItem : COMMIT");
editor.commit(StyleItem.this);
if (event != null && event.getSource() instanceof TextField) {
((TextField) event.getSource()).selectAll();
}
}
if (propertyTf.getText().isEmpty() && valueTf.getText().isEmpty()) {
remove(null);
}
updateButtons();
currentValue = EditorUtils.toString(getValue());
};
ChangeListener<String> textPropertyChange = (ov, prevText, newText) -> {
if (prevText.isEmpty() || newText.isEmpty()) {
// Text changed FROM empty value, or TO empty value: buttons status change
updateButtons();
}
};
propertyTf.textProperty().addListener(textPropertyChange);
valueTf.textProperty().addListener(textPropertyChange);
updateButtons();
// Do not add a generic focus listener on each of the text fields,
// but implement a specific one.
setTextEditorBehavior(propertyTf, onActionListener, false);
setTextEditorBehavior(valueTf, onActionListener, false);
ChangeListener<Boolean> focusListener = (observable, oldValue, newValue) -> {
if (!newValue) {
// focus lost: commit
editor.editing(false, onActionListener);
} else {
// got focus
editor.editing(true, onActionListener);
}
};
propertyTf.focusedProperty().addListener(focusListener);
valueTf.focusedProperty().addListener(focusListener);
// Initialize menu items text
removeMi.setText(I18N.getString("inspector.list.remove"));
moveUpMi.setText(I18N.getString("inspector.list.moveup"));
moveDownMi.setText(I18N.getString("inspector.list.movedown"));
errorListener = change -> {
while (change.next()) {
if (change.wasAdded()) {
for (CssParser.ParseError error : change.getAddedSubList()) {
if ("InlineStyleParsingError".equals(error.getClass().getSimpleName())) {
parsingError = true;
break;
}
}
}
}
};
// Select all text when the value of this editor is selected
// property text field is already taken care of in AutoSuggestEditor
valueTf.setOnMousePressed(event -> valueTf.selectAll());
valueTf.focusedProperty().addListener(((observable, oldValue, newValue) -> {
if (newValue) {
valueTf.selectAll();
}
}));
}