Search in sources :

Example 1 with AddRepositoryDialog

use of org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog in project phoenicis by PhoenicisOrg.

the class RepositoriesPanel method populateRepositoryGrid.

private void populateRepositoryGrid() {
    this.title = new TextWithStyle(tr("Repositories Settings"), "title");
    this.repositoryGrid = new GridPane();
    this.repositoryGrid.getStyleClass().add("grid");
    this.repositoryText = new TextWithStyle(tr("Repository:"), "captionTitle");
    this.repositoryLayout = new VBox();
    this.repositoryLayout.setSpacing(5);
    this.repositoryListView = new ListView<>(repositories);
    this.repositoryListView.setPrefHeight(0);
    this.repositoryListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    this.repositoryListView.setEditable(true);
    this.repositoryListView.setCellFactory(param -> new DragableRepositoryListCell((repositoryUrl, toIndex) -> {
        this.repositoryManager.moveRepository(repositoryUrl, toIndex.intValue());
        this.save();
    }));
    this.repositoryButtonLayout = new HBox();
    this.repositoryButtonLayout.setSpacing(5);
    this.addButton = new Button();
    this.addButton.setText(tr("Add"));
    this.addButton.setOnAction((ActionEvent event) -> {
        AddRepositoryDialog dialog = new AddRepositoryDialog();
        dialog.initOwner(this.getParent().getScene().getWindow());
        Optional<RepositoryLocation<? extends Repository>> successResult = dialog.showAndWait();
        successResult.ifPresent(repositoryLocation -> {
            repositories.add(repositoryLocation);
            this.save();
            repositoryManager.addRepositories(0, repositoryLocation);
        });
    });
    this.removeButton = new Button();
    this.removeButton.setText(tr("Remove"));
    this.removeButton.setOnAction((ActionEvent event) -> {
        RepositoryLocation<? extends Repository>[] toRemove = repositoryListView.getSelectionModel().getSelectedItems().toArray(new RepositoryLocation[0]);
        repositories.removeAll(toRemove);
        this.save();
        repositoryManager.removeRepositories(toRemove);
    });
    this.repositoryButtonLayout.getChildren().addAll(addButton, removeButton);
    this.repositoryLayout.getChildren().addAll(repositoryListView, repositoryButtonLayout);
    VBox.setVgrow(repositoryListView, Priority.ALWAYS);
    this.repositoryGrid.add(repositoryText, 0, 0);
    this.repositoryGrid.add(repositoryLayout, 1, 0);
    GridPane.setHgrow(repositoryLayout, Priority.ALWAYS);
    GridPane.setVgrow(repositoryLayout, Priority.ALWAYS);
    GridPane.setValignment(repositoryText, VPos.TOP);
}
Also used : Pos(javafx.geometry.Pos) javafx.scene.layout(javafx.scene.layout) Repository(org.phoenicis.repository.types.Repository) javafx.scene.control(javafx.scene.control) TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) RepositoryManager(org.phoenicis.repository.RepositoryManager) FXCollections(javafx.collections.FXCollections) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) ActionEvent(javafx.event.ActionEvent) AddRepositoryDialog(org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog) Insets(javafx.geometry.Insets) SettingsManager(org.phoenicis.settings.SettingsManager) VPos(javafx.geometry.VPos) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) ActionEvent(javafx.event.ActionEvent) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation) Repository(org.phoenicis.repository.types.Repository) AddRepositoryDialog(org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog)

Example 2 with AddRepositoryDialog

use of org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog in project POL-POM-5 by PlayOnLinux.

the class RepositoriesPanelSkin method createRepositoryButtons.

/**
 * Creates a new container for the repository buttons.
 * These buttons consist of:
 * - an add button
 * - a delete button
 * - a restore defaults button
 *
 * @param repositoryLocationTable The repository location table
 * @return A new container for the repository buttons
 */
private HBox createRepositoryButtons(TableView<RepositoryLocation<? extends Repository>> repositoryLocationTable) {
    final Button addButton = new Button(tr("Add"));
    addButton.getStyleClass().add("repositories-add");
    addButton.setOnAction((ActionEvent event) -> {
        final AddRepositoryDialog dialog = new AddRepositoryDialog();
        dialog.initOwner(getControl().getScene().getWindow());
        final Optional<RepositoryLocation<? extends Repository>> successResult = dialog.showAndWait();
        successResult.ifPresent(repositoryLocation -> getControl().getRepositoryLocations().add(0, repositoryLocation));
    });
    final Button removeButton = new Button(tr("Remove"));
    removeButton.getStyleClass().add("repositories-remove");
    removeButton.setOnAction((ActionEvent event) -> {
        final List<RepositoryLocation<? extends Repository>> toRemove = repositoryLocationTable.getSelectionModel().getSelectedItems();
        getControl().getRepositoryLocations().removeAll(toRemove);
    });
    final Button restoreDefault = new Button(tr("Restore defaults"));
    restoreDefault.getStyleClass().add("repositories-restore");
    restoreDefault.setOnAction(event -> {
        final SimpleConfirmDialog dialog = SimpleConfirmDialog.builder().withTitle(tr("Restore default repositories")).withMessage(tr("Are you sure you want to restore the default repositories?")).withYesCallback(() -> Platform.runLater(() -> getControl().getRepositoryLocations().setAll(getControl().getRepositoryLocationLoader().getDefaultRepositoryLocations()))).withOwner(getControl().getScene().getWindow()).withResizable(true).build();
        dialog.showAndCallback();
    });
    final HBox container = new HBox(addButton, removeButton, restoreDefault);
    container.getStyleClass().add("repositories-buttons-container");
    return container;
}
Also used : Repository(org.phoenicis.repository.types.Repository) HBox(javafx.scene.layout.HBox) AddRepositoryDialog(org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog) ActionEvent(javafx.event.ActionEvent) SimpleConfirmDialog(org.phoenicis.javafx.dialogs.SimpleConfirmDialog) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation)

