Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
torakiki committed Dec 14, 2023
1 parent 82ae0ed commit 472f185
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
Expand Up @@ -18,14 +18,22 @@
*/
package org.pdfsam.ui.components.selection.multiple;

import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.util.Collections;
import javafx.scene.control.*;
import javafx.scene.input.*;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;
import javafx.scene.input.DragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.VBox;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;

class MockFileExplorer extends VBox {

MockFileExplorer(Path tempFolder) throws URISyntaxException, IOException {
Expand All @@ -36,10 +44,8 @@ class MockFileExplorer extends VBox {
fileList.setOnDragDetected(event -> onDragDetected(event, fileList));
fileList.setOnDragOver(this::onDragOver);

var pdfs = new File[]{
Files.createFile(tempFolder.resolve("1.pdf")).toFile(),
Files.createFile(tempFolder.resolve("2.pdf")).toFile()
};
var pdfs = new File[] { Files.createFile(tempFolder.resolve("1.pdf")).toFile(),
Files.createFile(tempFolder.resolve("2.pdf")).toFile() };

fileList.getItems().addAll(pdfs);

Expand All @@ -48,12 +54,12 @@ class MockFileExplorer extends VBox {

private void onDragDetected(MouseEvent event, ListView<File> fileList) {
var selectedIndex = fileList.getSelectionModel().getSelectedIndex();

if (selectedIndex >= 0) {
var file = fileList.getItems().get(selectedIndex);
var dragboard = fileList.startDragAndDrop(TransferMode.COPY);
var content = new ClipboardContent();

content.put(DataFormat.FILES, Collections.singletonList(file));
dragboard.setContent(content);

Expand All @@ -63,7 +69,7 @@ private void onDragDetected(MouseEvent event, ListView<File> fileList) {

private void onDragOver(DragEvent event) {
var dragboard = event.getDragboard();

if (dragboard.hasFiles()) {
event.acceptTransferModes(TransferMode.COPY);
}
Expand Down
Expand Up @@ -18,8 +18,11 @@
*/
package org.pdfsam.ui.components.selection.multiple;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.Clipboard;
import javafx.scene.input.DataFormat;
import javafx.scene.input.KeyCode;
Expand Down Expand Up @@ -61,13 +64,12 @@
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import javafx.application.Platform;
import javafx.scene.*;
import javafx.scene.control.*;
import org.pdfsam.model.ui.dnd.FilesDroppedEvent;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -109,8 +111,8 @@ public static void setUp() {
@Start
public void start(Stage stage) throws Exception {
victim = new SelectionTable(MODULE, true, true,
new SelectionTableColumn<?>[]{new LoadingColumn(MODULE), FileColumn.NAME, LongColumn.SIZE,
IntColumn.PAGES, LongColumn.LAST_MODIFIED, new PageRangesColumn()});
new SelectionTableColumn<?>[] { new LoadingColumn(MODULE), FileColumn.NAME, LongColumn.SIZE,
IntColumn.PAGES, LongColumn.LAST_MODIFIED, new PageRangesColumn() });
victim.setId("victim");
firstItem = populate();
Scene scene = new Scene(victim);
Expand Down Expand Up @@ -413,12 +415,8 @@ public void dropsOnFirstIndex() throws Exception {

var listView = robot.lookup("#file-list").queryAs(ListView.class);
var cells = listView.lookupAll(".list-cell");
var cell = cells.stream()
.filter(ListCell.class::isInstance)
.map(ListCell.class::cast)
.filter(c -> Objects.nonNull(c.getItem()))
.findFirst()
.orElseThrow();
var cell = cells.stream().filter(ListCell.class::isInstance).map(ListCell.class::cast)
.filter(c -> Objects.nonNull(c.getItem())).findFirst().orElseThrow();

robot.drag(cell).dropTo("temp.pdf");

Expand All @@ -434,10 +432,7 @@ public void dropsOnFirstIndex() throws Exception {

WaitForAsyncUtils.waitForFxEvents();

var actualDescriptor = victim.getItems()
.stream()
.map(SelectionTableRowData::descriptor)
.findFirst()
var actualDescriptor = victim.getItems().stream().map(SelectionTableRowData::descriptor).findFirst()
.orElseThrow();

assertThat(actualDescriptor).isEqualTo(descriptor);
Expand Down

0 comments on commit 472f185

Please sign in to comment.