Skip to content

Commit

Permalink
Enhanced pre-condition checks
Browse files Browse the repository at this point in the history
  • Loading branch information
subhramit committed Sep 22, 2024
1 parent 073d550 commit 7958e7d
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,23 +402,25 @@ private void connectManually() {
}

private void updateButtonAvailability() {
boolean isConnected = ooBase != null;
boolean isConnectedToDocument = isConnected && !ooBase.isDocumentConnectionMissing();

selectDocument.setDisable(!isConnected);
pushEntries.setDisable(!isConnectedToDocument);

boolean cslStyleSelected = openOfficePreferences.getCurrentStyle() instanceof CitationStyle;
pushEntriesInt.setDisable(!isConnectedToDocument);
pushEntriesEmpty.setDisable(!isConnectedToDocument);
pushEntriesAdvanced.setDisable(!isConnectedToDocument || cslStyleSelected);

update.setDisable(!isConnectedToDocument);
merge.setDisable(!isConnectedToDocument || cslStyleSelected);
unmerge.setDisable(!isConnectedToDocument || cslStyleSelected);
manageCitations.setDisable(!isConnectedToDocument || cslStyleSelected);

exportCitations.setDisable(!isConnectedToDocument || cslStyleSelected);
boolean isConnectedToDocument = (ooBase != null && !ooBase.isDocumentConnectionMissing());
boolean hasStyle = (currentStyle != null);
boolean hasDatabase = !getBaseList().isEmpty();
boolean canRefreshDocument = isConnectedToDocument && hasStyle;
boolean canCite = isConnectedToDocument && hasStyle;
boolean cslStyleSelected = currentStyle instanceof CitationStyle;

selectDocument.setDisable(!isConnectedToDocument);

pushEntries.setDisable(!(canCite && hasDatabase));
pushEntriesInt.setDisable(!(canCite && hasDatabase));
pushEntriesEmpty.setDisable(!(canCite && hasDatabase));
pushEntriesAdvanced.setDisable(!(canCite && hasDatabase) || cslStyleSelected);

update.setDisable(!canRefreshDocument);
merge.setDisable(!canRefreshDocument || cslStyleSelected);
unmerge.setDisable(!canRefreshDocument || cslStyleSelected);
manageCitations.setDisable(!canRefreshDocument || cslStyleSelected);
exportCitations.setDisable(!(isConnectedToDocument && hasDatabase) || cslStyleSelected);
}

private void connect() {
Expand Down Expand Up @@ -502,23 +504,19 @@ private static CitationType citationTypeFromOptions(boolean withText, boolean in
private void pushEntries(CitationType citationType, boolean addPageInfo) {
final String errorDialogTitle = Localization.lang("Error pushing entries");

if (stateManager.getActiveDatabase().isEmpty()
|| (stateManager.getActiveDatabase().get().getDatabase() == null)) {
final Optional<BibDatabaseContext> activeDatabase = stateManager.getActiveDatabase();

if (activeDatabase.isEmpty()
|| (activeDatabase.get().getDatabase() == null)) {
OOError.noDataBaseIsOpenForCiting()
.setTitle(errorDialogTitle)
.showErrorDialog(dialogService);
return;
}

final BibDatabaseContext bibDatabaseContext = stateManager.getActiveDatabase().get();
final BibDatabaseContext bibDatabaseContext = activeDatabase.get();

List<BibEntry> entries = stateManager.getSelectedEntries();
if (entries.isEmpty()) {
OOError.noEntriesSelectedForCitation()
.setTitle(errorDialogTitle)
.showErrorDialog(dialogService);
return;
}

if (getOrUpdateTheStyle(errorDialogTitle)) {
return;
Expand Down

0 comments on commit 7958e7d

Please sign in to comment.