Skip to content

Commit

Permalink
Reimplement journal editior in JavaFX
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Apr 18, 2017
1 parent 472ca3c commit 9f04b08
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 131 deletions.
5 changes: 0 additions & 5 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,6 @@ public Optional<JComponent> getExtra(final FieldEditor editor) {
fieldExtras.contains(FieldProperty.DATE), fieldExtras.contains(FieldProperty.ISO_DATE));
} else if (fieldExtras.contains(FieldProperty.EXTERNAL)) {
return FieldExtraComponents.getExternalExtraComponent(panel, editor);
} else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) {
// Add controls for switching between abbreviated and full journal names.
// If this field also has a FieldContentSelector, we need to combine these.
return FieldExtraComponents.getJournalExtraComponent(frame, panel, editor, entry, contentSelectors,
storeFieldAction);
} else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) {
return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors,
storeFieldAction);
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField
fieldEditor.setAutoCompleteListener(autoCompleteListener);
*/

FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService());
FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences());
editors.put(fieldName, fieldEditor);
/*
// TODO: Reenable this
Expand All @@ -182,6 +182,18 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField
}
*/

/*
// TODO: Reenable content selector
if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(editor.getFieldName()).isEmpty()) {
FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, editor, storeFieldAction, false,
", ");
contentSelectors.add(ws);
controls.add(ws, BorderLayout.NORTH);
}
//} else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) {
//return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, storeFieldAction);
*/

builder.append(new FieldNameLabel(fieldName));

JFXPanel swingPanel = new JFXPanel();
Expand Down
51 changes: 0 additions & 51 deletions src/main/java/org/jabref/gui/entryeditor/FieldExtraComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.entryeditor.EntryEditor.StoreFieldAction;
import org.jabref.gui.fieldeditors.FieldEditor;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldProperty;
import org.jabref.model.entry.InternalBibtexFields;
import org.jabref.model.entry.Month;
Expand All @@ -40,58 +37,10 @@
public class FieldExtraComponents {

private static final Log LOGGER = LogFactory.getLog(FieldExtraComponents.class);
private static final String ABBREVIATION_TOOLTIP_TEXT = "<HTML>"
+ Localization.lang("Switches between full and abbreviated journal name if the journal name is known.")
+ "<BR>" + Localization.lang("To set up, go to") + " <B>" + Localization.lang("Options") + " -> "
+ Localization.lang("Manage journal abbreviations") + "</B></HTML>";

private FieldExtraComponents() {
}

/**
* Add controls for switching between abbreviated and full journal names.
* If this field also has a FieldContentSelector, we need to combine these.
*
* @param panel
* @param editor
* @param entry
* @param storeFieldAction
* @return
*/
public static Optional<JComponent> getJournalExtraComponent(JabRefFrame frame, BasePanel panel, FieldEditor editor,
BibEntry entry, Set<FieldContentSelector> contentSelectors, StoreFieldAction storeFieldAction) {
JPanel controls = new JPanel();
controls.setLayout(new BorderLayout());
if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(editor.getFieldName()).isEmpty()) {
FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, editor, storeFieldAction, false,
", ");
contentSelectors.add(ws);
controls.add(ws, BorderLayout.NORTH);
}


// Button to toggle abbreviated/full journal names
JButton button = new JButton(Localization.lang("Toggle abbreviation"));
button.setToolTipText(ABBREVIATION_TOOLTIP_TEXT);
button.addActionListener(actionEvent -> {
String text = editor.getText();
JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader
.getRepository(Globals.prefs.getJournalAbbreviationPreferences());
if (abbreviationRepository.isKnownName(text)) {
String s = abbreviationRepository.getNextAbbreviation(text).orElse(text);

if (s != null) {
editor.setText(s);
storeFieldAction.actionPerformed(new ActionEvent(editor, 0, ""));
panel.getUndoManager().addEdit(new UndoableFieldChange(entry, editor.getFieldName(), text, s));
}
}
});

