/******************************************************************************************************************* * *{@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public PresentationModel createPresentationModel (final @Nonnull Object... localRolesOrFactories) { return new DefaultPresentationModel(datum, localRolesOrFactories); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public PresentationModel createPresentationModel (final @Nonnull Object owner, final @Nonnull Object... localRolesOrFactories) { return new DefaultPresentationModel(owner, localRolesOrFactories); } }
@Override public Void run() { for (final Taxon taxon : taxa) { taxaPM.addChild(new DefaultPresentationModel(taxon)); } return null; } });
@Override public PresentationModel createPresentationModel (final @Nonnull Object... instanceRoles) { final List<Object> temp = new ArrayList<>(); temp.addAll(Arrays.asList(instanceRoles)); temp.add((Displayable) () -> customer.getName()); return new DefaultPresentationModel(customer, temp.toArray()); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Function<List<PresentationModel>, PresentationModel> finisher() { return childrenPms -> { final List<Object> temp = new ArrayList<>(roles); temp.add(new ArrayListSimpleComposite<>(childrenPms)); // FIXME: "" triggers a NPE in RoleManagerSupport.java:341 return new DefaultPresentationModel("", temp.toArray()); }; }
@Override public PresentationModel createPresentationModel (final @Nonnull Object... instanceRoles) { return new DefaultPresentationModel(project, concat(aggregatePresentationModel(), instanceRoles)); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Override protected void onCreate (final @Nonnull Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_news_item); final AndroidNewsItemView view = (AndroidNewsItemView)findViewById(R.id.viewNewsItem); final Intent intent = getIntent(); final Document message = (Document)intent.getExtras().get("message"); view.populate(new DefaultPresentationModel(message)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(expectedExceptions = AsException.class) public void must_not_find_inexistent_role() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerNoAs, localRole1); fixture.as(Role2.class); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(expectedExceptions = AsException.class) public void must_not_find_inexistent_role_bis() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerAsWithRole2, localRole2); fixture.as(Role1.class); }
@Override public PresentationModel createPresentationModel (final @Nonnull Object... instanceRoles) { final Styleable styleable = new DefaultStyleable(getStyles()); return new DefaultPresentationModel("", aggregateBuilder().create(), styleable); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_give_priority_to_local_roles() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerAsWithRole2, localRole2); assertThat(fixture.as(Role2.class), is(sameInstance(localRole2))); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_find_roles_in_owner() { final DefaultPresentationModel fixture = new DefaultPresentationModel(ownerAsWithRole2); assertThat(fixture.as(Role2.class), is(sameInstance(role2InOwner))); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void treeItemChangeListener_must_do_nothing_when_there_is_no_Selectable_role() { // given final Object datum = new Object(); final PresentationModel oldPm = new DefaultPresentationModel(datum); final PresentationModel pm = new DefaultPresentationModel(datum); // when fixture.treeItemChangeListener.changed(null, new TreeItem<>(oldPm), new TreeItem<>(pm)); // then // no exceptions are thrown } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void treeItemChangeListener_must_do_nothing_when_there_is_no_Selectable_role() { // given final Object datum = new Object(); final PresentationModel oldPm = new DefaultPresentationModel(datum); final PresentationModel pm = new DefaultPresentationModel(datum); // when fixture.treeItemChangeListener.changed(null, new TreeItem<>(oldPm), new TreeItem<>(pm)); // then // no exceptions are thrown } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_find_local_roles() { final DefaultPresentationModel fixture1 = new DefaultPresentationModel(ownerNoAs, localRole1); final DefaultPresentationModel fixture2 = new DefaultPresentationModel(ownerNoAs, localRole1, localRole2); assertThat(fixture1.as(Role1.class), is(sameInstance(localRole1))); assertThat(fixture2.as(Role1.class), is(sameInstance(localRole1))); assertThat(fixture2.as(Role2.class), is(sameInstance(localRole2))); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void treeItemChangeListener_must_callback_a_Selectable_on_selection_change() throws InterruptedException { // given final Selectable selectable = mock(Selectable.class); final Object datum = new Object(); final PresentationModel oldPm = new DefaultPresentationModel(datum, selectable); final PresentationModel pm = new DefaultPresentationModel(datum, selectable); // when fixture.treeItemChangeListener.changed(null, new TreeItem<>(oldPm), new TreeItem<>(pm)); // then executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS); verify(selectable, times(1)).select(); verifyNoMoreInteractions(selectable); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void treeItemChangeListener_must_callback_a_Selectable_on_selection_change() throws InterruptedException { // given final Selectable selectable = mock(Selectable.class); final Object datum = new Object(); final PresentationModel oldPm = new DefaultPresentationModel(datum, selectable); final PresentationModel pm = new DefaultPresentationModel(datum, selectable); // when fixture.treeItemChangeListener.changed(null, new TreeItem<>(oldPm), new TreeItem<>(pm)); // then executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS); verify(selectable, times(1)).select(); verifyNoMoreInteractions(selectable); }
@VisibleForTesting void onProjectHourlyReportRequest (final @Nonnull @ListensTo ProjectHourlyReportRequest request) { final HourlyReport report = request.getProject().as(HourlyReportGenerator).createReport(); presentation.bind(); presentation.showUp(notificationWithFeedback().withCaption("Project Hourly Report")); presentation.populate(new DefaultPresentationModel(null, (PlainTextRenderableSupport8) (args) -> report.asString())); } }
/******************************************************************************************************************* * * Factory method for the PresentationModel of SimpleEntity instances. * * It aggregates a few extra roles into the PresentationModel that are used by the control, such as callbacks * for action associated to the context menu. Also a Displayable role is usually injected to control the rendering * of entities. * ******************************************************************************************************************/ @Nonnull private PresentationModel pmFor (final @Nonnull SimpleEntity entity) { final Selectable selectable = () -> onSelected(entity); final UserAction action1 = new UserActionSupport8(() -> action1(entity), new DefaultDisplayable("Action 1")); final UserAction action2 = new UserActionSupport8(() -> action2(entity), new DefaultDisplayable("Action 2")); final UserAction action3 = new UserActionSupport8(() -> action3(entity), new DefaultDisplayable("Action 3")); return new DefaultPresentationModel(entity, new DefaultDisplayable("Item #" + entity.getName()), selectable, UserActionProvider.of(action1, action2, action3)); }
/******************************************************************************************************************* * * Factory method for the PresentationModel of SimpleDciEntity instances. * ******************************************************************************************************************/ @Nonnull private PresentationModel pmFor (final @Nonnull SimpleDciEntity entity) { // FIXME: column names final Aggregate aggregate = AggregatePresentationModelBuilder.newInstance() .with("C1", new DefaultDisplayable(entity.getName())) .with("C2", new DefaultDisplayable("" + entity.getAttribute1())) .with("C3", new DefaultDisplayable("" + entity.getAttribute2())) .create(); final Selectable selectable = () -> onSelected(entity); final UserAction action1 = new UserActionSupport8(() -> action1(entity), new DefaultDisplayable("Action 1")); final UserAction action2 = new UserActionSupport8(() -> action2(entity), new DefaultDisplayable("Action 2")); final UserAction action3 = new UserActionSupport8(() -> action3(entity), new DefaultDisplayable("Action 3")); // No explicit Displayable here, as the one inside SimpleDciEntity is used. return new DefaultPresentationModel(entity, aggregate, selectable, UserActionProvider.of(action1, action2, action3)); }