-
-
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 1 commit
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import java.util.List; | ||
|
||
import javafx.collections.ListChangeListener; | ||
import javafx.collections.ObservableList; | ||
import javafx.scene.control.TableColumn; | ||
|
||
import org.jabref.preferences.JabRefPreferences; | ||
|
@@ -22,6 +23,30 @@ public PersistenceVisualStateTable(final MainTable mainTable, JabRefPreferences | |
this.preferences = preferences; | ||
|
||
mainTable.getColumns().addListener(this::onColumnsChanged); | ||
mainTable.getSortOrder().addListener(this::onColumnSortOrderChanged); | ||
|
||
} | ||
|
||
private void onColumnSortOrderChanged(ListChangeListener.Change<? extends TableColumn<BibEntryTableViewModel, ?>> change) { | ||
boolean changed = false; | ||
while (change.next()) { | ||
changed = true; | ||
} | ||
|
||
if (changed) { | ||
updateSortOrderPreferences(change.getList()); | ||
} | ||
} | ||
|
||
private void updateSortOrderPreferences(ObservableList<? extends TableColumn<BibEntryTableViewModel, ?>> observableList) { | ||
if(observableList.isEmpty()) | ||
return; | ||
TableColumn<BibEntryTableViewModel, ?> column = observableList.get(0); | ||
if (column instanceof NormalTableColumn) { | ||
NormalTableColumn normalColumn = (NormalTableColumn) column; | ||
preferences.setMainTableColumnSortOrder(normalColumn.getColumnName(), normalColumn.getSortType().name()); | ||
} | ||
|
||
} | ||
|
||
private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<BibEntryTableViewModel, ?>> change) { | ||
|
@@ -33,6 +58,7 @@ private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<Bi | |
if (changed) { | ||
updateColumnPreferences(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
@@ -41,13 +67,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); | ||
|
@@ -1870,6 +1874,17 @@ private Map<String, Double> createColumnWidths() { | |
return map; | ||
} | ||
|
||
private Map<String, String> createColumnSortOrder() { | ||
List<String> columns = getStringList(COLUMN_NAMES); | ||
List<String> sortOrders = getStringList(SORT_COLUMN); | ||
|
||
Map<String, String> map = new TreeMap<>(); | ||
for (int i = 0; i < columns.size(); i++) { | ||
map.put(columns.get(i), sortOrders.get(i)); | ||
} | ||
return map; | ||
} | ||
|
||
public ColumnPreferences getColumnPreferences() { | ||
return new ColumnPreferences( | ||
getBoolean(FILE_COLUMN), | ||
|
@@ -1879,7 +1894,9 @@ public ColumnPreferences getColumnPreferences() { | |
getStringList(COLUMN_NAMES), | ||
createSpecialFieldColumns(), | ||
createExtraFileColumns(), | ||
createColumnWidths()); | ||
createColumnWidths(), | ||
getMainTableColumnSortOrder()); | ||
|
||
} | ||
|
||
public MainTablePreferences getMainTablePreferences() { | ||
|
@@ -1955,4 +1972,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