Search in sources :

Example 1 with IMoleculeFragmenter

use of de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter in project MORTAR by FelixBaensch.

the class FragmentationService method reloadFragmenterSettings.

/**
 * Reloads settings of the available fragmenters. If something goes wrong, it is logged.
 */
public void reloadFragmenterSettings() {
    String tmpDirectoryPath = FileUtil.getSettingsDirPath() + FragmentationService.FRAGMENTER_SETTINGS_SUBFOLDER_NAME + File.separator;
    for (IMoleculeFragmenter tmpFragmenter : this.fragmenters) {
        String tmpClassName = tmpFragmenter.getClass().getSimpleName();
        File tmpFragmenterSettingsFile = new File(tmpDirectoryPath + tmpClassName + BasicDefinitions.PREFERENCE_CONTAINER_FILE_EXTENSION);
        if (tmpFragmenterSettingsFile.exists() && tmpFragmenterSettingsFile.isFile() && tmpFragmenterSettingsFile.canRead()) {
            PreferenceContainer tmpContainer;
            try {
                tmpContainer = new PreferenceContainer(tmpFragmenterSettingsFile);
            } catch (IllegalArgumentException | IOException anException) {
                FragmentationService.LOGGER.log(Level.WARNING, "Unable to reload settings of fragmenter " + tmpClassName + " : " + anException.toString(), anException);
                continue;
            }
            this.updatePropertiesFromPreferences(tmpFragmenter.settingsProperties(), tmpContainer);
        } else {
            // settings will remain in default
            FragmentationService.LOGGER.log(Level.WARNING, "No persisted settings for " + tmpClassName + " available.");
        }
    }
}
Also used : PreferenceContainer(de.unijena.cheminf.mortar.preference.PreferenceContainer) IOException(java.io.IOException) IMoleculeFragmenter(de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter) File(java.io.File)

Example 2 with IMoleculeFragmenter

use of de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter in project MORTAR by FelixBaensch.

the class FragmentationService method persistSelectedFragmenterAndPipeline.

/**
 * Persists the fragmentation service settings (the selected fragmenter) and the currently configured pipeline.
 * All settings are saved as matching preference objects in preference container files in a respective subfolder in
 * the settings directory. If anything fails, a warning is given to the user.
 */
