From d88129ce46f8720ab55da425dc45e4eaa23eeace Mon Sep 17 00:00:00 2001 From: gabriel nogueras Date: Fri, 25 Oct 2024 17:05:43 -0400 Subject: [PATCH 1/4] Made changes to FileColumn allowing for specific files to be accesed by mouse click. --- .../gui/maintable/MainTableColumnFactory.java | 12 +++++-- .../gui/maintable/MainTableColumnModel.java | 10 ++++++ .../gui/maintable/columns/FileColumn.java | 31 +++++++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index bd592f6b22c..470c19562ff 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -84,6 +84,7 @@ public MainTableColumnFactory(BibDatabaseContext database, this.tooltip = new MainTableTooltip(database, dialogService, preferences, themeManager, taskExecutor); } + @SuppressWarnings("checkstyle:WhitespaceAround") public TableColumn createColumn(MainTableColumnModel column) { TableColumn returnColumn = null; switch (column.getType()) { @@ -109,10 +110,17 @@ public MainTableColumnFactory(BibDatabaseContext database, returnColumn = createLibraryColumn(column); break; case EXTRAFILE: - if (!column.getQualifier().isBlank()) { - returnColumn = createExtraFileColumn(column); + String qualifier = column.getQualifier(); + if (qualifier.isBlank()) { + column.setQualifier("default-file-type"); + } else { + column.setQualifier(qualifier); } + LOGGER.info("EXTRAFILE column assigned with qualifier: {}", qualifier); + + returnColumn = createExtraFileColumn(column); break; + case SPECIALFIELD: if (!column.getQualifier().isBlank()) { Field field = FieldFactory.parseField(column.getQualifier()); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java index d0d5f7366de..727d51d94a7 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java @@ -143,6 +143,16 @@ public String getQualifier() { return qualifierProperty.getValue(); } + public MainTableColumnModel setQualifier(String qualifier) { + if (qualifier == null || qualifier.isBlank()) { + LOGGER.warn("Attempted to set a blank or null qualifier."); + this.qualifierProperty.setValue(""); + } else { + this.qualifierProperty.setValue(qualifier); + } + return this; + } + public String getName() { if (qualifierProperty.getValue().isBlank()) { return typeProperty.getValue().getName(); diff --git a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java index ce1fc758ef3..5eb5ac70f78 100644 --- a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java +++ b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java @@ -98,8 +98,35 @@ public FileColumn(MainTableColumnModel model, .getGraphicNode()); new ValueTableCellFactory>() - .withGraphic((entry, linkedFiles) -> createFileIcon(entry, linkedFiles.stream().filter(linkedFile -> - linkedFile.getFileType().equalsIgnoreCase(fileType)).collect(Collectors.toList()))) + .withGraphic((entry, linkedFiles) -> createFileIcon(entry, linkedFiles.stream() + .filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(fileType)) + .collect(Collectors.toList()))) + .withOnMouseClickedEvent((entry, linkedFiles) -> event -> { + List filteredFiles = linkedFiles.stream() + .filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(fileType)) + .collect(Collectors.toList()); + + if (event.getButton() == MouseButton.PRIMARY) { + if (filteredFiles.size() == 1) { + // Only one file - open directly + LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(filteredFiles.get(0), + entry.getEntry(), database, taskExecutor, dialogService, preferences); + linkedFileViewModel.open(); + } else if (filteredFiles.size() > 1) { + // Multiple files - show context menu to choose file + ContextMenu contextMenu = new ContextMenu(); + for (LinkedFile linkedFile : filteredFiles) { + LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile, + entry.getEntry(), database, taskExecutor, dialogService, preferences); + MenuItem menuItem = new MenuItem(linkedFileViewModel.getTruncatedDescriptionAndLink(), + linkedFileViewModel.getTypeIcon().getGraphicNode()); + menuItem.setOnAction(e -> linkedFileViewModel.open()); + contextMenu.getItems().add(menuItem); + } + contextMenu.show(((Node) event.getSource()), event.getScreenX(), event.getScreenY()); + } + } + }) .install(this); } From a223f3f60c54190c54af7a851c15684a030b93eb Mon Sep 17 00:00:00 2001 From: gabriel nogueras Date: Fri, 25 Oct 2024 17:14:19 -0400 Subject: [PATCH 2/4] Made minor changes to 'case EXTRAFILE' for readability. --- .../jabref/gui/maintable/MainTableColumnFactory.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index 470c19562ff..2861644ffff 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -110,15 +110,9 @@ public MainTableColumnFactory(BibDatabaseContext database, returnColumn = createLibraryColumn(column); break; case EXTRAFILE: - String qualifier = column.getQualifier(); - if (qualifier.isBlank()) { - column.setQualifier("default-file-type"); - } else { - column.setQualifier(qualifier); + if (!column.getQualifier().isBlank()) { + returnColumn = createExtraFileColumn(column); } - LOGGER.info("EXTRAFILE column assigned with qualifier: {}", qualifier); - - returnColumn = createExtraFileColumn(column); break; case SPECIALFIELD: From e0dbeb26413a9c6dc9a3a59bafced87fa9aee1d0 Mon Sep 17 00:00:00 2001 From: gabriel nogueras Date: Fri, 1 Nov 2024 10:20:38 -0400 Subject: [PATCH 3/4] ran rewriteRun --- .../org/jabref/gui/maintable/MainTableColumnModel.java | 10 ---------- .../org/jabref/gui/maintable/columns/FileColumn.java | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java index 727d51d94a7..d0d5f7366de 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java @@ -143,16 +143,6 @@ public String getQualifier() { return qualifierProperty.getValue(); } - public MainTableColumnModel setQualifier(String qualifier) { - if (qualifier == null || qualifier.isBlank()) { - LOGGER.warn("Attempted to set a blank or null qualifier."); - this.qualifierProperty.setValue(""); - } else { - this.qualifierProperty.setValue(qualifier); - } - return this; - } - public String getName() { if (qualifierProperty.getValue().isBlank()) { return typeProperty.getValue().getName(); diff --git a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java index 5eb5ac70f78..974b5fd111e 100644 --- a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java +++ b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java @@ -109,7 +109,7 @@ public FileColumn(MainTableColumnModel model, if (event.getButton() == MouseButton.PRIMARY) { if (filteredFiles.size() == 1) { // Only one file - open directly - LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(filteredFiles.get(0), + LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(filteredFiles.getFirst(), entry.getEntry(), database, taskExecutor, dialogService, preferences); linkedFileViewModel.open(); } else if (filteredFiles.size() > 1) { From 41cf122f22962b6be9c65dee802078ed269a96f4 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 1 Nov 2024 18:28:47 +0100 Subject: [PATCH 4/4] remove checkstyle and sort case --- .../java/org/jabref/gui/maintable/MainTableColumnFactory.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index bceb37aa6e8..94a3362ac29 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -83,7 +83,6 @@ public MainTableColumnFactory(BibDatabaseContext database, this.tooltip = new MainTableTooltip(database, dialogService, preferences, themeManager, taskExecutor); } - @SuppressWarnings("checkstyle:WhitespaceAround") public TableColumn createColumn(MainTableColumnModel column) { TableColumn returnColumn = null; switch (column.getType()) { @@ -110,7 +109,6 @@ public MainTableColumnFactory(BibDatabaseContext database, returnColumn = createExtraFileColumn(column); } break; - case SPECIALFIELD: if (!column.getQualifier().isBlank()) { Field field = FieldFactory.parseField(column.getQualifier()); @@ -122,12 +120,12 @@ public MainTableColumnFactory(BibDatabaseContext database, } } break; - default: case NORMALFIELD: if (!column.getQualifier().isBlank()) { returnColumn = createFieldColumn(column, tooltip); } break; + default: } return returnColumn; }