Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection util rework #53

Merged
merged 12 commits into from
Mar 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ private BarChart createHistogram(int aFragmentNumber,
boolean tmpSortByFragmentFrequency = this.displayFrequencySetting.get().equals(FrequencyOption.ABSOLUTE_FREQUENCY.name());
String tmpSortProperty = (tmpSortByFragmentFrequency ? "absoluteFrequency" : "moleculeFrequency");
//TODO: rework method and usage
CollectionUtil.sortGivenFragmentListByPropertyAndSortType(this.fragmentListCopy, tmpSortProperty, "ASCENDING");
CollectionUtil.sortGivenFragmentListByPropertyAndSortType(this.fragmentListCopy, tmpSortProperty, true); // true to sort the list in ascending order
for (FragmentDataModel tmpFragmentDataModel : this.fragmentListCopy) {
if (tmpFragmentDataModel.getUniqueSmiles().length() > aSmilesLength) {
tmpNewSmiles = Message.get("HistogramView.smilesTooLong") + " (" + tmpFragmentListIndexDecreasing + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static void sortTableViewGlobally(SortEvent<TableView> anEvent, Paginatio
return;
String tmpSortProp = ((PropertyValueFactory)((TableColumn) anEvent.getSource().getSortOrder().get(0)).cellValueFactoryProperty().getValue()).getProperty().toString();
TableColumn.SortType tmpSortType = ((TableColumn) anEvent.getSource().getSortOrder().get(0)).getSortType();
CollectionUtil.sortGivenFragmentListByPropertyAndSortType(((IDataTableView)anEvent.getSource()).getItemsList(), tmpSortProp, tmpSortType.toString());
CollectionUtil.sortGivenFragmentListByPropertyAndSortType(((IDataTableView)anEvent.getSource()).getItemsList(), tmpSortProp, tmpSortType == TableColumn.SortType.ASCENDING);
int fromIndex = tmpPagination.getCurrentPageIndex() * tmpRowsPerPage;
int toIndex = Math.min(fromIndex + tmpRowsPerPage, ((IDataTableView)anEvent.getSource()).getItemsList().size());
anEvent.getSource().getItems().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import de.unijena.cheminf.mortar.gui.util.GuiUtil;
import de.unijena.cheminf.mortar.message.Message;
import de.unijena.cheminf.mortar.model.data.DataModelPropertiesForTableView;
import de.unijena.cheminf.mortar.model.data.FragmentDataModel;
import de.unijena.cheminf.mortar.model.data.MoleculeDataModel;
import de.unijena.cheminf.mortar.model.settings.SettingsContainer;
Expand Down Expand Up @@ -129,7 +130,7 @@ public FragmentsDataTableView(){
this.structureColumn.setResizable(true);
this.structureColumn.setEditable(false);
this.structureColumn.setSortable(false);
this.structureColumn.setCellValueFactory(new PropertyValueFactory("structure"));
this.structureColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.STRUCTURE.getText()));
this.structureColumn.setStyle("-fx-alignment: CENTER");
this.getColumns().add(this.structureColumn);
//-smilesColumn
Expand All @@ -141,7 +142,7 @@ public FragmentsDataTableView(){
this.smilesColumn.setResizable(true);
this.smilesColumn.setEditable(false);
this.smilesColumn.setSortable(true);
this.smilesColumn.setCellValueFactory(new PropertyValueFactory("uniqueSmiles"));
this.smilesColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.UNIQUE_SMILES.getText()));
this.smilesColumn.setCellFactory(tableColumn ->{
TableCell<FragmentDataModel, String> tmpCell = new TableCell<>();
Text tmpText = new Text();
Expand All @@ -166,7 +167,7 @@ public FragmentsDataTableView(){
this.parentMolColumn.setResizable(true);
this.parentMolColumn.setEditable(false);
this.parentMolColumn.setSortable(false);
this.parentMolColumn.setCellValueFactory(new PropertyValueFactory("parentMoleculeStructure"));
this.parentMolColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.PARENT_MOLECULE_STRUCTURE.getText()));
this.parentMolColumn.setStyle("-fx-alignment: CENTER");
this.getColumns().add(this.parentMolColumn);
//-parentMolNameColumn
Expand All @@ -180,7 +181,7 @@ public FragmentsDataTableView(){
this.parentMolNameColumn.setResizable(true);
this.parentMolNameColumn.setEditable(false);
this.parentMolNameColumn.setSortable(true);
this.parentMolNameColumn.setCellValueFactory(new PropertyValueFactory("parentMoleculeName"));
this.parentMolNameColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.PARENT_MOLECULE_NAME.getText()));
this.parentMolNameColumn.setStyle("-fx-alignment: CENTER");
this.getColumns().add(this.parentMolNameColumn);
//-frequencyColumn
Expand All @@ -192,7 +193,7 @@ public FragmentsDataTableView(){
this.frequencyColumn.setResizable(true);
this.frequencyColumn.setEditable(false);
this.frequencyColumn.setSortable(true);
this.frequencyColumn.setCellValueFactory(new PropertyValueFactory("absoluteFrequency"));
this.frequencyColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.ABSOLUTE_FREQUENCY.getText()));
this.frequencyColumn.setStyle("-fx-alignment: CENTER-RIGHT");
this.getColumns().add(this.frequencyColumn);
//-percentageColumn
Expand All @@ -204,7 +205,7 @@ public FragmentsDataTableView(){
this.percentageColumn.setResizable(true);
this.percentageColumn.setEditable(false);
this.percentageColumn.setSortable(true);
this.percentageColumn.setCellValueFactory(new PropertyValueFactory("absolutePercentage"));
this.percentageColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.ABSOLUTE_PERCENTAGE.getText()));
this.percentageColumn.setCellFactory(tc -> new TableCell<>(){
@Override
protected void updateItem(Double value, boolean empty){
Expand All @@ -227,7 +228,7 @@ protected void updateItem(Double value, boolean empty){
this.moleculeFrequencyColumn.setResizable(true);
this.moleculeFrequencyColumn.setEditable(false);
this.moleculeFrequencyColumn.setSortable(true);
this.moleculeFrequencyColumn.setCellValueFactory(new PropertyValueFactory("moleculeFrequency"));
this.moleculeFrequencyColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.MOLECULE_FREQUENCY.getText()));
this.moleculeFrequencyColumn.setStyle("-fx-alignment: CENTER-RIGHT");
this.getColumns().add(this.moleculeFrequencyColumn);
//-percentageColumn
Expand All @@ -239,7 +240,7 @@ protected void updateItem(Double value, boolean empty){
this.moleculePercentageColumn.setResizable(true);
this.moleculePercentageColumn.setEditable(false);
this.moleculePercentageColumn.setSortable(true);
this.moleculePercentageColumn.setCellValueFactory(new PropertyValueFactory("moleculePercentage"));
this.moleculePercentageColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.MOLECULE_PERCENTAGE.getText()));
this.moleculePercentageColumn.setCellFactory(tc -> new TableCell<>() {
@Override
protected void updateItem(Double value, boolean empty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import de.unijena.cheminf.mortar.gui.util.GuiUtil;
import de.unijena.cheminf.mortar.message.Message;
import de.unijena.cheminf.mortar.model.data.DataModelPropertiesForTableView;
import de.unijena.cheminf.mortar.model.data.FragmentDataModel;
import de.unijena.cheminf.mortar.model.data.MoleculeDataModel;
import de.unijena.cheminf.mortar.model.settings.SettingsContainer;
Expand Down Expand Up @@ -109,7 +110,7 @@ public ItemizationDataTableView(int anItemAmount, String aFragmentationName){
this.nameColumn.setResizable(true);
this.nameColumn.setEditable(false);
this.nameColumn.setSortable(true);
this.nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
this.nameColumn.setCellValueFactory(new PropertyValueFactory<>(DataModelPropertiesForTableView.NAME.getText()));
this.nameColumn.setCellFactory(TextFieldTableCell.<MoleculeDataModel>forTableColumn());
this.nameColumn.setStyle("-fx-alignment: CENTER");
this.nameColumn.prefWidthProperty().bind(
Expand All @@ -121,7 +122,7 @@ public ItemizationDataTableView(int anItemAmount, String aFragmentationName){
this.moleculeStructureColumn.setResizable(true);
this.moleculeStructureColumn.setEditable(false);
this.moleculeStructureColumn.setSortable(false);
this.moleculeStructureColumn.setCellValueFactory(new PropertyValueFactory("structure"));
this.moleculeStructureColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.STRUCTURE.getText()));
this.moleculeStructureColumn.setStyle("-fx-alignment: CENTER");
this.moleculeStructureColumn.prefWidthProperty().bind(
this.widthProperty().multiply(0.3) //magic number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.unijena.cheminf.mortar.gui.util.GuiDefinitions;
import de.unijena.cheminf.mortar.gui.util.GuiUtil;
import de.unijena.cheminf.mortar.message.Message;
import de.unijena.cheminf.mortar.model.data.DataModelPropertiesForTableView;
import de.unijena.cheminf.mortar.model.data.MoleculeDataModel;
import de.unijena.cheminf.mortar.model.settings.SettingsContainer;

Expand Down Expand Up @@ -120,7 +121,7 @@ public MoleculesDataTableView(){
this.nameColumn.setResizable(true);
this.nameColumn.setEditable(false);
this.nameColumn.setSortable(true);
this.nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
this.nameColumn.setCellValueFactory(new PropertyValueFactory<>(DataModelPropertiesForTableView.NAME.getText()));
this.nameColumn.setCellFactory(TextFieldTableCell.<MoleculeDataModel>forTableColumn());
this.nameColumn.setStyle("-fx-alignment: CENTER");
//-structureColumn
Expand All @@ -132,7 +133,7 @@ public MoleculesDataTableView(){
this.structureColumn.setResizable(true);
this.structureColumn.setEditable(false);
this.structureColumn.setSortable(false);
this.structureColumn.setCellValueFactory(new PropertyValueFactory("structure"));
this.structureColumn.setCellValueFactory(new PropertyValueFactory(DataModelPropertiesForTableView.STRUCTURE.getText()));
this.structureColumn.setStyle("-fx-alignment: CENTER");
//
this.getColumns().addAll(this.selectionColumn, this.nameColumn, this.structureColumn);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* MORTAR - MOlecule fRagmenTAtion fRamework
* Copyright (C) 2024 Felix Baensch, Jonas Schaub ([email protected], [email protected])
*
* Source code is available at <https://github.com/FelixBaensch/MORTAR>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.unijena.cheminf.mortar.model.data;

/**
* Enum for the data model properties that are displayed in the TableViews
*
* @author Felix Baensch
* @version 1.0.0.0
*/
public enum DataModelPropertiesForTableView {
/**
* Enum for name property
*/
NAME ("name"),
/**
* Enum for uniqueSmiles property
*/
UNIQUE_SMILES ("uniqueSmiles"),
/**
* Enum for parentMoleculeName property
*/
PARENT_MOLECULE_NAME ("parentMoleculeName"),
/**
* Enum for absoluteFrequency property
*/
ABSOLUTE_FREQUENCY ("absoluteFrequency"),
/**
* Enum for absolutePercentage property
*/
ABSOLUTE_PERCENTAGE ("absolutePercentage"),
/**
* Enum for moleculeFrequency property
*/
MOLECULE_FREQUENCY ("moleculeFrequency"),
/**
* Enum for moleculePercentage property
*/
MOLECULE_PERCENTAGE ("moleculePercentage"),
/**
* Enum for structure property
*/
STRUCTURE("structure"),
/**
* Enum for parent molecule structure property
*/
PARENT_MOLECULE_STRUCTURE("parentMoleculeStructure");
//
/**
* String representation
*/
private final String text;
//
/**
* Constructor
*
* @param aText String representation of enum property
*/
DataModelPropertiesForTableView(String aText) {
this.text = aText;
}
//
/**
* Gets String representation
*
* @return text String representation
*/
public String getText() {
return this.text;
}
//
/**
* Gets enum from String representation. Returns null if no enum can be found for the String.
*
* @param aText String representation
* @return DataModelPropertiesForTableView
*/
public static DataModelPropertiesForTableView fromString(String aText) {
for (DataModelPropertiesForTableView property : DataModelPropertiesForTableView.values()) {
if(property.text.equalsIgnoreCase(aText)) {
return property;
}
}
return null;
}
}
Loading
Loading