use of eu.esdihumboldt.hale.common.align.extension.category.Category in project hale by halestudio.
the class FunctionContentProvider method getChildren.
/**
* @see ITreeContentProvider#getChildren(Object)
*/
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof Category) {
Category category = (Category) parentElement;
List<FunctionDefinition<?>> functions = new ArrayList<>();
functions.addAll(Collections2.filter(FunctionUtil.getTypeFunctions(category.getId(), serviceProvider), this));
functions.addAll(Collections2.filter(FunctionUtil.getPropertyFunctions(category.getId(), serviceProvider), this));
return functions.toArray();
}
return null;
}
use of eu.esdihumboldt.hale.common.align.extension.category.Category in project hale by halestudio.
the class FunctionContentProvider method getParent.
/**
* @see ITreeContentProvider#getParent(Object)
*/
@Override
public Object getParent(Object element) {
if (element instanceof FunctionDefinition<?>) {
String catId = ((FunctionDefinition<?>) element).getCategoryId();
Category cat = (catId == null) ? (null) : (CategoryExtension.getInstance().get(catId));
if (cat == null) {
cat = CAT_OTHER;
}
return cat;
}
return null;
}
use of eu.esdihumboldt.hale.common.align.extension.category.Category in project hale by halestudio.
the class FunctionReferenceContent method getFunctionContent.
private InputStream getFunctionContent(String func_id) throws Exception {
// maps "function" to the real function ID (used by the template)
final FunctionDefinition<?> function = FunctionUtil.getFunction(func_id, null);
if (function == null) {
log.warn("Unknown function " + func_id);
return null;
}
Callable<VelocityContext> contextFactory = new Callable<VelocityContext>() {
@Override
public VelocityContext call() throws Exception {
VelocityContext context = new VelocityContext();
context.put("showImage", imageContentMethod != null);
context.put("function", function);
// Map<paramDisplayName, sampleDataStringRepresentation>
Map<String, String> parameterDocu = new HashMap<String, String>();
for (FunctionParameterDefinition param : function.getDefinedParameters()) {
if (param.getValueDescriptor() != null && param.getValueDescriptor().getSampleData() != null) {
Value sample = param.getValueDescriptor().getSampleData();
if (sample.isRepresentedAsDOM()) {
// get DOM Element as String
Element ele = sample.getDOMRepresentation();
StringWriter writer = new StringWriter();
StreamResult formattedXmlString = new StreamResult(writer);
XmlUtil.prettyPrint(new DOMSource(ele), formattedXmlString);
// escape special chars to display xml code on html
String xmlString = formattedXmlString.getWriter().toString();
xmlString = StringEscapeUtils.escapeXml(xmlString);
parameterDocu.put(param.getDisplayName(), xmlString);
} else {
parameterDocu.put(param.getDisplayName(), sample.getStringRepresentation());
}
}
}
context.put("parameterDocu", parameterDocu);
if (function.getCategoryId() != null) {
String categoryId = function.getCategoryId();
Category category = (CategoryExtension.getInstance().get(categoryId));
// String category = categoryId.substring(categoryId
// .lastIndexOf(".") + 1);
//
// category = capitalize(category);
context.put("category", category);
}
// creating path for the file to be included
URL help_url = function.getHelpURL();
if (help_url != null) {
String help_path = help_url.getPath();
String bundle = function.getDefiningBundle();
StringBuffer sb_include = new StringBuffer();
sb_include.append(bundle);
sb_include.append(help_path);
sb_include.append("/help");
String final_help_url = sb_include.toString();
context.put("include", final_help_url);
}
return context;
}
};
return getContentFromTemplate(func_id, "function", contextFactory);
}
use of eu.esdihumboldt.hale.common.align.extension.category.Category in project hale by halestudio.
the class FunctionLabelProvider method getImage.
/**
* @see LabelProvider#getImage(Object)
*/
@Override
public Image getImage(Object element) {
if (element instanceof Category) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
// get image based on getIconURL in AbstractFunction (and cache them)
if (element instanceof FunctionDefinition<?>) {
URL iconUrl = ((FunctionDefinition<?>) element).getIconURL();
if (iconUrl != null) {
String iconString = iconUrl.toString();
Image image = urlImages.get(iconString);
if (image == null) {
try {
image = ImageDescriptor.createFromURL(iconUrl).createImage();
if (image != null) {
urlImages.put(iconString, image);
}
} catch (Throwable e) {
// ignore
}
}
return image;
}
}
return super.getImage(element);
}
Aggregations