Skip to content
Snippets Groups Projects

Resolve "Ajout d'un fonctionnalité permettant la création d'ontologie depuis l'interface"

2 files
+ 142
3
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -20,9 +20,10 @@ package fr.inra.po2vocabmanager.view;
import fr.inra.po2vocabmanager.MainApp;
import fr.inra.po2vocabmanager.utils.UITools;
import fr.inrae.po2engine.exception.ProjectExistException;
import fr.inrae.po2engine.exception.AlreadyExistException;
import fr.inrae.po2engine.externalTools.CloudConnector;
import fr.inrae.po2engine.model.Datas;
import fr.inrae.po2engine.model.Ontologies;
import fr.inrae.po2engine.model.Ontology;
import fr.inrae.po2engine.model.dataModel.ProjectFile;
import fr.inrae.po2engine.utils.PO2Properties;
@@ -40,6 +41,7 @@ import javafx.util.Pair;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.function.UnaryOperator;
@@ -84,6 +86,8 @@ public class RootLayoutController {
MenuItem addConceptScheme;
@FXML
MenuItem itemNewProject;
@FXML
MenuItem itemNewOntology;
@FXML
@@ -104,6 +108,8 @@ public class RootLayoutController {
addConceptScheme.setDisable(true);
itemNewProject.setVisible(false);
itemNewProject.setDisable(false);
itemNewOntology.setVisible(false);
itemNewOntology.setDisable(false);
}
@@ -138,6 +144,9 @@ public class RootLayoutController {
itemNewProject.visibleProperty().bind(mainApp.onDataViewProperty());
itemNewProject.disableProperty().bind(mainApp.onDataViewProperty().not());
itemNewOntology.visibleProperty().bind(mainApp.onOntologyViewProperty());
itemNewOntology.disableProperty().bind(mainApp.onOntologyViewProperty().not());
switchMode.textProperty().bind(Bindings.when(PO2Properties.productionModeProperty()).then("Switch to SandBox").otherwise("Switch to Production"));
switchMode.setOnAction(event -> {
if(mainApp.canLeaveApp()) {
@@ -156,8 +165,137 @@ public class RootLayoutController {
MainApp.importOnto();
}
@FXML
public void createNewOntology() {
if(!mainApp.unlock()) {
return;
}
if(!CloudConnector.isInitUser()) {
if(!UITools.startLogin()) {
return;
}
}
if(MainApp.getOntologyControler() != null && MainApp.getOntologyControler().isModified()) {
Alert confirm = new Alert(Alert.AlertType.CONFIRMATION);
confirm.setTitle("Change");
confirm.setHeaderText("Current ontology changed will be lost. Are you sure ?");
ButtonType buttonCancel = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
ButtonType buttonYes = new ButtonType("Yes", ButtonBar.ButtonData.YES);
confirm.getButtonTypes().setAll(buttonCancel, buttonYes);
confirm.initOwner(MainApp.primaryStage);
//
Optional<ButtonType> result = confirm.showAndWait();
if (result.isPresent()) {
if (result.get().equals(buttonCancel)) {
return;
}
}
}
Dialog<Pair<String, Boolean>> dialog = new Dialog<>();
dialog.setTitle("New domain ontology");
dialog.setHeaderText("New domain ontology creation");
ButtonType createButtonType = new ButtonType("Create", ButtonBar.ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(createButtonType, ButtonType.CANCEL);
dialog.initOwner(MainApp.primaryStage);
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));
TextField ontologyName = new TextField();
ontologyName.setPromptText("ontology name");
ontologyName.setTextFormatter(new TextFormatter<Object>(new UnaryOperator<TextFormatter.Change>() {
@Override
public TextFormatter.Change apply(TextFormatter.Change change) {
if(change.getControlNewText().length() > 100) {
return null;
}
return change;
}
}));
ChoiceBox<String> choiceTypePublic = new ChoiceBox<>();
choiceTypePublic.getItems().add("Public");
choiceTypePublic.getItems().add("Private");
grid.add(new Label("Ontology name :"), 0, 0);
grid.add(ontologyName, 1, 0);
grid.add(new Label("Ontology type :"), 0, 1);
grid.add(choiceTypePublic, 1, 1);
Node createButton = dialog.getDialogPane().lookupButton(createButtonType);
createButton.setDisable(true);
ontologyName.textProperty().addListener((observable, oldValue, newValue) -> {
createButton.setDisable(false);
if(newValue.trim().isEmpty()) {
createButton.setDisable(true);
}
boolean nameExist = Ontologies.getOntologies().keySet().stream().filter(d -> d.trim().equalsIgnoreCase(newValue.trim()) || Tools.normalize(d.trim()).equalsIgnoreCase(Tools.normalize(newValue.trim()))).findAny().isPresent();
if(nameExist) {
createButton.setDisable(true);
}
if(choiceTypePublic.getValue() == null || choiceTypePublic.getValue().trim().isEmpty()) {
createButton.setDisable(true);
}
});
choiceTypePublic.valueProperty().addListener((observableValue, s, t1) -> {
createButton.setDisable(false);
if(ontologyName.getText().trim().isEmpty()) {
createButton.setDisable(true);
}
if(Ontologies.getOntologies().keySet().stream().filter(d -> d.trim().equalsIgnoreCase(ontologyName.getText().trim()) || Tools.normalize(d.trim()).equalsIgnoreCase(Tools.normalize(ontologyName.getText().trim()))).findAny().isPresent()) {
createButton.setDisable(true);
}
if(choiceTypePublic.getValue() == null || choiceTypePublic.getValue().trim().isEmpty()) {
createButton.setDisable(true);
}
});
dialog.getDialogPane().setContent(grid);
Platform.runLater(ontologyName::requestFocus);
dialog.setResultConverter(dialogButton -> {
if (dialogButton == createButtonType) {
return new Pair<String, Boolean>(ontologyName.getText(), "public".equalsIgnoreCase(choiceTypePublic.getValue()));
}
return null;
});
Optional<Pair<String, Boolean>> result = dialog.showAndWait();
result.ifPresent(projectPublic -> {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Ontology newOnto = null;
try {
newOnto = CloudConnector.createNewOntology(projectPublic.getKey(), projectPublic.getValue());
} catch (AlreadyExistException | IOException | URISyntaxException | InterruptedException e) {
MainApp.logger.error("error during ontology creation : " + projectPublic.getKey(), e);
}
if(newOnto != null) {
MainApp.getOntologyControler().startOpenFile(ontologyName.getText());
} else {
Alert errorCreate = new Alert(Alert.AlertType.ERROR);
errorCreate.initModality(Modality.WINDOW_MODAL);
errorCreate.initOwner(MainApp.primaryStage);
errorCreate.setTitle("Error");
errorCreate.setHeaderText("An error occurred during ontology creation");
errorCreate.show();
}
}
});
t.start();
});
}
@FXML
public void createNewProject() {
if(!mainApp.unlock()) {
return;
}
if(!CloudConnector.isInitUser()) {
if(!UITools.startLogin()) {
return;
@@ -260,7 +398,7 @@ public class RootLayoutController {
ProjectFile newProject = null;
try {
newProject = CloudConnector.createNewProject(projectPublic.getKey(), projectPublic.getValue());
} catch (ProjectExistException e) {
} catch (AlreadyExistException e) {
MainApp.logger.error("error during project creation : " + projectPublic.getKey(), e);
}
if(newProject != null) {
Loading