Search in sources :

Example 1 with Category

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;
}
Also used : Category(eu.esdihumboldt.hale.common.align.extension.category.Category) ArrayList(java.util.ArrayList) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)

Example 2 with Category

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;
}
Also used : Category(eu.esdihumboldt.hale.common.align.extension.category.Category) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)

Example 3 with Category

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);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Category(eu.esdihumboldt.hale.common.align.extension.category.Category) StreamResult(javax.xml.transform.stream.StreamResult) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) Element(org.w3c.dom.Element) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) Callable(java.util.concurrent.Callable) URL(java.net.URL) StringWriter(java.io.StringWriter) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 4 with Category

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);
}
Also used : Category(eu.esdihumboldt.hale.common.align.extension.category.Category) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL)

Aggregations

Category (eu.esdihumboldt.hale.common.align.extension.category.Category)4 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)3 URL (java.net.URL)2 FunctionParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Callable (java.util.concurrent.Callable)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 VelocityContext (org.apache.velocity.VelocityContext)1 Image (org.eclipse.swt.graphics.Image)1 Element (org.w3c.dom.Element)1