Skip to content

Commit 1d2ecff

Browse files
authored
Fix sort order in main table not stored (#6898)
* Fix sort order in main table not stored Compare propertys correctly with equals * add issue to changelog
1 parent 46e9fe2 commit 1d2ecff

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
3434
- We fixed an issue where the `.sav` file was not deleted upon exiting JabRef. [#6109](https://github.com/JabRef/jabref/issues/6109)
3535
- We fixed a linked identifier icon inconsistency. [#6705](https://github.com/JabRef/jabref/issues/6705)
3636
- We fixed the wrong behavior that font size changes are not reflected in dialogs. [#6039](https://github.com/JabRef/jabref/issues/6039)
37+
- We fixed an issue where the sort order of the entry table was reset after a restart of JabRef [#6898](https://github.com/JabRef/jabref/pull/6898)
3738

3839
### Removed
3940

src/main/java/org/jabref/gui/maintable/MainTable.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,20 @@ public MainTable(MainTableDataModel model,
117117
.install(this);
118118

119119
this.getSortOrder().clear();
120-
mainTablePreferences.getColumnPreferences().getColumnSortOrder().forEach(columnModel ->
120+
121+
/* KEEP for debugging purposes
122+
for (var colModel : mainTablePreferences.getColumnPreferences().getColumnSortOrder()) {
123+
for (var col : this.getColumns()) {
124+
var tablecColModel = ((MainTableColumn<?>) col).getModel();
125+
if (tablecColModel.equals(colModel)) {
126+
LOGGER.debug("Adding sort order for col {} ", col);
127+
this.getSortOrder().add(col);
128+
break;
129+
}
130+
}
131+
}
132+
*/
133+
mainTablePreferences.getColumnPreferences().getColumnSortOrder().forEach(columnModel ->
121134
this.getColumns().stream()
122135
.map(column -> (MainTableColumn<?>) column)
123136
.filter(column -> column.getModel().equals(columnModel))

src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public String getName() {
138138

139139
public String getDisplayName() {
140140
if ((Type.ICON_COLUMNS.contains(typeProperty.getValue()) && qualifierProperty.getValue().isBlank())
141-
|| typeProperty.getValue() == Type.INDEX) {
141+
|| (typeProperty.getValue() == Type.INDEX)) {
142142
return typeProperty.getValue().getDisplayName();
143143
} else {
144144
return FieldsUtil.getNameWithType(FieldFactory.parseField(qualifierProperty.getValue()));
@@ -165,23 +165,25 @@ public ObjectProperty<TableColumn.SortType> sortTypeProperty() {
165165
return sortTypeProperty;
166166
}
167167

168+
@Override
168169
public boolean equals(Object o) {
169170
if (this == o) {
170171
return true;
171172
}
172173

173-
if (o == null || getClass() != o.getClass()) {
174+
if ((o == null) || (getClass() != o.getClass())) {
174175
return false;
175176
}
176177

177178
MainTableColumnModel that = (MainTableColumnModel) o;
178179

179-
if (typeProperty != that.typeProperty) {
180+
if (typeProperty.getValue() != that.typeProperty.getValue()) {
180181
return false;
181182
}
182-
return Objects.equals(qualifierProperty, that.qualifierProperty);
183+
return Objects.equals(qualifierProperty.getValue(), that.qualifierProperty.getValue());
183184
}
184185

186+
@Override
185187
public int hashCode() {
186188
return Objects.hash(typeProperty.getValue(), qualifierProperty.getValue());
187189
}
@@ -199,9 +201,9 @@ public static MainTableColumnModel parse(String rawColumnName) {
199201
Type type = Type.fromString(splittedName[0]);
200202
String qualifier = "";
201203

202-
if (type == Type.NORMALFIELD
203-
|| type == Type.SPECIALFIELD
204-
|| type == Type.EXTRAFILE) {
204+
if ((type == Type.NORMALFIELD)
205+
|| (type == Type.SPECIALFIELD)
206+
|| (type == Type.EXTRAFILE)) {
205207
if (splittedName.length == 1) {
206208
qualifier = splittedName[0]; // By default the rawColumnName is parsed as NORMALFIELD
207209
} else {

0 commit comments

Comments
 (0)