Skip to content

Commit f1cf3fa

Browse files
K1-mbfMemeelcalixtus
authored
DropDown menu in MainTable rows (#14475)
* Added combo box in main table for content selectors * Update CHANGELOG with new features Added a drop-down menu for custom fields in the main table. * Update CHANGELOG with issue reference for drop-down menu Added a reference to issue #14087 for the drop-down menu feature. * Update CHANGELOG for style * Update CHANGELOG.md Minor changes on the issue #14087 Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> * add new line for arguments --------- Co-authored-by: Mélina Wang <dgtrhb@gmail.com> Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
1 parent 5f9f1e8 commit f1cf3fa

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
1111

1212
### Added
1313

14+
- We added a drop-down menu to those custom fields in the main table for which content selector values exists. [#14087](https://github.com/JabRef/jabref/issues/14087)
1415
- We added a "Jump to Field" dialog (`Ctrl+J`) to quickly search for and navigate to any field across all tabs. [#12276](https://github.com/JabRef/jabref/issues/12276).
1516
- We made the "Configure API key" option in the Web Search preferences tab searchable via preferences search. [#13929](https://github.com/JabRef/jabref/issues/13929)
1617
- We added the integrity check to the jabkit cli application. [#13848](https://github.com/JabRef/jabref/issues/13848)

jabgui/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.jabref.gui.StateManager;
2525
import org.jabref.gui.icon.IconTheme;
2626
import org.jabref.gui.icon.JabRefIcon;
27+
import org.jabref.gui.maintable.columns.ContentSelectorColumn;
2728
import org.jabref.gui.maintable.columns.FieldColumn;
2829
import org.jabref.gui.maintable.columns.FileColumn;
2930
import org.jabref.gui.maintable.columns.LibraryColumn;
@@ -122,7 +123,14 @@ public MainTableColumnFactory(@NonNull BibDatabaseContext database,
122123
break;
123124
case NORMALFIELD:
124125
if (!column.getQualifier().isBlank()) {
125-
returnColumn = createFieldColumn(column, tooltip);
126+
Field field = FieldFactory.parseField(column.getQualifier());
127+
List<String> values = database.getMetaData().getContentSelectorValuesForField(field);
128+
129+
if (values != null && !values.isEmpty()) {
130+
returnColumn = createContentSelectorColumn(column, values);
131+
} else {
132+
returnColumn = createFieldColumn(column, tooltip);
133+
}
126134
}
127135
break;
128136
default:
@@ -297,6 +305,14 @@ private TableColumn<BibEntryTableViewModel, Optional<SpecialFieldValueViewModel>
297305
return new SpecialFieldColumn(columnModel, preferences, undoManager);
298306
}
299307

308+
/**
309+
* Creates a column for fields with content selectors.
310+
*/
311+
private TableColumn<BibEntryTableViewModel, ?> createContentSelectorColumn(MainTableColumnModel columnModel,
312+
List<String> values) {
313+
return new ContentSelectorColumn(columnModel, values, undoManager);
314+
}
315+
300316
/**
301317
* Creates a column for all the linked files. Instead of creating a column for a single file type, like {@link
302318
* #createExtraFileColumn(MainTableColumnModel)} createExtraFileColumn} does, this creates one single column collecting all file links.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.jabref.gui.maintable.columns;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
import javax.swing.undo.UndoManager;
7+
8+
import javafx.scene.control.ContextMenu;
9+
import javafx.scene.control.MenuItem;
10+
11+
import org.jabref.gui.maintable.BibEntryTableViewModel;
12+
import org.jabref.gui.maintable.MainTableColumnModel;
13+
import org.jabref.gui.undo.UndoableFieldChange;
14+
import org.jabref.gui.util.OptionalValueTableCellFactory;
15+
import org.jabref.logic.util.strings.StringUtil;
16+
import org.jabref.model.entry.BibEntry;
17+
import org.jabref.model.entry.field.Field;
18+
import org.jabref.model.entry.field.FieldFactory;
19+
import org.jabref.model.entry.field.OrFields;
20+
21+
import com.tobiasdiez.easybind.EasyBind;
22+
23+
/**
24+
* A column for fields with content selectors.
25+
*/
26+
public class ContentSelectorColumn extends MainTableColumn<Optional<String>> {
27+
28+
private final List<String> values;
29+
private final Field field;
30+
private final UndoManager undoManager;
31+
32+
public ContentSelectorColumn(MainTableColumnModel model, List<String> values, UndoManager undoManager) {
33+
super(model);
34+
this.values = values;
35+
this.undoManager = undoManager;
36+
this.field = FieldFactory.parseField(model.getQualifier());
37+
38+
setText(field.getName());
39+
setCellValueFactory(param -> EasyBind.map(param.getValue().getFields(new OrFields(field)),
40+
value -> StringUtil.isBlank(value) ? Optional.empty() : Optional.of(value)));
41+
42+
new OptionalValueTableCellFactory<BibEntryTableViewModel, String>()
43+
.withText(value -> value.orElse(""))
44+
.withMenu(this::createMenu)
45+
.install(this);
46+
47+
this.setSortable(true);
48+
}
49+
50+
private ContextMenu createMenu(BibEntryTableViewModel model, Optional<String> value) {
51+
ContextMenu menu = new ContextMenu();
52+
BibEntry entry = model.getEntry();
53+
54+
for (String item : values) {
55+
MenuItem menuItem = new MenuItem(item);
56+
menuItem.setOnAction(event -> {
57+
String oldValue = entry.getField(field).orElse(null);
58+
entry.setField(field, item);
59+
if (undoManager != null) {
60+
undoManager.addEdit(new UndoableFieldChange(entry, field, oldValue, item));
61+
}
62+
});
63+
menu.getItems().add(menuItem);
64+
}
65+
return menu;
66+
}
67+
}

0 commit comments

Comments
 (0)