Skip to content

Commit

Permalink
Added logic and implementation for library selector
Browse files Browse the repository at this point in the history
  • Loading branch information
caitlinlilley authored and koppor committed Oct 27, 2023
1 parent 55f89d8 commit 9799dc4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
8 changes: 2 additions & 6 deletions src/main/java/org/jabref/gui/auximport/FromAuxDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
Expand All @@ -13,6 +12,8 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import org.jabref.gui.icon.JabRefIconView?>

<?import javafx.scene.control.ComboBox?>
<DialogPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="650.0" prefWidth="500.0"
xmlns="http://javafx.com/javafx/8.0.121" fx:controller="org.jabref.gui.auximport.FromAuxDialog">
<content>
Expand Down Expand Up @@ -44,11 +45,6 @@
<Label text="%Unknown BibTeX entries:"/>
<ListView fx:id="notFoundList" prefHeight="200"/>
<VBox spacing="10">
<HBox spacing="4">
<Button onAction="#selectAllNewEntries" text="%Select all new entries"/>
<Button onAction="#selectAllEntries" text="%Select all entries"/>
<Button onAction="#unselectAll" text="%Unselect all"/>
</HBox>
<HBox spacing="4" alignment="CENTER_LEFT">
<Label text="%Select library"/>
<ComboBox fx:id="libraryListView" layoutX="16.0" layoutY="52.0"/>
Expand Down
64 changes: 37 additions & 27 deletions src/main/java/org/jabref/gui/auximport/FromAuxDialog.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jabref.gui.auximport;

import java.nio.file.Path;
import java.util.Optional;


import javafx.fxml.FXML;
import javafx.scene.control.Button;
Expand All @@ -10,36 +12,36 @@
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;


import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.importer.ImportEntriesViewModel;
import org.jabref.gui.StateManager;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.auxparser.AuxParser;
import org.jabref.logic.auxparser.AuxParserResult;
import org.jabref.logic.auxparser.DefaultAuxParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.DatabaseLocation;
import org.jabref.logic.util.StandardFileType;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import jakarta.inject.Inject;
import org.controlsfx.control.CheckListView;



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

public CheckListView<BibEntry> entriesListView;

private ImportEntriesViewModel viewModel;
public ComboBox<String> libraryListView;
private final LibraryTab libraryTab;
@FXML private ButtonType generateButtonType;
private final Button generateButton;
Expand All @@ -51,15 +53,19 @@ public class FromAuxDialog extends BaseDialog<Void> {
@Inject private PreferencesService preferences;
@Inject private DialogService dialogService;
@Inject private ThemeManager themeManager;
public ComboBox<BibDatabaseContext> libraryListView;
@Inject private StateManager stateManager;





public FromAuxDialog(JabRefFrame frame) {
libraryTab = frame.getCurrentLibraryTab();
this.setTitle(Localization.lang("AUX file import"));

ViewLoader.view(this)
.load()
.setAsDialogPane(this);

generateButton = (Button) this.getDialogPane().lookupButton(generateButtonType);
generateButton.setDisable(true);
generateButton.defaultButtonProperty().bind(generateButton.disableProperty().not());
Expand All @@ -70,10 +76,8 @@ public FromAuxDialog(JabRefFrame frame) {
}
return null;
});

themeManager.updateFontStyle(getDialogPane().getScene());
}

@FXML
private void parseActionPerformed() {
notFoundList.getItems().clear();
Expand Down Expand Up @@ -108,22 +112,28 @@ private void browseButtonClicked() {
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> auxFileField.setText(file.toAbsolutePath().toString()));
}

public void unselectAll() {
entriesListView.getCheckModel().clearChecks();
}

public void selectAllNewEntries() {
unselectAll();
for (BibEntry entry : entriesListView.getItems()) {
if (!viewModel.hasDuplicate(entry)) {
entriesListView.getCheckModel().check(entry);
}
}
}

public void selectAllEntries() {
unselectAll();
entriesListView.getCheckModel().checkAll();
@FXML
private void initialize() {

libraryListView.setEditable(false);
libraryListView.getItems().addAll(stateManager.getOpenDatabases());
new ViewModelListCellFactory<BibDatabaseContext>()
.withText(database -> {
Optional<String> dbOpt = Optional.empty();
if (database.getDatabasePath().isPresent()) {
dbOpt = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), database.getDatabasePath().get());
}
if (database.getLocation() == DatabaseLocation.SHARED) {
return database.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]";
}

if (dbOpt.isEmpty()) {
return Localization.lang("untitled");
}

return dbOpt.get();
})
.install(libraryListView);
}

}

0 comments on commit 9799dc4

Please sign in to comment.