public void open() { progressArea.setText(""); canceled = false; Util.placeDialog(optDiag, panel.frame()); okButton.setEnabled(false); cancelButton.setEnabled(true); new FocusRequester(okButton); optDiag.setVisible(true); }
@Override public void actionPerformed(ActionEvent e) { BasePanel bp = frame.basePanel(); if (bp == null) { return; } BibtexEntry[] entries = bp.getSelectedEntries(); // Lazy creation of the dialog: if (diag == null) { createDialog(); } cancelled = true; prepareDialog(entries.length > 0); Util.placeDialog(diag, frame); diag.setVisible(true); if (cancelled) { return; } Collection<BibtexEntry> entryList; // If all entries should be treated, change the entries array: if (all.isSelected()) { entryList = bp.database().getEntries(); } else { entryList = Arrays.asList(entries); } String toSet = text.getText(); if (toSet.isEmpty()) { toSet = null; } String[] fields = getFieldNames(field.getText().trim().toLowerCase()); NamedCompound ce = new NamedCompound(Globals.lang("Set field")); if (rename.isSelected()) { if (fields.length > 1) { // TODO: message: can only rename a single field } else { ce.addEdit( Util.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected())); } } else { for (String field1 : fields) { ce.addEdit( Util.massSetField( entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected())); } } ce.end(); bp.undoManager.addEdit(ce); bp.markBaseChanged(); }
private BibtexEntry createNewEntry() { // Find out what type is wanted. EntryTypeDialog etd = new EntryTypeDialog(frame); // We want to center the dialog, to make it look nicer. Util.placeDialog(etd, frame); etd.setVisible(true); BibtexEntryType type = etd.getChoice(); if (type != null) { // Only if the dialog was not cancelled. String id = Util.createNeutralId(); final BibtexEntry be = new BibtexEntry(id, type); try { panel.database().insertEntry(be); // Set owner/timestamp if options are enabled: ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>(); list.add(be); Util.setAutomaticFields(list, true, true, false); // Create an UndoableInsertEntry object. panel.undoManager.addEdit(new UndoableInsertEntry(panel.database(), be, panel)); panel.output( Globals.lang("Added new") + " '" + type.getName().toLowerCase() + "' " + Globals.lang("entry") + "."); // We are going to select the new entry. Before that, make sure that we are in // show-entry mode. If we aren't already in that mode, enter the WILL_SHOW_EDITOR // mode which makes sure the selection will trigger display of the entry editor // and adjustment of the splitter. if (panel.getMode() != panel.SHOWING_EDITOR) { panel.setMode(panel.WILL_SHOW_EDITOR); } /*int row = entryTable.findEntry(be); if (row >= 0) // Selects the entry. The selection listener will open the editor. if (row >= 0) { try{ entryTable.setRowSelectionInterval(row, row); }catch(IllegalArgumentException e){ System.out.println("RowCount: " + entryTable.getRowCount()); } //entryTable.setActiveRow(row); entryTable.ensureVisible(row); } else { // The entry is not visible in the table, perhaps due to a filtering search // or group selection. Show the entry editor anyway: panel.showEntry(be); } */ panel.showEntry(be); panel.markBaseChanged(); // The database just changed. new FocusRequester(panel.getEntryEditor(be)); return be; } catch (KeyCollisionException ex) { Util.pr(ex.getMessage()); } } return null; }