use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class OpenOfficePanel method checkThatEntriesHaveKeys.
/**
* Check that all entries in the list have BibTeX keys, if not ask if they should be generated
*
* @param entries A list of entries to be checked
* @return true if all entries have BibTeX keys, if it so may be after generating them
*/
private boolean checkThatEntriesHaveKeys(List<BibEntry> entries) {
// Check if there are empty keys
boolean emptyKeys = false;
for (BibEntry entry : entries) {
if (!entry.getCiteKeyOptional().isPresent()) {
// Found one, no need to look further for now
emptyKeys = true;
break;
}
}
// If no empty keys, return true
if (!emptyKeys) {
return true;
}
// Ask if keys should be generated
String[] options = { Localization.lang("Generate keys"), Localization.lang("Cancel") };
int answer = JOptionPane.showOptionDialog(this.frame, Localization.lang("Cannot cite entries without BibTeX keys. Generate keys now?"), Localization.lang("Cite"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null);
BasePanel panel = frame.getCurrentBasePanel();
if ((answer == JOptionPane.OK_OPTION) && (panel != null)) {
// Generate keys
BibtexKeyPatternPreferences prefs = Globals.prefs.getBibtexKeyPatternPreferences();
NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite"));
for (BibEntry entry : entries) {
if (!entry.getCiteKeyOptional().isPresent()) {
// Generate key
BibtexKeyPatternUtil.makeAndSetLabel(panel.getBibDatabaseContext().getMetaData().getCiteKeyPattern(prefs.getKeyPattern()), panel.getDatabase(), entry, prefs);
// Add undo change
undoCompound.addEdit(new UndoableKeyChange(entry, null, entry.getCiteKeyOptional().get()));
}
}
undoCompound.end();
// Add all undos
panel.getUndoManager().addEdit(undoCompound);
// Now every entry has a key
return true;
} else {
// No, we canceled (or there is no panel to get the database from, highly unlikely)
return false;
}
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class OpenOfficePanel method pushEntries.
private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addPageInfo) {
if (!ooBase.isConnectedToDocument()) {
JOptionPane.showMessageDialog(frame, Localization.lang("Not connected to any Writer document. Please" + " make sure a document is open, and use the 'Select Writer document' button to connect to it."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
return;
}
Boolean inParenthesis = inParenthesisIn;
String pageInfo = null;
if (addPageInfo) {
AdvancedCiteDialog citeDialog = new AdvancedCiteDialog(frame);
citeDialog.showDialog();
if (citeDialog.canceled()) {
return;
}
if (!citeDialog.getPageInfo().isEmpty()) {
pageInfo = citeDialog.getPageInfo();
}
inParenthesis = citeDialog.isInParenthesisCite();
}
BasePanel panel = frame.getCurrentBasePanel();
if (panel != null) {
final BibDatabase database = panel.getDatabase();
List<BibEntry> entries = panel.getSelectedEntries();
if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) {
try {
if (style == null) {
style = loader.getUsedStyle();
}
ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, withText, pageInfo, preferences.syncWhenCiting());
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE);
LOGGER.warn("Problem with style file", ex);
} catch (ConnectionLostException ex) {
showConnectionLostErrorMessage();
} catch (UndefinedCharacterFormatException ex) {
reportUndefinedCharacterFormat(ex);
} catch (UndefinedParagraphFormatException ex) {
reportUndefinedParagraphFormat(ex);
} catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | CreationException | NoSuchElementException | WrappedTargetException | IOException | BibEntryNotFoundException | IllegalTypeException | PropertyExistException | NotRemoveableException ex) {
LOGGER.warn("Could not insert entry", ex);
}
}
}
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class SearchResultFrame method selectEntryInBasePanel.
private void selectEntryInBasePanel(BibEntry entry) {
BasePanel basePanel = entryHome.get(entry);
frame.showBasePanel(basePanel);
basePanel.requestFocus();
basePanel.highlightEntry(entry);
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class LookupIdentifiersWorker method run.
@Override
public void run() {
BasePanel basePanel = Objects.requireNonNull(frame.getCurrentBasePanel());
List<BibEntry> bibEntries = basePanel.getSelectedEntries();
if (!bibEntries.isEmpty()) {
String totalCount = Integer.toString(bibEntries.size());
NamedCompound namedCompound = new NamedCompound(Localization.lang("Look up %0", fetcher.getIdentifierName()));
int count = 0;
int foundCount = 0;
for (BibEntry bibEntry : bibEntries) {
count++;
frame.output(Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", fetcher.getIdentifierName(), Integer.toString(count), totalCount, Integer.toString(foundCount)));
Optional<T> identifier = Optional.empty();
try {
identifier = fetcher.findIdentifier(bibEntry);
} catch (FetcherException e) {
LOGGER.error("Could not fetch " + fetcher.getIdentifierName(), e);
}
if (identifier.isPresent() && !bibEntry.hasField(identifier.get().getDefaultField())) {
Optional<FieldChange> fieldChange = bibEntry.setField(identifier.get().getDefaultField(), identifier.get().getNormalized());
if (fieldChange.isPresent()) {
namedCompound.addEdit(new UndoableFieldChange(fieldChange.get()));
foundCount++;
frame.output(Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", Integer.toString(count), totalCount, Integer.toString(foundCount)));
}
}
}
namedCompound.end();
if (foundCount > 0) {
basePanel.getUndoManager().addEdit(namedCompound);
basePanel.markBaseChanged();
}
message = Localization.lang("Determined %0 for %1 entries", fetcher.getIdentifierName(), Integer.toString(foundCount));
}
}
use of org.jabref.gui.BasePanel in project jabref by JabRef.
the class OpenDatabaseAction method openFiles.
/**
* Opens the given files. If one of it is null or 404, nothing happens
*
* @param filesToOpen the filesToOpen, may be null or not existing
*/
public void openFiles(List<Path> filesToOpen, boolean raisePanel) {
BasePanel toRaise = null;
int initialCount = filesToOpen.size();
int removed = 0;
// Check if any of the files are already open:
for (Iterator<Path> iterator = filesToOpen.iterator(); iterator.hasNext(); ) {
Path file = iterator.next();
for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
BasePanel basePanel = frame.getBasePanelAt(i);
if ((basePanel.getBibDatabaseContext().getDatabaseFile().isPresent()) && basePanel.getBibDatabaseContext().getDatabaseFile().get().equals(file)) {
iterator.remove();
removed++;
// raise the BasePanel in question:
if (removed == initialCount) {
toRaise = basePanel;
}
// no more bps to check, we found a matching one
break;
}
}
}
// locking until the file is loaded.
if (!filesToOpen.isEmpty()) {
final List<Path> theFiles = Collections.unmodifiableList(filesToOpen);
JabRefExecutorService.INSTANCE.execute(() -> {
for (Path theFile : theFiles) {
openTheFile(theFile, raisePanel);
}
});
for (Path theFile : theFiles) {
frame.getFileHistory().newFile(theFile.toString());
}
} else // already open. If so, we may have to raise the correct tab:
if (toRaise != null) {
frame.output(Localization.lang("File '%0' is already open.", toRaise.getBibDatabaseContext().getDatabaseFile().get().getPath()));
frame.getTabbedPane().setSelectedComponent(toRaise);
}
frame.output(Localization.lang("Files opened") + ": " + (filesToOpen.size()));
}
Aggregations