Example 3 with AddRepositoryDialog

use of org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog in project POL-POM-5 by PhoenicisOrg.

the class RepositoriesPanel method populateRepositoryGrid.

private void populateRepositoryGrid() {
    this.title = new TextWithStyle(tr("Repositories Settings"), "title");
    this.repositoryGrid = new GridPane();
    this.repositoryGrid.getStyleClass().add("grid");
    this.repositoryText = new TextWithStyle(tr("Repository:"), "captionTitle");
    this.repositoryLayout = new VBox();
    this.repositoryLayout.setSpacing(5);
    this.repositoryListView = new ListView<>(repositories);
    this.repositoryListView.setPrefHeight(0);
    this.repositoryListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    this.repositoryListView.setEditable(true);
    this.repositoryListView.setCellFactory(param -> new DragableRepositoryListCell((repositoryUrl, toIndex) -> {
        this.repositoryManager.moveRepository(repositoryUrl, toIndex.intValue());
        this.save();
    }));
    this.repositoryButtonLayout = new HBox();
    this.repositoryButtonLayout.setSpacing(5);
    this.addButton = new Button();
    this.addButton.setText(tr("Add"));
    this.addButton.setOnAction((ActionEvent event) -> {
        AddRepositoryDialog dialog = new AddRepositoryDialog();
        dialog.initOwner(this.getParent().getScene().getWindow());
        Optional<RepositoryLocation<? extends Repository>> successResult = dialog.showAndWait();
        successResult.ifPresent(repositoryLocation -> {
            repositories.add(repositoryLocation);
            this.save();
            repositoryManager.addRepositories(0, repositoryLocation);
        });
    });
    this.removeButton = new Button();
    this.removeButton.setText(tr("Remove"));
    this.removeButton.setOnAction((ActionEvent event) -> {
        RepositoryLocation<? extends Repository>[] toRemove = repositoryListView.getSelectionModel().getSelectedItems().toArray(new RepositoryLocation[0]);
        repositories.removeAll(toRemove);
        this.save();
        repositoryManager.removeRepositories(toRemove);
    });
    this.repositoryButtonLayout.getChildren().addAll(addButton, removeButton);
    this.repositoryLayout.getChildren().addAll(repositoryListView, repositoryButtonLayout);
    VBox.setVgrow(repositoryListView, Priority.ALWAYS);
    this.repositoryGrid.add(repositoryText, 0, 0);
    this.repositoryGrid.add(repositoryLayout, 1, 0);
    GridPane.setHgrow(repositoryLayout, Priority.ALWAYS);
    GridPane.setVgrow(repositoryLayout, Priority.ALWAYS);
    GridPane.setValignment(repositoryText, VPos.TOP);
}
Also used : Pos(javafx.geometry.Pos) javafx.scene.layout(javafx.scene.layout) Repository(org.phoenicis.repository.types.Repository) javafx.scene.control(javafx.scene.control) TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) RepositoryManager(org.phoenicis.repository.RepositoryManager) FXCollections(javafx.collections.FXCollections) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) ActionEvent(javafx.event.ActionEvent) AddRepositoryDialog(org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog) Insets(javafx.geometry.Insets) SettingsManager(org.phoenicis.settings.SettingsManager) VPos(javafx.geometry.VPos) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) ActionEvent(javafx.event.ActionEvent) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation) Repository(org.phoenicis.repository.types.Repository) AddRepositoryDialog(org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog)

Aggregations

ActionEvent (javafx.event.ActionEvent)3 AddRepositoryDialog (org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog)3 RepositoryLocation (org.phoenicis.repository.location.RepositoryLocation)3 Repository (org.phoenicis.repository.types.Repository)3 Optional (java.util.Optional)2 Platform (javafx.application.Platform)2 FXCollections (javafx.collections.FXCollections)2 ObservableList (javafx.collections.ObservableList)2 Insets (javafx.geometry.Insets)2 Pos (javafx.geometry.Pos)2 VPos (javafx.geometry.VPos)2 javafx.scene.control (javafx.scene.control)2 javafx.scene.layout (javafx.scene.layout)2 Text (javafx.scene.text.Text)2 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)2 TextWithStyle (org.phoenicis.javafx.views.common.TextWithStyle)2 RepositoryManager (org.phoenicis.repository.RepositoryManager)2 SettingsManager (org.phoenicis.settings.SettingsManager)2 HBox (javafx.scene.layout.HBox)1 SimpleConfirmDialog (org.phoenicis.javafx.dialogs.SimpleConfirmDialog)1