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); } } };
/******************************************************************************************************************* * * Constrains the search to artists who are makers of the given entity. * * @param entity the entity * @return the {@code Finder}, in fluent fashion * ******************************************************************************************************************/ @Nonnull public default MusicArtistFinder makerOf (final @Nonnull Identifiable entity) { return makerOf(entity.getId()); } }
@Nonnull public static String shortId (final @Nullable Object object) { if (object == null) { return "null"; } String s = String.format("%s@%x", shortName(object.getClass()), System.identityHashCode(object)); if (object instanceof Identifiable) { s += "/" + ((Identifiable)object).getId(); } return s; }
@Nonnull protected final String resourceUri (final @Nonnull String resourceType, final @Nonnull Identifiable resource) { return resourceUri(resourceType, resource.getId().stringValue()); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull private static Path idToPathSegment (final @Nonnull Entity entity) { return Paths.get(entity.as(Identifiable).getId().stringValue().replace('/', '_')); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Override public boolean isEnabled() { try { observation.as(Identifiable).getId(); // to probe existence of id return true; } catch (AsException e) { return false; } } }
@Nonnull private static MediaFolder createMediaFolder (final @Nonnull MediaFolder parent, final @Nonnull EntityBrowser browser) { final String fallBack = browser.getClass().getSimpleName(); final String pathSegment = browser.asOptional(Identifiable).map(i -> i.getId().stringValue()).orElse(fallBack); final Displayable displayable = browser.asOptional(Displayable).orElse(new DefaultDisplayable(fallBack)); log.trace("createMediaFolder({}, {}) - path: {} displayable: {}", parent, browser, pathSegment, displayable); return new PathAwareMediaFolderDecorator(browser.getRoot(), parent, Paths.get(pathSegment), displayable); } }
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 } } } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ @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(); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ public void actionPerformed (final @Nonnull ActionEvent event) { try { log.info("actionPerformed({}) - media: {}", event, observation); view.openWebPage(observation.as(Identifiable).getId().stringValue()); } catch (Exception e) { log.warn("Can't open web page {}", e); log.warn("", e); // FIXME: non fatal notification to the view } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull private String displayNameOf (final @Nonnull Entity entity) { return String.format("%s (%s)", entity.as(Displayable).getDisplayName(), entity.as(Identifiable).getId()); }
private void must_find_the_correct_adapter_for_decorated_entities (final @Nonnull Entity datum, final @Nonnull Class<?> expectedAdapterClass) { // given final PathAwareEntity parent = mock(PathAwareEntity.class); when(parent.getPath()).thenReturn(Paths.get("/")); final Path pathSegment = Paths.get(datum.as(Identifiable).getId().stringValue()); final PathAwareMediaFolderDecorator decorator = new PathAwareMediaFolderDecorator(datum, parent, pathSegment); // when final DIDLAdapter adapter = decorator.as(DIDLAdapter); // then assertThat(adapter, instanceOf(expectedAdapterClass)); }
observationId = observation.as(Identifiable).getId().stringValue(); observationId = observationId.replaceAll(".*/", "");
/******************************************************************************************************************* * * * ******************************************************************************************************************/ protected <D extends DIDLObject> D setCommonFields (final @Nonnull D didlObject) { didlObject.setRestricted(false); didlObject.setCreator("blueMarine II"); // FIXME datum.asOptional(Identifiable).ifPresent(identifiable -> didlObject.setId(externalized(identifiable.getId().stringValue()))); datum.asOptional(Displayable).map(displayable -> didlObject.setTitle(displayable.getDisplayName())); if (didlObject instanceof Container) { final Container container = (Container)didlObject; datum.asOptional(SimpleComposite8).ifPresent(c -> container.setChildCount(c.findChildren().count())); container.setItems(Collections.emptyList()); } return didlObject; } }