@Override public void run() { if (!searchAllBases.isSelected()) { // Search only the current database: for (BibtexEntry entry : panel.getDatabase().getEntries()) { boolean hit = rule.applyRule(searchTerm, entry) > 0; entry.setSearchHit(hit); if (hit) { hits++; } } } else { // Search all databases: for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) { BasePanel p = frame.baseAt(i); for (BibtexEntry entry : p.getDatabase().getEntries()) { boolean hit = rule.applyRule(searchTerm, entry) > 0; entry.setSearchHit(hit); if (hit) { hits++; } } } } }
@Override public void setActiveBasePanel(BasePanel panel) { super.setActiveBasePanel(panel); if (panel != null) { escape.setEnabled(panel.isShowingFloatSearch() || panel.isShowingFilterSearch()); } else { escape.setEnabled(false); } }
private void applyChanges() { boolean changedFieldSet = false; // Watch if we need to rebuild entry editors // First remove the mappings for fields that have been deleted. // If these were re-added, they will be added below, so it doesn't // cause any harm to remove them here. for (Iterator<String> i = removedFields.iterator(); i.hasNext(); ) { String fieldName = i.next(); metaData.remove(Globals.SELECTOR_META_PREFIX + fieldName); changedFieldSet = true; } // Cycle through all fields that we have created listmodels for: loop: for (Iterator<String> i = wordListModels.keySet().iterator(); i.hasNext(); ) { // For each field name, store the values: String fieldName = i.next(); if ((fieldName == null) || FIELD_FIRST_LINE.equals(fieldName)) continue loop; DefaultListModel lm = wordListModels.get(fieldName); int start = 0; // Avoid storing the <new word> marker if it is there: if (lm.size() > 0) while ((start < lm.size()) && (lm.get(start)).equals(WORD_FIRSTLINE_TEXT)) start++; Vector<String> data = metaData.getData(Globals.SELECTOR_META_PREFIX + fieldName); boolean newField = false; if (data == null) { newField = true; data = new Vector<String>(); changedFieldSet = true; } else data.clear(); for (int wrd = start; wrd < lm.size(); wrd++) { String word = (String) lm.get(wrd); data.add(word); } if (newField) metaData.putData(Globals.SELECTOR_META_PREFIX + fieldName, data); } // System.out.println("TODO: remove metadata for removed selector field."); panel.markNonUndoableBaseChanged(); // Update all selectors in the current BasePanel. if (changedFieldSet) { panel.rebuildAllEntryEditors(); } else { panel.updateAllContentSelectors(); } panel.addContentSelectorValuesToAutoCompleters(); }
/** * Cycle through all databases, and make sure everything is updated with the new type * customization. This includes making sure all entries have a valid type, that no obsolete entry * editors are around, and that the right-click menus' change type menu is up-to-date. */ private void updateTypesForEntries(String typeName) { if (frame.getTabbedPane().getTabCount() == 0) { return; } for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) { BasePanel bp = (BasePanel) frame.getTabbedPane().getComponentAt(i); // Invalidate associated cached entry editor bp.entryEditors.remove(typeName); for (BibtexEntry entry : bp.database().getEntries()) { entry.updateType(); } } }
void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) { InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED); ActionMap am = panel.getActionMap(); im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev"); am.put("prev", parent.prevEntryAction); im.put(Globals.prefs.getKey("Entry editor, next entry"), "next"); am.put("next", parent.nextEntryAction); im.put(Globals.prefs.getKey("Entry editor, store field"), "store"); am.put("store", parent.storeFieldAction); im.put(Globals.prefs.getKey("Entry editor, next panel"), "right"); im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right"); am.put("left", parent.switchLeftAction); im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left"); im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left"); am.put("right", parent.switchRightAction); im.put(Globals.prefs.getKey("Help"), "help"); am.put("help", parent.helpAction); im.put(Globals.prefs.getKey("Save database"), "save"); am.put("save", parent.saveDatabaseAction); im.put(Globals.prefs.getKey("Next tab"), "nexttab"); am.put("nexttab", parent.frame.nextTab); im.put(Globals.prefs.getKey("Previous tab"), "prevtab"); am.put("prevtab", parent.frame.prevTab); panel.setName(title); // String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref"; String colSpec = "fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref, " + "8dlu, fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref"; StringBuffer sb = new StringBuffer(); int rows = (int) Math.ceil((double) fields.length / 2.0); for (int i = 0; i < rows; i++) { sb.append("fill:pref:grow, "); } if (addKeyField) sb.append("4dlu, fill:pref"); else if (sb.length() >= 2) sb.delete(sb.length() - 2, sb.length()); String rowSpec = sb.toString(); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(colSpec, rowSpec), panel); for (int i = 0; i < fields.length; i++) { // Create the text area: int editorType = BibtexFields.getEditorType(fields[i]); final FieldEditor ta; if (editorType == GUIGlobals.FILE_LIST_EDITOR) ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent); else ta = new FieldTextArea(fields[i], null); // ta.addUndoableEditListener(bPanel.undoListener); JComponent ex = parent.getExtra(fields[i], ta); // Add autocompleter listener, if required for this field: AbstractAutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]); AutoCompleteListener acl = null; if (autoComp != null) { acl = new AutoCompleteListener(autoComp); } setupJTextComponent(ta.getTextComponent(), acl); ta.setAutoCompleteListener(acl); // Store the editor for later reference: editors.put(fields[i], ta); if (i == 0) activeField = ta; // System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i])); // ta.getPane().setPreferredSize(new Dimension(100, // (int)(50.0*BibtexFields.getFieldWeight(fields[i])))); builder.append(ta.getLabel()); if (ex == null) builder.append(ta.getPane(), 3); else { builder.append(ta.getPane()); JPanel pan = new JPanel(); pan.setLayout(new BorderLayout()); pan.add(ex, BorderLayout.NORTH); builder.append(pan); } if (i % 2 == 1) builder.nextLine(); } // Add the edit field for Bibtex-key. if (addKeyField) { final FieldTextField tf = new FieldTextField( BibtexFields.KEY_FIELD, parent.getEntry().getField(BibtexFields.KEY_FIELD), true); // tf.addUndoableEditListener(bPanel.undoListener); setupJTextComponent(tf, null); editors.put("bibtexkey", tf); /* * If the key field is the only field, we should have only one * editor, and this one should be set as active initially: */ if (editors.size() == 1) activeField = tf; builder.nextLine(); builder.append(tf.getLabel()); builder.append(tf, 3); } }
@Override public void update() { panel.output(Globals.lang("Searched database. Number of hits") + ": " + hits); // Show the result in the chosen way: if (searchAllBases.isSelected()) { // Search all databases. This means we need to use the search results dialog. // Turn off other search mode, if activated: if (startedFloatSearch) { panel.mainTable.stopShowingFloatSearch(); startedFloatSearch = false; } if (startedFilterSearch) { panel.stopShowingSearchResults(); startedFilterSearch = false; } // Make sure the search dialog is instantiated and cleared: instantiateSearchDialog(); searchDialog.clear(); for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) { BasePanel p = frame.baseAt(i); for (BibtexEntry entry : p.getDatabase().getEntries()) { if (entry.isSearchHit()) { searchDialog.addEntry(entry, p); } } } searchDialog.selectFirstEntry(); searchDialog.setVisible(true); } else if (showResultsInDialog.isSelected()) { // Turn off other search mode, if activated: if (startedFloatSearch) { panel.mainTable.stopShowingFloatSearch(); startedFloatSearch = false; } if (startedFilterSearch) { panel.stopShowingSearchResults(); startedFilterSearch = false; } // Make sure the search dialog is instantiated and cleared: instantiateSearchDialog(); searchDialog.clear(); for (BibtexEntry entry : panel.getDatabase().getEntries()) { if (entry.isSearchHit()) { searchDialog.addEntry(entry, panel); } } searchDialog.selectFirstEntry(); searchDialog.setVisible(true); } else if (hideSearch.isSelected()) { // Filtering search - removes non-hits from the table: if (startedFloatSearch) { panel.mainTable.stopShowingFloatSearch(); startedFloatSearch = false; } startedFilterSearch = true; panel.setSearchMatcher(new SearchMatcher()); } else { // Float search - floats hits to the top of the table: if (startedFilterSearch) { panel.stopShowingSearchResults(); startedFilterSearch = false; } startedFloatSearch = true; panel.mainTable.showFloatSearch(new SearchMatcher()); } // Afterwards, select all text in the search field. searchField.select(0, searchField.getText().length()); }