protected void internalEditItem(final M m) { this.model = m; if (m != null) { driver.edit(m); } }
protected boolean submitAction() { final M editedModel = driver.flush(); if (editedModel != null) { if (!driver.hasErrors()) { if (editedModel.getId() != null) { updateService(editedModel).update(editedModel); } else { createService().create(editedModel); } return true; } final List<String> errors = driver .getErrors() .stream() .filter(Objects::nonNull) .map(EditorError::getMessage) .collect(Collectors.toList()); showErrors(errors); return false; } return true; }
@Test public void testEdit() { List<DataColumnDef> columnDefs = mock( List.class ); presenter.edit( dataSetDef, columnDefs ); assertEquals( editor, presenter.getEditor() ); verify( driver, times( 1 ) ).initialize( editor ); verify( editor, times( 1 ) ).setAcceptableValues( columnDefs ); verify( driver, times( 1 ) ).edit( dataSetDef ); verify( view, times( 2 ) ).clearView(); verify( view, times( 1 ) ).add( any( IsWidget.class ) ); verify( view, times( 0 ) ).init( presenter ); verify( view, times( 0 ) ).addButton( anyString(), anyString(), anyBoolean(), any( Command.class ) ); verify( view, times( 0 ) ).clearButtons(); }
public DataSetEditWorkflow edit( final T definition, List<DataColumnDef> allColumns ) { clear(); this.dataSetDef = definition; checkDataSetDefNotNull(); this.driver = beanManager.lookupBean( getDriverClass() ).newInstance(); this.editor = beanManager.lookupBean( getEditorClass() ).newInstance(); driver.initialize( editor ); editor.setAcceptableValues( allColumns ); driver.edit( definition ); this.flushCommand = () -> flush(DataSetEditWorkflow.this.driver); this.stepValidator = () -> { final boolean isCacheEnabled = definition.isCacheEnabled(); final boolean isPushEnabled = definition.isPushEnabled(); final boolean isRefreshEnabled = definition.getRefreshTime() != null; Iterable<ConstraintViolation<?>> violations = validate( isCacheEnabled, isPushEnabled, isRefreshEnabled ); driver.setConstraintViolations( violations ); addViolations( violations ); }; // Show data set editor view. view.clearView(); view.add( getWidget() ); return this; }
public void flush(final SimpleBeanEditorDriver driver) { checkDataSetDefNotNull(); this.violations.clear(); driver.flush(); afterFlush(); // Validations for current step. if (stepValidator != null) { stepValidator.execute(); } }
@Override public void execute() { // Data set definition basic attributes validation. Iterable<ConstraintViolation<?>> basicAttsViolations = validatorProvider.validateBasicAttributes(getDataSetDef()); dataSetDefBasicAttributesDriver.setConstraintViolations(basicAttsViolations); addViolations(basicAttsViolations); Iterable<ConstraintViolation<?>> violations = validate(); driver.setConstraintViolations(violations); addViolations(violations); } };
driver.initialize(editor); driver.edit(getDataSetDef());
public DataSetEditWorkflow edit( final T definition, List<DataColumnDef> allColumns ) { clear(); this.dataSetDef = definition; checkDataSetDefNotNull(); this.driver = beanManager.lookupBean( getDriverClass() ).newInstance(); this.editor = beanManager.lookupBean( getEditorClass() ).newInstance(); driver.initialize( editor ); editor.setAcceptableValues( allColumns ); driver.edit( definition ); this.flushCommand = () -> flush(DataSetEditWorkflow.this.driver); this.stepValidator = () -> { final boolean isCacheEnabled = definition.isCacheEnabled(); final boolean isPushEnabled = definition.isPushEnabled(); final boolean isRefreshEnabled = definition.getRefreshTime() != null; Iterable<ConstraintViolation<?>> violations = validate( isCacheEnabled, isPushEnabled, isRefreshEnabled ); driver.setConstraintViolations( violations ); addViolations( violations ); }; // Show data set editor view. view.clearView(); view.add( getWidget() ); return this; }
public void flush(final SimpleBeanEditorDriver driver) { checkDataSetDefNotNull(); this.violations.clear(); driver.flush(); afterFlush(); // Validations for current step. if (stepValidator != null) { stepValidator.execute(); } }
@Override public void execute() { // Data set definition basic attributes validation. Iterable<ConstraintViolation<?>> basicAttsViolations = validatorProvider.validateBasicAttributes(getDataSetDef()); dataSetDefBasicAttributesDriver.setConstraintViolations(basicAttsViolations); addViolations(basicAttsViolations); Iterable<ConstraintViolation<?>> violations = validate(); driver.setConstraintViolations(violations); addViolations(violations); } };
driver.initialize(editor); driver.edit(getDataSetDef());
@Test public void testFlushDriver() { final Collection violations = mock(Collection.class); when(violations.isEmpty()).thenReturn(true); presenter.violations = violations; final Command c = mock(Command.class); presenter.stepValidator = c; presenter.flush(driver); verify(driver, times(1)).flush(); verify(c, times(1)).execute(); assertFalse(presenter.hasErrors()); verify(view, times(0)).clearButtons(); verify(view, times(0)).addButton(anyString(), anyString(), anyBoolean(), any(Command.class)); verify(view, times(0)).add(any(IsWidget.class)); verify(view, times(0)).init(presenter); verify(view, times(0)).clearView(); }
protected void rejectAction() { if (model != null) { driver.edit(model); } bus.fire(config.getCrudEventType().createUpdateCompleteEvent(model)); }