public void actionPerformed (final @Nonnull ActionEvent event) { log.info("SelectTaxonAction.actionPerformed(): {}", taxonPM); flowController.toNextStep(taxonPM.as(Taxon.class)); } }
public void propertyChange (final @Nonnull PropertyChangeEvent event) { if (PROP_STATUS.equals(event.getPropertyName())) // FIXME: drop this, use a property-specific listener { final Status status = (Status)event.getNewValue(); log.info("download change status for {}: {}", image.as(Identifiable).getId(), status); if (status.isFinal()) { image.removePropertyChangeListener(downloadProgressListener); } switch (status) { case DOWNLOADED: doRender(); break; case BROKEN: log.warn("broken image: {}", image.as(Identifiable).getId()); // FIXME: show broken } } } };
@Test(dependsOnMethods = "must_create_a_ContentPresentationModel_and_register_it") public void must_unregister_a_disposed_PresentationModel() { // given final PresentationModel pm = underTest.createPresentationModel(content, role); // when pm.dispose(); // then assertThat(underTest.map.containsKey(content), is(false)); }
@Test public void changed_must_dispose_all_PresentationModels() { // given final TreeItem<PresentationModel> treeItem = createTreeItemWithChildren(0); assertThat(allPMs.size(), is(85)); // when fixture.changed(null, treeItem, null); // then for (final PresentationModel pm : allPMs) { verify(pm).dispose(); verifyNoMoreInteractions(pm); } }
public void propertyChange (final @Nonnull PropertyChangeEvent event) { if (PROP_DOWNLOAD_PROGRESS.equals(event.getPropertyName())) // FIXME: drop this, use a property-specific listener { final float progress = (Float)event.getNewValue(); log.debug("download progress for {}: {}", image.as(Identifiable).getId(), progress); } } };
@Test public void changed_must_dispose_all_PresentationModels() { // given final TreeItem<PresentationModel> treeItem = createTreeItemWithChildren(0); assertThat(allPMs.size(), is(85)); // when fixture.changed(null, treeItem, null); // then for (final PresentationModel pm : allPMs) { verify(pm).dispose(); verifyNoMoreInteractions(pm); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ Observation getObservation (final @Nonnegative int index) { return getPresentationModel(index).as(Observation); }
public void actionPerformed (final @Nonnull ActionEvent event) { log.info("SelectTaxonomyAction.actionPerformed(): {}", taxonomyPM); taxonomyPreferences.get().setTaxonomy(taxonomyPM.as(Taxonomy.class)); flowController.finish(); } }
@Override public boolean matches (final Object item) { if (!(item instanceof PresentationModel)) { return false; } final PresentationModel pm = (PresentationModel)item; for (final Class<?> roleType : expectedRoleTypes) { try { pm.as(roleType); } catch (AsException e) { return false; } } return true; }
@Override public void populate (final @Nonnull PresentationModel pm) { taReport.setText(pm.as(PlainTextRenderable).render()); } }
public void renderTo (View view, Object... extra) { final Document message = newsItemPM.as(Document.class); try { final String date = preferences.get().formatDateAndTime(message.get(PUB_DATE)); final TextView tvDate = (TextView)view.findViewById(R.id.tvDate); final TextView tvTitle = (TextView)view.findViewById(R.id.tvTitle); tvDate.setText(date); tvTitle.setText(message.get(TITLE)); final int icon = newsItemPM.as(Readable).isRead() ? android.R.drawable.star_off : android.R.drawable.star_on; ((ImageView)view.findViewById(R.id.ivRead)).setImageResource(icon); } catch (NotFoundException e) { } } };
public void showCommonNameInFullScreen (final @Nonnull PresentationModel commonNamesPM) { log.info("showCommonNameInFullScreen({})", commonNamesPM); final Intent intent = commonNamesPM.as(IntentProvider).createIntent(getBaseContext(), TaxonLargeCommonNameFactSheetActivity.class); startActivity(intent); } };
public void onItemClick (final @Nonnull AdapterView<?> adapterView, final @Nonnull View view, final int index, final long id) { try { final ActionEvent actionEvent = new ActionEvent(view, ActionEvent.ACTION_PERFORMED, "actionPerformed"); getItem(index).as(ActionProvider).getDefaultAction().actionPerformed(actionEvent); } catch (AsException e) { // ok, no ActionProvider } catch (NotFoundException e) { // ok, no default Action } } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ public PresentationModelAdapter (final @Nonnull Context context, final @Nonnull PresentationModel presentationModel) { log.debug("PresentationModelAdapter()"); this.context = context; this.presentationModels = new ArrayList<PresentationModel>(); try { // FIXME: why SimpleComposite? final SimpleComposite<PresentationModel> composite = presentationModel.as(SimpleComposite.class); presentationModels.addAll(composite.findChildren().results()); } catch (AsException e) { log.debug(">>>> presentationModel is not a Composite"); // ok, no Composite } // log.debug(">>>> created from {}, {} items", presentationModel, presentationModels.size()); log.debug("PresentationModelAdapter - created from {}@{}, {} items", new Object[] { presentationModel.getClass().getSimpleName(), Integer.toHexString(System.identityHashCode(presentationModel)), presentationModels.size() }); }
public boolean apply (final @Nonnull Object object) { if (!(object instanceof PresentationModel)) { return false; } final PresentationModel presentationModel = (PresentationModel)object; try { return TYPE_STILL_IMAGE.stringValue().equals(presentationModel.as(Media).get(TYPE)); } catch (NotFoundException e) { return false; } catch (AsException e) { return false; } } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void doRender() { final Uri uri = Uri.parse(image.as(Downloadable).getFile().getAbsolutePath()); // Uri.fromFile(file) doesn't work here log.debug(">>>> loading image from {}...", uri); AndroidUtilities.runOnUIThread(new Runnable() { public void run() { try { setImageURI(uri); // FIXME: is this blocking? } catch (OutOfMemoryError e) { log.error("Cannot display image because OutOfMemoryError: {}", uri); // FIXME: user notification } } }); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ public boolean onContextItemSelected (final @Nonnull MenuItem item) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo(); try { final ActionProvider actionProvider = getItem(info.position).as(ActionProvider); final Action[] actions = actionProvider.getActions().toArray(new Action[0]); final int menuIndex = item.getItemId(); actions[menuIndex].actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "actionPerformed")); } catch (AsException e) { return false; // no ActionProvider } return true; } }
final TextView tvDuration = (TextView)view.findViewById(R.id.tvDuration); final Media movie = presentationModel.as(Media.class);
/******************************************************************************************************************* * * ******************************************************************************************************************/ public void onCreateContextMenu (final @Nonnull ContextMenu menu, final @Nonnull View view, final @Nonnull ContextMenuInfo menuInfo) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo; try { final ActionProvider actionProvider = getItem(info.position).as(ActionProvider); int id = 0; for (final Action action : actionProvider.getActions()) { final MenuItem menuItem = menu.add(0, id++, 0, (String)action.getValue(Action.NAME)); menuItem.setEnabled(action.isEnabled()); } } catch (AsException e) { // ok, no ActionProvider } }