in kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/hierarchy/treeview/HierarchyTreeCell.java [588:701]
public void startEditingDisplayInfo() {
assert getItem().hasDisplayInfo(panelController.getDisplayOption());
final InlineEditController inlineEditController
= panelController.getEditorController().getInlineEditController();
final TextInputControl editor;
final Type type;
final String initialValue;
// 1) Build the TextInputControl used to inline edit
//----------------------------------------------------------------------
// INFO display option may use either a TextField or a TextArea
if (panelController.getDisplayOption() == DisplayOption.INFO) {
final String info = getItem().getDescription();
final Object sceneGraphObject = getItem().getFxomObject().getSceneGraphObject();
if (sceneGraphObject instanceof TextArea || DesignHierarchyMask.containsLineFeed(info)) {
type = Type.TEXT_AREA;
} else {
type = Type.TEXT_FIELD;
}
// displayInfoLabel.getText() may be truncated to a single line description
// We set the initial value with the complete description value
initialValue = getItem().getDescription();
} //
// FXID and NODEID options use a TextField
else {
type = Type.TEXT_FIELD;
initialValue = displayInfoLabel.getText();
}
editor = inlineEditController.createTextInputControl(type, displayInfoLabel, initialValue);
// CSS
final ObservableList<String> styleSheets
= panelController.getPanelRoot().getStylesheets();
editor.getStylesheets().addAll(styleSheets);
editor.getStyleClass().add("theme-presets"); //NOI18N
editor.getStyleClass().add(InlineEditController.INLINE_EDITOR);
// 2) Build the COMMIT Callback
// This callback will be invoked to commit the new value
// It returns true if the value is unchanged or if the commit succeeded,
// false otherwise
//----------------------------------------------------------------------
final Callback<String, Boolean> requestCommit = newValue -> {
// 1) Check the input value is valid
// 2) If valid, commit the new value and return true
// 3) Otherwise, return false
final HierarchyItem item = getItem();
// Item may be null when invoking UNDO while inline editing session is on going
if (item != null) {
final FXOMObject fxomObject = item.getFxomObject();
final DisplayOption option = panelController.getDisplayOption();
final EditorController editorController = panelController.getEditorController();
switch (option) {
case INFO:
case NODEID:
if (fxomObject instanceof FXOMInstance) {
final FXOMInstance fxomInstance = (FXOMInstance) fxomObject;
final PropertyName propertyName = item.getPropertyNameForDisplayInfo(option);
assert propertyName != null;
final ValuePropertyMetadata vpm
= Metadata.getMetadata().queryValueProperty(fxomInstance, propertyName);
final ModifyObjectJob job1
= new ModifyObjectJob(fxomInstance, vpm, newValue, editorController);
if (job1.isExecutable()) {
editorController.getJobManager().push(job1);
}
}
break;
case FXID:
assert newValue != null;
final String fxId = newValue.isEmpty() ? null : newValue;
final ModifyFxIdJob job2
= new ModifyFxIdJob(fxomObject, fxId, editorController);
if (job2.isExecutable()) {
// If a controller class has been defined,
// check if the fx id is an injectable field
final String controllerClass
= editorController.getFxomDocument().getFxomRoot().getFxController();
if (controllerClass != null && fxId != null) {
final URL location = editorController.getFxmlLocation();
final Class<?> clazz = fxomObject.getSceneGraphObject() == null ? null
: fxomObject.getSceneGraphObject().getClass();
final Glossary glossary = editorController.getGlossary();
final List<String> fxIds1 = glossary.queryFxIds(location, controllerClass, clazz);
if (fxIds1.contains(fxId) == false) {
editorController.getMessageLog().logWarningMessage(
"log.warning.no.injectable.fxid", fxId);
}
}
// Check duplicared fx ids
final FXOMDocument fxomDocument = editorController.getFxomDocument();
final Set<String> fxIds2 = fxomDocument.collectFxIds().keySet();
if (fxIds2.contains(fxId)) {
editorController.getMessageLog().logWarningMessage(
"log.warning.duplicate.fxid", fxId);
}
editorController.getJobManager().push(job2);
} else if (fxId != null) {
editorController.getMessageLog().logWarningMessage(
"log.warning.invalid.fxid", fxId);
}
break;
default:
assert false;
return false;
}
}
return true;
};
inlineEditController.startEditingSession(editor, displayInfoLabel, requestCommit, null);
}