-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement option field editors in JavaFX (#2824)
* Reimplement option field editors in JavaFX * Update localization * Update EditorTypeEditorViewModel.java * Update GenderEditorViewModel.java * Update PaginationEditorViewModel.java * Update PatentTypeEditorViewModel.java * Update TypeEditorViewModel.java * Update YesNoEditorViewModel.java
- Loading branch information
1 parent
98e2e43
commit 4543592
Showing
32 changed files
with
364 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.google.common.collect.HashBiMap; | ||
|
||
public class EditorTypeEditorViewModel extends MapBasedEditorViewModel<String> { | ||
|
||
private BiMap<String, String> itemMap = HashBiMap.create(7); | ||
|
||
public EditorTypeEditorViewModel() { | ||
itemMap.put("editor", Localization.lang("Editor")); | ||
itemMap.put("compiler", Localization.lang("Compiler")); | ||
itemMap.put("founder", Localization.lang("Founder")); | ||
itemMap.put("continuator", Localization.lang("Continuator")); | ||
itemMap.put("redactor", Localization.lang("Redactor")); | ||
itemMap.put("reviser", Localization.lang("Reviser")); | ||
itemMap.put("collaborator", Localization.lang("Collaborator")); | ||
} | ||
|
||
@Override | ||
protected BiMap<String, String> getItemMap() { | ||
return itemMap; | ||
} | ||
|
||
@Override | ||
public String convertToDisplayText(String object) { | ||
return object; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.google.common.collect.HashBiMap; | ||
|
||
public class GenderEditorViewModel extends MapBasedEditorViewModel<String> { | ||
|
||
private BiMap<String, String> itemMap = HashBiMap.create(7); | ||
|
||
public GenderEditorViewModel() { | ||
itemMap.put("sf", Localization.lang("Female name")); | ||
itemMap.put("sm", Localization.lang("Male name")); | ||
itemMap.put("sn", Localization.lang("Neuter name")); | ||
itemMap.put("pf", Localization.lang("Female names")); | ||
itemMap.put("pm", Localization.lang("Male names")); | ||
itemMap.put("pn", Localization.lang("Neuter names")); | ||
itemMap.put("pp", Localization.lang("Mixed names")); | ||
} | ||
|
||
@Override | ||
protected BiMap<String, String> getItemMap() { | ||
return itemMap; | ||
} | ||
|
||
@Override | ||
public String convertToDisplayText(String object) { | ||
return object; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javafx.util.StringConverter; | ||
|
||
import com.google.common.collect.BiMap; | ||
|
||
/** | ||
* View model for a field editor that shows various options backed by a map. | ||
*/ | ||
public abstract class MapBasedEditorViewModel<T> extends OptionEditorViewModel<T> { | ||
|
||
protected abstract BiMap<String, T> getItemMap(); | ||
|
||
@Override | ||
public StringConverter<T> getStringConverter() { | ||
return new StringConverter<T>() { | ||
@Override | ||
public String toString(T object) { | ||
if (object == null) { | ||
return null; | ||
} else { | ||
return getItemMap().inverse().getOrDefault(object, ""); | ||
} | ||
} | ||
|
||
@Override | ||
public T fromString(String string) { | ||
if (string == null) { | ||
return null; | ||
} else { | ||
return getItemMap().getOrDefault(string, null); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public List<T> getItems() { | ||
return new ArrayList<>(getItemMap().values()); | ||
} | ||
} |
Oops, something went wrong.