public void persistSelectedFragmenterAndPipeline() {
    String tmpFragmentationServiceSettingsPath = FileUtil.getSettingsDirPath() + FragmentationService.FRAGMENTATION_SERVICE_SETTINGS_SUBFOLDER_NAME + File.separator;
    File tmpFragmentationServiceSettingsDir = new File(tmpFragmentationServiceSettingsPath);
    if (!tmpFragmentationServiceSettingsDir.exists()) {
        tmpFragmentationServiceSettingsDir.mkdirs();
    } else {
        FileUtil.deleteAllFilesInDirectory(tmpFragmentationServiceSettingsPath);
    }
    if (!tmpFragmentationServiceSettingsDir.canWrite()) {
        GuiUtil.guiMessageAlert(Alert.AlertType.ERROR, Message.get("Error.ExceptionAlert.Title"), Message.get("Error.ExceptionAlert.Header"), Message.get("FragmentationService.Error.settingsPersistence"));
        return;
    }
    PreferenceContainer tmpFragmentationServiceSettingsContainer = new PreferenceContainer(tmpFragmentationServiceSettingsPath + FragmentationService.FRAGMENTATION_SERVICE_SETTINGS_FILE_NAME + BasicDefinitions.PREFERENCE_CONTAINER_FILE_EXTENSION);
    if (!SingleTermPreference.isValidContent(this.selectedFragmenter.getFragmentationAlgorithmName())) {
        FragmentationService.LOGGER.log(Level.WARNING, "Selected fragmenter could not be persisted");
        GuiUtil.guiMessageAlert(Alert.AlertType.WARNING, Message.get("Error.ExceptionAlert.Title"), Message.get("Error.ExceptionAlert.Header"), Message.get("FragmentationService.Error.settingsPersistence"));
        for (IMoleculeFragmenter tmpFragmenter : this.fragmenters) {
            if (tmpFragmenter.getFragmentationAlgorithmName().equals(FragmentationService.DEFAULT_SELECTED_FRAGMENTER_ALGORITHM_NAME)) {
                this.selectedFragmenter = tmpFragmenter;
            }
        }
    }
    SingleTermPreference tmpSelectedFragmenterPreference = new SingleTermPreference(FragmentationService.SELECTED_FRAGMENTER_SETTING_NAME, this.selectedFragmenter.getFragmentationAlgorithmName());
    tmpFragmentationServiceSettingsContainer.add(tmpSelectedFragmenterPreference);
    if (Objects.isNull(this.pipeliningFragmentationName) || this.pipeliningFragmentationName.isEmpty()) {
        this.pipeliningFragmentationName = FragmentationService.DEFAULT_PIPELINE_NAME;
    }
    if (!SingleTermPreference.isValidContent(this.pipeliningFragmentationName)) {
        FragmentationService.LOGGER.log(Level.WARNING, "Given pipeline name " + this.pipeliningFragmentationName + " is invalid, will be reset to default.");
        this.pipeliningFragmentationName = FragmentationService.DEFAULT_PIPELINE_NAME;
    }
    SingleTermPreference tmpPipelineNamePreference = new SingleTermPreference(FragmentationService.PIPELINE_SETTING_NAME, this.pipeliningFragmentationName);
    tmpFragmentationServiceSettingsContainer.add(tmpPipelineNamePreference);
    tmpFragmentationServiceSettingsContainer.add(new SingleIntegerPreference(FragmentationService.PIPELINE_SIZE_SETTING_NAME, this.pipelineFragmenter.length));
    try {
        tmpFragmentationServiceSettingsContainer.writeRepresentation();
    } catch (IOException | SecurityException anException) {
        FragmentationService.LOGGER.log(Level.WARNING, "Fragmentation service settings persistence went wrong, exception: " + anException.toString(), anException);
        GuiUtil.guiExceptionAlert(Message.get("Error.ExceptionAlert.Title"), Message.get("Error.ExceptionAlert.Header"), Message.get("FragmentationService.Error.settingsPersistence"), anException);
    }
    for (int i = 0; i < this.pipelineFragmenter.length; i++) {
        IMoleculeFragmenter tmpFragmenter = this.pipelineFragmenter[i];
        List<Property> tmpSettings = tmpFragmenter.settingsProperties();
        String tmpFilePath = tmpFragmentationServiceSettingsPath + FragmentationService.PIPELINE_FRAGMENTER_FILE_NAME_PREFIX + i + BasicDefinitions.PREFERENCE_CONTAINER_FILE_EXTENSION;
        PreferenceContainer tmpPrefContainer = PreferenceUtil.translateJavaFxPropertiesToPreferences(tmpSettings, tmpFilePath);
        tmpPrefContainer.add(new SingleTermPreference(FragmentationService.PIPELINE_FRAGMENTER_ALGORITHM_NAME_SETTING_NAME, tmpFragmenter.getFragmentationAlgorithmName()));
        try {
            tmpPrefContainer.writeRepresentation();
        } catch (IOException | SecurityException anException) {
            FragmentationService.LOGGER.log(Level.WARNING, "Pipeline fragmenter settings persistence went wrong, exception: " + anException.toString(), anException);
            GuiUtil.guiExceptionAlert(Message.get("Error.ExceptionAlert.Title"), Message.get("Error.ExceptionAlert.Header"), Message.get("FragmentationService.Error.settingsPersistence"), anException);
            continue;
        }
    }
}
Also used : SingleTermPreference(de.unijena.cheminf.mortar.preference.SingleTermPreference) SingleIntegerPreference(de.unijena.cheminf.mortar.preference.SingleIntegerPreference) PreferenceContainer(de.unijena.cheminf.mortar.preference.PreferenceContainer) IOException(java.io.IOException) File(java.io.File) IMoleculeFragmenter(de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) SimpleEnumConstantNameProperty(de.unijena.cheminf.mortar.model.util.SimpleEnumConstantNameProperty) Property(javafx.beans.property.Property) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty)

Example 3 with IMoleculeFragmenter

use of de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter in project MORTAR by FelixBaensch.

the class FragmentationSettingsViewController method openFragmentationSettingsView.

// 
/**
 * Initialises and opens a settings view for fragmentationSettings
 */
private void openFragmentationSettingsView() {
    if (this.settingsView == null)
        this.settingsView = new SettingsView();
    this.fragmentationSettingsViewStage = new Stage();
    Scene tmpScene = new Scene(this.settingsView, GuiDefinitions.GUI_MAIN_VIEW_WIDTH_VALUE, GuiDefinitions.GUI_MAIN_VIEW_HEIGHT_VALUE);
    this.fragmentationSettingsViewStage.setScene(tmpScene);
    this.fragmentationSettingsViewStage.initModality(Modality.WINDOW_MODAL);
    this.fragmentationSettingsViewStage.initOwner(this.mainStage);
    this.fragmentationSettingsViewStage.show();
    this.fragmentationSettingsViewStage.setTitle(Message.get("FragmentationSettingsView.title"));
    this.fragmentationSettingsViewStage.setMinHeight(GuiDefinitions.GUI_MAIN_VIEW_HEIGHT_VALUE);
    this.fragmentationSettingsViewStage.setMinWidth(GuiDefinitions.GUI_MAIN_VIEW_WIDTH_VALUE);
    // 
    this.addListener();
    for (IMoleculeFragmenter tmpFragmenter : this.fragmenters) {
        HashMap<String, Object> tmpRecentProperties = new HashMap<>(tmpFragmenter.settingsProperties().size());
        this.recentProperties.put(tmpFragmenter.getFragmentationAlgorithmName(), tmpRecentProperties);
        Tab tmpTab = this.settingsView.addTab(this.fragmentationSettingsViewStage, tmpFragmenter.getFragmentationAlgorithmName(), tmpFragmenter.settingsProperties(), tmpFragmenter.getSettingNameToTooltipTextMap(), tmpRecentProperties);
        if (tmpFragmenter.getFragmentationAlgorithmName().equals(this.selectedFragmenterName)) {
            this.settingsView.getSelectionModel().select(tmpTab);
        }
    }
}
Also used : Tab(javafx.scene.control.Tab) HashMap(java.util.HashMap) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene) SettingsView(de.unijena.cheminf.mortar.gui.views.SettingsView) IMoleculeFragmenter(de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter)

