Search in sources :

Example 1 with FieldName

use of org.jabref.model.entry.FieldName in project jabref by JabRef.

the class ContentSelectorDialog method setupActions.

private void setupActions() {
    wordList.addListSelectionListener(e -> {
        wordEditField.setText(wordList.getSelectedValue());
        wordEditField.selectAll();
        wordEditField.requestFocus();
    });
    newWord.addActionListener(e -> newWordAction());
    ActionListener wordEditFieldListener = e -> actOnWordEdit();
    wordEditField.addActionListener(wordEditFieldListener);
    removeWord.addActionListener(e -> {
        int index = wordList.getSelectedIndex();
        if (index == -1) {
            return;
        }
        wordListModel.remove(index);
        wordEditField.setText("");
        if (!wordListModel.isEmpty()) {
            wordList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
        }
    });
    fieldList.addListSelectionListener(e -> {
        currentField = fieldList.getSelectedValue();
        fieldNameField.setText("");
        setupWordSelector();
    });
    newField.addActionListener(e -> {
        if (!fieldListModel.get(0).equals(FIELD_FIRST_LINE)) {
            fieldListModel.add(0, FIELD_FIRST_LINE);
        }
        fieldList.setSelectedIndex(0);
        fPane.getVerticalScrollBar().setValue(0);
        fieldNameField.setEnabled(true);
        fieldNameField.setText(currentField);
        fieldNameField.selectAll();
        fieldNameField.requestFocus();
    });
    fieldNameField.addActionListener(e -> fieldNameField.transferFocus());
    fieldNameField.addFocusListener(new FieldNameFocusAdapter());
    removeField.addActionListener(e -> {
        int index = fieldList.getSelectedIndex();
        if (index == -1) {
            return;
        }
        String fieldName = fieldListModel.get(index);
        removedFields.add(fieldName);
        fieldListModel.remove(index);
        wordListModels.remove(fieldName);
        fieldNameField.setText("");
        if (!fieldListModel.isEmpty()) {
            fieldList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
        }
    });
    ok.addActionListener(e -> {
        try {
            applyChanges();
            dispose();
        } catch (Exception ex) {
            LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes."));
        }
    });
    apply.addActionListener(e -> {
        if (!"".equals(wordEditField.getText())) {
            wordEditFieldListener.actionPerformed(null);
        }
        try {
            applyChanges();
        } catch (Exception ex) {
            LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes."));
        }
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    cancelAction.putValue(Action.NAME, Localization.lang("Cancel"));
    cancel.setAction(cancelAction);
}
Also used : Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) SortedSet(java.util.SortedSet) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) ContentSelector(org.jabref.model.metadata.ContentSelector) HashMap(java.util.HashMap) ContentSelectors(org.jabref.model.metadata.ContentSelectors) Action(javax.swing.Action) BasePanel(org.jabref.gui.BasePanel) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FocusAdapter(java.awt.event.FocusAdapter) JabRefFrame(org.jabref.gui.JabRefFrame) Map(java.util.Map) MetaData(org.jabref.model.metadata.MetaData) Localization(org.jabref.logic.l10n.Localization) KeyBinder(org.jabref.gui.keyboard.KeyBinder) HelpFile(org.jabref.logic.help.HelpFile) JButton(javax.swing.JButton) Window(java.awt.Window) JList(javax.swing.JList) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) JScrollPane(javax.swing.JScrollPane) List(java.util.List) JabRefDialog(org.jabref.gui.JabRefDialog) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) FocusEvent(java.awt.event.FocusEvent) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) HelpAction(org.jabref.gui.help.HelpAction) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) HelpAction(org.jabref.gui.help.HelpAction) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 2 with FieldName

use of org.jabref.model.entry.FieldName in project jabref by JabRef.

the class MainTableSelectionListener method mouseClicked.

