-
-
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
Persistent column sortorder #5730
Merged
Siedlerchr
merged 10 commits into
JabRef:master
from
calixtus:persistent_column_sortorder
Dec 16, 2019
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bcfde60
Reworked persistent column sort order
calixtus 4e71482
Merge remote-tracking branch 'upstream/master' into persistent_column…
calixtus be0a58d
Fixes storing of the correct value
calixtus 1860102
Refactored for simplicity, fixed hardwired icon-column width, added J…
calixtus 6a2fb63
Merge remote-tracking branch 'upstream/master' into persistent_column…
calixtus b36c1b5
Fixed some comments and added entry in CHANGELOG.md
calixtus d7918e1
Spelling
calixtus 019e81f
Changed datatype in migragtions, added comment
calixtus 9ad0e44
Merge branch 'persistent_column_sortorder' of https://github.com/cali…
calixtus b96c2e1
Refactored ICON_COLUMNS from ArrayList to EnumSet
calixtus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 6 additions & 13 deletions
19
src/main/java/org/jabref/gui/maintable/ColumnPreferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,25 @@ | ||
package org.jabref.gui.maintable; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javafx.scene.control.TableColumn.SortType; | ||
|
||
public class ColumnPreferences { | ||
|
||
public static final double DEFAULT_WIDTH = 100; | ||
public static final double DEFAULT_COLUMN_WIDTH = 100; | ||
public static final double ICON_COLUMN_WIDTH = 16 + 12; // add some additional space to improve appearance | ||
|
||
private final List<MainTableColumnModel> columns; | ||
private final boolean extraFileColumnsEnabled; | ||
private final Map<String, SortType> columnSortType; | ||
private final List<MainTableColumnModel> columnSortOrder; | ||
|
||
public ColumnPreferences(List<MainTableColumnModel> columns, boolean extraFileColumnsEnabled, Map<String, SortType> columnSortType) { | ||
public ColumnPreferences(List<MainTableColumnModel> columns, List<MainTableColumnModel> columnSortOrder) { | ||
this.columns = columns; | ||
this.extraFileColumnsEnabled = extraFileColumnsEnabled; | ||
this.columnSortType = columnSortType; | ||
this.columnSortOrder = columnSortOrder; | ||
} | ||
|
||
public boolean getExtraFileColumnsEnabled() { return extraFileColumnsEnabled; } | ||
|
||
public List<MainTableColumnModel> getColumns() { | ||
return columns; | ||
} | ||
|
||
public Map<String, SortType> getSortTypesForColumns() { | ||
return columnSortType; | ||
public List<MainTableColumnModel> getColumnSortOrder() { | ||
return columnSortOrder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 18 additions & 36 deletions
54
src/main/java/org/jabref/gui/maintable/PersistenceVisualStateTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,45 @@ | ||
package org.jabref.gui.maintable; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import javafx.collections.ListChangeListener; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableColumn.SortType; | ||
import javafx.beans.InvalidationListener; | ||
|
||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
/** | ||
* Keep track of changes made to the columns, like reordering or resizing. | ||
* | ||
* Keep track of changes made to the columns (reordering, resorting, resizing). | ||
*/ | ||
public class PersistenceVisualStateTable { | ||
|
||
private final MainTable mainTable; | ||
private final JabRefPreferences preferences; | ||
private final Map<String, SortType> columnsSortOrder = new LinkedHashMap<>(); | ||
|
||
public PersistenceVisualStateTable(final MainTable mainTable, JabRefPreferences preferences) { | ||
this.mainTable = mainTable; | ||
this.preferences = preferences; | ||
|
||
mainTable.getColumns().addListener(this::onColumnsChanged); | ||
mainTable.getColumns().forEach(col -> { | ||
MainTableColumn column = (MainTableColumn) col; | ||
col.sortTypeProperty().addListener(obs -> updateColumnSortType(column.getModel().getName(), column.getSortType())); | ||
}); | ||
mainTable.getColumns().forEach(col -> col.widthProperty().addListener(obs -> updateColumnPreferences())); | ||
mainTable.getColumns().addListener((InvalidationListener) obs -> updateColumnPreferences()); | ||
mainTable.getSortOrder().addListener((InvalidationListener) obs -> updateColumnPreferences()); | ||
|
||
} | ||
|
||
private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<BibEntryTableViewModel, ?>> change) { | ||
boolean changed = false; | ||
while (change.next()) { | ||
changed = true; | ||
} | ||
|
||
if (changed) { | ||
updateColumnPreferences(); | ||
} | ||
|
||
} | ||
|
||
private void updateColumnSortType(String text, SortType sortType) { | ||
columnsSortOrder.put(text, sortType); | ||
preferences.setMainTableColumnSortType(columnsSortOrder); | ||
// As we store the ColumnModels of the MainTable, we need to add the listener to the ColumnModel properties, | ||
// since the value is bound to the model after the listener to the column itself is called. | ||
mainTable.getColumns().forEach(col -> | ||
((MainTableColumn<?>) col).getModel().widthProperty().addListener(obs -> updateColumnPreferences())); | ||
mainTable.getColumns().forEach(col -> | ||
((MainTableColumn<?>) col).getModel().sortTypeProperty().addListener(obs -> updateColumnPreferences())); | ||
} | ||
|
||
/** | ||
* Store shown columns and their width in preferences. | ||
* Store shown columns, their width and their sortType in preferences. | ||
*/ | ||
private void updateColumnPreferences() { | ||
ColumnPreferences oldColumnPreferences = preferences.getColumnPreferences(); | ||
preferences.storeColumnPreferences(new ColumnPreferences( | ||
mainTable.getColumns().stream().map(column -> ((MainTableColumn) column).getModel()).collect(Collectors.toList()), | ||
oldColumnPreferences.getExtraFileColumnsEnabled(), | ||
columnsSortOrder)); | ||
mainTable.getColumns().stream() | ||
.map(column -> ((MainTableColumn<?>) column).getModel()) | ||
.collect(Collectors.toList()), | ||
mainTable.getSortOrder().stream() | ||
.map(column -> ((MainTableColumn<?>) column).getModel()) | ||
.collect(Collectors.toList()) | ||
)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why not an EnumSet? EnumSet.allOf() https://www.baeldung.com/java-enumset
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.
I'm just using this as a constant (i know, I forgot 'final' here) to spare the subsequent checks on each single column type, if it is an icon column. I implemented this in the first time as an additional argument of the single Types constructor (boolean isIconColumn), but it would have brought way more complexity. So this way someone later, who wants to add another column type can simply add it in this array (if needed). It does not really make a difference if this is an Array or an EnumSet.