@Override public boolean isEnabled() { return getComposition().isEnabled(); }
@Test public void testSetPossibleMoveLocations() throws Exception { //GIVEN Set<MoveLocation> locations = new HashSet<MoveLocation>(); locations.add(MoveLocation.AFTER); //WHEN presenter.setPossibleMoveLocations(locations); //THEN assert(view.getViewForAction(MoveLocation.AFTER.name()).asVaadinComponent().isEnabled()); assert(!view.getViewForAction(MoveLocation.BEFORE.name()).asVaadinComponent().isEnabled()); assert(!view.getViewForAction(MoveLocation.INSIDE.name()).asVaadinComponent().isEnabled()); } }
@Test public void isEnabledForValidSelection() { // GIVEN when(availabilityChecker.isAvailable(any(ConfiguredAvailabilityDefinition.class), anyList())).thenReturn(true); View view = renderer.start(actionDefinition, actionListener); // WHEN // applicable item change event is sent, should pass availability check chooseDialogEventBus.fireEvent(event); // THEN assertTrue(view.asVaadinComponent().isEnabled()); }
@Test public void isDisabledForInvalidSelection() { // GIVEN when(availabilityChecker.isAvailable(any(ConfiguredAvailabilityDefinition.class), anyList())).thenReturn(false); View view = renderer.start(actionDefinition, actionListener); // WHEN // non-applicable item change event is sent, shouldn't pass availability check chooseDialogEventBus.fireEvent(event); // THEN assertFalse(view.asVaadinComponent().isEnabled()); } }
/** * Tests if component enabled and visible and its container enabled. * * @param child component * @return component enabled state */ public static boolean isComponentEnabled(Component child) { if (child.getParent() instanceof TabSheet) { TabSheet tabSheet = (TabSheet) child.getParent(); TabSheet.Tab tab = tabSheet.getTab(child); if (!tab.isEnabled()) { return false; } } return child.isEnabled() && (child.getParent() == null || isComponentEnabled(child.getParent())) && isComponentVisible(child); }