Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special field editor for fields with entry keys #1637

Merged
merged 10 commits into from
Sep 20, 2016
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 @@ -520,8 +520,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 @@ -142,6 +143,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