Skip to content

Commit

Permalink
Do not resize main table columns in search dialog window
Browse files Browse the repository at this point in the history
Follow up from #8134
Fixes part of #8054
  • Loading branch information
Siedlerchr committed Nov 15, 2021
1 parent 9955a33 commit a396d6c
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jabref.gui.maintable;

import java.util.List;

public interface AbstractColumnPreferences {

public static final double DEFAULT_COLUMN_WIDTH = 100;
public static final double ICON_COLUMN_WIDTH = 16 + 12; // add some additional space to improve appearance

public List<MainTableColumnModel> getColumns();

public List<MainTableColumnModel> getColumnSortOrder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

public class ColumnPreferences {
public class ColumnPreferences implements AbstractColumnPreferences {

public static final double DEFAULT_COLUMN_WIDTH = 100;
public static final double ICON_COLUMN_WIDTH = 16 + 12; // add some additional space to improve appearance
Expand All @@ -15,10 +15,12 @@ public ColumnPreferences(List<MainTableColumnModel> columns, List<MainTableColum
this.columnSortOrder = columnSortOrder;
}

@Override
public List<MainTableColumnModel> getColumns() {
return columns;
}

@Override
public List<MainTableColumnModel> getColumnSortOrder() {
return columnSortOrder;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public MainTable(MainTableDataModel model,
new MainTableColumnFactory(
database,
preferencesService,
preferencesService.getColumnPreferences(),
externalFileTypes,
libraryTab.getUndoManager(),
dialogService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class MainTableColumnFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(MainTableColumnFactory.class);

private final PreferencesService preferencesService;
private final ColumnPreferences columnPreferences;
private final AbstractColumnPreferences columnPreferences;
private final ExternalFileTypes externalFileTypes;
private final BibDatabaseContext database;
private final CellFactory cellFactory;
Expand All @@ -62,13 +62,14 @@ public class MainTableColumnFactory {

public MainTableColumnFactory(BibDatabaseContext database,
PreferencesService preferencesService,
AbstractColumnPreferences abstractColumnPrefs,
ExternalFileTypes externalFileTypes,
UndoManager undoManager,
DialogService dialogService,
StateManager stateManager) {
this.database = Objects.requireNonNull(database);
this.preferencesService = Objects.requireNonNull(preferencesService);
this.columnPreferences = preferencesService.getColumnPreferences();
this.columnPreferences = abstractColumnPrefs;
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.dialogService = dialogService;
this.cellFactory = new CellFactory(externalFileTypes, preferencesService, undoManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jabref.gui.maintable;

import java.util.List;

public class SearchDialogColumnPreferences implements AbstractColumnPreferences{

private final List<MainTableColumnModel> columns;
private final List<MainTableColumnModel> columnSortOrder;

public SearchDialogColumnPreferences(List<MainTableColumnModel> columns, List<MainTableColumnModel> columnSortOrder) {
this.columns = columns;
this.columnSortOrder = columnSortOrder;
}

@Override
public List<MainTableColumnModel> getColumns() {
return columns;
}

@Override
public List<MainTableColumnModel> getColumnSortOrder() {
return columnSortOrder;
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/search/SearchResultsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ public SearchResultsTable(SearchResultsTableDataModel model,
this.getColumns().addAll(new MainTableColumnFactory(
database,
preferencesService,
preferencesService.getSearchDialogColumnPreferences(),
externalFileTypes,
undoManager,
dialogService,
stateManager).createColumns());

this.getSortOrder().clear();
mainTablePreferences.getColumnPreferences().getColumnSortOrder().forEach(columnModel ->
preferencesService.getSearchDialogColumnPreferences().getColumnSortOrder().forEach(columnModel ->
this.getColumns().stream()
.map(column -> (MainTableColumn<?>) column)
.filter(column -> column.getModel().equals(columnModel))
Expand Down
132 changes: 123 additions & 9 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.jabref.gui.maintable.MainTableNameFormatPreferences.AbbreviationStyle;
import org.jabref.gui.maintable.MainTableNameFormatPreferences.DisplayStyle;
import org.jabref.gui.maintable.MainTablePreferences;
import org.jabref.gui.maintable.SearchDialogColumnPreferences;
import org.jabref.gui.mergeentries.MergeEntries;
import org.jabref.gui.search.SearchDisplayMode;
import org.jabref.gui.sidepane.SidePaneType;
Expand Down Expand Up @@ -157,7 +158,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String REFORMAT_FILE_ON_SAVE_AND_EXPORT = "reformatFileOnSaveAndExport";
public static final String EXPORT_IN_ORIGINAL_ORDER = "exportInOriginalOrder";
public static final String EXPORT_IN_SPECIFIED_ORDER = "exportInSpecifiedOrder";

public static final String EXPORT_PRIMARY_SORT_FIELD = "exportPriSort";
public static final String EXPORT_PRIMARY_SORT_DESCENDING = "exportPriDescending";
public static final String EXPORT_SECONDARY_SORT_FIELD = "exportSecSort";
Expand All @@ -173,6 +174,11 @@ public class JabRefPreferences implements PreferencesService {
public static final String COLUMN_SORT_TYPES = "mainTableColumnSortTypes";
public static final String COLUMN_SORT_ORDER = "mainTableColumnSortOrder";

public static final String SEARCH_DIALOG_COLUMN_NAMES = "mainTableColumnNames";
public static final String SEARCH_DIALOG_COLUMN_WIDTHS = "mainTableColumnWidths";
public static final String SEARCH_DIALOG_COLUMN_SORT_TYPES = "searchDialogColumnSortTypes";
public static final String SEARCH_DIALOG_COLUMN_SORT_ORDER = "searchDalogColumnSortOrder";

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";
Expand Down Expand Up @@ -421,6 +427,10 @@ public class JabRefPreferences implements PreferencesService {
private Map<String, Set<Field>> entryEditorTabList;
private List<MainTableColumnModel> mainTableColumns;
private List<MainTableColumnModel> mainTableColumnSortOrder;

private List<MainTableColumnModel> searchDialogTableColunns;
private List<MainTableColumnModel> searchDialogColumnSortOrder;

private Theme globalTheme;
private Set<CustomImporter> customImporters;
private String userName;
Expand Down Expand Up @@ -1826,21 +1836,13 @@ public void storeExternalApplicationsPreferences(ExternalApplicationsPreferences
// MainTablePreferences
//*************************************************************************************************************

/**
* Creates the GlobalCitationKeyPattern from cache
*
* @return GlobalCitationKeyPattern containing all keys without a parent AbstractKeyPattern
*/
private List<MainTableColumnModel> createMainTableColumns() {
if (this.mainTableColumns == null) {
updateMainTableColumns();
}
return this.mainTableColumns;
}

/**
* Reloads the GlobalCitationKeyPattern from scratch
*/
@Override
public void updateMainTableColumns() {
List<String> columnNames = getStringList(COLUMN_NAMES);
Expand Down Expand Up @@ -1988,6 +1990,118 @@ public void storeMainTableNameFormatPreferences(MainTableNameFormatPreferences p
putBoolean(NAMES_LAST_ONLY, preferences.getAbbreviationStyle() == AbbreviationStyle.LASTNAME_ONLY);
}

//*************************************************************************************************************
// SearchDialogColumnsPreferences
//***********************************************s**************************************************************

public void updateSearchDialogTableColumns() {
List<String> columnNames = getStringList(SEARCH_DIALOG_COLUMN_NAMES);

List<Double> columnWidths = getStringList(SEARCH_DIALOG_COLUMN_WIDTHS)
.stream()
.map(string -> {
try {
return Double.parseDouble(string);
} catch (NumberFormatException e) {
LOGGER.error("Exception while parsing column widths. Choosing default.", e);
return SearchDialogColumnPreferences.DEFAULT_COLUMN_WIDTH;
}
})
.collect(Collectors.toList());

List<SortType> columnSortTypes = getStringList(SEARCH_DIALOG_COLUMN_SORT_TYPES)
.stream()
.map(SortType::valueOf)
.collect(Collectors.toList());

List<MainTableColumnModel> columns = new ArrayList<>();
for (int i = 0; i < columnNames.size(); i++) {
MainTableColumnModel columnModel = MainTableColumnModel.parse(columnNames.get(i));

if (i < columnWidths.size()) {
columnModel.widthProperty().setValue(columnWidths.get(i));
}

if (i < columnSortTypes.size()) {
columnModel.sortTypeProperty().setValue(columnSortTypes.get(i));
}

columns.add(columnModel);
}

searchDialogTableColunns = columns;
}


private List<MainTableColumnModel> createSearchDialogColumns() {
if (this.searchDialogTableColunns == null) {
updateSearchDialogTableColumns();
}
return this.searchDialogTableColunns;
}

/**
* Creates the ColumnSortOrder from cache
*
* @return List containing only the the columns in its proper sort order
*/
private List<MainTableColumnModel> createSearchDialogColumnSortOrder() {
if (this.searchDialogColumnSortOrder == null) {
updateSearchDialogColumnSortOrder();
}
return this.searchDialogColumnSortOrder;
}


/**
* Reloads the MainTableColumnSortOrder from scratch to cache
*/
private void updateSearchDialogColumnSortOrder() {
List<MainTableColumnModel> columnsOrdered = new ArrayList<>();
getStringList(SEARCH_DIALOG_COLUMN_SORT_ORDER).forEach(columnName ->
searchDialogTableColunns.stream().filter(column ->
column.getName().equals(columnName))
.findFirst()
.ifPresent(columnsOrdered::add));

searchDialogColumnSortOrder = columnsOrdered;
}

@Override
public SearchDialogColumnPreferences getSearchDialogColumnPreferences() {
return new SearchDialogColumnPreferences(
createSearchDialogColumns(),
createSearchDialogColumnSortOrder());
}

// TODO is that needed?
/**
* Stores the {@link SearchDialogColumnPreferences} in the preferences
*
* @param columnPreferences the preferences to store
*/
public void storeSearchDialogColumnPreferences(SearchDialogColumnPreferences columnPreferences) {
putStringList(SEARCH_DIALOG_COLUMN_NAMES, columnPreferences.getColumns().stream()
.map(MainTableColumnModel::getName)
.collect(Collectors.toList()));

List<String> columnWidthsInOrder = new ArrayList<>();
columnPreferences.getColumns().forEach(column -> columnWidthsInOrder.add(column.widthProperty().getValue().toString()));
putStringList(SEARCH_DIALOG_COLUMN_WIDTHS, columnWidthsInOrder);

List<String> columnSortTypesInOrder = new ArrayList<>();
columnPreferences.getColumns().forEach(column -> columnSortTypesInOrder.add(column.sortTypeProperty().getValue().toString()));
putStringList(SEARCH_DIALOG_COLUMN_SORT_TYPES, columnSortTypesInOrder);

putStringList(SEARCH_DIALOG_COLUMN_SORT_ORDER, columnPreferences
.getColumnSortOrder().stream()
.map(MainTableColumnModel::getName)
.collect(Collectors.toList()));

// Update cache
searchDialogTableColunns = columnPreferences.getColumns();
}

//*************************************************************************************************************
// AppearancePreferences
//*************************************************************************************************************
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.jabref.gui.maintable.ColumnPreferences;
import org.jabref.gui.maintable.MainTableNameFormatPreferences;
import org.jabref.gui.maintable.MainTablePreferences;
import org.jabref.gui.maintable.SearchDialogColumnPreferences;
import org.jabref.gui.specialfields.SpecialFieldsPreferences;
import org.jabref.gui.util.Theme;
import org.jabref.logic.JabRefException;
Expand Down Expand Up @@ -220,6 +221,12 @@ public interface PreferencesService {

void storeMainTableNameFormatPreferences(MainTableNameFormatPreferences preferences);

//*************************************************************************************************************
// SearchDialogColumnPreferences
//*************************************************************************************************************

SearchDialogColumnPreferences getSearchDialogColumnPreferences();

//*************************************************************************************************************
// AppearancePreferences
//*************************************************************************************************************
Expand Down Expand Up @@ -340,4 +347,5 @@ public interface PreferencesService {
void storeIdBasedFetcherForEntryGenerator(String fetcherName);

ProtectedTermsPreferences getProtectedTermsPreferences();

}

0 comments on commit a396d6c

Please sign in to comment.