Search in sources :

Example 1 with GridTabForTableView

use of de.unijena.cheminf.mortar.gui.panes.GridTabForTableView in project MORTAR by FelixBaensch.

the class MainViewController method openMoleculesTab.

// 
/**
 * Opens molecules tab
 */
private void openMoleculesTab() {
    this.moleculesDataTableView = new MoleculesDataTableView();
    this.moleculesDataTableView.setItemsList(this.moleculeDataModelList);
    GridTabForTableView tmpMoleculesTab = new GridTabForTableView(Message.get("MainTabPane.moleculesTab.title"), TabNames.Molecules.name(), this.moleculesDataTableView);
    this.mainTabPane.getTabs().add(tmpMoleculesTab);
    int tmpRowsPerPage = this.settingsContainer.getRowsPerPageSetting();
    int tmpPageCount = this.moleculeDataModelList.size() / tmpRowsPerPage;
    if (this.moleculeDataModelList.size() % tmpRowsPerPage > 0) {
        tmpPageCount++;
    }
    Pagination tmpPagination = new Pagination(tmpPageCount, 0);
    tmpPagination.setPageFactory((pageIndex) -> this.moleculesDataTableView.createMoleculeTableViewPage(pageIndex, this.settingsContainer));
    VBox.setVgrow(tmpPagination, Priority.ALWAYS);
    HBox.setHgrow(tmpPagination, Priority.ALWAYS);
    tmpMoleculesTab.addPaginationToGridPane(tmpPagination, 0, 0, 2, 2);
    this.fragmentationButton = new Button(Message.get("MainTabPane.moleculesTab.fragmentButton.text"));
    ButtonBar tmpButtonBar = new ButtonBar();
    tmpButtonBar.setPadding(new Insets(0, 0, 0, 0));
    this.fragmentationButton.setPrefWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    this.fragmentationButton.setMinWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    this.fragmentationButton.setMaxWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    this.fragmentationButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    tmpButtonBar.getButtons().add(this.fragmentationButton);
    tmpButtonBar.setButtonMinWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    Label tmpLabel = new Label();
    tmpLabel.textProperty().bind(this.fragmentationService.selectedFragmenterNamePropertyProperty());
    Tooltip tmpTooltip = new Tooltip();
    tmpTooltip.textProperty().bind(this.fragmentationService.selectedFragmenterNamePropertyProperty());
    tmpLabel.setTooltip(tmpTooltip);
    HBox.setHgrow(tmpLabel, Priority.ALWAYS);
    tmpButtonBar.getButtons().add(tmpLabel);
    this.cancelFragmentationButton = new Button(Message.get("MainTabPane.moleculesTab.cancelFragmentationButton.text"));
    this.cancelFragmentationButton.setTooltip(new Tooltip(Message.get("MainTabPane.moleculesTab.cancelFragmentationButton.tooltip")));
    this.cancelFragmentationButton.setPrefWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    this.cancelFragmentationButton.setMinWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    this.cancelFragmentationButton.setMaxWidth(GuiDefinitions.GUI_BUTTON_WIDTH_VALUE);
    this.cancelFragmentationButton.setPrefHeight(GuiDefinitions.GUI_BUTTON_HEIGHT_VALUE);
    this.cancelFragmentationButton.setVisible(false);
    tmpButtonBar.getButtons().add(this.cancelFragmentationButton);
    tmpMoleculesTab.addNodeToGridPane(tmpButtonBar, 0, 1, 1, 1);
    this.fragmentationButton.setOnAction(event -> {
        this.startFragmentation();
    });
    this.cancelFragmentationButton.setOnAction(event -> {
        this.interruptFragmentation();
    });
    this.moleculesDataTableView.addTableViewHeightListener(this.settingsContainer);
    this.moleculesDataTableView.getCopyMenuItem().setOnAction(event -> GuiUtil.copySelectedTableViewCellsToClipboard(this.moleculesDataTableView));
    this.moleculesDataTableView.setOnKeyPressed(event -> {
        if (GuiDefinitions.KEY_CODE_COPY.match(event)) {
            GuiUtil.copySelectedTableViewCellsToClipboard(this.moleculesDataTableView);
        }
    });
    this.moleculesDataTableView.setOnSort((EventHandler<SortEvent<TableView>>) event -> {
        GuiUtil.sortTableViewGlobally(event, tmpPagination, tmpRowsPerPage);
    });
}
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) Pagination(javafx.scene.control.Pagination) SortEvent(javafx.scene.control.SortEvent) ButtonBar(javafx.scene.control.ButtonBar) Insets(javafx.geometry.Insets) GridTabForTableView(de.unijena.cheminf.mortar.gui.panes.GridTabForTableView) Button(javafx.scene.control.Button) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) MoleculesDataTableView(de.unijena.cheminf.mortar.gui.views.MoleculesDataTableView)

