-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Save sort order column of main table #4327
Changes from 4 commits
ed6aeb0
f9f7d33
2300b75
bde05ce
6e9a564
5aad511
067896e
15c7c44
2a8296b
3f28f72
9af6979
81cd54e
4868593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,6 @@ public class MainTable extends TableView<BibEntryTableViewModel> { | |
private final NewDroppedFileHandler fileHandler; | ||
private final CustomLocalDragboard localDragboard = GUIGlobals.localDragboard; | ||
|
||
|
||
public MainTable(MainTableDataModel model, JabRefFrame frame, | ||
BasePanel panel, BibDatabaseContext database, | ||
MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) { | ||
|
@@ -83,6 +82,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, | |
); | ||
|
||
this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes, panel.getUndoManager(), frame.getDialogService()).createColumns()); | ||
|
||
new ViewModelTableRowFactory<BibEntryTableViewModel>() | ||
.withOnMouseClickedEvent((entry, event) -> { | ||
if (event.getClickCount() == 2) { | ||
|
@@ -114,6 +114,12 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, | |
|
||
this.pane.getStylesheets().add(MainTable.class.getResource("MainTable.css").toExternalForm()); | ||
|
||
//Set sort order column from preferences, currently only single column suported | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is only one column supported? You already transverse all columns here and set the right sort order, or do I miss something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I learned from the SO answer, with shift it's possible to add multiple columns to the sort order. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The standard way is to have two lists, one for the keys and one for the values. In the progress, it would be nice if you would add the corresponding wrapper methods (get/putMap) in |
||
this.getColumns().forEach(col -> preferences.getColumnPreferences().getSortTypeForColumn(col.getText()).ifPresent(sortType -> { | ||
this.getSortOrder().add(col); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I found it out while testing. The sort oder defines the column which are considered to be sorting. |
||
col.setSortType(sortType); | ||
})); | ||
|
||
// Store visual state | ||
new PersistenceVisualStateTable(this, Globals.prefs); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ public PersistenceVisualStateTable(final MainTable mainTable, JabRefPreferences | |
this.preferences = preferences; | ||
|
||
mainTable.getColumns().addListener(this::onColumnsChanged); | ||
mainTable.getColumns().forEach(col -> col.sortTypeProperty().addListener(observable -> preferences.setMainTableColumnSortOrder(col.getText(), col.getSortType().name()))); | ||
} | ||
|
||
private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<BibEntryTableViewModel, ?>> change) { | ||
|
@@ -33,6 +34,7 @@ private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<Bi | |
if (changed) { | ||
updateColumnPreferences(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
@@ -41,13 +43,16 @@ private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<Bi | |
private void updateColumnPreferences() { | ||
List<String> columnNames = new ArrayList<>(); | ||
List<String> columnsWidths = new ArrayList<>(); | ||
List<String> columnSortOrders = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it's not used... |
||
|
||
for (TableColumn<BibEntryTableViewModel, ?> column : mainTable.getColumns()) { | ||
if (column instanceof NormalTableColumn) { | ||
NormalTableColumn normalColumn = (NormalTableColumn) column; | ||
|
||
columnNames.add(normalColumn.getColumnName()); | ||
columnsWidths.add(String.valueOf(normalColumn.getWidth())); | ||
columnSortOrders.add(normalColumn.getSortType().name()); | ||
|
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,8 @@ public class JabRefPreferences implements PreferencesService { | |
public static final String NEWLINE = "newline"; | ||
public static final String COLUMN_WIDTHS = "columnWidths"; | ||
public static final String COLUMN_NAMES = "columnNames"; | ||
public static final String SORT_COLUMN = "columnSortOrders"; | ||
|
||
public static final String SIDE_PANE_COMPONENT_PREFERRED_POSITIONS = "sidePaneComponentPreferredPositions"; | ||
public static final String SIDE_PANE_COMPONENT_NAMES = "sidePaneComponentNames"; | ||
public static final String XMP_PRIVACY_FILTERS = "xmpPrivacyFilters"; | ||
|
@@ -536,6 +538,8 @@ private JabRefPreferences() { | |
|
||
defaults.put(COLUMN_NAMES, "entrytype;author/editor;title;year;journal/booktitle;bibtexkey"); | ||
defaults.put(COLUMN_WIDTHS, "75;300;470;60;130;100"); | ||
defaults.put(SORT_COLUMN, "title;ASCENDING"); | ||
|
||
defaults.put(XMP_PRIVACY_FILTERS, "pdf;timestamp;keywords;owner;note;review"); | ||
defaults.put(USE_XMP_PRIVACY_FILTER, Boolean.FALSE); | ||
defaults.put(WORKING_DIRECTORY, USER_HOME); | ||
|
@@ -1879,7 +1883,9 @@ public ColumnPreferences getColumnPreferences() { | |
getStringList(COLUMN_NAMES), | ||
createSpecialFieldColumns(), | ||
createExtraFileColumns(), | ||
createColumnWidths()); | ||
createColumnWidths(), | ||
getMainTableColumnSortOrder()); | ||
|
||
} | ||
|
||
public MainTablePreferences getMainTablePreferences() { | ||
|
@@ -1955,4 +1961,13 @@ public void setIdBasedFetcherForEntryGenerator(String fetcherName) { | |
public String getIdBasedFetcherForEntryGenerator() { | ||
return get(ID_ENTRY_GENERATOR); | ||
} | ||
|
||
public void setMainTableColumnSortOrder(String column, String sortType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accept |
||
putStringList(SORT_COLUMN, Arrays.asList(column, sortType)); | ||
} | ||
|
||
public List<String> getMainTableColumnSortOrder() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used? |
||
return getStringList(SORT_COLUMN); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parsing should happen in the
JabRefPreferences
class so that the constructor here admits a map: column > sort order