@Nonnull public String getTaxonomyDisplayName() { return taxonomyPreferences.getTaxonomy().as(Displayable.class).getDisplayName(); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Override public void readExternal (final @Nonnull ObjectInput oi) throws IOException, ClassNotFoundException { final Id id = (Id)oi.readObject(); try { final Taxonomy taxonomy = Locator.find(TaxonomyPreferences.class).getTaxonomy(); taxon = taxonomy.findTaxa().withId(id).result(); } catch (NotFoundException e) { throw new IOException(e.toString()); // Java 5 / Android compatibility } }
for (final Locale locale : taxonomyPreferences.get().getTaxonomy().getLocales())
/******************************************************************************************************************* * * Retrieves the {@link Taxon} parameter from an {@link Intent}. * * @return the {@code Taxon} * @throws NotFoundException if no {@code Taxon} has been passed as a parameter * ******************************************************************************************************************/ @Nonnull public static Taxon getTaxon (final @Nonnull Intent intent) throws NotFoundException { NotFoundException.throwWhenNull(intent, "No Intent"); final String id = NotFoundException.throwWhenNull(intent.getExtras(), "No extras").getString(TAXON_ID); NotFoundException.throwWhenNull(id, "No taxonId"); return Locator.find(TaxonomyPreferences.class).getTaxonomy().findTaxa().withId(new Id(id)).result(); }
/******************************************************************************************************************* * * Loads the taxa. If a {@link Taxon} is contained in the {@link Intent}, the sub taxa will be loaded and the cache * disabled since there are no taxa with a number of sub taxa so large to create performance problems while sorting. * If no {@code Taxon} is contained in the {@code Intent}, all the taxa with the {@link Rank} bound to this * controller will be loaded; and the cache enabled if the rank is {@code SPECIES} since there can be so many * items to create performance problems when sorting. The latter behaviour also happens if the {@code Intent} * contains a {@code Taxon}, but it's not from the current taxonomy. * * TODO: This management of cache is cumbersome. Using Finders with sorting capabilities could be a solution, * moving all the caching logics to the Finder themselves (and eventually could opaquely implement sorting * based on OpenSesame query that could be fast enough to avoid caching). * ******************************************************************************************************************/ @Nonnull private void loadTaxa (final @Nonnull Intent intent) { taxa.clear(); cacheEnabled = false; try { taxa.addAll(TaxonIntentHelper.getTaxon(intent).findSubTaxa().results()); } catch (NotFoundException e) // no Taxon in the Intent { taxa.addAll(taxonomyPreferences.get().getTaxonomy().findTaxa().withRank(rank).results()); cacheEnabled = rank == Rank.SPECIES; } ensureTaxaAreSorted(); }
tvName.setText(taxonomy.as(Displayable.class).getDisplayName()); x(tvDescription, "", taxonomy.as(Document.class), DublinCoreVocabulary.DC_DESCRIPTION); x2(tvLanguages, "Common names in: ", taxonomy.as(Document.class), KEY_LANGUAGE, _); x(tvLanguages, "Common names in: ", taxonomy.as(Document.class), KEY_LANGUAGE, _); x(tvPublisher, "Publisher: ", taxonomy.as(Document.class), DublinCoreVocabulary.DC_PUBLISHER); x(tvDate, "Publishing date: ", taxonomy.as(Document.class), KEY_DATE); x(tvAuthors, "Authors: ", taxonomy.as(Document.class), DublinCoreVocabulary.DC_CREATOR); x(tvLicense, "License: ", taxonomy.as(Document.class), DublinCoreVocabulary.DC_RIGHTS);
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public List<Taxon> getRecentTaxa() { logger.info("getRecentTaxa()"); final List<Taxon> taxa = new ArrayList<Taxon>(); final Taxonomy taxonomy = Locator.find(TaxonomyPreferences.class).getTaxonomy(); for (final Id taxonId : taxonIdHistory) { try { taxa.add(taxonomy.findTaxa().withId(taxonId).result()); } catch (NotFoundException e) { logger.warning("Can't retrieve taxon for id: %s", taxonId); } } return taxa; }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Override public void setTaxonomy (final @Nonnull Taxonomy taxonomy) { logger.info("setTaxonomy(%s)", taxonomy); final Id taxonomyId = taxonomy.as(Identifiable.class).getId(); if (!taxonomyId.stringValue().equals(preferences.getString(TaxonomyPreferencesSupport.PREF_TAXONOMY, ""))) { final Editor editor = preferences.edit(); editor.putString(TaxonomyPreferencesSupport.PREF_TAXONOMY, taxonomyId.stringValue()); editor.commit(); } }
final String taxonomyName = taxonomyPreferences.get().getTaxonomy().as(Displayable.class).getDisplayName(); latestSortLocale = taxonomyPreferences.get().getTaxonomyLocales().get(0);
/******************************************************************************************************************* * * {@inheritDoc} * Eventually loads the data - remember that this is called both after the Activity creation and after a real * resume. While the activity was suspended, the user might have changed the Taxonomy or the sort order. which would * need some care be taken of. * ******************************************************************************************************************/ @Override protected void onResume() { logger.info("onResume()"); super.onResume(); final Taxonomy taxonomy = taxonomyPreferences.get().getTaxonomy(); final String newTaxonomyName = taxonomy.as(Displayable.class).getDisplayName(); logger.info(">>>> current taxonomy: %s new taxonomy: %s", currentTaxonomyName, newTaxonomyName); if ((currentTaxonomyName == null) || !currentTaxonomyName.equals(newTaxonomyName)) { currentTaxonomyName = newTaxonomyName; new LoadTaxonomyTask().execute(); } if ((controller != null) && controller.needsResorting()) { new EnsureTaxaSortedTask().execute(); } }