Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to FileColumn allowing mouse click access to multiple files(.md, .png, etc.) #12085

Merged
merged 7 commits into from
Nov 1, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public MainTableColumnFactory(BibDatabaseContext database,
this.tooltip = new MainTableTooltip(database, dialogService, preferences, themeManager, taskExecutor);
}

@SuppressWarnings("checkstyle:WhitespaceAround")
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
public TableColumn<BibEntryTableViewModel, ?> createColumn(MainTableColumnModel column) {
TableColumn<BibEntryTableViewModel, ?> returnColumn = null;
switch (column.getType()) {
Expand All @@ -109,6 +110,7 @@ public MainTableColumnFactory(BibDatabaseContext database,
returnColumn = createExtraFileColumn(column);
}
break;

Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
case SPECIALFIELD:
if (!column.getQualifier().isBlank()) {
Field field = FieldFactory.parseField(column.getQualifier());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ public String getQualifier() {
return qualifierProperty.getValue();
}

public MainTableColumnModel setQualifier(String qualifier) {
if (qualifier == null || qualifier.isBlank()) {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
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();
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/org/jabref/gui/maintable/columns/FileColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,35 @@ public FileColumn(MainTableColumnModel model,
.getGraphicNode());

new ValueTableCellFactory<BibEntryTableViewModel, List<LinkedFile>>()
.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<LinkedFile> 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());
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
}
}
})
.install(this);
}

Expand Down
Loading