Search in sources :

Example 1 with ItemizationDataTableView

use of de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView in project MORTAR by FelixBaensch.

the class MainViewController method addFragmentationResultTabs.

// 
/**
 * Adds a tab for fragments and a tab for items (results of fragmentation)
 *
 * @param aFragmentationName
 */
private void addFragmentationResultTabs(String aFragmentationName) {
    // fragments tab
    FragmentsDataTableView tmpFragmentsDataTableView = new FragmentsDataTableView();
    GridTabForTableView tmpFragmentsTab = new GridTabForTableView(Message.get("MainTabPane.fragmentsTab.title") + " - " + aFragmentationName, TabNames.Fragments.name(), tmpFragmentsDataTableView);
    this.mainTabPane.getTabs().add(tmpFragmentsTab);
    ObservableList<MoleculeDataModel> tmpList = FXCollections.observableArrayList(this.mapOfFragmentDataModelLists.get(aFragmentationName));
    tmpFragmentsDataTableView.setItemsList(tmpList);
    int tmpRowsPerPage = this.settingsContainer.getRowsPerPageSetting();
    int tmpPageCount = tmpList.size() / tmpRowsPerPage;
    if (tmpList.size() % tmpRowsPerPage > 0) {
        tmpPageCount++;
    }
    Pagination tmpPagination = new Pagination(tmpPageCount, 0);
    tmpPagination.setPageFactory((pageIndex) -> tmpFragmentsDataTableView.createFragmentsTableViewPage(pageIndex, this.settingsContainer));
    VBox.setVgrow(tmpPagination, Priority.ALWAYS);
    HBox.setHgrow(tmpPagination, Priority.ALWAYS);
    tmpFragmentsTab.addPaginationToGridPane(tmpPagination, 0, 0, 2, 2);
    Button tmpExportCsvButton = new Button(Message.get("MainTabPane.fragments.buttonCSV.txt"));
    tmpExportCsvButton.setTooltip(new Tooltip(Message.get("MainTabPane.fragments.buttonCSV.tooltip")));
    Button tmpExportPdfButton = new Button(Message.get("MainTabPane.fragments.buttonPDF.txt"));
    tmpExportPdfButton.setTooltip(new Tooltip(Message.get("MainTabPane.fragments.buttonPDF.tooltip")));
    Button tmpCancelExportButton = new Button(Message.get("MainTabPane.fragments.buttonCancelExport.txt"));
    tmpCancelExportButton.setTooltip(new Tooltip(Message.get("MainTabPane.fragments.buttonCancelExport.tooltip")));
    tmpCancelExportButton.visibleProperty().bind(this.isExportRunningProperty);
    ButtonBar tmpButtonBarFragments = new ButtonBar();
    tmpButtonBarFragments.setPadding(new Insets(0, 0, 0, 0));
    tmpExportCsvButton.setPrefWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    tmpExportCsvButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpExportPdfButton.setPrefWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    tmpExportPdfButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpCancelExportButton.setPrefWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    tmpCancelExportButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpButtonBarFragments.getButtons().addAll(tmpExportCsvButton, tmpExportPdfButton, tmpCancelExportButton);
    tmpFragmentsTab.addNodeToGridPane(tmpButtonBarFragments, 0, 1, 1, 1);
    tmpExportPdfButton.setOnAction(event -> this.exportFile(Exporter.ExportTypes.FRAGMENT_PDF_FILE));
    tmpExportCsvButton.setOnAction(event -> this.exportFile(Exporter.ExportTypes.FRAGMENT_CSV_FILE));
    tmpCancelExportButton.setOnAction(event -> this.interruptExport());
    tmpFragmentsDataTableView.setOnSort((EventHandler<SortEvent<TableView>>) event -> {
        GuiUtil.sortTableViewGlobally(event, tmpPagination, tmpRowsPerPage);
    });
    tmpFragmentsDataTableView.addTableViewHeightListener(this.settingsContainer);
    tmpFragmentsDataTableView.getCopyMenuItem().setOnAction(event -> GuiUtil.copySelectedTableViewCellsToClipboard(tmpFragmentsDataTableView));
    tmpFragmentsDataTableView.setOnKeyPressed(event -> {
        if (GuiDefinitions.KEY_CODE_COPY.match(event)) {
            GuiUtil.copySelectedTableViewCellsToClipboard(tmpFragmentsDataTableView);
        }
    });
    // itemization tab
    // tmpAmount is the number of fragments appearing in the molecule with the highest number of fragments
    int tmpAmount = 0;
    for (int i = 0; i < this.moleculeDataModelList.size(); i++) {
        if (!this.moleculeDataModelList.get(i).hasMoleculeUndergoneSpecificFragmentation(aFragmentationName)) {
            continue;
        }
        HashMap<String, Integer> tmpCurrentFragmentsMap = this.moleculeDataModelList.get(i).getFragmentFrequencyOfSpecificAlgorithm(aFragmentationName);
        if (tmpCurrentFragmentsMap == null) {
            // redundant, see if clause above
            continue;
        }
        int tmpNrOfFragmentsOfCurrentMolecule = tmpCurrentFragmentsMap.size();
        tmpAmount = Math.max(tmpAmount, tmpNrOfFragmentsOfCurrentMolecule);
    }
    ItemizationDataTableView tmpItemizationDataTableView = new ItemizationDataTableView(tmpAmount, aFragmentationName);
    tmpItemizationDataTableView.setItemsList(this.moleculeDataModelList);
    GridTabForTableView tmpItemizationTab = new GridTabForTableView(Message.get("MainTabPane.itemizationTab.title") + " - " + aFragmentationName, TabNames.Itemization.name(), tmpItemizationDataTableView);
    this.mainTabPane.getTabs().add(tmpItemizationTab);
    tmpPageCount = this.moleculeDataModelList.size() / tmpRowsPerPage;
    if (this.moleculeDataModelList.size() % tmpRowsPerPage > 0) {
        tmpPageCount++;
    }
    Pagination tmpPaginationItems = new Pagination(tmpPageCount, 0);
    tmpPaginationItems.setPageFactory((pageIndex) -> tmpItemizationDataTableView.createItemizationTableViewPage(pageIndex, this.settingsContainer));
    VBox.setVgrow(tmpPaginationItems, Priority.ALWAYS);
    HBox.setHgrow(tmpPaginationItems, Priority.ALWAYS);
    tmpItemizationTab.addPaginationToGridPane(tmpPaginationItems, 0, 0, 2, 2);
    Button tmpItemizationTabExportPDfButton = new Button(Message.get("MainTabPane.itemizationTab.pdfButton.txt"));
    tmpItemizationTabExportPDfButton.setTooltip(new Tooltip(Message.get("MainTabPane.itemizationTab.pdfButton.tooltip")));
    Button tmpItemizationExportCsvButton = new Button(Message.get("MainTabPane.itemizationTab.csvButton.txt"));
    tmpItemizationExportCsvButton.setTooltip(new Tooltip(Message.get("MainTabPane.itemizationTab.csvButton.tooltip")));
    ButtonBar tmpButtonBarItemization = new ButtonBar();
    tmpButtonBarItemization.setPadding(new Insets(0, 0, 0, 0));
    tmpItemizationExportCsvButton.setPrefWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    tmpItemizationExportCsvButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpItemizationTabExportPDfButton.setPrefWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    tmpItemizationTabExportPDfButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpButtonBarItemization.getButtons().addAll(tmpItemizationExportCsvButton, tmpItemizationTabExportPDfButton, tmpCancelExportButton);
    tmpItemizationTab.addNodeToGridPane(tmpButtonBarItemization, 0, 1, 1, 1);
    tmpItemizationExportCsvButton.setOnAction(event -> this.exportFile(Exporter.ExportTypes.ITEM_CSV_FILE));
    tmpItemizationTabExportPDfButton.setOnAction(event -> this.exportFile(Exporter.ExportTypes.ITEM_PDF_FILE));
    tmpItemizationDataTableView.setOnSort((EventHandler<SortEvent<TableView>>) event -> {
        GuiUtil.sortTableViewGlobally(event, tmpPaginationItems, tmpRowsPerPage);
    });
    tmpItemizationDataTableView.addTableViewHeightListener(this.settingsContainer);
    tmpItemizationDataTableView.getCopyMenuItem().setOnAction(event -> GuiUtil.copySelectedTableViewCellsToClipboard(tmpItemizationDataTableView));
    tmpItemizationDataTableView.setOnKeyPressed(event -> {
        if (GuiDefinitions.KEY_CODE_COPY.match(event)) {
            GuiUtil.copySelectedTableViewCellsToClipboard(tmpItemizationDataTableView);
        }
    });
    // 
    this.mainTabPane.getSelectionModel().select(tmpFragmentsTab);
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) MainView(de.unijena.cheminf.mortar.gui.views.MainView) SettingsContainer(de.unijena.cheminf.mortar.model.settings.SettingsContainer) VBox(javafx.scene.layout.VBox) FragmentsDataTableView(de.unijena.cheminf.mortar.gui.views.FragmentsDataTableView) Task(javafx.concurrent.Task) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) TabPane(javafx.scene.control.TabPane) BasicDefinitions(de.unijena.cheminf.mortar.model.util.BasicDefinitions) WindowEvent(javafx.stage.WindowEvent) Message(de.unijena.cheminf.mortar.message.Message) TableView(javafx.scene.control.TableView) Alert(javafx.scene.control.Alert) HBox(javafx.scene.layout.HBox) ButtonBar(javafx.scene.control.ButtonBar) Set(java.util.Set) KeyEvent(javafx.scene.input.KeyEvent) Observable(javafx.beans.Observable) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Importer(de.unijena.cheminf.mortar.model.io.Importer) MoleculesDataTableView(de.unijena.cheminf.mortar.gui.views.MoleculesDataTableView) Platform(javafx.application.Platform) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) Objects(java.util.Objects) Priority(javafx.scene.layout.Priority) BooleanProperty(javafx.beans.property.BooleanProperty) List(java.util.List) FragmentationService(de.unijena.cheminf.mortar.model.fragmentation.FragmentationService) ObservableList(javafx.collections.ObservableList) FileUtil(de.unijena.cheminf.mortar.model.util.FileUtil) Pagination(javafx.scene.control.Pagination) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Scene(javafx.scene.Scene) MoleculeDataModel(de.unijena.cheminf.mortar.model.data.MoleculeDataModel) RadioMenuItem(javafx.scene.control.RadioMenuItem) FragmentDataModel(de.unijena.cheminf.mortar.model.data.FragmentDataModel) ItemizationDataTableView(de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView) ButtonType(javafx.scene.control.ButtonType) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) IDataTableView(de.unijena.cheminf.mortar.gui.views.IDataTableView) Level(java.util.logging.Level) GridTabForTableView(de.unijena.cheminf.mortar.gui.panes.GridTabForTableView) Insets(javafx.geometry.Insets) ChemFileTypes(de.unijena.cheminf.mortar.model.io.ChemFileTypes) Tooltip(javafx.scene.control.Tooltip) ChemUtil(de.unijena.cheminf.mortar.model.util.ChemUtil) KeyCode(javafx.scene.input.KeyCode) GuiUtil(de.unijena.cheminf.mortar.gui.util.GuiUtil) Label(javafx.scene.control.Label) GuiDefinitions(de.unijena.cheminf.mortar.gui.util.GuiDefinitions) LogUtil(de.unijena.cheminf.mortar.model.util.LogUtil) File(java.io.File) EventType(javafx.event.EventType) ExecutionException(java.util.concurrent.ExecutionException) ToggleGroup(javafx.scene.control.ToggleGroup) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SortEvent(javafx.scene.control.SortEvent) Stage(javafx.stage.Stage) Tab(javafx.scene.control.Tab) IMoleculeFragmenter(de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter) Image(javafx.scene.image.Image) Exporter(de.unijena.cheminf.mortar.model.io.Exporter) InputStream(java.io.InputStream) ButtonBar(javafx.scene.control.ButtonBar) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) FragmentsDataTableView(de.unijena.cheminf.mortar.gui.views.FragmentsDataTableView) Pagination(javafx.scene.control.Pagination) SortEvent(javafx.scene.control.SortEvent) GridTabForTableView(de.unijena.cheminf.mortar.gui.panes.GridTabForTableView) Button(javafx.scene.control.Button) MoleculeDataModel(de.unijena.cheminf.mortar.model.data.MoleculeDataModel) ItemizationDataTableView(de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView)

