<commit_before>package programminglife.gui.controller;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import programminglife.ProgrammingLife;
import programminglife.controller.BookmarkController;
import programminglife.model.Bookmark;
import programminglife.model.Graph;
import programminglife.model.exception.UnknownTypeException;
import programminglife.parser.GraphParser;
import programminglife.utility.Alerts;
import programminglife.utility.Console;

import java.io.File;
import java.io.IOException;
import java.util.*;

/**
 * Controller for loading bookmarks.
 */
public class GuiLoadBookmarkController implements Observer {
    private GuiController guiController;

    @FXML private Button btnOpenBookmark;
    @FXML private Button btnDeleteBookmark;
    @FXML private Button btnCreateBookmark;
    @FXML private Button btnShowInfo;
    @FXML private Accordion accordionBookmark;
    private List<TableView<Bookmark>> tableViews;

    /**
     * Initialize method for BookmarkController.
     */
    @FXML
    @SuppressWarnings("unused")
    public void initialize() {
        btnCreateBookmark.setDisable(true);
        initButtons();
    }

    /**
     * Checks whether the user has selected a bookmark.
     * @return True if selected, false otherwise.
     */
    private Bookmark checkBookmarkSelection() {
        Bookmark bookmark;
        for (TableView<Bookmark> tableView : tableViews) {
            if (tableView.getSelectionModel().getSelectedItem() != null) {
                bookmark = tableView.getSelectionModel().getSelectedItem();
                return bookmark;
            }
        }
        Alerts.warning("No bookmark selected");
        return null;
    }

    /**
     * Initializes the buttons in the window.
     */
    private void initButtons() {
        btnOpenBookmark.setOnAction(event -> openBookmark());
        btnDeleteBookmark.setOnAction(event -> buttonDelete());
        btnCreateBookmark.setOnAction(event -> createBookmark());
        btnShowInfo.setOnAction(event -> showInfo());
    }

    /**
     * Handles the actions of the open bookmark button.
     */
    private void openBookmark() {
        Bookmark bookmark = checkBookmarkSelection();
        if (bookmark != null) {
            guiController.setText(bookmark.getNodeID(), bookmark.getRadius());
            if (guiController.getFile() == null
                    || !bookmark.getPath().equals(guiController.getFile().getAbsolutePath())) {
                File file = new File(bookmark.getPath());
                try {
                    guiController.setFile(file);
                    guiController.openFile(file).addObserver(this);
                } catch (IOException | UnknownTypeException e) {
                    Alerts.error("File location has changed");
                }
            } else {
                guiController.draw();
            }
            ((Stage) btnOpenBookmark.getScene().getWindow()).close();
            Console.println("Loaded bookmark " + bookmark.getBookmarkName()
                    + " Center Node: " + bookmark.getNodeID() + " Radius: " + bookmark.getRadius());
        }
    }

    /**
     * Handles the actions of the delete bookmark button.
     */
    private void buttonDelete() {
        Bookmark bookmark = checkBookmarkSelection();
        if (bookmark != null) {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setTitle("Confirm Deletion");
            alert.setHeaderText("Do you really want to delete bookmark: \"" + bookmark.getBookmarkName() + "\"?");
            Optional<ButtonType> result = alert.showAndWait();
            result.ifPresent(buttonType -> {
                if (buttonType == ButtonType.OK) {
                    BookmarkController.deleteBookmark(bookmark.getFile(), bookmark.getBookmarkName());
                    Console.println("Deleted bookmark " + bookmark.getBookmarkName()<commit_msg>Forgot a line. Travis should work again<commit_after>package programminglife.gui.controller;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import programminglife.ProgrammingLife;
import programminglife.controller.BookmarkController;
import programminglife.model.Bookmark;
import programminglife.model.Graph;
import programminglife.parser.GraphParser;
import programminglife.utility.Alerts;
import programminglife.utility.Console;

import java.io.File;
import java.io.IOException;
import java.util.*;

/**
 * Controller for loading bookmarks.
 */
public class GuiLoadBookmarkController implements Observer {
    private GuiController guiController;

    @FXML private Button btnOpenBookmark;
    @FXML private Button btnDeleteBookmark;
    @FXML private Button btnCreateBookmark;
    @FXML private Button btnShowInfo;
    @FXML private Accordion accordionBookmark;
    private List<TableView<Bookmark>> tableViews;

    /**
     * Initialize method for BookmarkController.
     */
    @FXML
    @SuppressWarnings("unused")
    public void initialize() {
        btnCreateBookmark.setDisable(true);
        initButtons();
    }

    /**
     * Checks whether the user has selected a bookmark.
     * @return True if selected, false otherwise.
     */
    private Bookmark checkBookmarkSelection() {
        Bookmark bookmark;
        for (TableView<Bookmark> tableView : tableViews) {
            if (tableView.getSelectionModel().getSelectedItem() != null) {
                bookmark = tableView.getSelectionModel().getSelectedItem();
                return bookmark;
            }
        }
        Alerts.warning("No bookmark selected");
        return null;
    }

    /**
     * Initializes the buttons in the window.
     */
    private void initButtons() {
        btnOpenBookmark.setOnAction(event -> openBookmark());
        btnDeleteBookmark.setOnAction(event -> buttonDelete());
        btnCreateBookmark.setOnAction(event -> createBookmark());
        btnShowInfo.setOnAction(event -> showInfo());
    }

    /**
     * Handles the actions of the open bookmark button.
     */
    private void openBookmark() {
        Bookmark bookmark = checkBookmarkSelection();
        if (bookmark != null) {
            guiController.setText(bookmark.getNodeID(), bookmark.getRadius());
            if (guiController.getFile() == null
                    || !bookmark.getPath().equals(guiController.getFile().getAbsolutePath())) {
                File file = new File(bookmark.getPath());
                try {
                    guiController.setFile(file);
                    guiController.openFile(file).addObserver(this);
                } catch (IOException e) {
                    Alerts.error("File location has changed");
                }
            } else {
                guiController.draw();
            }
            ((Stage) btnOpenBookmark.getScene().getWindow()).close();
            Console.println("Loaded bookmark " + bookmark.getBookmarkName()
                    + " Center Node: " + bookmark.getNodeID() + " Radius: " + bookmark.getRadius());
        }
    }

    /**
     * Handles the actions of the delete bookmark button.
     */
    private void buttonDelete() {
        Bookmark bookmark = checkBookmarkSelection();
        if (bookmark != null) {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setTitle("Confirm Deletion");
            alert.setHeaderText("Do you really want to delete bookmark: \"" + bookmark.getBookmarkName() + "\"?");
            Optional<ButtonType> result = alert.showAndWait();
            result.ifPresent(buttonType -> {
                if (buttonType == ButtonType.OK) {
                    BookmarkController.deleteBookmark(bookmark.getFile(), bookmark.getBookmarkName());
                    Console.println("Deleted bookmark " + bookmark.getBookmarkName()
{'fraction_non_alphanumeric': 0.1038653070903486, 'fraction_numerical': 0.0, 'mean_word_length': 2.6753812636165577, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '19303', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2189, 'n_words': 476}