Example 2 with GridTabForTableView

use of de.unijena.cheminf.mortar.gui.panes.GridTabForTableView in project MORTAR by FelixBaensch.

the class MainViewController method addListener.

// 
// <editor-fold desc="private methods" defaultstate="collapsed">
/**
 * Adds listeners and event handlers to control elements etc.
 */
private void addListener() {
    this.mainView.getMainMenuBar().getExitMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.closeApplication(0));
    this.mainView.getMainMenuBar().getLoadMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.importMoleculeFile(this.primaryStage));
    this.mainView.getMainMenuBar().getCancelImportMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.interruptImport());
    this.mainView.getMainMenuBar().getCancelImportMenuItem().visibleProperty().bind(this.isImportRunningProperty);
    this.mainView.getMainMenuBar().getCancelExportMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.interruptExport());
    this.mainView.getMainMenuBar().getCancelExportMenuItem().visibleProperty().bind(this.isExportRunningProperty);
    // <editor-fold desc="export">
    // fragments export to CSV
    this.mainView.getMainMenuBar().getFragmentsExportToCSVMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.exportFile(Exporter.ExportTypes.FRAGMENT_CSV_FILE));
    // fragments export to PDB
    this.mainView.getMainMenuBar().getFragmentsExportToPDBMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.exportFile(Exporter.ExportTypes.PDB_FILE));
    // fragments export to PDF
    this.mainView.getMainMenuBar().getFragmentsExportToPDFMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.exportFile(Exporter.ExportTypes.FRAGMENT_PDF_FILE));
    // fragments export to single SDF
    this.mainView.getMainMenuBar().getFragmentsExportToSingleSDFMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.exportFile(Exporter.ExportTypes.SINGLE_SD_FILE));
    // fragments export to separate SDFs
    this.mainView.getMainMenuBar().getFragmentsExportToSeparateSDFsMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.exportFile(Exporter.ExportTypes.SD_FILE));
    // items export to CSV
    this.mainView.getMainMenuBar().getItemsExportToCSVMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.exportFile(Exporter.ExportTypes.ITEM_CSV_FILE));
    // items export to PDF
    this.mainView.getMainMenuBar().getItemsExportToPDFMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.exportFile(Exporter.ExportTypes.ITEM_PDF_FILE));
    // </editor-fold>
    this.mainView.getMainMenuBar().getFragmentationSettingsMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.openFragmentationSettingsView());
    this.mainView.getMainMenuBar().getGlobalSettingsMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.openGlobalSettingsView());
    this.mainView.getMainMenuBar().getPipelineSettingsMenuItem().addEventHandler(EventType.ROOT, anEvent -> this.openPipelineSettingsView());
    this.primaryStage.addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, (this::closeWindowEvent));
    this.mainView.getMainMenuBar().getAboutViewMenuItem().setOnAction(actionEvent -> new AboutViewController(this.primaryStage));
    this.scene.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> {
        GridTabForTableView tmpGrid = ((GridTabForTableView) this.mainTabPane.getSelectionModel().getSelectedItem());
        if (tmpGrid == null) {
            keyEvent.consume();
            return;
        }
        if (keyEvent.getCode() == KeyCode.RIGHT) {
            tmpGrid.getPagination().setCurrentPageIndex(tmpGrid.getPagination().getCurrentPageIndex() + 1);
            keyEvent.consume();
        } else if (keyEvent.getCode() == KeyCode.LEFT) {
            tmpGrid.getPagination().setCurrentPageIndex(tmpGrid.getPagination().getCurrentPageIndex() - 1);
            keyEvent.consume();
        }
    // else if(GuiDefinitions.KEY_CODE_LAST_PAGE.match(keyEvent)){
    // tmpGrid.getPagination().setCurrentPageIndex(tmpGrid.getPagination().getPageCount() - 1);
    // keyEvent.consume();
    // }
    // else if(GuiDefinitions.KEY_CODE_FIRST_PAGE.match(keyEvent)){
    // tmpGrid.getPagination().setCurrentPageIndex(0);
    // keyEvent.consume();
    // }
    });
}
Also used : GridTabForTableView(de.unijena.cheminf.mortar.gui.panes.GridTabForTableView)