Example 2 with ItemizationDataTableView

use of de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView in project MORTAR by FelixBaensch.

the class GuiUtil method setImageStructureHeight.

// 
/**
 * Sets the height for structure images to each MoleculeDataModel object of the items list of the tableView.
 * If image height is too small it will be set to GuiDefinitions.GUI_STRUCTURE_IMAGE_MIN_HEIGHT (50.0)
 *
 * @param aTableView TableView
 * @param aHeight double
 * @param aSettingsContainer SettingsContainer
 */
public static void setImageStructureHeight(TableView aTableView, double aHeight, SettingsContainer aSettingsContainer) {
    double tmpHeight = (aHeight - GuiDefinitions.GUI_TABLE_VIEW_HEADER_HEIGHT - GuiDefinitions.GUI_PAGINATION_CONTROL_PANEL_HEIGHT) / aSettingsContainer.getRowsPerPageSetting();
    if (aTableView.getClass().equals(ItemizationDataTableView.class)) {
        tmpHeight = (aHeight - 2 * GuiDefinitions.GUI_TABLE_VIEW_HEADER_HEIGHT - GuiDefinitions.GUI_PAGINATION_CONTROL_PANEL_HEIGHT) / aSettingsContainer.getRowsPerPageSetting();
    }
    if (tmpHeight < GuiDefinitions.GUI_STRUCTURE_IMAGE_MIN_HEIGHT) {
        tmpHeight = GuiDefinitions.GUI_STRUCTURE_IMAGE_MIN_HEIGHT;
    }
    if (aTableView.getClass().equals(ItemizationDataTableView.class)) {
        for (MoleculeDataModel tmpMoleculeDataModel : ((IDataTableView) aTableView).getItemsList()) {
            tmpMoleculeDataModel.setStructureImageHeight(tmpHeight);
            String tmpFragmentationName = ((ItemizationDataTableView) aTableView).getFragmentationName();
            if (!tmpMoleculeDataModel.hasMoleculeUndergoneSpecificFragmentation(tmpFragmentationName)) {
                continue;
            }
            for (FragmentDataModel tmpFragmentDataModel : tmpMoleculeDataModel.getFragmentsOfSpecificAlgorithm(tmpFragmentationName)) {
                tmpFragmentDataModel.setStructureImageHeight(tmpHeight);
            }
        }
    } else {
        for (MoleculeDataModel tmpMoleculeDataModel : ((IDataTableView) aTableView).getItemsList()) {
            tmpMoleculeDataModel.setStructureImageHeight(tmpHeight);
        }
    }
}
Also used : FragmentDataModel(de.unijena.cheminf.mortar.model.data.FragmentDataModel) MoleculeDataModel(de.unijena.cheminf.mortar.model.data.MoleculeDataModel) ItemizationDataTableView(de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView) IDataTableView(de.unijena.cheminf.mortar.gui.views.IDataTableView)