@Override
public void mouseClicked(MouseEvent e) {
    // First find the column on which the user has clicked.
    final int row = table.rowAtPoint(e.getPoint());
    // A double click on an entry should open the entry's editor.
    if (e.getClickCount() == 2) {
        BibEntry toShow = tableRows.get(row);
        editSignalled(toShow);
        return;
    }
    final int col = table.columnAtPoint(e.getPoint());
    // get the MainTableColumn which is currently visible at col
    int modelIndex = table.getColumnModel().getColumn(col).getModelIndex();
    MainTableColumn modelColumn = table.getMainTableColumn(modelIndex);
    // action will be taken when the button is released:
    if (OS.WINDOWS && (modelColumn.isIconColumn()) && (e.getButton() != MouseEvent.BUTTON1)) {
        return;
    }
    // Check if the clicked colum is a specialfield column
    if (modelColumn.isIconColumn() && (SpecialField.isSpecialField(modelColumn.getColumnName()))) {
        // handle specialfield
        handleSpecialFieldLeftClick(e, modelColumn.getColumnName());
    } else if (modelColumn.isIconColumn()) {
        // left click on icon field
        Object value = table.getValueAt(row, col);
        if (value == null) {
            // No icon here, so we do nothing.
            return;
        }
        final BibEntry entry = tableRows.get(row);
        final List<String> fieldNames = modelColumn.getBibtexFields();
        // Open it now. We do this in a thread, so the program won't freeze during the wait.
        JabRefExecutorService.INSTANCE.execute(() -> {
            panel.output(Localization.lang("External viewer called") + '.');
            // (is relevant for combinations such as "url/doi")
            for (String fieldName : fieldNames) {
                // Check if field is present, if not skip this field
                if (entry.hasField(fieldName)) {
                    String link = entry.getField(fieldName).get();
                    // field that can specify a list of links:
                    if (fieldName.equals(FieldName.FILE)) {
                        // We use a FileListTableModel to parse the field content:
                        FileListTableModel fileList = new FileListTableModel();
                        fileList.setContent(link);
                        FileListEntry flEntry = null;
                        // If there are one or more links of the correct type, open the first one:
                        if (modelColumn.isFileFilter()) {
                            for (int i = 0; i < fileList.getRowCount(); i++) {
                                if (fileList.getEntry(i).getType().toString().equals(modelColumn.getColumnName())) {
                                    flEntry = fileList.getEntry(i);
                                    break;
                                }
                            }
                        } else if (fileList.getRowCount() > 0) {
                            //If there are no file types specified open the first file
                            flEntry = fileList.getEntry(0);
                        }
                        if (flEntry != null) {
                            ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "", flEntry.getLink(), flEntry.getType().map(ExternalFileType::getIcon).orElse(null), panel.getBibDatabaseContext(), flEntry.getType());
                            item.doClick();
                        }
                    } else {
                        try {
                            JabRefDesktop.openExternalViewer(panel.getBibDatabaseContext(), link, fieldName);
                        } catch (IOException ex) {
                            panel.output(Localization.lang("Unable to open link."));
                            LOGGER.info("Unable to open link", ex);
                        }
                    }
                    // only open the first link
                    break;
                }
            }
        });
    } else if (modelColumn.getBibtexFields().contains(FieldName.CROSSREF)) {
        // Clicking on crossref column
        tableRows.get(row).getField(FieldName.CROSSREF).ifPresent(crossref -> panel.getDatabase().getEntryByKey(crossref).ifPresent(entry -> panel.highlightEntry(entry)));
    }
    panel.frame().updateEnabledState();
}
Also used : FocusListener(java.awt.event.FocusListener) KeyListener(java.awt.event.KeyListener) PreviewPanel(org.jabref.gui.PreviewPanel) FieldName(org.jabref.model.entry.FieldName) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop) IconTheme(org.jabref.gui.IconTheme) SpecialField(org.jabref.model.entry.specialfields.SpecialField) BasePanel(org.jabref.gui.BasePanel) SpecialFieldValue(org.jabref.model.entry.specialfields.SpecialFieldValue) SwingUtilities(javax.swing.SwingUtilities) SpecialFieldViewModel(org.jabref.gui.specialfields.SpecialFieldViewModel) Locale(java.util.Locale) SpecialFieldValueViewModel(org.jabref.gui.specialfields.SpecialFieldValueViewModel) Localization(org.jabref.logic.l10n.Localization) CopyDoiUrlAction(org.jabref.gui.actions.CopyDoiUrlAction) SpecialFieldMenuAction(org.jabref.gui.specialfields.SpecialFieldMenuAction) MouseListener(java.awt.event.MouseListener) Timer(javax.swing.Timer) ExternalFileType(org.jabref.gui.externalfiletype.ExternalFileType) BasePanelMode(org.jabref.gui.BasePanelMode) EventList(ca.odell.glazedlists.EventList) JPopupMenu(javax.swing.JPopupMenu) BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) IOException(java.io.IOException) Icon(javax.swing.Icon) JabRefGUI(org.jabref.JabRefGUI) EntryEditor(org.jabref.gui.entryeditor.EntryEditor) KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) Globals(org.jabref.Globals) FileListEntry(org.jabref.gui.filelist.FileListEntry) RightClickMenu(org.jabref.gui.menus.RightClickMenu) ListEvent(ca.odell.glazedlists.event.ListEvent) Objects(java.util.Objects) List(java.util.List) GUIGlobals(org.jabref.gui.GUIGlobals) ListEventListener(ca.odell.glazedlists.event.ListEventListener) FocusEvent(java.awt.event.FocusEvent) JLabel(javax.swing.JLabel) OS(org.jabref.logic.util.OS) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) JabRefExecutorService(org.jabref.JabRefExecutorService) ExternalFileMenuItem(org.jabref.gui.externalfiletype.ExternalFileMenuItem) PreviewPreferences(org.jabref.preferences.PreviewPreferences) BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) ExternalFileMenuItem(org.jabref.gui.externalfiletype.ExternalFileMenuItem) FileListEntry(org.jabref.gui.filelist.FileListEntry) EventList(ca.odell.glazedlists.EventList) List(java.util.List) IOException(java.io.IOException)

Aggregations

FocusEvent (java.awt.event.FocusEvent)2 List (java.util.List)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 BasePanel (org.jabref.gui.BasePanel)2 EventList (ca.odell.glazedlists.EventList)1 ListEvent (ca.odell.glazedlists.event.ListEvent)1 ListEventListener (ca.odell.glazedlists.event.ListEventListener)1 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 Window (java.awt.Window)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 FocusAdapter (java.awt.event.FocusAdapter)1 FocusListener (java.awt.event.FocusListener)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 MouseEvent (java.awt.event.MouseEvent)1