Search in sources :

Example 6 with RepositoryLocation

use of org.phoenicis.repository.location.RepositoryLocation in project POL-POM-5 by PhoenicisOrg.

the class FilesystemJsonRepositoryLocationLoader method loadRepositoryLocations.

@Override
public List<RepositoryLocation<? extends Repository>> loadRepositoryLocations() {
    List<RepositoryLocation<? extends Repository>> result = new ArrayList<>();
    File repositoryListFile = new File(repositoryListPath);
    if (repositoryListFile.exists()) {
        try {
            result = this.objectMapper.readValue(new File(repositoryListPath), TypeFactory.defaultInstance().constructParametricType(List.class, RepositoryLocation.class));
        } catch (IOException e) {
            LOGGER.error("Couldn't load repository location list", e);
        }
    } else {
        result.addAll(getDefaultRepositoryLocations());
    }
    return result;
}
Also used : Repository(org.phoenicis.repository.types.Repository) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) GitRepositoryLocation(org.phoenicis.repository.location.GitRepositoryLocation) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation) ClasspathRepositoryLocation(org.phoenicis.repository.location.ClasspathRepositoryLocation)

Example 7 with RepositoryLocation

use of org.phoenicis.repository.location.RepositoryLocation in project POL-POM-5 by PhoenicisOrg.

the class RepositoriesPanelSkin method createRepositoryLocationTable.

/**
 * Creates a {@link TableView} containing the {@link RepositoryLocation} objects
 *
 * @return A {@link TableView} containing the {@link RepositoryLocation} objects
 */
private TableView<RepositoryLocation<? extends Repository>> createRepositoryLocationTable() {
    final TableView<RepositoryLocation<? extends Repository>> repositoryLocationTable = new TableView<>();
    repositoryLocationTable.getStyleClass().add("repositories-table");
    // add the priority column
    repositoryLocationTable.getColumns().add(createColumn(tr("Priority"), repositoryLocation -> getControl().getRepositoryLocations().indexOf(repositoryLocation) + 1));
    // add the repository name column
    repositoryLocationTable.getColumns().add(createColumn(tr("Repository name"), RepositoryLocation::toDisplayString));
    repositoryLocationTable.setRowFactory(tv -> {
        final TableRow<RepositoryLocation<? extends Repository>> row = new TableRow<>();
        row.getStyleClass().add("repository-row");
        final Tooltip repositoryLocationTooltip = new Tooltip(tr("Move the repository up or down to change its priority"));
        // ensure that the tooltip is only shown for non empty rows
        row.emptyProperty().addListener((Observable invalidation) -> {
            if (row.isEmpty()) {
                Tooltip.uninstall(row, repositoryLocationTooltip);
            } else {
                Tooltip.install(row, repositoryLocationTooltip);
            }
        });
        row.setOnDragDetected(event -> {
            if (!row.isEmpty()) {
                final int index = row.getIndex();
                final Dragboard dragboard = row.startDragAndDrop(TransferMode.MOVE);
                // create a preview image
                final RepositoryLocation<? extends Repository> repositoryLocation = getControl().getRepositoryLocations().get(index);
                dragboard.setDragView(createPreviewImage(repositoryLocation));
                // save the dragged repository index
                final ClipboardContent content = new ClipboardContent();
                content.put(repositoryLocationFormat, index);
                dragboard.setContent(content);
                event.consume();
            }
        });
        row.setOnDragOver(event -> {
            final Dragboard dragboard = event.getDragboard();
            if (dragboard.hasContent(repositoryLocationFormat) && row.getIndex() != (Integer) dragboard.getContent(repositoryLocationFormat)) {
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                event.consume();
            }
        });
        row.setOnDragDropped(event -> {
            final Dragboard dragboard = event.getDragboard();
            if (dragboard.hasContent(repositoryLocationFormat)) {
                final int draggedIndex = (Integer) dragboard.getContent(repositoryLocationFormat);
                final List<RepositoryLocation<? extends Repository>> workingCopy = new ArrayList<>(getControl().getRepositoryLocations());
                final RepositoryLocation<? extends Repository> draggedRepositoryLocation = workingCopy.remove(draggedIndex);
                final int dropIndex = row.isEmpty() ? workingCopy.size() : row.getIndex();
                workingCopy.add(dropIndex, draggedRepositoryLocation);
                getControl().getRepositoryLocations().setAll(workingCopy);
                event.setDropCompleted(true);
                event.consume();
            }
        });
        return row;
    });
    Bindings.bindContent(repositoryLocationTable.getItems(), getControl().getRepositoryLocations());
    return repositoryLocationTable;
}
Also used : Scene(javafx.scene.Scene) Repository(org.phoenicis.repository.types.Repository) javafx.scene.control(javafx.scene.control) SnapshotParameters(javafx.scene.SnapshotParameters) VBox(javafx.scene.layout.VBox) Bindings(javafx.beans.binding.Bindings) Function(java.util.function.Function) TransferMode(javafx.scene.input.TransferMode) RepositoriesPanel(org.phoenicis.javafx.components.setting.control.RepositoriesPanel) ArrayList(java.util.ArrayList) Dragboard(javafx.scene.input.Dragboard) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation) SkinBase(org.phoenicis.javafx.components.common.skin.SkinBase) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Observable(javafx.beans.Observable) Group(javafx.scene.Group) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) Priority(javafx.scene.layout.Priority) ActionEvent(javafx.event.ActionEvent) AddRepositoryDialog(org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog) List(java.util.List) DataFormat(javafx.scene.input.DataFormat) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) SimpleConfirmDialog(org.phoenicis.javafx.dialogs.SimpleConfirmDialog) Optional(java.util.Optional) ClipboardContent(javafx.scene.input.ClipboardContent) Image(javafx.scene.image.Image) ClipboardContent(javafx.scene.input.ClipboardContent) ArrayList(java.util.ArrayList) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation) Observable(javafx.beans.Observable) Repository(org.phoenicis.repository.types.Repository) Dragboard(javafx.scene.input.Dragboard)

