Skip to content

Commit

Permalink
Special field editor for fields with entry keys (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus authored and koppor committed Sep 20, 2016
1 parent 5186b9e commit 67583d9
Show file tree
Hide file tree
Showing 11 changed files with 698 additions and 50 deletions.
2 changes: 0 additions & 2 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,6 @@ public Optional<JComponent> getExtra(final FieldEditor editor) {
return FieldExtraComponents.getPaginationExtraComponent(editor, this);
} else if (fieldExtras.contains(FieldProperty.TYPE)) {
return FieldExtraComponents.getTypeExtraComponent(editor, this, "patent".equalsIgnoreCase(entry.getType()));
} else if (fieldExtras.contains(FieldProperty.CROSSREF)) {
return FieldExtraComponents.getCrossrefExtraComponent(editor, frame.getCurrentBasePanel());
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.autocompleter.AutoCompleteListener;
import net.sf.jabref.gui.fieldeditors.EntryLinkListEditor;
import net.sf.jabref.gui.fieldeditors.FieldEditor;
import net.sf.jabref.gui.fieldeditors.FileListEditor;
import net.sf.jabref.gui.fieldeditors.TextArea;
Expand Down Expand Up @@ -141,6 +142,14 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField
GUIUtil.correctRowHeight(fileListEditor);

defaultHeight = 0;
} else if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.SINGLE_ENTRY_LINK)) {
fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
true);
defaultHeight = 0;
} else if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
false);
defaultHeight = 0;
} else {
fieldEditor = new TextArea(field, null);
bPanel.frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener((TextArea) fieldEditor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,51 +549,4 @@ public static Optional<JComponent> getGenderExtraComponent(FieldEditor fieldEdit

}

/**
* Return a button which allows to go to the parent entry of the crossref field
* @param fieldEditor The FieldEditor component to get the entry key from
* @param panel The current BasePanel
* @return
*/

public static Optional<JComponent> getCrossrefExtraComponent(FieldEditor fieldEditor,
BasePanel panel) {
JButton button = new JButton(Localization.lang("Select"));
JTextComponent crossref = (JTextComponent) fieldEditor;

button.addActionListener(
actionEvent -> panel.getDatabase().getEntryByKey(crossref.getText()).ifPresent(e -> panel.highlightEntry(e))
);

// enable/disable button
crossref.getDocument().addDocumentListener(new DocumentListener() {

@Override
public void changedUpdate(DocumentEvent documentEvent) {
checkValidKey();
}

@Override
public void insertUpdate(DocumentEvent documentEvent) {
checkValidKey();
}

@Override
public void removeUpdate(DocumentEvent documentEvent) {
checkValidKey();
}

private void checkValidKey() {
if (panel.getDatabase().getEntryByKey(crossref.getText()) != null) {
button.setEnabled(true);
} else {
button.setEnabled(false);
}
}
});

return Optional.of(button);

}

}
Loading

0 comments on commit 67583d9

Please sign in to comment.