From 2ab9b3dd292bab0a55716f02acf26576c2907763 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 4 Sep 2022 18:00:34 +0200 Subject: [PATCH 1/4] Resimplify Action interface --- .../java/org/jabref/gui/actions/Action.java | 68 ------------------- .../sidebuttons/ToggleMergeUnmergeButton.java | 42 +++++++++--- 2 files changed, 34 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/jabref/gui/actions/Action.java b/src/main/java/org/jabref/gui/actions/Action.java index 28859e00225..e6ccfe487b2 100644 --- a/src/main/java/org/jabref/gui/actions/Action.java +++ b/src/main/java/org/jabref/gui/actions/Action.java @@ -1,6 +1,5 @@ package org.jabref.gui.actions; -import java.util.Objects; import java.util.Optional; import org.jabref.gui.icon.JabRefIcon; @@ -20,71 +19,4 @@ default Optional getKeyBinding() { default String getDescription() { return ""; } - - class Builder { - private final ActionImpl actionImpl; - - public Builder(String text) { - this.actionImpl = new ActionImpl(); - setText(text); - } - - public Builder() { - this(""); - } - - public Action setIcon(JabRefIcon icon) { - Objects.requireNonNull(icon); - actionImpl.icon = icon; - return actionImpl; - } - - public Action setText(String text) { - Objects.requireNonNull(text); - actionImpl.text = text; - return actionImpl; - } - - public Action setKeyBinding(KeyBinding keyBinding) { - Objects.requireNonNull(keyBinding); - actionImpl.keyBinding = keyBinding; - return actionImpl; - } - - public Action setDescription(String description) { - Objects.requireNonNull(description); - actionImpl.description = description; - return actionImpl; - } - } - - class ActionImpl implements Action { - private JabRefIcon icon; - private KeyBinding keyBinding; - private String text; - private String description; - - private ActionImpl() { - } - - @Override - public Optional getIcon() { - return Optional.ofNullable(icon); - } - - @Override - public Optional getKeyBinding() { - return Optional.ofNullable(keyBinding); - } - - @Override - public String getText() { - return text != null ? text : ""; - } - - @Override - public String getDescription() { - return description != null ? description : ""; - } - } } diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java index de958837778..74656fe958e 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java @@ -1,5 +1,7 @@ package org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons; +import java.util.Optional; + import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; @@ -11,6 +13,7 @@ import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.icon.JabRefIcon; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.Field; @@ -32,16 +35,13 @@ public ToggleMergeUnmergeButton(Field field) { } private void configureMergeButton() { - Action mergeAction = new Action.Builder(Localization.lang("Merge %0", field.getDisplayName())) - .setIcon(IconTheme.JabRefIcons.MERGE_GROUPS); - - actionFactory.configureIconButton(mergeAction, new ToggleMergeUnmergeAction(), this); + ToggleMergeCommand mergeCommand = new ToggleMergeCommand(); + actionFactory.configureIconButton(mergeCommand.mergeAction, mergeCommand, this); } private void configureUnmergeButton() { - Action unmergeAction = new Action.Builder(Localization.lang("Unmerge %0", field.getDisplayName())) - .setIcon(IconTheme.JabRefIcons.UNDO); - actionFactory.configureIconButton(unmergeAction, new ToggleMergeUnmergeAction(), this); + ToggleMergeCommand unmergeCommand = new ToggleMergeCommand(); + actionFactory.configureIconButton(unmergeCommand.unmergeAction, unmergeCommand, this); } public ObjectProperty fieldStateProperty() { @@ -71,7 +71,7 @@ public void setCanMerge(boolean value) { canMergeProperty().set(value); } - private class ToggleMergeUnmergeAction extends SimpleCommand { + private class ToggleMergeCommand extends SimpleCommand { @Override public void execute() { @@ -83,6 +83,32 @@ public void execute() { configureUnmergeButton(); } } + + private final Action mergeAction = new Action() { + + @Override + public Optional getIcon() { + return Optional.of(IconTheme.JabRefIcons.MERGE_GROUPS); + } + + @Override + public String getText() { + return Localization.lang("Merge %0", field.getDisplayName()); + } + }; + + private final Action unmergeAction = new Action() { + + @Override + public Optional getIcon() { + return Optional.of(IconTheme.JabRefIcons.UNDO); + } + + @Override + public String getText() { + return Localization.lang("Unmerge %0", field.getDisplayName()); + } + }; } public enum FieldState { From 4d449a6f3ac0235a6a5caaa12f35db67834a6a1c Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 4 Sep 2022 19:37:45 +0200 Subject: [PATCH 2/4] checkstyle --- .../sidebuttons/ToggleMergeUnmergeButton.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java index 74656fe958e..c2fdcf3a97b 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java @@ -73,19 +73,7 @@ public void setCanMerge(boolean value) { private class ToggleMergeCommand extends SimpleCommand { - @Override - public void execute() { - if (fieldStateProperty().get() == FieldState.MERGED) { - setFieldState(FieldState.UNMERGED); - configureMergeButton(); - } else { - setFieldState(FieldState.MERGED); - configureUnmergeButton(); - } - } - private final Action mergeAction = new Action() { - @Override public Optional getIcon() { return Optional.of(IconTheme.JabRefIcons.MERGE_GROUPS); @@ -98,7 +86,6 @@ public String getText() { }; private final Action unmergeAction = new Action() { - @Override public Optional getIcon() { return Optional.of(IconTheme.JabRefIcons.UNDO); @@ -109,6 +96,17 @@ public String getText() { return Localization.lang("Unmerge %0", field.getDisplayName()); } }; + + @Override + public void execute() { + if (fieldStateProperty().get() == FieldState.MERGED) { + setFieldState(FieldState.UNMERGED); + configureMergeButton(); + } else { + setFieldState(FieldState.MERGED); + configureUnmergeButton(); + } + } } public enum FieldState { From 81f8335b17761f85776cdd279719882641ca0473 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 4 Sep 2022 19:45:37 +0200 Subject: [PATCH 3/4] checkstyle --- .../cell/sidebuttons/ToggleMergeUnmergeButton.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java index c2fdcf3a97b..4622918ec50 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/ToggleMergeUnmergeButton.java @@ -72,7 +72,6 @@ public void setCanMerge(boolean value) { } private class ToggleMergeCommand extends SimpleCommand { - private final Action mergeAction = new Action() { @Override public Optional getIcon() { From 3c2cb9bf17ab1d0a832063552fe7cc4288cf34db Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 4 Sep 2022 20:07:56 +0200 Subject: [PATCH 4/4] InfoButton --- .../cell/sidebuttons/InfoButton.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java index da37e2267ce..55bb2009bbf 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java @@ -1,5 +1,7 @@ package org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons; +import java.util.Optional; + import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.scene.control.Button; @@ -9,6 +11,7 @@ import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.icon.JabRefIcon; import com.tobiasdiez.easybind.EasyBind; @@ -16,18 +19,27 @@ public class InfoButton extends Button { private final StringProperty infoMessage = new SimpleStringProperty(); private final ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); + private final Action mergeAction = new Action() { + @Override + public Optional getIcon() { + return Optional.of(IconTheme.JabRefIcons.INTEGRITY_INFO); + } + + @Override + public String getText() { + return infoMessage.get(); + } + }; + public InfoButton(String infoMessage) { - setInfoMessage(infoMessage); + this.infoMessage.setValue(infoMessage); configureButton(); - EasyBind.subscribe(infoMessageProperty(), newWarningMessage -> { - configureButton(); - }); + EasyBind.subscribe(this.infoMessage, newWarningMessage -> configureButton()); } private void configureButton() { setMaxHeight(Double.MAX_VALUE); setFocusTraversable(false); - Action mergeAction = new Action.Builder(getInfoMessage()).setIcon(IconTheme.JabRefIcons.INTEGRITY_INFO); actionFactory.configureIconButton(mergeAction, new SimpleCommand() { @Override @@ -36,16 +48,4 @@ public void execute() { } }, this); } - - private void setInfoMessage(String infoMessage) { - infoMessageProperty().set(infoMessage); - } - - public StringProperty infoMessageProperty() { - return infoMessage; - } - - public String getInfoMessage() { - return infoMessage.get(); - } }