use of controller.command.RenameClassSchemeCommand in project uPMT by coco35700.
the class TypeTreeViewControllerClass method rename.
@Override
public void rename() {
super.rename();
ChangeListener<Boolean> listener = new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
if (!newPropertyValue) {
if (type.getType().isCategory()) {
String oldName = new String(type.getType().getName());
if (!oldName.equals(textField.getText())) {
boolean hasName = false;
// System.out.println("Parent: "+type.getParent().getName());
for (Type classe : type.getParent().getTypes()) {
// System.out.println("Classes: "+classe.getName());
if (classe.getName().equals(textField.getText())) {
hasName = true;
break;
}
}
if (!hasName) {
RenameClassSchemeCommand cmd = new RenameClassSchemeCommand(type.getClassNameController(), oldName, textField.getText(), main);
cmd.execute();
UndoCollector.INSTANCE.add(cmd);
} else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(main._langBundle.getString("invalid_name"));
alert.setHeaderText(null);
alert.setContentText(main._langBundle.getString("class_name_invalid"));
alert.show();
}
}
}
typePane.setLeft(nomType);
rename.setDisable(false);
textField.focusedProperty().removeListener(this);
}
}
};
textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.ENTER) {
if (type.getType().isProperty()) {
textField.setText(textField.getText());
}
typePane.setLeft(nomType);
rename.setDisable(false);
}
if (event.getCode() == KeyCode.ESCAPE) {
typePane.setLeft(nomType);
rename.setDisable(true);
}
}
});
textField.focusedProperty().addListener(listener);
typePane.setLeft(textField);
Platform.runLater(() -> textField.requestFocus());
Platform.runLater(() -> textField.selectAll());
}
Aggregations