Skip to content

Commit 9799dc4

Browse files
caitlinlilleykoppor
authored andcommitted
Added logic and implementation for library selector
1 parent 55f89d8 commit 9799dc4

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/main/java/org/jabref/gui/auximport/FromAuxDialog.fxml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<?import javafx.scene.control.Button?>
44
<?import javafx.scene.control.ButtonType?>
5-
<?import javafx.scene.control.ComboBox?>
65
<?import javafx.scene.control.DialogPane?>
76
<?import javafx.scene.control.Label?>
87
<?import javafx.scene.control.ListView?>
@@ -13,6 +12,8 @@
1312
<?import javafx.scene.layout.VBox?>
1413
<?import javafx.scene.text.Font?>
1514
<?import org.jabref.gui.icon.JabRefIconView?>
15+
16+
<?import javafx.scene.control.ComboBox?>
1617
<DialogPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="650.0" prefWidth="500.0"
1718
xmlns="http://javafx.com/javafx/8.0.121" fx:controller="org.jabref.gui.auximport.FromAuxDialog">
1819
<content>
@@ -44,11 +45,6 @@
4445
<Label text="%Unknown BibTeX entries:"/>
4546
<ListView fx:id="notFoundList" prefHeight="200"/>
4647
<VBox spacing="10">
47-
<HBox spacing="4">
48-
<Button onAction="#selectAllNewEntries" text="%Select all new entries"/>
49-
<Button onAction="#selectAllEntries" text="%Select all entries"/>
50-
<Button onAction="#unselectAll" text="%Unselect all"/>
51-
</HBox>
5248
<HBox spacing="4" alignment="CENTER_LEFT">
5349
<Label text="%Select library"/>
5450
<ComboBox fx:id="libraryListView" layoutX="16.0" layoutY="52.0"/>

src/main/java/org/jabref/gui/auximport/FromAuxDialog.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.jabref.gui.auximport;
22

33
import java.nio.file.Path;
4+
import java.util.Optional;
5+
46

57
import javafx.fxml.FXML;
68
import javafx.scene.control.Button;
@@ -10,36 +12,36 @@
1012
import javafx.scene.control.TextArea;
1113
import javafx.scene.control.TextField;
1214

15+
1316
import org.jabref.gui.DialogService;
1417
import org.jabref.gui.JabRefFrame;
1518
import org.jabref.gui.LibraryTab;
16-
import org.jabref.gui.importer.ImportEntriesViewModel;
19+
import org.jabref.gui.StateManager;
1720
import org.jabref.gui.theme.ThemeManager;
1821
import org.jabref.gui.util.BaseDialog;
1922
import org.jabref.gui.util.FileDialogConfiguration;
23+
import org.jabref.gui.util.ViewModelListCellFactory;
2024
import org.jabref.logic.auxparser.AuxParser;
2125
import org.jabref.logic.auxparser.AuxParserResult;
2226
import org.jabref.logic.auxparser.DefaultAuxParser;
2327
import org.jabref.logic.l10n.Localization;
28+
import org.jabref.logic.shared.DatabaseLocation;
2429
import org.jabref.logic.util.StandardFileType;
30+
import org.jabref.logic.util.io.FileUtil;
2531
import org.jabref.model.database.BibDatabase;
2632
import org.jabref.model.database.BibDatabaseContext;
27-
import org.jabref.model.entry.BibEntry;
2833
import org.jabref.preferences.PreferencesService;
2934

3035
import com.airhacks.afterburner.views.ViewLoader;
3136
import jakarta.inject.Inject;
32-
import org.controlsfx.control.CheckListView;
37+
38+
3339

3440
/**
3541
* A wizard dialog for generating a new sub database from existing TeX AUX file
3642
*/
3743
public class FromAuxDialog extends BaseDialog<Void> {
3844

39-
public CheckListView<BibEntry> entriesListView;
40-
41-
private ImportEntriesViewModel viewModel;
42-
public ComboBox<String> libraryListView;
4345
private final LibraryTab libraryTab;
4446
@FXML private ButtonType generateButtonType;
4547
private final Button generateButton;
@@ -51,15 +53,19 @@ public class FromAuxDialog extends BaseDialog<Void> {
5153
@Inject private PreferencesService preferences;
5254
@Inject private DialogService dialogService;
5355
@Inject private ThemeManager themeManager;
56+
public ComboBox<BibDatabaseContext> libraryListView;
57+
@Inject private StateManager stateManager;
58+
59+
60+
61+
5462

5563
public FromAuxDialog(JabRefFrame frame) {
5664
libraryTab = frame.getCurrentLibraryTab();
5765
this.setTitle(Localization.lang("AUX file import"));
58-
5966
ViewLoader.view(this)
6067
.load()
6168
.setAsDialogPane(this);
62-
6369
generateButton = (Button) this.getDialogPane().lookupButton(generateButtonType);
6470
generateButton.setDisable(true);
6571
generateButton.defaultButtonProperty().bind(generateButton.disableProperty().not());
@@ -70,10 +76,8 @@ public FromAuxDialog(JabRefFrame frame) {
7076
}
7177
return null;
7278
});
73-
7479
themeManager.updateFontStyle(getDialogPane().getScene());
7580
}
76-
7781
@FXML
7882
private void parseActionPerformed() {
7983
notFoundList.getItems().clear();
@@ -108,22 +112,28 @@ private void browseButtonClicked() {
108112
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> auxFileField.setText(file.toAbsolutePath().toString()));
109113
}
110114

111-
public void unselectAll() {
112-
entriesListView.getCheckModel().clearChecks();
113-
}
114-
115-
public void selectAllNewEntries() {
116-
unselectAll();
117-
for (BibEntry entry : entriesListView.getItems()) {
118-
if (!viewModel.hasDuplicate(entry)) {
119-
entriesListView.getCheckModel().check(entry);
120-
}
121-
}
122-
}
123-
124-
public void selectAllEntries() {
125-
unselectAll();
126-
entriesListView.getCheckModel().checkAll();
115+
@FXML
116+
private void initialize() {
117+
118+
libraryListView.setEditable(false);
119+
libraryListView.getItems().addAll(stateManager.getOpenDatabases());
120+
new ViewModelListCellFactory<BibDatabaseContext>()
121+
.withText(database -> {
122+
Optional<String> dbOpt = Optional.empty();
123+
if (database.getDatabasePath().isPresent()) {
124+
dbOpt = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), database.getDatabasePath().get());
125+
}
126+
if (database.getLocation() == DatabaseLocation.SHARED) {
127+
return database.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]";
128+
}
129+
130+
if (dbOpt.isEmpty()) {
131+
return Localization.lang("untitled");
132+
}
133+
134+
return dbOpt.get();
135+
})
136+
.install(libraryListView);
127137
}
128138

129139
}

0 commit comments

Comments
 (0)