Example 3 with GridTabForTableView

use of de.unijena.cheminf.mortar.gui.panes.GridTabForTableView in project MORTAR by FelixBaensch.

the class MainViewController method exportFile.

// 
/**
 * Exports the given type of file
 *
 * @param anExportType Enum to specify what type of file to export
 */
private void exportFile(Exporter.ExportTypes anExportType) {
    if ((this.mainTabPane.getSelectionModel().getSelectedItem()).getId() == TabNames.Molecules.toString()) {
        GuiUtil.guiConformationAlert(Message.get("Exporter.confirmationAlert.moleculesTabSelected.title"), Message.get("Exporter.confirmationAlert.moleculesTabSelected.header"), Message.get("Exporter.confirmationAlert.moleculesTabSelected.text"));
        return;
    }
    switch(anExportType) {
        case FRAGMENT_CSV_FILE:
        case PDB_FILE:
        case FRAGMENT_PDF_FILE:
        case SINGLE_SD_FILE:
        case SD_FILE:
            if (this.getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments) == null || this.getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments).size() == 0 || ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle() == null) {
                GuiUtil.guiMessageAlert(Alert.AlertType.INFORMATION, Message.get("Exporter.MessageAlert.NoDataAvailable.title"), Message.get("Exporter.MessageAlert.NoDataAvailable.header"), null);
                return;
            }
            break;
        case ITEM_CSV_FILE:
        case ITEM_PDF_FILE:
            if (this.getItemsListOfSelectedFragmenterByTabId(TabNames.Itemization) == null || this.getItemsListOfSelectedFragmenterByTabId(TabNames.Itemization).size() == 0 || this.moleculeDataModelList == null || this.moleculeDataModelList.size() == 0 || ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle() == null) {
                GuiUtil.guiMessageAlert(Alert.AlertType.INFORMATION, Message.get("Exporter.MessageAlert.NoDataAvailable.title"), Message.get("Exporter.MessageAlert.NoDataAvailable.header"), null);
                return;
            }
            break;
    }
    Exporter tmpExporter = new Exporter(this.settingsContainer);
    if (this.isExportRunningProperty.get()) {
        this.interruptExport();
    }
    tmpExporter.saveFile(this.primaryStage, anExportType, ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle());
    boolean tmpGenerate2dAtomCoordinates = false;
    switch(anExportType) {
        case PDB_FILE:
        case SINGLE_SD_FILE:
            if (!ChemUtil.checkMoleculeListForCoordinates(getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments))) {
                ButtonType tmpConformationResult = GuiUtil.guiConformationAlert(Message.get("Exporter.FragmentsTab.ConformationAlert.No3dInformationAvailable.title"), Message.get("Exporter.FragmentsTab.ConformationAlert.No3dInformationAvailable.header"), Message.get("Exporter.FragmentsTab.ConformationAlert.No3dInformationAvailable.text"));
                tmpGenerate2dAtomCoordinates = tmpConformationResult == ButtonType.OK;
            }
            break;
    }
    boolean tmpGenerate2dAtomCoordinatesFinal = tmpGenerate2dAtomCoordinates;
    this.exportTask = new Task<>() {

        @Override
        protected List<String> call() throws Exception {
            switch(anExportType) {
                case FRAGMENT_CSV_FILE:
                    return tmpExporter.exportCsvFile(getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments), ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle(), settingsContainer.getCsvExportSeparatorSetting(), TabNames.Fragments);
                case PDB_FILE:
                    return tmpExporter.exportFragmentsAsChemicalFile(getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments), ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle(), ChemFileTypes.PDB, tmpGenerate2dAtomCoordinatesFinal);
                case FRAGMENT_PDF_FILE:
                    return tmpExporter.exportPdfFile(getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments), moleculeDataModelList, ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle(), TabNames.Fragments);
                case SINGLE_SD_FILE:
                    return tmpExporter.exportFragmentsAsChemicalFile(getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments), ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle(), ChemFileTypes.SDF, tmpGenerate2dAtomCoordinatesFinal, true);
                case SD_FILE:
                    return tmpExporter.exportFragmentsAsChemicalFile(getItemsListOfSelectedFragmenterByTabId(TabNames.Fragments), ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle(), ChemFileTypes.SDF, false);
                case ITEM_CSV_FILE:
                    return tmpExporter.exportCsvFile(moleculeDataModelList, ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle(), settingsContainer.getCsvExportSeparatorSetting(), TabNames.Itemization);
                case ITEM_PDF_FILE:
                    return tmpExporter.exportPdfFile(getItemsListOfSelectedFragmenterByTabId(TabNames.Itemization), moleculeDataModelList, ((GridTabForTableView) mainTabPane.getSelectionModel().getSelectedItem()).getFragmentationNameOutOfTitle(), TabNames.Itemization);
            }
            return null;
        }
    };
    this.exportTask.setOnSucceeded(event -> {
        this.isExportRunningProperty.setValue(false);
        this.updateStatusBar(this.exporterThread, Message.get("Status.finished"));
        List<String> tmpFailedExportFragments = this.exportTask.getValue();
        if (tmpFailedExportFragments == null) {
            GuiUtil.guiMessageAlert(Alert.AlertType.WARNING, Message.get("Exporter.FragmentsTab.ExportNotPossible.title"), Message.get("Exporter.FragmentsTab.ExportNotPossible.header"), null);
        }
        if (tmpFailedExportFragments.size() > 0) {
            StringBuilder tmpStringBuilder = new StringBuilder();
            for (String tmpFragmentName : tmpFailedExportFragments) {
                tmpStringBuilder.append(tmpFragmentName + "\n");
            }
            GuiUtil.guiExpandableAlert(Alert.AlertType.WARNING.toString(), Message.get("Exporter.FragmentsTab.ExportNotPossible.title"), Message.get("Exporter.FragmentsTab.ExportNotPossible.header"), tmpFailedExportFragments.size() + " " + Message.get("Exporter.FragmentsTab.ExportNotPossible.label"), tmpStringBuilder.toString());
        }
    });
    this.exportTask.setOnCancelled(event -> {
        this.isExportRunningProperty.setValue(false);
        MainViewController.LOGGER.log(Level.SEVERE, "Export canceled");
        this.updateStatusBar(this.exporterThread, Message.get("Status.canceled"));
    });
    this.exportTask.setOnFailed(event -> {
        this.isExportRunningProperty.setValue(false);
        MainViewController.LOGGER.log(Level.WARNING, event.getSource().getException().toString(), event.getSource().getException());
        this.updateStatusBar(this.exporterThread, Message.get("Status.failed"));
        GuiUtil.guiMessageAlert(Alert.AlertType.WARNING, Message.get("Exporter.FragmentsTab.ExportNotPossible.title"), Message.get("Exporter.FragmentsTab.ExportNotPossible.header"), null);
    });
    this.exporterThread = new Thread(this.exportTask);
    this.exporterThread.setName(ThreadType.EXPORT_THREAD.getThreadName());
    this.exporterThread.setUncaughtExceptionHandler(LogUtil.getUncaughtExceptionHandler());
    this.exporterThread.setDaemon(false);
    // magic number
    this.exporterThread.setPriority(Thread.currentThread().getPriority() - 2);
    this.isExportRunningProperty.setValue(true);
    this.updateStatusBar(this.exporterThread, Message.get("Status.exporting"));
    this.exporterThread.start();
}
Also used : GridTabForTableView(de.unijena.cheminf.mortar.gui.panes.GridTabForTableView) List(java.util.List) ObservableList(javafx.collections.ObservableList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Exporter(de.unijena.cheminf.mortar.model.io.Exporter) ButtonType(javafx.scene.control.ButtonType) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with GridTabForTableView

use of de.unijena.cheminf.mortar.gui.panes.GridTabForTableView 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 5 with GridTabForTableView

use of de.unijena.cheminf.mortar.gui.panes.GridTabForTableView in project MORTAR by FelixBaensch.

the class MainViewController method openGlobalSettingsView.

// 
/**
 * Opens settings view for global settings
 */
private void openGlobalSettingsView() {
    SettingsViewController tmpSettingsViewController = new SettingsViewController(this.primaryStage, this.settingsContainer);
    Platform.runLater(() -> {
        if (tmpSettingsViewController.hasRowsPerPageChanged()) {
            for (Tab tmpTab : this.mainTabPane.getTabs()) {
                TableView tmpTableView = ((GridTabForTableView) tmpTab).getTableView();
                int tmpListSize = 0;
                tmpListSize = ((IDataTableView) tmpTableView).getItemsList().size();
                int tmpPageIndex = ((GridTabForTableView) tmpTab).getPagination().getCurrentPageIndex();
                int tmpRowsPerPage = this.settingsContainer.getRowsPerPageSetting();
                int tmpPageCount = tmpListSize / tmpRowsPerPage;
                if (tmpListSize % tmpRowsPerPage > 0) {
                    tmpPageCount++;
                }
                if (tmpPageIndex > tmpPageCount) {
                    tmpPageIndex = tmpPageCount;
                }
                ((GridTabForTableView) tmpTab).getPagination().setPageCount(tmpPageCount);
                ((GridTabForTableView) tmpTab).getPagination().setCurrentPageIndex(tmpPageIndex);
                ((GridTabForTableView) tmpTab).getTableView().refresh();
                GuiUtil.setImageStructureHeight(((GridTabForTableView) tmpTab).getTableView(), ((GridTabForTableView) tmpTab).getTableView().getHeight(), this.settingsContainer);
                ((GridTabForTableView) tmpTab).getTableView().refresh();
            }
        }
        if (tmpSettingsViewController.hasKeepAtomContainerInDataModelChanged()) {
            for (MoleculeDataModel tmpMoleculeDataModel : this.moleculeDataModelList) {
                tmpMoleculeDataModel.setKeepAtomContainer(this.settingsContainer.getKeepAtomContainerInDataModelSetting());
            }
            for (ObservableList<FragmentDataModel> tmpFragmentDataModelList : this.mapOfFragmentDataModelLists.values()) {
                for (FragmentDataModel tmpFragmentDataModel : tmpFragmentDataModelList) {
                    tmpFragmentDataModel.setKeepAtomContainer(this.settingsContainer.getKeepAtomContainerInDataModelSetting());
                }
            }
        }
    });
}
Also used : FragmentDataModel(de.unijena.cheminf.mortar.model.data.FragmentDataModel) Tab(javafx.scene.control.Tab) GridTabForTableView(de.unijena.cheminf.mortar.gui.panes.GridTabForTableView) MoleculeDataModel(de.unijena.cheminf.mortar.model.data.MoleculeDataModel) IDataTableView(de.unijena.cheminf.mortar.gui.views.IDataTableView) FragmentsDataTableView(de.unijena.cheminf.mortar.gui.views.FragmentsDataTableView) TableView(javafx.scene.control.TableView) MoleculesDataTableView(de.unijena.cheminf.mortar.gui.views.MoleculesDataTableView) ItemizationDataTableView(de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView) IDataTableView(de.unijena.cheminf.mortar.gui.views.IDataTableView) GridTabForTableView(de.unijena.cheminf.mortar.gui.panes.GridTabForTableView)

Aggregations

GridTabForTableView (de.unijena.cheminf.mortar.gui.panes.GridTabForTableView)5 FragmentsDataTableView (de.unijena.cheminf.mortar.gui.views.FragmentsDataTableView)3 IDataTableView (de.unijena.cheminf.mortar.gui.views.IDataTableView)3 ItemizationDataTableView (de.unijena.cheminf.mortar.gui.views.ItemizationDataTableView)3 MoleculesDataTableView (de.unijena.cheminf.mortar.gui.views.MoleculesDataTableView)3 FragmentDataModel (de.unijena.cheminf.mortar.model.data.FragmentDataModel)3 MoleculeDataModel (de.unijena.cheminf.mortar.model.data.MoleculeDataModel)3 Exporter (de.unijena.cheminf.mortar.model.io.Exporter)3 List (java.util.List)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 ObservableList (javafx.collections.ObservableList)3 ButtonType (javafx.scene.control.ButtonType)3 GuiDefinitions (de.unijena.cheminf.mortar.gui.util.GuiDefinitions)2 GuiUtil (de.unijena.cheminf.mortar.gui.util.GuiUtil)2 MainView (de.unijena.cheminf.mortar.gui.views.MainView)2 Message (de.unijena.cheminf.mortar.message.Message)2 FragmentationService (de.unijena.cheminf.mortar.model.fragmentation.FragmentationService)2 IMoleculeFragmenter (de.unijena.cheminf.mortar.model.fragmentation.algorithm.IMoleculeFragmenter)2 ChemFileTypes (de.unijena.cheminf.mortar.model.io.ChemFileTypes)2