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

Resimplify Action interface #9133

Merged
merged 5 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions src/main/java/org/jabref/gui/actions/Action.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui.actions;

import java.util.Objects;
import java.util.Optional;

import org.jabref.gui.icon.JabRefIcon;
Expand All @@ -20,71 +19,4 @@ default Optional<KeyBinding> 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<JabRefIcon> getIcon() {
return Optional.ofNullable(icon);
}

@Override
public Optional<KeyBinding> getKeyBinding() {
return Optional.ofNullable(keyBinding);
}

@Override
public String getText() {
return text != null ? text : "";
}

@Override
public String getDescription() {
return description != null ? description : "";
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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<FieldState> fieldStateProperty() {
Expand Down Expand Up @@ -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() {
Expand All @@ -83,6 +83,32 @@ public void execute() {
configureUnmergeButton();
}
}

private final Action mergeAction = new Action() {
calixtus marked this conversation as resolved.
Show resolved Hide resolved
calixtus marked this conversation as resolved.
Show resolved Hide resolved

@Override
public Optional<JabRefIcon> 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() {
calixtus marked this conversation as resolved.
Show resolved Hide resolved
calixtus marked this conversation as resolved.
Show resolved Hide resolved

@Override
public Optional<JabRefIcon> getIcon() {
return Optional.of(IconTheme.JabRefIcons.UNDO);
}

@Override
public String getText() {
return Localization.lang("Unmerge %0", field.getDisplayName());
}
};
}

public enum FieldState {
Expand Down