Search in sources :

Example 1 with SearchQuery

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;
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery) ParserResult(org.jabref.logic.importer.ParserResult) SearchPreferences(org.jabref.preferences.SearchPreferences) BibEntry(org.jabref.model.entry.BibEntry) IExportFormat(org.jabref.logic.exporter.IExportFormat) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) JabRefException(org.jabref.JabRefException) BackingStoreException(java.util.prefs.BackingStoreException) SaveException(org.jabref.logic.exporter.SaveException) IOException(java.io.IOException) ImportException(org.jabref.logic.importer.ImportException) DatabaseSearcher(org.jabref.logic.search.DatabaseSearcher)

Example 2 with SearchQuery

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();
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery) WindowAdapter(java.awt.event.WindowAdapter) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) SearchPreferences(org.jabref.preferences.SearchPreferences) OpenOfficeSidePanel(org.jabref.gui.openoffice.OpenOfficeSidePanel) WindowEvent(java.awt.event.WindowEvent) GroupSidePane(org.jabref.gui.groups.GroupSidePane) GeneralFetcher(org.jabref.gui.importer.fetcher.GeneralFetcher) WindowLocation(org.jabref.gui.util.WindowLocation) MacAdapter(osx.macadapter.MacAdapter)

Example 3 with SearchQuery

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);
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 4 with SearchQuery

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;
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery)

Example 5 with 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();
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery) BasePanel(org.jabref.gui.BasePanel)

Aggregations

SearchQuery (org.jabref.logic.search.SearchQuery)5 IOException (java.io.IOException)2 SearchPreferences (org.jabref.preferences.SearchPreferences)2 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BackingStoreException (java.util.prefs.BackingStoreException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 JabRefException (org.jabref.JabRefException)1 BasePanel (org.jabref.gui.BasePanel)1 GroupSidePane (org.jabref.gui.groups.GroupSidePane)1 GeneralFetcher (org.jabref.gui.importer.fetcher.GeneralFetcher)1 OpenOfficeSidePanel (org.jabref.gui.openoffice.OpenOfficeSidePanel)1 WindowLocation (org.jabref.gui.util.WindowLocation)1 IExportFormat (org.jabref.logic.exporter.IExportFormat)1 SaveException (org.jabref.logic.exporter.SaveException)1 ImportException (org.jabref.logic.importer.ImportException)1 ParserResult (org.jabref.logic.importer.ParserResult)1 DatabaseSearcher (org.jabref.logic.search.DatabaseSearcher)1 BibDatabase (org.jabref.model.database.BibDatabase)1