Search in sources :

Example 6 with CommonPbModel

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();
}
Also used : StageStyle(javafx.stage.StageStyle) Pos(javafx.geometry.Pos) Initializable(javafx.fxml.Initializable) java.util(java.util) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) javafx.scene.control(javafx.scene.control) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) URL(java.net.URL) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) FXCollections(javafx.collections.FXCollections) SquidMessageDialog(org.cirdles.squid.gui.dialogs.SquidMessageDialog) SquidUIController.squidLabData(org.cirdles.squid.gui.SquidUIController.squidLabData) ParametersModel(org.cirdles.squid.parameters.parameterModels.ParametersModel) BigDecimal(java.math.BigDecimal) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) DataDictionary(org.cirdles.squid.parameters.util.DataDictionary) DirectoryChooser(javafx.stage.DirectoryChooser) HBox(javafx.scene.layout.HBox) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) FileHandler(org.cirdles.squid.gui.utilities.fileUtilities.FileHandler) SquidPersistentState(org.cirdles.squid.utilities.stateUtilities.SquidPersistentState) Node(javafx.scene.Node) DecimalFormat(java.text.DecimalFormat) ParametersModelComparator(org.cirdles.squid.parameters.ParametersModelComparator) ParametersLauncher.squidLabDataWindow(org.cirdles.squid.gui.parameters.ParametersLauncher.squidLabDataWindow) SquidException(org.cirdles.squid.exceptions.SquidException) AbstractMatrixModel(org.cirdles.squid.parameters.matrices.AbstractMatrixModel) IOException(java.io.IOException) ValueModel(org.cirdles.squid.parameters.valueModels.ValueModel) ParametersLauncher.squidLabDataStage(org.cirdles.squid.gui.parameters.ParametersLauncher.squidLabDataStage) File(java.io.File) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) AnchorPane(javafx.scene.layout.AnchorPane) ParametersTab(org.cirdles.squid.gui.parameters.ParametersLauncher.ParametersTab) ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) SquidException(org.cirdles.squid.exceptions.SquidException) Node(javafx.scene.Node) IOException(java.io.IOException) File(java.io.File) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) SquidException(org.cirdles.squid.exceptions.SquidException) IOException(java.io.IOException) FXML(javafx.fxml.FXML)

Example 7 with CommonPbModel

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();
        }
    }
}
Also used : ReferenceMaterialModel(org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel) Task(org.cirdles.squid.tasks.Task) Squid3ProjectParametersAPI(org.cirdles.squid.projects.Squid3ProjectParametersAPI) PhysicalConstantsModel(org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel) TaskInterface(org.cirdles.squid.tasks.TaskInterface) ParametersModelComparator(org.cirdles.squid.parameters.ParametersModelComparator) ZipUtility.extractZippedFile(org.cirdles.squid.utilities.fileUtilities.ZipUtility.extractZippedFile) PrawnFile(org.cirdles.squid.prawn.PrawnFile) File(java.io.File) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) SquidException(org.cirdles.squid.exceptions.SquidException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException)

Aggregations

CommonPbModel (org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel)7 File (java.io.File)4 PhysicalConstantsModel (org.cirdles.squid.parameters.parameterModels.physicalConstantsModels.PhysicalConstantsModel)4 ReferenceMaterialModel (org.cirdles.squid.parameters.parameterModels.referenceMaterialModels.ReferenceMaterialModel)4 Task (org.cirdles.squid.tasks.Task)4 IOException (java.io.IOException)3 SquidException (org.cirdles.squid.exceptions.SquidException)3 ParametersModelComparator (org.cirdles.squid.parameters.ParametersModelComparator)3 TaskInterface (org.cirdles.squid.tasks.TaskInterface)3 BigDecimal (java.math.BigDecimal)2 FXML (javafx.fxml.FXML)2 JAXBException (javax.xml.bind.JAXBException)2 ResourceExtractor (org.cirdles.commons.util.ResourceExtractor)2 ZipUtility.extractZippedFile (org.cirdles.squid.utilities.fileUtilities.ZipUtility.extractZippedFile)2 Test (org.junit.Test)2 SAXException (org.xml.sax.SAXException)2 BufferedWriter (java.io.BufferedWriter)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1