Example 4 with IMoleculeFragmenter

use of de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter in project MORTAR by FelixBaensch.

the class MainViewController method addFragmentationAlgorithmCheckMenuItems.

// 
/**
 * Adds CheckMenuItems for fragmentation algorithms to MainMenuBar
 */
private void addFragmentationAlgorithmCheckMenuItems() {
    ToggleGroup tmpToggleGroup = new ToggleGroup();
    for (IMoleculeFragmenter tmpFragmenter : this.fragmentationService.getFragmenters()) {
        RadioMenuItem tmpRadioMenuItem = new RadioMenuItem(tmpFragmenter.getFragmentationAlgorithmName());
        tmpRadioMenuItem.setToggleGroup(tmpToggleGroup);
        this.mainView.getMainMenuBar().getFragmentationAlgorithmMenu().getItems().add(tmpRadioMenuItem);
        if (!Objects.isNull(this.fragmentationService.getSelectedFragmenter()) && tmpFragmenter.getFragmentationAlgorithmName().equals(this.fragmentationService.getSelectedFragmenter().getFragmentationAlgorithmName())) {
            tmpToggleGroup.selectToggle(tmpRadioMenuItem);
        }
    }
    tmpToggleGroup.selectedToggleProperty().addListener((observableValue, oldValue, newValue) -> {
        if (tmpToggleGroup.getSelectedToggle() != null) {
            this.fragmentationService.setSelectedFragmenter(((RadioMenuItem) newValue).getText());
            this.fragmentationService.setSelectedFragmenterNameProperty(((RadioMenuItem) newValue).getText());
        }
    });
}
Also used : ToggleGroup(javafx.scene.control.ToggleGroup) RadioMenuItem(javafx.scene.control.RadioMenuItem) IMoleculeFragmenter(de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter)

Example 5 with IMoleculeFragmenter

use of de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter in project MORTAR by FelixBaensch.

the class PipelineSettingsViewController method addNewChoiceRow.

// 
/**
 * Adds a new row to the pipeline settings view, which allows to add a new fragmentation algorithms. ComboBox is
 * initially set to fragmentation algorithm corresponding to the given name
 *
 * @param aFragmenterName name of Fragmenter to initially set ComboBox
 */
