@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(); }
@Override public JPanel getSettingsPanel() { if (settings == null) { initSettingsPanel(); } lyxPipe.setText(Globals.prefs.get(JabRefPreferences.LYXPIPE)); return settings; }
/** * This method presents a dialog box explaining and offering to make the changes. If the user * confirms, the changes are performed. * * @param panel * @param parserResult */ @Override public void performAction(BasePanel panel, ParserResult parserResult) { if (!isThereSomethingToBeDone()) { return; // Nothing to do, just return. } JCheckBox changeSettings = new JCheckBox( Localization.lang( "Change table column and General fields settings to use the new feature"), offerChangeSettings); JCheckBox changeDatabase = new JCheckBox( Localization.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase); JCheckBox setFileDir = new JCheckBox(Localization.lang("Set main external file directory") + ":", offerSetFileDir); JTextField fileDir = new JTextField(30); JCheckBox doNotShowDialog = new JCheckBox(Localization.lang("Do not show these options in the future"), false); JPanel message = new JPanel(); FormBuilder formBuilder = FormBuilder.create().layout(new FormLayout("left:pref", "p")); // Keep the formatting of these lines. Otherwise, strings have to be translated again. // See updated JabRef_en.properties modifications by python syncLang.py -s -u int row = 1; formBuilder .add( new JLabel( "<html>" + Localization.lang("This database uses outdated file links.") + "<br><br>" + Localization.lang( "JabRef no longer supports 'ps' or 'pdf' fields.<br>File links are now stored in the 'file' field and files are stored in an external file directory.<br>To make use of this feature, JabRef needs to upgrade file links.<br><br>") + "<p>" + Localization.lang("Do you want JabRef to do the following operations?") + "</html>")) .xy(1, row); if (offerChangeSettings) { formBuilder.appendRows("2dlu, p"); row += 2; formBuilder.add(changeSettings).xy(1, row); } if (offerChangeDatabase) { formBuilder.appendRows("2dlu, p"); row += 2; formBuilder.add(changeDatabase).xy(1, row); } if (offerSetFileDir) { if (Globals.prefs.hasKey("pdfDirectory")) { fileDir.setText(Globals.prefs.get("pdfDirectory")); } else { fileDir.setText(Globals.prefs.get("psDirectory")); } JPanel builderPanel = new JPanel(); builderPanel.add(setFileDir); builderPanel.add(fileDir); JButton browse = new JButton(Localization.lang("Browse")); browse.addActionListener(BrowseAction.buildForDir(fileDir)); builderPanel.add(browse); formBuilder.appendRows("2dlu, p"); row += 2; formBuilder.add(builderPanel).xy(1, row); } formBuilder.appendRows("6dlu, p"); formBuilder.add(doNotShowDialog).xy(1, row + 2); message.add(formBuilder.build()); int answer = JOptionPane.showConfirmDialog( panel.frame(), message, Localization.lang("Upgrade file"), JOptionPane.YES_NO_OPTION); if (doNotShowDialog.isSelected()) { Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false); } if (answer == JOptionPane.YES_OPTION) { makeChanges( panel, parserResult, changeSettings.isSelected(), changeDatabase.isSelected(), setFileDir.isSelected() ? fileDir.getText() : null); } }
@Override public void storeSettings() { Globals.prefs.put(JabRefPreferences.LYXPIPE, lyxPipe.getText()); }
/** * This method presents a dialog box explaining and offering to make the changes. If the user * confirms, the changes are performed. * * @param panel * @param pr */ @Override public void performAction(BasePanel panel, ParserResult pr) { // Find out which actions should be offered: // Only offer to change Preferences if file column is not already visible: boolean offerChangeSettings = !Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN) || !showsFileInGenFields(); // Only offer to upgrade links if the pdf/ps fields are used: boolean offerChangeDatabase = linksFound(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR); // If the "file" directory is not set, offer to migrate pdf/ps dir: boolean offerSetFileDir = !Globals.prefs.hasKey(GUIGlobals.FILE_FIELD + "Directory") && (Globals.prefs.hasKey("pdfDirectory") || Globals.prefs.hasKey("psDirectory")); if (!offerChangeDatabase && !offerChangeSettings && !offerSetFileDir) { return; // Nothing to do, just return. } JCheckBox changeSettings = new JCheckBox( Globals.lang("Change table column and General fields settings to use the new feature"), offerChangeSettings); JCheckBox changeDatabase = new JCheckBox( Globals.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase); JCheckBox setFileDir = new JCheckBox(Globals.lang("Set main external file directory") + ":", offerSetFileDir); JTextField fileDir = new JTextField(30); JCheckBox doNotShowDialog = new JCheckBox(Globals.lang("Do not show these options in the future"), false); JPanel message = new JPanel(); DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref", ""), message); // Keep the formatting of these lines. Otherwise, strings have to be translated again. // See updated JabRef_en.properties modifications by python syncLang.py -s -u b.append( new JLabel( "<html>" + Globals.lang("This database was written using an older version of JabRef.") + "<br>" + Globals.lang( "The current version features a new way of handling links to external files.<br>To take advantage of this, your links must be changed into the new format, and<br>JabRef must be configured to show the new links.") + "<p>" + Globals.lang("Do you want JabRef to do the following operations?") + "</html>")); b.nextLine(); if (offerChangeSettings) { b.append(changeSettings); b.nextLine(); } if (offerChangeDatabase) { b.append(changeDatabase); b.nextLine(); } if (offerSetFileDir) { if (Globals.prefs.hasKey("pdfDirectory")) { fileDir.setText(Globals.prefs.get("pdfDirectory")); } else { fileDir.setText(Globals.prefs.get("psDirectory")); } JPanel pan = new JPanel(); pan.add(setFileDir); pan.add(fileDir); JButton browse = new JButton(Globals.lang("Browse")); browse.addActionListener(BrowseAction.buildForDir(fileDir)); pan.add(browse); b.append(pan); b.nextLine(); } b.append(""); b.nextLine(); b.append(doNotShowDialog); int answer = JOptionPane.showConfirmDialog( panel.frame(), message, Globals.lang("Upgrade file"), JOptionPane.YES_NO_OPTION); if (doNotShowDialog.isSelected()) { Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false); } if (answer == JOptionPane.YES_OPTION) { makeChanges( panel, pr, changeSettings.isSelected(), changeDatabase.isSelected(), setFileDir.isSelected() ? fileDir.getText() : null); } }
private void createDialog() { diag = new JDialog(frame, Globals.lang("Set/clear/rename fields"), true); field = new JTextField(); text = new JTextField(); text.setEnabled(false); renameTo = new JTextField(); renameTo.setEnabled(false); JButton ok = new JButton(Globals.lang("Ok")); JButton cancel = new JButton(Globals.lang("Cancel")); all = new JRadioButton(Globals.lang("All entries")); selected = new JRadioButton(Globals.lang("Selected entries")); clear = new JRadioButton(Globals.lang("Clear fields")); set = new JRadioButton(Globals.lang("Set fields")); rename = new JRadioButton(Globals.lang("Rename field to:")); rename.setToolTipText( Globals.lang("Move contents of a field into a field with a different name")); set.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { // Entering a text is only relevant if we are setting, not clearing: text.setEnabled(set.isSelected()); } }); clear.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { // Overwrite protection makes no sense if we are clearing the field: overwrite.setEnabled(!clear.isSelected()); } }); rename.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { // Entering a text is only relevant if we are renaming renameTo.setEnabled(rename.isSelected()); } }); overwrite = new JCheckBox(Globals.lang("Overwrite existing field values"), true); ButtonGroup bg = new ButtonGroup(); bg.add(all); bg.add(selected); bg = new ButtonGroup(); bg.add(clear); bg.add(set); bg.add(rename); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:100dlu", "")); builder.appendSeparator(Globals.lang("Field name")); builder.append(Globals.lang("Field name")); builder.append(field); builder.nextLine(); builder.appendSeparator(Globals.lang("Include entries")); builder.append(all, 3); builder.nextLine(); builder.append(selected, 3); builder.nextLine(); builder.appendSeparator(Globals.lang("New field value")); builder.append(set); builder.append(text); builder.nextLine(); builder.append(clear); builder.nextLine(); builder.append(rename); builder.append(renameTo); builder.nextLine(); builder.append(overwrite, 3); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(ok); bb.addButton(cancel); bb.addGlue(); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER); diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); diag.pack(); ok.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Check if the user tries to rename multiple fields: if (rename.isSelected()) { String[] fields = getFieldNames(field.getText()); if (fields.length > 1) { JOptionPane.showMessageDialog( diag, Globals.lang("You can only rename one field at a time"), "", JOptionPane.ERROR_MESSAGE); return; // Do not close the dialog. } } cancelled = false; diag.dispose(); } }); AbstractAction cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancelled = true; diag.dispose(); } }; cancel.addActionListener(cancelAction); // Key bindings: ActionMap am = builder.getPanel().getActionMap(); InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.prefs.getKey("Close dialog"), "close"); am.put("close", cancelAction); }
@Override public void storeSettings() { super.storeSettings(); Globals.prefs.put(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS, additionalParams.getText()); Globals.prefs.putBoolean(JabRefPreferences.EMACS_23, useEmacs23.isSelected()); }
@Override public JPanel getSettingsPanel() { additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); useEmacs23.setSelected(Globals.prefs.getBoolean(JabRefPreferences.EMACS_23)); return super.getSettingsPanel(); }