Skip to content

Commit

Permalink
Merge pull request #9 from InAnYan/add-ai-service
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan authored May 29, 2024
2 parents baad7b3 + bda1efb commit 5755334
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jabref.gui.Globals;
import org.jabref.gui.JabRefGUI;
import org.jabref.logic.UiCommand;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.net.ProxyAuthenticator;
import org.jabref.logic.net.ProxyPreferences;
Expand Down Expand Up @@ -70,6 +71,9 @@ public static void main(String[] args) {
// Initialize preferences
final JabRefPreferences preferences = JabRefPreferences.getInstance();

// Initialize AI service.
final AiService aiService = new AiService(preferences.getAiPreferences());

// Early exit in case another instance is already running
if (!handleMultipleAppInstances(args, preferences.getRemotePreferences())) {
return;
Expand Down Expand Up @@ -103,7 +107,7 @@ public static void main(String[] args) {
}

List<UiCommand> uiCommands = new ArrayList<>(argumentProcessor.getUiCommands());
JabRefGUI.setup(uiCommands, preferences, fileUpdateMonitor);
JabRefGUI.setup(uiCommands, preferences, aiService, fileUpdateMonitor);
JabRefGUI.launch(JabRefGUI.class, args);
} catch (ParseException e) {
LOGGER.error("Problem parsing arguments", e);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.entry.BibEntryTypesManager;
Expand Down Expand Up @@ -52,6 +53,8 @@ private static Object createDependency(Class<?> clazz) {
return Globals.undoManager;
} else if (clazz == BibEntryTypesManager.class) {
return Globals.entryTypesManager;
} else if (clazz == AiService.class) {
return JabRefGUI.getAiService();
} else {
try {
return clazz.newInstance();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jabref.gui.telemetry.Telemetry;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.logic.UiCommand;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.ProxyRegisterer;
import org.jabref.logic.util.WebViewStore;
Expand All @@ -40,6 +41,7 @@ public class JabRefGUI extends Application {

private static List<UiCommand> uiCommands;
private static JabRefPreferences preferencesService;
private static AiService aiService;
private static FileUpdateMonitor fileUpdateMonitor;
private static JabRefFrame mainFrame;
private static DialogService dialogService;
Expand All @@ -50,9 +52,11 @@ public class JabRefGUI extends Application {

public static void setup(List<UiCommand> uiCommands,
JabRefPreferences preferencesService,
AiService aiService,
FileUpdateMonitor fileUpdateMonitor) {
JabRefGUI.uiCommands = uiCommands;
JabRefGUI.preferencesService = preferencesService;
JabRefGUI.aiService = aiService;
JabRefGUI.fileUpdateMonitor = fileUpdateMonitor;
}

Expand All @@ -75,6 +79,7 @@ public void start(Stage stage) {
dialogService,
fileUpdateMonitor,
preferencesService,
aiService,
Globals.stateManager,
Globals.undoManager,
Globals.entryTypesManager,
Expand Down Expand Up @@ -257,4 +262,8 @@ public static DialogService getDialogService() {
public static ThemeManager getThemeManager() {
return themeManager;
}

public static AiService getAiService() {
return aiService;
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.citationstyle.CitationStyleCache;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.util.FileFieldParser;
Expand Down Expand Up @@ -110,6 +111,7 @@ private enum PanelMode { MAIN_TABLE, MAIN_TABLE_AND_ENTRY_EDITOR }
private final CountingUndoManager undoManager;
private final DialogService dialogService;
private final PreferencesService preferencesService;
private final AiService aiService;
private final FileUpdateMonitor fileUpdateMonitor;
private final StateManager stateManager;
private final BibEntryTypesManager entryTypesManager;
Expand Down Expand Up @@ -158,6 +160,7 @@ private LibraryTab(BibDatabaseContext bibDatabaseContext,
LibraryTabContainer tabContainer,
DialogService dialogService,
PreferencesService preferencesService,
AiService aiService,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor,
BibEntryTypesManager entryTypesManager,
Expand All @@ -168,6 +171,7 @@ private LibraryTab(BibDatabaseContext bibDatabaseContext,
this.undoManager = undoManager;
this.dialogService = dialogService;
this.preferencesService = Objects.requireNonNull(preferencesService);
this.aiService = Objects.requireNonNull(aiService);
this.stateManager = Objects.requireNonNull(stateManager);
this.fileUpdateMonitor = fileUpdateMonitor;
this.entryTypesManager = entryTypesManager;
Expand Down Expand Up @@ -972,6 +976,7 @@ public static LibraryTab createLibraryTab(BackgroundTask<ParserResult> dataLoadi
Path file,
DialogService dialogService,
PreferencesService preferencesService,
AiService aiService,
StateManager stateManager,
LibraryTabContainer tabContainer,
FileUpdateMonitor fileUpdateMonitor,
Expand All @@ -986,6 +991,7 @@ public static LibraryTab createLibraryTab(BackgroundTask<ParserResult> dataLoadi
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand All @@ -1005,6 +1011,7 @@ public static LibraryTab createLibraryTab(BibDatabaseContext databaseContext,
LibraryTabContainer tabContainer,
DialogService dialogService,
PreferencesService preferencesService,
AiService aiService,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor,
BibEntryTypesManager entryTypesManager,
Expand All @@ -1017,6 +1024,7 @@ public static LibraryTab createLibraryTab(BibDatabaseContext databaseContext,
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class EntryEditor extends BorderPane {
@Inject private DialogService dialogService;
@Inject private TaskExecutor taskExecutor;
@Inject private PreferencesService preferencesService;
@Inject private AiService aiService;
@Inject private StateManager stateManager;
@Inject private ThemeManager themeManager;
@Inject private FileUpdateMonitor fileMonitor;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.UiCommand;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.undo.AddUndoableActionEvent;
import org.jabref.logic.undo.UndoChangeEvent;
import org.jabref.logic.undo.UndoRedoEvent;
Expand Down Expand Up @@ -77,6 +78,7 @@ public class JabRefFrame extends BorderPane implements LibraryTabContainer {

private final SplitPane splitPane = new SplitPane();
private final PreferencesService prefs;
private final AiService aiService;
private final GlobalSearchBar globalSearchBar;

private final FileHistoryMenu fileHistory;
Expand All @@ -103,6 +105,7 @@ public JabRefFrame(Stage mainStage,
DialogService dialogService,
FileUpdateMonitor fileUpdateMonitor,
PreferencesService preferencesService,
AiService aiService,
StateManager stateManager,
CountingUndoManager undoManager,
BibEntryTypesManager entryTypesManager,
Expand All @@ -111,6 +114,7 @@ public JabRefFrame(Stage mainStage,
this.dialogService = dialogService;
this.fileUpdateMonitor = fileUpdateMonitor;
this.prefs = preferencesService;
this.aiService = aiService;
this.stateManager = stateManager;
this.undoManager = undoManager;
this.entryTypesManager = entryTypesManager;
Expand All @@ -121,6 +125,7 @@ public JabRefFrame(Stage mainStage,
// Create components
this.viewModel = new JabRefFrameViewModel(
preferencesService,
aiService,
stateManager,
dialogService,
this,
Expand All @@ -146,6 +151,7 @@ public JabRefFrame(Stage mainStage,
this.sidePane = new SidePane(
this,
prefs,
aiService,
Globals.journalAbbreviationRepository,
taskExecutor,
dialogService,
Expand Down Expand Up @@ -186,6 +192,7 @@ private void initLayout() {
dialogService,
stateManager,
prefs,
aiService,
fileUpdateMonitor,
taskExecutor,
entryTypesManager,
Expand Down Expand Up @@ -427,6 +434,7 @@ public void addTab(@NonNull BibDatabaseContext databaseContext, boolean raisePan
this,
dialogService,
prefs,
aiService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
Expand Down Expand Up @@ -502,6 +510,7 @@ private OpenDatabaseAction getOpenDatabaseAction() {
return new OpenDatabaseAction(
this,
prefs,
aiService,
dialogService,
stateManager,
fileUpdateMonitor,
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/frame/JabRefFrameViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.UiCommand;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.importer.ImportCleanup;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
Expand All @@ -45,6 +46,7 @@ public class JabRefFrameViewModel {
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefFrameViewModel.class);

private final PreferencesService prefs;
private final AiService aiService;
private final StateManager stateManager;
private final DialogService dialogService;
private final LibraryTabContainer tabContainer;
Expand All @@ -54,6 +56,7 @@ public class JabRefFrameViewModel {
private final TaskExecutor taskExecutor;

public JabRefFrameViewModel(PreferencesService preferencesService,
AiService aiService,
StateManager stateManager,
DialogService dialogService,
LibraryTabContainer tabContainer,
Expand All @@ -62,6 +65,7 @@ public JabRefFrameViewModel(PreferencesService preferencesService,
UndoManager undoManager,
TaskExecutor taskExecutor) {
this.prefs = preferencesService;
this.aiService = aiService;
this.stateManager = stateManager;
this.dialogService = dialogService;
this.tabContainer = tabContainer;
Expand Down Expand Up @@ -196,6 +200,7 @@ private void openDatabases(List<ParserResult> parserResults) {
tabContainer,
dialogService,
prefs,
aiService,
stateManager,
entryTypesManager,
fileUpdateMonitor,
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/gui/frame/MainToolBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.jabref.gui.undo.UndoRedoAction;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.types.StandardEntryType;
Expand All @@ -54,6 +55,7 @@ public class MainToolBar extends ToolBar {
private final DialogService dialogService;
private final StateManager stateManager;
private final PreferencesService preferencesService;
private final AiService aiService;
private final FileUpdateMonitor fileUpdateMonitor;
private final TaskExecutor taskExecutor;
private final BibEntryTypesManager entryTypesManager;
Expand All @@ -68,6 +70,7 @@ public MainToolBar(LibraryTabContainer tabContainer,
DialogService dialogService,
StateManager stateManager,
PreferencesService preferencesService,
AiService aiService,
FileUpdateMonitor fileUpdateMonitor,
TaskExecutor taskExecutor,
BibEntryTypesManager entryTypesManager,
Expand All @@ -78,6 +81,7 @@ public MainToolBar(LibraryTabContainer tabContainer,
this.dialogService = dialogService;
this.stateManager = stateManager;
this.preferencesService = preferencesService;
this.aiService = aiService;
this.fileUpdateMonitor = fileUpdateMonitor;
this.taskExecutor = taskExecutor;
this.entryTypesManager = entryTypesManager;
Expand All @@ -100,7 +104,7 @@ private void createToolBar() {
getItems().addAll(
new HBox(
factory.createIconButton(StandardActions.NEW_LIBRARY, new NewDatabaseAction(frame, preferencesService)),
factory.createIconButton(StandardActions.OPEN_LIBRARY, new OpenDatabaseAction(frame, preferencesService, dialogService, stateManager, fileUpdateMonitor, entryTypesManager, undoManager, taskExecutor)),
factory.createIconButton(StandardActions.OPEN_LIBRARY, new OpenDatabaseAction(frame, preferencesService, aiService, dialogService, stateManager, fileUpdateMonitor, entryTypesManager, undoManager, taskExecutor)),
factory.createIconButton(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager))),

leftSpacer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class OpenDatabaseAction extends SimpleCommand {

private final LibraryTabContainer tabContainer;
private final PreferencesService preferencesService;
private final AiService aiService;
private final StateManager stateManager;
private final FileUpdateMonitor fileUpdateMonitor;
private final DialogService dialogService;
Expand All @@ -68,6 +70,7 @@ public class OpenDatabaseAction extends SimpleCommand {

public OpenDatabaseAction(LibraryTabContainer tabContainer,
PreferencesService preferencesService,
AiService aiService,
DialogService dialogService,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor,
Expand All @@ -76,6 +79,7 @@ public OpenDatabaseAction(LibraryTabContainer tabContainer,
TaskExecutor taskExecutor) {
this.tabContainer = tabContainer;
this.preferencesService = preferencesService;
this.aiService = aiService;
this.dialogService = dialogService;
this.stateManager = stateManager;
this.fileUpdateMonitor = fileUpdateMonitor;
Expand Down Expand Up @@ -198,6 +202,7 @@ private void openTheFile(Path file) {
file,
dialogService,
preferencesService,
aiService,
stateManager,
tabContainer,
fileUpdateMonitor,
Expand Down Expand Up @@ -249,6 +254,7 @@ private ParserResult loadDatabase(Path file) throws Exception {
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
entryTypesManager,
fileUpdateMonitor,
Expand All @@ -269,6 +275,7 @@ public static void openSharedDatabase(ParserResult parserResult,
LibraryTabContainer tabContainer,
DialogService dialogService,
PreferencesService preferencesService,
AiService aiService,
StateManager stateManager,
BibEntryTypesManager entryTypesManager,
FileUpdateMonitor fileUpdateMonitor,
Expand All @@ -280,6 +287,7 @@ public static void openSharedDatabase(ParserResult parserResult,
tabContainer,
dialogService,
preferencesService,
aiService,
stateManager,
entryTypesManager,
fileUpdateMonitor,
Expand Down
Loading

0 comments on commit 5755334

Please sign in to comment.