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.");
}
}
}
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;
}
}
}
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);
}
}
}
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());
}
});
}
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);
}
Aggregations