use of org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel in project Squid by CIRDLES.
the class ParametersManagerGUIController method commonPbImpXMLAction.
@FXML
private void commonPbImpXMLAction(ActionEvent event) {
File file = null;
try {
file = FileHandler.parametersManagerSelectCommonPbModelXMLFile(squidLabDataWindow);
} catch (IOException e) {
SquidMessageDialog.showWarningDialog(e.getMessage(), squidLabDataWindow);
}
if (file != null) {
try {
CommonPbModel importedMod = (CommonPbModel) commonPbModel.readXMLObject(file.getAbsolutePath(), false);
if (commonPbModels.contains(importedMod)) {
ButtonType renameButton = new ButtonType("Rename");
ButtonType changeVersionButton = new ButtonType("Change Version");
ButtonType cancelButton = new ButtonType("Cancel");
ButtonType overwriteButton = new ButtonType("Overwrite");
Alert alert;
if (commonPbModels.get(commonPbModels.indexOf(importedMod)).isEditable()) {
alert = new Alert(Alert.AlertType.WARNING, "A Common Pb Model with the same name and version exists." + "What would you like to do?", overwriteButton, renameButton, changeVersionButton, cancelButton);
} else {
alert = new Alert(Alert.AlertType.WARNING, "A Common Pb Model with the same name and version exists." + "What would you like to do?", renameButton, changeVersionButton, cancelButton);
}
alert.initStyle(StageStyle.UNDECORATED);
alert.initOwner(squidLabDataWindow);
alert.setX(squidLabDataStage.getX() + (squidLabDataStage.getWidth() - alert.getWidth()) / 2);
alert.setY(squidLabDataStage.getY() + (squidLabDataStage.getHeight() - alert.getHeight()) / 2);
alert.showAndWait().ifPresent(p -> {
if (p.equals(renameButton)) {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Rename");
dialog.setHeaderText("Rename " + importedMod.getModelName());
dialog.setContentText("Enter the new name:");
Button okBtn = (Button) dialog.getDialogPane().lookupButton(ButtonType.OK);
TextField newName = null;
for (Node n : dialog.getDialogPane().getChildren()) {
if (n instanceof TextField) {
newName = (TextField) n;
}
}
if (okBtn != null && newName != null) {
newName.textProperty().addListener((observable, oldValue, newValue) -> {
importedMod.setModelName(newValue);
okBtn.setDisable(commonPbModels.contains(importedMod) || newValue.isEmpty());
});
}
dialog.initStyle(StageStyle.UNDECORATED);
dialog.initOwner(squidLabDataStage.getScene().getWindow());
dialog.setX(squidLabDataStage.getX() + (squidLabDataStage.getWidth() - 200) / 2);
dialog.setY(squidLabDataStage.getY() + (squidLabDataStage.getHeight() - 150) / 2);
dialog.showAndWait().ifPresent(d -> {
importedMod.setModelName(dialog.getResult());
if (!commonPbModels.contains(importedMod)) {
importedMod.setIsEditable(true);
commonPbModels.add(importedMod);
commonPbCB.getItems().add(importedMod.getModelNameWithVersion());
commonPbCB.getSelectionModel().selectLast();
commonPbModel = importedMod;
setUpCommonPb();
try {
squidLabData.storeState();
} catch (SquidException e) {
e.printStackTrace();
}
} else {
SquidMessageDialog.showWarningDialog("Invalid new name, model not imported", squidLabDataStage);
}
});
} else if (p.equals(changeVersionButton)) {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Change Version");
dialog.setHeaderText("Change Version " + importedMod.getModelName());
dialog.setContentText("Enter the new version:");
Button okBtn = (Button) dialog.getDialogPane().lookupButton(ButtonType.OK);
TextField newName = null;
for (Node n : dialog.getDialogPane().getChildren()) {
if (n instanceof TextField) {
newName = (TextField) n;
}
}
if (okBtn != null && newName != null) {
newName.textProperty().addListener((observable, oldValue, newValue) -> {
importedMod.setModelName(newValue);
okBtn.setDisable(commonPbModels.contains(importedMod) || newValue.isEmpty());
});
}
dialog.initStyle(StageStyle.UNDECORATED);
dialog.initOwner(squidLabDataStage.getScene().getWindow());
dialog.setX(squidLabDataStage.getX() + (squidLabDataStage.getWidth() - 200) / 2);
dialog.setY(squidLabDataStage.getY() + (squidLabDataStage.getHeight() - 150) / 2);
dialog.showAndWait().ifPresent(d -> {
importedMod.setVersion(dialog.getResult());
if (!commonPbModels.contains(importedMod)) {
importedMod.setIsEditable(true);
commonPbModels.add(importedMod);
commonPbCB.getItems().add(importedMod.getModelNameWithVersion());
commonPbCB.getSelectionModel().selectLast();
commonPbModel = importedMod;
setUpCommonPb();
try {
squidLabData.storeState();
} catch (SquidException e) {
e.printStackTrace();
}
} else {
SquidMessageDialog.showWarningDialog("Invalid new version, model not imported", squidLabDataStage);
}
});
} else if (p.equals(overwriteButton)) {
commonPbModels.remove(importedMod);
importedMod.setIsEditable(true);
commonPbModels.add(importedMod);
commonPbCB.getItems().add(importedMod.getModelNameWithVersion());
commonPbCB.getSelectionModel().selectLast();
commonPbModel = importedMod;
setUpCommonPb();
try {
squidLabData.storeState();
} catch (SquidException e) {
e.printStackTrace();
}
}
});
} else {
importedMod.setIsEditable(true);
commonPbModels.add(importedMod);
commonPbCB.getItems().add(importedMod.getModelNameWithVersion());
commonPbCB.getSelectionModel().selectLast();
commonPbModel = importedMod;
setUpCommonPb();
squidLabData.storeState();
}
} catch (Exception e) {
SquidMessageDialog.showWarningDialog("An error occurred: \n" + e.getMessage(), squidLabDataWindow);
}
}
chosenTab = ParametersTab.commonPb;
squidLabDataStage.requestFocus();
}
use of org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel in project Squid by CIRDLES.
the class Squid3Ink method openSquid3Project.
/**
* Loads existing Squid3 project file.
*
* @param projectFilePath
* @return
*/
@Override
public void openSquid3Project(Path projectFilePath) throws SquidException {
squid3Project = (SquidProject) SquidSerializer.getSerializedObjectFromFile(projectFilePath.toString(), true);
if (squid3Project != null && squid3Project.getTask() != null) {
TaskInterface task = squid3Project.getTask();
SquidProject.setProjectChanged(((Task) task).synchronizeTaskVersion());
(((Task) task).verifySquidLabDataParameters()).forEach(model -> {
if (model instanceof PhysicalConstantsModel) {
squidLabData.addPhysicalConstantsModel(model);
squidLabData.getPhysicalConstantsModels().sort(new ParametersModelComparator());
} else if (model instanceof CommonPbModel) {
squidLabData.addcommonPbModel(model);
squidLabData.getCommonPbModels().sort(new ParametersModelComparator());
} else if (model instanceof ReferenceMaterialModel) {
squidLabData.addReferenceMaterial(model);
squidLabData.getReferenceMaterials().sort(new ParametersModelComparator());
}
});
((Squid3ProjectParametersAPI) squid3Project).setReferenceMaterialModel(task.getReferenceMaterialModel());
((Squid3ProjectParametersAPI) squid3Project).setConcentrationReferenceMaterialModel(task.getConcentrationReferenceMaterialModel());
if (SquidProject.isProjectChanged()) {
// next two lines make sure 15-digit rounding is used by reprocessing data
task.setChanged(true);
task.setupSquidSessionSpecsAndReduceAndReport(true);
((Task) task).initTaskDefaultSquidReportTables(true);
}
((Task) task).buildExpressionDependencyGraphs();
((Task) task).updateSquidSpeciesModelsGeochronMode();
squidPersistentState.updateProjectListMRU(new File(projectFilePath.toString()));
try {
squid3Project.getPrawnFileHandler().getReportsEngine().setFolderToWriteCalamariReports(projectFilePath.toFile().getParentFile());
} catch (Exception e) {
e.printStackTrace();
}
try {
squid3Project.getPrawnFileHandler().initReportsEngineWithCurrentPrawnFileName();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations