GT-1 Fixed ActionBuilder so that not specifying an "enabledWhen"

condition doesn't interfere with manual action enablement.
This commit is contained in:
ghidravore 2020-09-22 10:56:55 -04:00
parent c50d32c792
commit 04de745ddd
2 changed files with 19 additions and 2 deletions

View file

@ -160,7 +160,7 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, C extends
/**
* Predicate for determining if an action is enabled for a given context
*/
private Predicate<C> enabledPredicate = ALWAYS_TRUE;
private Predicate<C> enabledPredicate = null;
/**
* Predicate for determining if an action should be included on the pop-up menu
@ -664,7 +664,10 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, C extends
action.setHelpLocation(helpLocation);
}
if (enabledPredicate != null) {
action.enabledWhen(adaptPredicate(enabledPredicate));
}
action.validContextWhen(adaptPredicate(validContextPredicate));
action.popupWhen(adaptPredicate(popupPredicate));
}

View file

@ -237,6 +237,20 @@ public class ActionBuilderTest {
assertTrue(action.isEnabledForContext(new FooActionContext()));
}
@Test
public void testManualEnablement() {
DockingAction action = new ActionBuilder("Test", "Test")
.onAction(e -> actionCount++)
.enabled(false)
.build();
assertFalse(action.isEnabledForContext(new ActionContext()));
action.setEnabled(true);
assertTrue(action.isEnabledForContext(new ActionContext()));
action.setEnabled(true);
assertTrue(action.isEnabledForContext(new ActionContext()));
}
static class FooActionContext extends ActionContext {
public boolean foo() {
return true;