Aggregations

IDataTableView (de.unijena.cheminf.mortar.gui.views.IDataTableView)2 ItemizationDataTableView (de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView)2 FragmentDataModel (de.unijena.cheminf.mortar.model.data.FragmentDataModel)2 MoleculeDataModel (de.unijena.cheminf.mortar.model.data.MoleculeDataModel)2 GridTabForTableView (de.unijena.cheminf.mortar.gui.panes.GridTabForTableView)1 GuiDefinitions (de.unijena.cheminf.mortar.gui.util.GuiDefinitions)1 GuiUtil (de.unijena.cheminf.mortar.gui.util.GuiUtil)1 FragmentsDataTableView (de.unijena.cheminf.mortar.gui.views.FragmentsDataTableView)1 MainView (de.unijena.cheminf.mortar.gui.views.MainView)1 MoleculesDataTableView (de.unijena.cheminf.mortar.gui.views.MoleculesDataTableView)1 Message (de.unijena.cheminf.mortar.message.Message)1 FragmentationService (de.unijena.cheminf.mortar.model.fragmentation.FragmentationService)1 IMoleculeFragmenter (de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter)1 ChemFileTypes (de.unijena.cheminf.mortar.model.io.ChemFileTypes)1 Exporter (de.unijena.cheminf.mortar.model.io.Exporter)1 Importer (de.unijena.cheminf.mortar.model.io.Importer)1 SettingsContainer (de.unijena.cheminf.mortar.model.settings.SettingsContainer)1 BasicDefinitions (de.unijena.cheminf.mortar.model.util.BasicDefinitions)1 ChemUtil (de.unijena.cheminf.mortar.model.util.ChemUtil)1 FileUtil (de.unijena.cheminf.mortar.model.util.FileUtil)1