Example 8 with RepositoryLocation

use of org.phoenicis.repository.location.RepositoryLocation in project POL-POM-5 by PhoenicisOrg.

the class RepositoriesPanelSkin method initialise.

/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final Text title = new Text(tr("Repository Settings"));
    title.getStyleClass().add("title");
    final TableView<RepositoryLocation<? extends Repository>> repositoryLocationTable = createRepositoryLocationTable();
    VBox.setVgrow(repositoryLocationTable, Priority.ALWAYS);
    final HBox repositoryButtons = createRepositoryButtons(repositoryLocationTable);
    final HBox refreshContainer = createRefreshButtonContainer();
    final VBox container = new VBox(title, repositoryLocationTable, repositoryButtons, refreshContainer);
    container.getStyleClass().addAll("settings-tab", "repositories-panel");
    getChildren().addAll(container);
}
Also used : Repository(org.phoenicis.repository.types.Repository) HBox(javafx.scene.layout.HBox) Text(javafx.scene.text.Text) VBox(javafx.scene.layout.VBox) RepositoryLocation(org.phoenicis.repository.location.RepositoryLocation)

Example 9 with RepositoryLocation

use of org.phoenicis.repository.location.RepositoryLocation in project POL-POM-5 by PhoenicisOrg.

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 10 with RepositoryLocation

use of org.phoenicis.repository.location.RepositoryLocation 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

RepositoryLocation (org.phoenicis.repository.location.RepositoryLocation)15 Repository (org.phoenicis.repository.types.Repository)15 ArrayList (java.util.ArrayList)7 ActionEvent (javafx.event.ActionEvent)6 HBox (javafx.scene.layout.HBox)6 Text (javafx.scene.text.Text)6 AddRepositoryDialog (org.phoenicis.javafx.views.mainwindow.settings.addrepository.AddRepositoryDialog)6 Optional (java.util.Optional)4 Platform (javafx.application.Platform)4 javafx.scene.control (javafx.scene.control)4 ClipboardContent (javafx.scene.input.ClipboardContent)4 Dragboard (javafx.scene.input.Dragboard)4 VBox (javafx.scene.layout.VBox)4 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)4 File (java.io.File)3 IOException (java.io.IOException)3 SimpleConfirmDialog (org.phoenicis.javafx.dialogs.SimpleConfirmDialog)3 List (java.util.List)2 Function (java.util.function.Function)2 Observable (javafx.beans.Observable)2