Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/maintable-beta' into fixdragan…
Browse files Browse the repository at this point in the history
…drop

* upstream/maintable-beta:
  Save order of columns across sessions (#3783)
  Allow side pane to be completely hidden (#3784)
  Show empty group pane if no database is open (#3785)
  Reenable drag'n'drop support for tabs / libraries (#3688)
  • Loading branch information
Siedlerchr committed Feb 28, 2018
2 parents b25151e + d8914a8 commit 262e0c9
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 313 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ dependencies {
compile 'org.fxmisc.easybind:easybind:1.0.3'
compile 'org.fxmisc.flowless:flowless:0.6'
compile 'org.fxmisc.richtext:richtextfx:0.8.2'
compile 'com.sibvisions.external.jvxfx:dndtabpane:0.1'


// Cannot be updated to 9.*.* until Jabref works with Java 9
compile 'org.controlsfx:controlsfx:8.40.15-SNAPSHOT'
Expand Down
5 changes: 5 additions & 0 deletions external-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ Project: Application Insights SDK for Java
URL: https://github.com/Microsoft/ApplicationInsights-Java
License: MIT

Id: com.sibvisions.external.jvxfx:DnDTabPane
Project: Drag'n'Drop TabPane
URL: https://github.com/sibvisions/javafx.DndTabPane
License: EPL-1.0

Id: commons-cli:commons-cli
Project: Apache Commons CLI
URL: http://commons.apache.org/cli/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/BasePanelPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public BasePanelPreferences(MainTablePreferences tablePreferences, AutoCompleteP

public static BasePanelPreferences from(JabRefPreferences preferences) {
BasePanelPreferences basePanelPreferences = new BasePanelPreferences(
MainTablePreferences.from(preferences),
preferences.getMainTablePreferences(),
preferences.getAutoCompletePreferences(),
EntryEditorPreferences.from(preferences),
Globals.getKeyPrefs(),
Expand Down
36 changes: 29 additions & 7 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
import org.jabref.preferences.SearchPreferences;

import com.google.common.eventbus.Subscribe;
import org.eclipse.fx.ui.controls.tabpane.DndTabPane;
import org.eclipse.fx.ui.controls.tabpane.DndTabPaneFactory;
import org.fxmisc.easybind.EasyBind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -205,7 +207,7 @@ public class JabRefFrame extends BorderPane implements OutputPrinter {
private final Stage mainStage;
// The sidepane manager takes care of populating the sidepane.
private SidePaneManager sidePaneManager;
private final TabPane tabbedPane = new TabPane();
private TabPane tabbedPane;
private PushToApplications pushApplications;
private final CountingUndoManager undoManager = new CountingUndoManager();
private final DialogService dialogService;
Expand Down Expand Up @@ -258,6 +260,9 @@ private void init() {
sidePaneManager = new SidePaneManager(Globals.prefs, this);
sidePane = sidePaneManager.getPane();

Pane containerPane = DndTabPaneFactory.createDefaultDnDPane(DndTabPaneFactory.FeedbackType.MARKER, null);
tabbedPane = (DndTabPane) containerPane.getChildren().get(0);

initLayout();

initActions();
Expand All @@ -269,15 +274,14 @@ private void init() {
// JabRefPreferences.SIZE_Y);
//pw.displayWindowAtStoredLocation();

tabbedPane.setBorder(null);

/*
* The following state listener makes sure focus is registered with the
* correct database when the user switches tabs. Without this,
* cut/paste/copy operations would some times occur in the wrong tab.
*/
EasyBind.subscribe(tabbedPane.getSelectionModel().selectedItemProperty(), e -> {
if (e == null) {
Globals.stateManager.activeDatabaseProperty().setValue(Optional.empty());
return;
}

Expand Down Expand Up @@ -589,9 +593,19 @@ private void initLayout() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean showing) {
if (showing) {
splitPane.setDividerPositions(prefs.getDouble(JabRefPreferences.SIDE_PANE_WIDTH));
EasyBind.subscribe(splitPane.getDividers().get(0).positionProperty(),
position -> prefs.putDouble(JabRefPreferences.SIDE_PANE_WIDTH, position.doubleValue()));
setDividerPosition();

EasyBind.subscribe(sidePane.visibleProperty(), visible -> {
if (visible) {
if (!splitPane.getItems().contains(sidePane)) {
splitPane.getItems().add(0, sidePane);
setDividerPosition();
}
} else {
splitPane.getItems().remove(sidePane);
}
});

mainStage.showingProperty().removeListener(this);
observable.removeListener(this);
}
Expand Down Expand Up @@ -627,6 +641,14 @@ public void changed(ObservableValue<? extends Boolean> observable, Boolean oldVa
statusLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR.darker());
}

private void setDividerPosition() {
splitPane.setDividerPositions(prefs.getDouble(JabRefPreferences.SIDE_PANE_WIDTH));
if (!splitPane.getDividers().isEmpty()) {
EasyBind.subscribe(splitPane.getDividers().get(0).positionProperty(),
position -> prefs.putDouble(JabRefPreferences.SIDE_PANE_WIDTH, position.doubleValue()));
}
}

private Node createToolbar() {
Pane leftSpacer = new Pane();
HBox.setHgrow(leftSpacer, Priority.SOMETIMES);
Expand All @@ -648,7 +670,7 @@ private Node createToolbar() {
factory.createIconButton(StandardActions.SAVE_LIBRARY, new OldDatabaseCommandWrapper(Actions.SAVE, this, Globals.stateManager)),

leftSpacer);
leftSide.minWidthProperty().bind(sidePane.widthProperty());
leftSide.setMinWidth(100);
leftSide.prefWidthProperty().bind(sidePane.widthProperty());
leftSide.maxWidthProperty().bind(sidePane.widthProperty());

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.metadata.MetaData;

import org.fxmisc.easybind.EasyBind;

public class GroupTreeViewModel extends AbstractViewModel {

private final ObjectProperty<GroupNodeViewModel> rootGroup = new SimpleObjectProperty<>();
Expand All @@ -53,9 +55,8 @@ public GroupTreeViewModel(StateManager stateManager, DialogService dialogService
this.taskExecutor = Objects.requireNonNull(taskExecutor);

// Register listener
stateManager.activeDatabaseProperty()
.addListener((observable, oldValue, newValue) -> onActiveDatabaseChanged(newValue));
selectedGroups.addListener((observable, oldValue, newValue) -> onSelectedGroupChanged(newValue));
EasyBind.subscribe(stateManager.activeDatabaseProperty(), this::onActiveDatabaseChanged);
EasyBind.subscribe(selectedGroups, this::onSelectedGroupChanged);

// Set-up bindings
filterPredicate
Expand Down Expand Up @@ -122,8 +123,10 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
rootGroup.setValue(newRoot);
this.selectedGroups.setAll(
stateManager.getSelectedGroup(newDatabase.get()).stream()
.map(selectedGroup -> new GroupNodeViewModel(newDatabase.get(), stateManager, taskExecutor, selectedGroup))
.collect(Collectors.toList()));
.map(selectedGroup -> new GroupNodeViewModel(newDatabase.get(), stateManager, taskExecutor, selectedGroup))
.collect(Collectors.toList()));
} else {
rootGroup.setValue(GroupNodeViewModel.getAllEntriesGroup(new BibDatabaseContext(), stateManager, taskExecutor));
}

currentDatabase = newDatabase;
Expand Down
83 changes: 0 additions & 83 deletions src/main/java/org/jabref/gui/maintable/ColumnPreferences.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
package org.jabref.gui.maintable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.jabref.model.entry.BibtexSingleField;
import org.jabref.model.entry.specialfields.SpecialField;
import org.jabref.preferences.JabRefPreferences;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ColumnPreferences {

private static final Logger LOGGER = LoggerFactory.getLogger(ColumnPreferences.class);

private final boolean showFileColumn;
private final boolean showUrlColumn;
private final boolean preferDoiOverUrl;
Expand All @@ -38,79 +28,6 @@ public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean
this.columnWidths = columnWidths;
}

public static ColumnPreferences from(JabRefPreferences preferences) {
return new ColumnPreferences(
preferences.getBoolean(JabRefPreferences.FILE_COLUMN),
preferences.getBoolean(JabRefPreferences.URL_COLUMN),
preferences.getBoolean(JabRefPreferences.PREFER_URL_DOI),
preferences.getBoolean(JabRefPreferences.ARXIV_COLUMN),
preferences.getStringList(JabRefPreferences.COLUMN_NAMES),
createSpecialFieldColumns(preferences),
createExtraFileColumns(preferences),
createColumnWidths(preferences)
);
}

private static Map<String, Double> createColumnWidths(JabRefPreferences preferences) {
List<String> columns = preferences.getStringList(JabRefPreferences.COLUMN_NAMES);
List<Double> widths = preferences
.getStringList(JabRefPreferences.COLUMN_WIDTHS)
.stream()
.map(string -> {
try {
return Double.parseDouble(string);
} catch (NumberFormatException e) {
LOGGER.error("Exception while parsing column widths. Choosing default.", e);
return BibtexSingleField.DEFAULT_FIELD_LENGTH;
}
})
.collect(Collectors.toList());

Map<String, Double> map = new TreeMap<>();
for (int i = 0; i < columns.size(); i++) {
map.put(columns.get(i), widths.get(i));
}
return map;
}

private static List<String> createExtraFileColumns(JabRefPreferences preferences) {
if (preferences.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) {
return preferences.getStringList(JabRefPreferences.LIST_OF_FILE_COLUMNS);
} else {
return Collections.emptyList();
}
}

private static List<SpecialField> createSpecialFieldColumns(JabRefPreferences preferences) {
if (preferences.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) {
List<SpecialField> fieldsToShow = new ArrayList<>();
if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) {
fieldsToShow.add(SpecialField.RANKING);
}
if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) {
fieldsToShow.add(SpecialField.RELEVANCE);
}
if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) {
fieldsToShow.add(SpecialField.QUALITY);
}

if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) {
fieldsToShow.add(SpecialField.PRIORITY);
}

if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) {
fieldsToShow.add(SpecialField.PRINTED);
}

if (preferences.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) {
fieldsToShow.add(SpecialField.READ_STATUS);
}
return fieldsToShow;
} else {
return Collections.emptyList();
}
}

public boolean showFileColumn() {
return showFileColumn;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class MainTable extends TableView<BibEntryTableViewModel> {
private final BibDatabaseContext database;
private final UndoManager undoManager;
// needed to activate/deactivate the listener
private PersistenceTableColumnListener tableColumnListener;
private PersistenceVisualStateTable tableColumnListener;

private final MainTableDataModel model;
private final NewDroppedFileHandler fileHandler;
Expand Down Expand Up @@ -151,9 +151,8 @@ public String getToolTipText(MouseEvent event) {
}
*/

// TODO: store column widths
//this.tableColumnListener = new PersistenceTableColumnListener(this);
//setWidths();
// Store visual state
new PersistenceVisualStateTable(this, Globals.prefs);

// TODO: enable DnD
//setDragEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre
// Stored column name will be used as header
// There might be more than one field to display, e.g., "author/editor" or "date/year" - so split
String[] fields = columnName.split(FieldName.FIELD_SEPARATOR);
StringTableColumn column = new StringTableColumn(columnName, Arrays.asList(fields), database.getDatabase());
NormalTableColumn column = new NormalTableColumn(columnName, Arrays.asList(fields), database.getDatabase());
new ValueTableCellFactory<BibEntryTableViewModel, String>()
.withText(text -> text)
.install(column);
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/jabref/gui/maintable/MainTablePreferences.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.jabref.gui.maintable;

import org.jabref.Globals;
import org.jabref.preferences.JabRefPreferences;

public class MainTablePreferences {
private final boolean showGrid;
private final ColumnPreferences columnPreferences;
Expand All @@ -14,13 +11,6 @@ public MainTablePreferences(boolean showGrid, ColumnPreferences columnPreference
this.resizeColumnsToFit = resizeColumnsToFit;
}

public static MainTablePreferences from(JabRefPreferences preferences) {
return new MainTablePreferences(
Globals.prefs.getBoolean(JabRefPreferences.TABLE_SHOW_GRID),
ColumnPreferences.from(preferences),
Globals.prefs.getBoolean(JabRefPreferences.AUTO_RESIZE_MODE));
}

public ColumnPreferences getColumnPreferences() {
return columnPreferences;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.jabref.model.entry.FieldProperty;
import org.jabref.model.entry.InternalBibtexFields;

public class StringTableColumn extends MainTableColumn<String> {
public class NormalTableColumn extends MainTableColumn<String> {

private final List<String> bibtexFields;

Expand All @@ -31,31 +31,17 @@ public class StringTableColumn extends MainTableColumn<String> {
private final Optional<BibDatabase> database;

private final LayoutFormatter toUnicode = new LatexToUnicodeFormatter();
private final String columnName;

public StringTableColumn(String columnName) {
super(columnName);
this.bibtexFields = Collections.emptyList();
this.isIconColumn = false;
this.iconLabel = Optional.empty();
this.database = Optional.empty();
}

public StringTableColumn(String columnName, List<String> bibtexFields, BibDatabase database) {
public NormalTableColumn(String columnName, List<String> bibtexFields, BibDatabase database) {
super(columnName);
this.columnName = columnName;
this.bibtexFields = Collections.unmodifiableList(bibtexFields);
this.isIconColumn = false;
this.iconLabel = Optional.empty();
this.database = Optional.of(database);
}

public StringTableColumn(String columnName, List<String> bibtexFields, JabRefIcon iconLabel) {
super(columnName);
this.bibtexFields = Collections.unmodifiableList(bibtexFields);
this.isIconColumn = true;
this.iconLabel = Optional.of(iconLabel);
this.database = Optional.empty();
}

/**
* Get the table column name to be displayed in the UI
*
Expand Down Expand Up @@ -161,4 +147,8 @@ public boolean isResolved(BibEntry entry) {
}
return (!resolvedFieldContent.equals(plainFieldContent));
}

public String getColumnName() {
return columnName;
}
}
Loading

0 comments on commit 262e0c9

Please sign in to comment.