Skip to content
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

Merged
merged 13 commits into from
Sep 13, 2018
Next Next commit
Save sort order column of main table
  • Loading branch information
Siedlerchr committed Sep 9, 2018
commit ed6aeb0bd6d2274d7d1e5798e722b84bd92caf32
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
@@ -1022,7 +1022,7 @@ public void addParserResult(ParserResult pr, boolean focusPanel) {
*/
@Deprecated
public void output(final String s) {
statusLine.show(s, 3000);
DefaultTaskExecutor.runInJavaFXThread(() -> statusLine.show(s, 3000));
}

private void initActions() {
16 changes: 15 additions & 1 deletion src/main/java/org/jabref/gui/maintable/ColumnPreferences.java
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import javafx.scene.control.TableColumn.SortType;

import org.jabref.model.entry.BibtexSingleField;
import org.jabref.model.entry.specialfields.SpecialField;
@@ -16,8 +18,9 @@ public class ColumnPreferences {
private final List<SpecialField> specialFieldColumns;
private final List<String> extraFileColumns;
private final Map<String, Double> columnWidths;
private final List<String> columnSortOrder;

public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEprintColumn, List<String> normalColumns, List<SpecialField> specialFieldColumns, List<String> extraFileColumns, Map<String, Double> columnWidths) {
public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEprintColumn, List<String> normalColumns, List<SpecialField> specialFieldColumns, List<String> extraFileColumns, Map<String, Double> columnWidths, List<String> columnSortOrder) {
this.showFileColumn = showFileColumn;
this.showUrlColumn = showUrlColumn;
this.preferDoiOverUrl = preferDoiOverUrl;
@@ -26,6 +29,7 @@ public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean
this.specialFieldColumns = specialFieldColumns;
this.extraFileColumns = extraFileColumns;
this.columnWidths = columnWidths;
this.columnSortOrder = columnSortOrder;
}

public boolean showFileColumn() {
@@ -59,4 +63,14 @@ public List<String> getNormalColumns() {
public double getPrefColumnWidth(String columnName) {
return columnWidths.getOrDefault(columnName, BibtexSingleField.DEFAULT_FIELD_LENGTH);
}

public Optional<SortType> getSortTypeForColumn(String columnName) {

if (columnName.equals(columnSortOrder.get(0))) {
Copy link
Member

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

return Optional.of(SortType.valueOf(columnSortOrder.get(1)));
}
return Optional.empty();

}

}
Original file line number Diff line number Diff line change
@@ -109,6 +109,7 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre
columns.add(createSpecialFieldColumn((field)));
}


return columns;
}

@@ -120,6 +121,7 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre
new ValueTableCellFactory<BibEntryTableViewModel, List<AbstractGroup>>()
.withGraphic(this::createGroupColorRegion)
.install(column);
column.setSortable(true);
return column;
}

@@ -156,8 +158,11 @@ private Node createGroupColorRegion(BibEntryTableViewModel entry, List<AbstractG
new ValueTableCellFactory<BibEntryTableViewModel, String>()
.withText(text -> text)
.install(column);
column.setSortable(true);
column.setPrefWidth(preferences.getPrefColumnWidth(columnName));
preferences.getSortTypeForColumn(columnName).ifPresent(column::setSortType);
columns.add(column);

}
return columns;
}
@@ -199,6 +204,7 @@ private TableColumn<BibEntryTableViewModel, Optional<SpecialFieldValueViewModel>
column.setComparator(new RankingFieldComparator());
}

column.setSortable(true);
return column;
}

@@ -375,6 +381,7 @@ private TableColumn<BibEntryTableViewModel, List<LinkedFile>> createExtraFileCol
.withGraphic(linkedFiles -> createFileIcon(linkedFiles.stream().filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(externalFileTypeName)).collect(Collectors.toList())))
.install(column);


return column;
}

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<>();
Copy link
Member

Choose a reason for hiding this comment

The 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());

}
}

28 changes: 27 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accept SortOrder and not a string as second argument.

putStringList(SORT_COLUMN, Arrays.asList(column, sortType));
}

public List<String> getMainTableColumnSortOrder() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used?

return getStringList(SORT_COLUMN);
}

}