private void addNewChoiceRow(String aFragmenterName) {
    ComboBox tmpComboBox = new ComboBox();
    for (IMoleculeFragmenter tmpFragmenter : this.fragmenters) {
        tmpComboBox.getItems().add(tmpFragmenter.getFragmentationAlgorithmName());
    }
    tmpComboBox.setPromptText(Message.get("PipelineSettingsView.comboBox.promptText"));
    if (aFragmenterName != null) {
        tmpComboBox.getSelectionModel().select(aFragmenterName);
    }
    tmpComboBox.setOnAction(anActionEvent -> {
        Object tmpSelectedFragmenterString = tmpComboBox.getSelectionModel().getSelectedItem();
        int tmpIndex = GridPane.getRowIndex(tmpComboBox) - 1;
        for (IMoleculeFragmenter tmpFragmenter : this.fragmenters) {
            if (tmpSelectedFragmenterString.equals(tmpFragmenter.getFragmentationAlgorithmName())) {
                if (this.fragmenterList.size() > tmpIndex) {
                    // will not work cause size of list is set - why not, it is in case a fragmenter that has already been set is changed
                    this.fragmenterList.set(tmpIndex, Arrays.stream(this.fragmenters).filter(x -> x.getFragmentationAlgorithmName().equals(tmpSelectedFragmenterString)).findFirst().orElse(null));
                } else {
                    this.fragmenterList.add(Arrays.stream(this.fragmenters).filter(x -> x.getFragmentationAlgorithmName().equals(tmpSelectedFragmenterString)).findFirst().orElse(null));
                }
                break;
            }
        }
        if (this.fragmenterList.contains(null)) {
            PipelineSettingsViewController.LOGGER.log(Level.SEVERE, "Error in pipeline fragmenter list, it contains null");
            throw new IllegalArgumentException("fragmenter list for pipeline must not contain null");
        }
    });
    Button tmpFragmenterSettingsButton = new Button();
    tmpFragmenterSettingsButton.setTooltip(new Tooltip(Message.get("PipelineSettingsView.settingButton.toolTip")));
    tmpFragmenterSettingsButton.setGraphic(new ImageView(new Image("de/unijena/cheminf/mortar/images/settings_gear_icon_16x16.png")));
    tmpFragmenterSettingsButton.setMinHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpFragmenterSettingsButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpFragmenterSettingsButton.setMaxHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    BooleanBinding tmpBooleanBinding = Bindings.isNull(tmpComboBox.getSelectionModel().selectedItemProperty());
    tmpFragmenterSettingsButton.disableProperty().bind(tmpBooleanBinding);
    tmpFragmenterSettingsButton.setOnAction(anActionEvent -> {
        int tmpFragmenterListIndex = GridPane.getRowIndex(tmpFragmenterSettingsButton) - 1;
        IMoleculeFragmenter[] tmpArray = new IMoleculeFragmenter[1];
        tmpArray[0] = this.fragmenterList.get(tmpFragmenterListIndex);
        FragmentationSettingsViewController tmpFragmentationSettingsViewController = new FragmentationSettingsViewController(this.pipelineSettingsViewStage, tmpArray, this.fragmenterList.get(tmpFragmenterListIndex).getFragmentationAlgorithmName());
    });
    Label tmpLabel = new Label(String.valueOf(++this.algorithmCounter));
    // remove removeButton from upper Row
    if (this.algorithmCounter > 1) {
        this.pipelineSettingsView.getGridPane().getChildren().removeIf(node -> node instanceof Button && (GridPane.getRowIndex(node) == this.algorithmCounter - 1) && ((Button) node).getText().equals("-"));
    }
    // remove addButton
    this.pipelineSettingsView.getGridPane().getChildren().removeIf(node -> GridPane.getRowIndex(node) == this.algorithmCounter);
    // add new content to row
    this.pipelineSettingsView.addAlgorithmChoiceRow(tmpLabel, tmpComboBox, tmpFragmenterSettingsButton, this.algorithmCounter);
    // add new remove button to row
    if (this.algorithmCounter > 1)
        this.addRemoveRowButton(this.algorithmCounter);
    // add new add button to next row
    // +1 cause of next row
    this.addAddRowButton(this.algorithmCounter + 1);
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Arrays(java.util.Arrays) BooleanBinding(javafx.beans.binding.BooleanBinding) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Bindings(javafx.beans.binding.Bindings) Level(java.util.logging.Level) ComboBox(javafx.scene.control.ComboBox) Message(de.unijena.cheminf.mortar.message.Message) LinkedList(java.util.LinkedList) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) Modality(javafx.stage.Modality) Label(javafx.scene.control.Label) GuiDefinitions(de.unijena.cheminf.mortar.gui.util.GuiDefinitions) PipelineSettingsView(de.unijena.cheminf.mortar.gui.views.PipelineSettingsView) Logger(java.util.logging.Logger) Platform(javafx.application.Platform) List(java.util.List) FragmentationService(de.unijena.cheminf.mortar.model.fragmentation.FragmentationService) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) StringProperty(javafx.beans.property.StringProperty) IMoleculeFragmenter(de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter) Image(javafx.scene.image.Image) ComboBox(javafx.scene.control.ComboBox) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) Image(javafx.scene.image.Image) BooleanBinding(javafx.beans.binding.BooleanBinding) Button(javafx.scene.control.Button) ImageView(javafx.scene.image.ImageView) IMoleculeFragmenter(de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter)

Aggregations

IMoleculeFragmenter (de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter)12 IOException (java.io.IOException)5 PreferenceContainer (de.unijena.cheminf.mortar.preference.PreferenceContainer)4 File (java.io.File)4 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)4 SimpleEnumConstantNameProperty (de.unijena.cheminf.mortar.model.util.SimpleEnumConstantNameProperty)3 LinkedList (java.util.LinkedList)3 CancellationException (java.util.concurrent.CancellationException)3 Property (javafx.beans.property.Property)3 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)3 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)3 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)3 Scene (javafx.scene.Scene)3 Stage (javafx.stage.Stage)3 PipelineSettingsView (de.unijena.cheminf.mortar.gui.views.PipelineSettingsView)2 FragmentDataModel (de.unijena.cheminf.mortar.model.data.FragmentDataModel)2 MoleculeDataModel (de.unijena.cheminf.mortar.model.data.MoleculeDataModel)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Hashtable (java.util.Hashtable)2 Future (java.util.concurrent.Future)2