DynamicMenuEditorPresenter extends BaseEditor<Plugin, DefaultMetadata> { public RuleValidator getMenuItemLabelValidator(final DynamicMenuItem menuItem, final DynamicMenuItem editedMenuItem) { return new RuleValidator() { private String error; private NameValidator menuLabelValidator = NameValidator.createNameValidator(getView().emptyMenuLabel(), getView().invalidMenuLabel()); @Override public boolean isValid(final String value) { if (!menuLabelValidator.isValid(value)) { this.error = menuLabelValidator.getValidationError(); return false; } DynamicMenuItem existingItem = getExistingMenuItem(menuItem, editedMenuItem); if (existingItem != null) { this.error = getView().duplicatedMenuLabel(); return false; } this.error = null; return true; } @Override public String getValidationError() { return this.error; } }; } @Inject  DynamicMenuEditorPresenter(final View baseView); @OnStartup void onStartup(final ObservablePath path,
                          final PlaceRequest place); @WorkbenchPartTitleDecoration IsWidget getTitle(); @WorkbenchPartTitle String getTitleText(); @WorkbenchMenu void getMenus(final Consumer<Menus> menusConsumer); RuleValidator getMenuItemActivityIdValidator(); RuleValidator getMenuItemLabelValidator(final DynamicMenuItem menuItem,
                                                   final DynamicMenuItem editedMenuItem); void addMenuItem(final DynamicMenuItem menuItem); DynamicMenuItem getExistingMenuItem(final DynamicMenuItem currentMenuItem,
                                               final DynamicMenuItem editedMenuItem); void removeObject(DynamicMenuItem object); void updateIndex(final DynamicMenuItem object,
                            final int index,
                            final UpdateIndexOperation operation); void setDataDisplay(final HasData<DynamicMenuItem> display); @WorkbenchPartView UberView<DynamicMenuEditorPresenter> getWidget(); @OnMayClose boolean onMayClose(); DynamicMenu getContent(); @Override Validator getRenameValidator(); @Override Validator getCopyValidator(); View getView();  }
@Test public void validateNewMenuItemLabel() { RuleValidator labelValidator; labelValidator = presenter.getMenuItemLabelValidator(new DynamicMenuItem(null, null), null); assertFalse(labelValidator.isValid(null)); labelValidator = presenter.getMenuItemLabelValidator(new DynamicMenuItem("", ""), null); assertFalse(labelValidator.isValid("")); labelValidator = presenter.getMenuItemLabelValidator(new DynamicMenuItem("existingActivityId", "existingMenuLabel"), null); assertFalse(labelValidator.isValid("existingMenuLabel")); labelValidator = presenter.getMenuItemLabelValidator(new DynamicMenuItem("newActivityId", "newMenuLabel"), null); assertTrue(labelValidator.isValid("newMenuLabel")); }
@Test public void validateEditedMenuItemLabel() { RuleValidator labelValidator = presenter.getMenuItemLabelValidator(new DynamicMenuItem("existingActivityId", "existingMenuLabel"), existingMenuItem); assertTrue(labelValidator.isValid("newMenuLabel")); assertTrue(labelValidator.isValid("existingMenuLabel")); }