Data Snippet Provider
FirstSpirit Developer API Interface: de.espirit.firstspirit.client.plugin.dataaccess.DataSnippetProvider
Developer API documentation: DataSnippetProvider<D>
This class identifies information about a data object which may be shown in UI representations (called "snippets") of that data object, such as header and extract texts, thumbnail, and icon.
XML-conform escaping should be applied to results of logic for the header and excerpt definitions so that XML-specific special characters are converted into corresponding entities. |
public class MyDataSnippetProvider implements DataSnippetProvider<MyDataObject> {
private final BaseContext _context;
public MyDataSnippetProvider(@NotNull final BaseContext context) {
_context = context;
}
@Nullable
@Override
public Image<?> getIcon(@NotNull final MyDataObject object) {
final ImageAgent imageAgent = _context.requireSpecialist(ImageAgent.TYPE);
if (_context.is(BaseContext.Env.WEBEDIT)) {
return imageAgent.getImageFromUrl("path/to/myDataObjectIcon.png");
} else {
return imageAgent.getImageFromIcon(new ImageIcon(getClass().getResource("myDataObjectIcon.png")));
}
}
/**
* Ideally, the thumbnail would be generated based on information sourced from the given object.
* For simplicity's sake, we're using a hardcoded thumbnail image here.
*/
@Nullable
@Override
public Image<?> getThumbnail(@NotNull final MyDataObject object, @Nullable final Language language) {
final ImageAgent imageAgent = _context.requireSpecialist(ImageAgent.TYPE);
if (_context.is(BaseContext.Env.WEBEDIT)) {
return imageAgent.getImageFromUrl("path/to/myDataObjectThumbnail.png");
} else {
return imageAgent.getImageFromIcon(new ImageIcon(getClass().getResource("myDataObjectThumbnail.png")));
}
}
@NotNull
@Override
public String getHeader(@NotNull final MyDataObject object, @Nullable final Language language) {
return object.getHeader();
}
@Nullable
@Override
public String getExtract(@NotNull final MyDataObject object, @Nullable final Language language) {
return object.getText();
}
}