public void execute(final UiCommand command) { run(command); }
/** Bind our property to source, two-way, and shows view when our property is true. */ public void to(final HasValue<Boolean> source, HasCss view) { super.to(source); b.when(bp).is(true).show(view); }
public WhenIsBinder<P> is(final P value) { return new WhenIsBinder<P>(b, property, new WhenCondition<P>() { public boolean evaluate(P current) { return eq(current, value); } public void setInitialValue(Property<P> property) { property.setInitialValue(value); } }); }
@Test public void whenSetToTakesValuesDoesNotTouchOnInitialEvaluation() { final BooleanProperty b = booleanProperty("b", true); final StringProperty s = stringProperty("s"); binder.when(b).is(true).set(s).to("t"); assertThat(s.get(), is("t")); assertThat(s.isTouched(), is(false)); }
@Override public void bind(FormPresenter p, Binder binder) { String id = p.getId() + "-" + Inflector.camelize(text); button.ensureDebugId(id); if (addOnlyIf) { command.addOnlyIf(p.allValid()); } binder.when(command.enabled()).is(true).show(button); if (command instanceof DispatchUiCommand) { binder.when(((DispatchUiCommand<?, ?>) command).active()).is(false).enable(button); } }
@Test public void whenTrueEnableLeavesEnabled() { final BooleanProperty b = booleanProperty("b", true); final StubFocusWidget w = new StubFocusWidget(); binder.when(b).is(true).enable(w); assertThat(w.isEnabled(), is(true)); }
/** Binds clicks from {@code clickable} to our command. */ public UiCommandBinder to(final HasClickHandlers clickable) { b.add(clickable.addClickHandler(e -> { command.execute(); e.preventDefault(); })); // Assume that if command.active() is available, and HasEnabled is available, // it just makes sense to disable clickable while the command is active if (command instanceof HasActive && clickable instanceof HasEnabled) { Property<Boolean> active = ((HasActive) command).active(); b.when(active).is(true).disable((HasEnabled) clickable); } return this; }
@Test public void whenTrueRemovesFromInitialSet() { final BooleanProperty b = booleanProperty("b", false); final ArrayList<String> list = new ArrayList<String>(); list.add("foo"); binder.when(b).is(true).add("foo").to(list); assertThat(list, not(hasItem("foo"))); }
@Test public void whenIsFadeInStartsFalse() { final BooleanProperty b = booleanProperty("b", false); final StubWidget w = new StubWidget(); binder.when(b).is(true).fadeIn(w); // if condition is false, jump right to display none assertThat(w, is(hidden())); assertThat(w.getStyle().getOpacity(), is(nullValue())); }
public void error(final String message) { b.add(property.addPropertyChangedHandler(e -> errorIfCondition(message))); errorIfCondition(message); }
@Test public void whenIsAttach() { final BooleanProperty b = booleanProperty("b", false); final StubWidget w = new StubWidget(); final StubFlowPanel p = new StubFlowPanel(); binder.when(b).is(true).attach(w).to(p); assertThat(p.getWidgetCount(), is(0)); b.set(true); assertThat(p.getWidgetCount(), is(1)); b.set(false); assertThat(p.getWidgetCount(), is(0)); }
@Test public void whenTrueDoesNotFireInitialValueWhenFalse() { final BooleanProperty b = booleanProperty("b", false); final StubWidget w = new StubWidget(); binder.when(b).is(true).set("c").on(w); assertThat(w, not(hasStyle("c"))); }
@Test public void whenTrueEnableIsFalseThenSetsDisabled() { final BooleanProperty b = booleanProperty("b", false); final StubFocusWidget w = new StubFocusWidget(); binder.when(b).is(true).enable(w); assertThat(w.isEnabled(), is(false)); }
@Test public void whenTrueDisabledChangesToDisabled() { final BooleanProperty b = booleanProperty("b", true); final StubFocusWidget w = new StubFocusWidget(); binder.when(b).is(true).disable(w); assertThat(w.isEnabled(), is(false)); }
@Test public void whenTrueAddDoesInitialSet() { final BooleanProperty b = booleanProperty("b", true); final ArrayList<String> list = new ArrayList<String>(); binder.when(b).is(true).add("foo").to(list); assertThat(list, contains("foo")); }
@Test public void whenIsFadeInStartsTrue() { StubAnimations.captureAnimations(); final BooleanProperty b = booleanProperty("b", true); final StubWidget w = new StubWidget(); binder.when(b).is(true).fadeIn(w); // if condition is true, jump right to fading in assertThat(w, is(shown())); StubAnimations.tickAnimation(0); assertThat(w.getStyle().getOpacity(), is("0.0")); StubAnimations.tickAnimation(1.0); assertThat(w.getStyle().getOpacity(), is("1.0")); }
@Test public void whenSetToOrElse() { final BooleanProperty b = booleanProperty("b"); binder.when(b).is(true).set(s).toOrElse("a", "b"); assertThat(s.get(), is("b")); b.set(true); assertThat(s.get(), is("a")); b.set(false); assertThat(s.get(), is("b")); }
@Test public void whenTrueShowHidesWhenFalse() { final BooleanProperty b = booleanProperty("b", false); final StubWidget w = new StubWidget(); binder.when(b).is(true).show(w); assertThat(w, is(hidden())); }
@Test public void whenTrueEnableChangesToFalseThenSetsDisabled() { final BooleanProperty b = booleanProperty("b", true); final StubFocusWidget w = new StubFocusWidget(); binder.when(b).is(true).enable(w); b.set(false); assertThat(w.isEnabled(), is(false)); }
@Test public void whenValueRun() { final boolean[] ran = { false }; final BooleanProperty b = booleanProperty("b", true); binder.when(b).is(false).run(new Runnable() { public void run() { ran[0] = true; } }); assertThat(ran[0], is(false)); b.set(false); assertThat(ran[0], is(true)); }