use of org.jabref.logic.search.SearchQuery in project jabref by JabRef.
the class ArgumentProcessor method exportMatches.
private boolean exportMatches(List<ParserResult> loaded) {
String[] data = cli.getExportMatches().split(",");
//enables blanks within the search term:
String searchTerm = data[0].replace("\\$", " ");
//$ stands for a blank
ParserResult pr = loaded.get(loaded.size() - 1);
BibDatabaseContext databaseContext = pr.getDatabaseContext();
BibDatabase dataBase = pr.getDatabase();
SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
SearchQuery query = new SearchQuery(searchTerm, searchPreferences.isCaseSensitive(), searchPreferences.isRegularExpression());
List<BibEntry> matches = new DatabaseSearcher(query, dataBase).getMatches();
//export matches
if (!matches.isEmpty()) {
String formatName;
//read in the export format, take default format if no format entered
switch(data.length) {
case 3:
formatName = data[2];
break;
case 2:
//default ExportFormat: HTML table (with Abstract & BibTeX)
formatName = "tablerefsabsbib";
break;
default:
System.err.println(Localization.lang("Output file missing").concat(". \n \t ").concat(Localization.lang("Usage")).concat(": ") + JabRefCLI.getExportMatchesSyntax());
noGUINeeded = true;
return false;
}
//export new database
IExportFormat format = ExportFormats.getExportFormat(formatName);
if (format == null) {
System.err.println(Localization.lang("Unknown export format") + ": " + formatName);
} else {
// We have an ExportFormat instance:
try {
System.out.println(Localization.lang("Exporting") + ": " + data[1]);
format.performExport(databaseContext, data[1], databaseContext.getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()), matches);
} catch (Exception ex) {
System.err.println(Localization.lang("Could not export file") + " '" + data[1] + "': " + ExceptionUtils.getStackTrace(ex));
}
}
} else {
System.err.println(Localization.lang("No search matches."));
}
return true;
}
use of org.jabref.logic.search.SearchQuery in project jabref by JabRef.
the class JabRefFrame method init.
private void init() {
tabbedPane = new DragDropPopupPane(tabPopupMenu());
MyGlassPane glassPane = new MyGlassPane();
setGlassPane(glassPane);
setTitle(FRAME_TITLE);
setIconImages(IconTheme.getLogoSet());
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (OS.OS_X) {
JabRefFrame.this.setVisible(false);
} else {
new CloseAction().actionPerformed(null);
}
}
});
initSidePane();
initLayout();
initActions();
// Show the toolbar if it was visible at last shutdown:
tlb.setVisible(Globals.prefs.getBoolean(JabRefPreferences.TOOLBAR_VISIBLE));
setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, JabRefPreferences.SIZE_Y);
pw.displayWindowAtStoredLocation();
tabbedPane.setBorder(null);
tabbedPane.setForeground(GUIGlobals.INACTIVE_TABBED_COLOR);
/*
* The following state listener makes sure focus is registered with the
* correct database when the user switches tabs. Without this,
* cut/paste/copy operations would some times occur in the wrong tab.
*/
tabbedPane.addChangeListener(e -> {
markActiveBasePanel();
BasePanel currentBasePanel = getCurrentBasePanel();
if (currentBasePanel == null) {
return;
}
Platform.runLater(() -> Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext())));
if (new SearchPreferences(Globals.prefs).isGlobalSearch()) {
globalSearchBar.performSearch();
} else {
String content = "";
Optional<SearchQuery> currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if (currentSearchQuery.isPresent()) {
content = currentSearchQuery.get().getQuery();
}
globalSearchBar.setSearchTerm(content, true);
}
currentBasePanel.getPreviewPanel().updateLayout();
groupSidePane.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class));
previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class));
openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));
Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());
setWindowTitle();
editModeAction.initName();
currentBasePanel.updateSearchManager();
currentBasePanel.setBackAndForwardEnabledState();
currentBasePanel.getUndoManager().postUndoRedoEvent();
currentBasePanel.getMainTable().requestFocus();
});
//opened (double-clicked) documents are not displayed.
if (OS.OS_X) {
try {
new MacAdapter().registerMacEvents(this);
} catch (Exception e) {
LOGGER.fatal("Could not interface with Mac OS X methods.", e);
}
}
initShowTrackingNotification();
}
use of org.jabref.logic.search.SearchQuery in project jabref by JabRef.
the class GroupDialog method updateComponents.
private void updateComponents() {
// all groups need a name
boolean okEnabled = !nameField.getText().trim().isEmpty();
if (!okEnabled) {
setDescription(Localization.lang("Please enter a name for the group."));
okButton.setEnabled(false);
return;
}
String s1;
String s2;
if (keywordsRadioButton.isSelected()) {
s1 = keywordGroupSearchField.getText().trim();
okEnabled = okEnabled && s1.matches("\\w+");
s2 = keywordGroupSearchTerm.getText().trim();
okEnabled = okEnabled && !s2.isEmpty();
if (okEnabled) {
if (keywordGroupRegExp.isSelected()) {
try {
Pattern.compile(s2);
setDescription(GroupDescriptions.getDescriptionForPreview(s1, s2, keywordGroupCaseSensitive.isSelected(), keywordGroupRegExp.isSelected()));
} catch (PatternSyntaxException e) {
okEnabled = false;
setDescription(formatRegExException(s2, e));
}
} else {
setDescription(GroupDescriptions.getDescriptionForPreview(s1, s2, keywordGroupCaseSensitive.isSelected(), keywordGroupRegExp.isSelected()));
}
} else {
setDescription(Localization.lang("Please enter the field to search (e.g. <b>keywords</b>) and the keyword to search it for (e.g. <b>electrical</b>)."));
}
setNameFontItalic(true);
} else if (searchRadioButton.isSelected()) {
s1 = searchGroupSearchExpression.getText().trim();
okEnabled = okEnabled & !s1.isEmpty();
if (okEnabled) {
setDescription(new SearchQuery(s1, isCaseSensitive(), isRegex()).getDescription());
if (isRegex()) {
try {
Pattern.compile(s1);
} catch (PatternSyntaxException e) {
okEnabled = false;
setDescription(formatRegExException(s1, e));
}
}
} else {
setDescription(Localization.lang("Please enter a search term. For example, to search all fields for <b>Smith</b>, enter:<p>" + "<tt>smith</tt><p>" + "To search the field <b>Author</b> for <b>Smith</b> and the field <b>Title</b> for <b>electrical</b>, enter:<p>" + "<tt>author=smith and title=electrical</tt>"));
}
setNameFontItalic(true);
} else if (explicitRadioButton.isSelected()) {
setDescription(GroupDescriptions.getDescriptionForPreview());
setNameFontItalic(false);
}
okButton.setEnabled(okEnabled);
}
use of org.jabref.logic.search.SearchQuery in project jabref by JabRef.
the class GlobalSearchBar method getSearchQuery.
private SearchQuery getSearchQuery() {
SearchQuery searchQuery = new SearchQuery(this.searchField.getText(), this.caseSensitive.isSelected(), this.regularExp.isSelected());
this.frame.getCurrentBasePanel().setCurrentSearchQuery(searchQuery);
return searchQuery;
}
use of org.jabref.logic.search.SearchQuery in project jabref by JabRef.
the class GlobalSearchBar method performSearch.
public void performSearch() {
BasePanel currentBasePanel = frame.getCurrentBasePanel();
if (currentBasePanel == null) {
return;
}
if (searchWorker != null) {
searchWorker.cancel(true);
}
// An empty search field should cause the search to be cleared.
if (searchField.getText().isEmpty()) {
clearSearch(currentBasePanel);
return;
}
SearchQuery searchQuery = getSearchQuery();
if (!searchQuery.isValid()) {
informUserAboutInvalidSearchQuery();
return;
}
searchWorker = new SearchWorker(currentBasePanel, searchQuery, searchDisplayMode);
searchWorker.execute();
}
Aggregations