controls.add(button, BorderLayout.SOUTH);
return Optional.of(controls);
}

/**
* Set up a mouse listener for opening an external viewer for with with EXTRA_EXTERNAL
*
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationPreferences;
import org.jabref.model.entry.FieldProperty;
import org.jabref.model.entry.InternalBibtexFields;
import org.jabref.preferences.JabRefPreferences;


public class FieldEditors {

public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService) {
public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) {
final Set<FieldProperty> fieldExtras = InternalBibtexFields.getFieldProperties(fieldName);

// TODO: Implement this
Expand All @@ -24,11 +26,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu
} else if (fieldExtras.contains(FieldProperty.EXTERNAL)) {
//return FieldExtraComponents.getExternalExtraComponent(panel, editor);
} else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) {
// Add controls for switching between abbreviated and full journal names.
// If this field also has a FieldContentSelector, we need to combine these.
//return FieldExtraComponents.getJournalExtraComponent(frame, panel, editor, entry, contentSelectors, storeFieldAction);
//} else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) {
//return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, storeFieldAction);
return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences);
} else if (fieldExtras.contains(FieldProperty.DOI) ||
fieldExtras.contains(FieldProperty.EPRINT) ||
fieldExtras.contains(FieldProperty.ISBN)) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/gui/fieldeditors/JournalEditor.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.HBox?>
<?import org.jabref.gui.fieldeditors.EditorTextArea?>
<?import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView?>
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="HBox" xmlns="http://javafx.com/javafx/8.0.112">
<EditorTextArea fx:id="textArea" prefHeight="0.0" text="Halo" HBox.hgrow="ALWAYS"/>
<Button onAction="#toggleAbbreviation"
styleClass="flatButton">
<graphic>
<MaterialDesignIconView glyphName="TEXT_SHADOW"/>
</graphic>
<tooltip>
<Tooltip text="%Switches between full and abbreviated journal name if the journal name is known."/>
</tooltip>
</Button>
</fx:root>
51 changes: 51 additions & 0 deletions src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jabref.gui.fieldeditors;

import java.util.Optional;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.layout.HBox;

import org.jabref.gui.util.ControlHelper;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationPreferences;
import org.jabref.model.entry.BibEntry;


public class JournalEditor extends HBox implements FieldEditorFX {

private final String fieldName;
@FXML private JournalEditorViewModel viewModel;
@FXML private EditorTextArea textArea;
private Optional<BibEntry> entry;

public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) {
this.fieldName = fieldName;
this.viewModel = new JournalEditorViewModel(journalAbbreviationLoader, journalAbbreviationPreferences);

ControlHelper.loadFXMLForControl(this);

viewModel.textProperty().bindBidirectional(textArea.textProperty());
}

public JournalEditorViewModel getViewModel() {
return viewModel;
}

@Override
public void bindToEntry(BibEntry entry) {
this.entry = Optional.of(entry);
textArea.bindToEntry(fieldName, entry);
}

@Override
public Parent getNode() {
return this;
}

@FXML
private void toggleAbbreviation(ActionEvent event) {
viewModel.toggleAbbreviation();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jabref.gui.fieldeditors;

import java.util.Optional;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.gui.AbstractViewModel;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.journals.JournalAbbreviationPreferences;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.model.strings.StringUtil;

public class JournalEditorViewModel extends AbstractViewModel {
private final JournalAbbreviationLoader journalAbbreviationLoader;
private final JournalAbbreviationPreferences journalAbbreviationPreferences;
private StringProperty text = new SimpleStringProperty();

public JournalEditorViewModel(JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) {
this.journalAbbreviationLoader = journalAbbreviationLoader;
this.journalAbbreviationPreferences = journalAbbreviationPreferences;
}

public StringProperty textProperty() {
return text;
}

public void toggleAbbreviation() {
if (StringUtil.isBlank(text.get())) {
return;
}

JournalAbbreviationRepository abbreviationRepository = journalAbbreviationLoader.getRepository(journalAbbreviationPreferences);
if (abbreviationRepository.isKnownName(text.get())) {
Optional<String> nextAbbreviation = abbreviationRepository.getNextAbbreviation(text.get());

if (nextAbbreviation.isPresent()) {
text.set(nextAbbreviation.get());
// TODO: Add undo
//panel.getUndoManager().addEdit(new UndoableFieldChange(entry, editor.getFieldName(), text, nextAbbreviation));
}
}
}
}
4 changes: 0 additions & 4 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ Manage_custom_exports=Opsæt_eksterne_eksportfiltre
Manage_custom_imports=Opsæt_eksterne_importfiltre
Manage_external_file_types=Opsæt_eksterne_filtyper

Manage_journal_abbreviations=Opsæt_tidsskriftsforkortelser

Mark_entries=Mærk_poster

Mark_entry=Mærk_post
Expand Down Expand Up @@ -1252,7 +1250,6 @@ This_operation_requires_all_selected_entries_to_have_BibTeX_keys_defined.=Denne_

This_operation_requires_one_or_more_entries_to_be_selected.=Denne_operation_kræver,_at_en_eller_flere_poster_er_valgt.

Toggle_abbreviation=Forkort/ekspander
Toggle_entry_preview=Vis/skjul_forhåndsvisning
Toggle_groups_interface=Vis/skjul_grupperingspanel
Try_different_encoding=Prøv_en_anden_tegnkodning
Expand Down Expand Up @@ -1852,7 +1849,6 @@ Copy_title=
Copy_\\cite{BibTeX_key}=Kopier_\\cite{BibTeX-nøgler}
Copy_BibTeX_key_and_title=
File_rename_failed_for_%0_entries.=
To_set_up,_go_to=For_at_sætte_op,_gå_til
Merged_BibTeX_source_code=
Invalid_DOI\:_'%0'.=Ugyldig_DOI\:_'%0'.
should_start_with_a_name=
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ Manage_custom_exports=Verwalte_externe_Exportfilter
Manage_custom_imports=Verwalte_externe_Importfilter
Manage_external_file_types=Externe_Dateitypen_verwalten

Manage_journal_abbreviations=Abkürzungen_der_Zeitschriften_verwalten

Mark_entries=Einträge_markieren

Mark_entry=Eintrag_markieren
Expand Down Expand Up @@ -1252,7 +1250,6 @@ This_operation_requires_all_selected_entries_to_have_BibTeX_keys_defined.=Für_d

This_operation_requires_one_or_more_entries_to_be_selected.=Für_diesen_Vorgang_muss_mindestens_ein_Eintrag_ausgewählt_sein.

Toggle_abbreviation=Abkürzung_an-/abschalten
Toggle_entry_preview=Eintragsvorschau_ein-/ausblenden
Toggle_groups_interface=Gruppenansicht_ein-/ausblenden
Try_different_encoding=Versuchen_Sie_es_mit_einer_anderen_Kodierung
Expand Down Expand Up @@ -1852,7 +1849,6 @@ Copy_title=Kopiere_Titel
Copy_\\cite{BibTeX_key}=\\cite{BibTeX_key}_kopieren
Copy_BibTeX_key_and_title=BibTeX-Key_und_Titel_kopieren
File_rename_failed_for_%0_entries.=Dateiumbennung_schlug_ür_%0_Einträge_fehl.
To_set_up,_go_to=Einstellungen_unter
Merged_BibTeX_source_code=BibTeX-Quelltext_zusammengeführt
Invalid_DOI\:_'%0'.=Ungültiger_DOI\:_'%0'.
should_start_with_a_name=sollte_mit_einem_Name_beginnen
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ Manage_custom_exports=Manage_custom_exports
Manage_custom_imports=Manage_custom_imports
Manage_external_file_types=Manage_external_file_types

Manage_journal_abbreviations=Manage_journal_abbreviations

Mark_entries=Mark_entries

Mark_entry=Mark_entry
Expand Down Expand Up @@ -1252,7 +1250,6 @@ This_operation_requires_all_selected_entries_to_have_BibTeX_keys_defined.=This_o

This_operation_requires_one_or_more_entries_to_be_selected.=This_operation_requires_one_or_more_entries_to_be_selected.

Toggle_abbreviation=Toggle_abbreviation
Toggle_entry_preview=Toggle_entry_preview
Toggle_groups_interface=Toggle_groups_interface
Try_different_encoding=Try_different_encoding
Expand Down Expand Up @@ -1852,7 +1849,6 @@ Copy_title=Copy_title
Copy_\\cite{BibTeX_key}=Copy_\\cite{BibTeX_key}
Copy_BibTeX_key_and_title=Copy_BibTeX_key_and_title
File_rename_failed_for_%0_entries.=File_rename_failed_for_%0_entries.
To_set_up,_go_to=To_set_up,_go_to
Merged_BibTeX_source_code=Merged_BibTeX_source_code
Invalid_DOI\:_'%0'.=Invalid_DOI\:_'%0'.
should_start_with_a_name=should_start_with_a_name
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ Manage_custom_exports=Administrar_esportaciones_personalizadas
Manage_custom_imports=Administrar_importaciones_personalizadas
Manage_external_file_types=Administrar_tipos_de_archivo_externos

Manage_journal_abbreviations=Administrar_abreviaturas_de_revistas

Mark_entries=Marcar_entradas

Mark_entry=Marcar_entrada
Expand Down Expand Up @@ -1252,7 +1250,6 @@ This_operation_requires_all_selected_entries_to_have_BibTeX_keys_defined.=Esta_o

This_operation_requires_one_or_more_entries_to_be_selected.=Esta_operación_requiere_seleccionar_una_o_más_entradas.

Toggle_abbreviation=Usar_abreviatura_si/no
Toggle_entry_preview=Usar_vista_previa_de_la_entrada_si/no
Toggle_groups_interface=Usar_interfaz_de_grupos_si/no
Try_different_encoding=Probar_una_codificación_diferente
Expand Down Expand Up @@ -1852,7 +1849,6 @@ Copy_title=
Copy_\\cite{BibTeX_key}=Copiar_\\cite{clave_BibTeX}
Copy_BibTeX_key_and_title=Copiar_clave_y_título_BibTeX
File_rename_failed_for_%0_entries.=Ha_fallado_el_renombrado_para_%0_entradas.
To_set_up,_go_to=Para_configurar,_vaya_a
Merged_BibTeX_source_code=Código_fuente_BibTex_fusionado
Invalid_DOI\:_'%0'.=DOI_no_válida\:_'%0'.
should_start_with_a_name=debería_comenzar_por_un_nombre
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ Manage_custom_exports=
Manage_custom_imports=
Manage_external_file_types=

Manage_journal_abbreviations=

Mark_entries=

Mark_entry=
Expand Down Expand Up @@ -1252,7 +1250,6 @@ This_operation_requires_all_selected_entries_to_have_BibTeX_keys_defined.=

This_operation_requires_one_or_more_entries_to_be_selected.=

Toggle_abbreviation=
Toggle_entry_preview=
Toggle_groups_interface=
Try_different_encoding=
Expand Down Expand Up @@ -1852,7 +1849,6 @@ Copy_title=
Copy_\\cite{BibTeX_key}=
Copy_BibTeX_key_and_title=
File_rename_failed_for_%0_entries.=
To_set_up,_go_to=
Merged_BibTeX_source_code=
Invalid_DOI\:_'%0'.=
should_start_with_a_name=
Expand Down
Loading

0 comments on commit 9f04b08

Please sign in to comment.