Search in sources :

Example 1 with HelperFunctionOrCategory

use of eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory in project hale by halestudio.

the class HelperFunctionComparator method compare.

/**
 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer,
 *      java.lang.Object, java.lang.Object)
 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    HelperFunctionOrCategory hfoc1 = (HelperFunctionOrCategory) e1;
    HelperFunctionOrCategory hfoc2 = (HelperFunctionOrCategory) e2;
    String name1 = hfoc1.getName();
    String name2 = hfoc2.getName();
    return name1.compareTo(name2);
}
Also used : HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory)

Example 2 with HelperFunctionOrCategory

use of eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory in project hale by halestudio.

the class HelperFunctionsExtension method getChildren.

@Override
public Iterable<HelperFunctionOrCategory> getChildren(Category cat, HelperContext context) {
    init();
    final HelperContext theContext = extendContext(context);
    synchronized (children) {
        final Map<String, HelperFunctionOrCategory> catMap = children.get(cat);
        if (catMap == null) {
            return Collections.emptyList();
        } else {
            return () -> catMap.values().stream().map(fc -> injectContext(fc, theContext)).iterator();
        }
    }
}
Also used : HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ALogger(de.fhg.igd.slf4jplus.ALogger) HelperContext(eu.esdihumboldt.cst.functions.groovy.helper.HelperContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Category(eu.esdihumboldt.cst.functions.groovy.helper.Category) ExtensionUtil(de.fhg.igd.eclipse.util.extension.ExtensionUtil) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) HelperFunction(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunction) Method(java.lang.reflect.Method) Splitter(com.google.common.base.Splitter) Nullable(javax.annotation.Nullable) ExecutionContext(eu.esdihumboldt.hale.common.align.transformation.function.ExecutionContext) HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) ALoggerFactory(de.fhg.igd.slf4jplus.ALoggerFactory) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) ContextAwareHelperFunction(eu.esdihumboldt.cst.functions.groovy.helper.ContextAwareHelperFunction) Field(java.lang.reflect.Field) List(java.util.List) Modifier(java.lang.reflect.Modifier) HelperFunctionsService(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService) Specification(eu.esdihumboldt.cst.functions.groovy.helper.spec.Specification) Platform(org.eclipse.core.runtime.Platform) Collections(java.util.Collections) HelperContext(eu.esdihumboldt.cst.functions.groovy.helper.HelperContext)

Example 3 with HelperFunctionOrCategory

use of eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory in project hale by halestudio.

the class HelperFunctionLabelProvider method update.

/**
 * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
 */
@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    String elementName = null;
    if (element instanceof Category) {
        cell.setText(((Category) element).getName());
        cell.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImagesConstants.IMG_DEFINITION_GROUP));
    } else if (element instanceof HelperFunctionOrCategory) {
        HelperFunctionSpecification hfs = null;
        elementName = ((HelperFunctionOrCategory) element).getName();
        StyledString text = new StyledString(elementName);
        try {
            HelperFunction<?> helper = ((HelperFunctionOrCategory) element).asFunction();
            hfs = (HelperFunctionSpecification) helper.getSpec(elementName);
            text.append(PageFunctions.getStyledParameters(hfs));
        } catch (Exception e) {
        // 
        }
        cell.setText(text.getString());
        cell.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImagesConstants.IMG_FUNCTION));
        cell.setStyleRanges(text.getStyleRanges());
    }
    super.update(cell);
}
Also used : HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) Category(eu.esdihumboldt.cst.functions.groovy.helper.Category) HelperFunctionSpecification(eu.esdihumboldt.cst.functions.groovy.helper.spec.impl.HelperFunctionSpecification) HelperFunction(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunction) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 4 with HelperFunctionOrCategory

use of eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory in project hale by halestudio.

the class PageFunctions method createContents.

/**
 * @see org.eclipse.jface.dialogs.DialogTray#createContents(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createContents(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(comp);
    Label label = new Label(comp, SWT.NONE);
    label.setText("Functions Overview");
    label.setFont(JFaceResources.getHeaderFont());
    // tree viwever
    PatternFilter patternFilter = new TreePathPatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    final FilteredTree filteredTree = new TreePathFilteredTree(comp, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    TreeViewer tree = filteredTree.getViewer();
    tree.setUseHashlookup(true);
    HelperFunctionLabelProvider labelProvider = new HelperFunctionLabelProvider();
    tree.setLabelProvider(labelProvider);
    IContentProvider contentProvider;
    HelperFunctionsService functions = HaleUI.getServiceProvider().getService(HelperFunctionsService.class);
    contentProvider = new TreePathProviderAdapter(new HelperFunctionContentProvider(functions));
    tree.setContentProvider(contentProvider);
    GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
    tree.setComparator(new HelperFunctionComparator());
    tree.setInput(Category.ROOT);
    // Examples
    Label example = new Label(comp, SWT.NONE);
    example.setText("Function documentation");
    try {
        browser = new Browser(comp, SWT.WRAP | SWT.BORDER);
        browser.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 250).create());
    } catch (Throwable e) {
        if (BROWSER_ERROR_REPORTED.compareAndSet(false, true)) {
            log.error("Could not create embedded browser, using text field as fall-back", e);
        }
        textField = new Text(comp, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        textField.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 250).create());
    }
    tree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String eg = null;
            HelperFunctionSpecification hfs = null;
            if (!event.getSelection().isEmpty()) {
                TreeSelection treesel = (TreeSelection) event.getSelection();
                TreePath[] paths = treesel.getPaths();
                if (paths != null) {
                    TreePath path = paths[0];
                    for (int i = 0; i < path.getSegmentCount(); i++) {
                        if (path.getSegment(i) instanceof Category) {
                            eg = "Select a function to see its documentation.";
                            if (browser != null) {
                                browser.setText(eg);
                            } else if (textField != null) {
                                textField.setText(eg);
                            }
                        } else if (path.getSegment(i) instanceof HelperFunctionOrCategory) {
                            HelperFunctionOrCategory hfoc = ((HelperFunctionOrCategory) path.getSegment(i));
                            try {
                                hfs = (HelperFunctionSpecification) hfoc.asFunction().getSpec(hfoc.getName());
                            } catch (Exception e) {
                                log.error("There is a problem in retrieving the specification for a helper function.", e);
                            }
                            // displaying the specification
                            if (browser != null) {
                                eg = getFunctionSpecHTML(hfs);
                                browser.setText(eg);
                            } else if (textField != null) {
                                eg = getFunctionSpecText(hfs);
                                textField.setText(eg);
                            }
                        }
                    }
                }
            }
        }
    });
    return comp;
}
Also used : HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) HelperFunctionsService(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService) Category(eu.esdihumboldt.cst.functions.groovy.helper.Category) HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) IContentProvider(org.eclipse.jface.viewers.IContentProvider) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) StyledString(org.eclipse.jface.viewers.StyledString) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) TreePathProviderAdapter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter) TreePath(org.eclipse.jface.viewers.TreePath) HelperFunctionSpecification(eu.esdihumboldt.cst.functions.groovy.helper.spec.impl.HelperFunctionSpecification) Browser(org.eclipse.swt.browser.Browser)

Example 5 with HelperFunctionOrCategory

use of eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory in project hale by halestudio.

the class HelperFunctionsExtension method get.

@Override
public HelperFunctionOrCategory get(Category cat, String name, HelperContext context) {
    init();
    context = extendContext(context);
    synchronized (children) {
        Map<String, HelperFunctionOrCategory> catMap = children.get(cat);
        if (catMap == null) {
            return null;
        } else {
            HelperFunctionOrCategory res = catMap.get(name);
            if (res != null) {
                return injectContext(res, context);
            } else {
                return null;
            }
        }
    }
}
Also used : HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory)

Aggregations

HelperFunctionOrCategory (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory)6 Category (eu.esdihumboldt.cst.functions.groovy.helper.Category)4 HelperFunction (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunction)2 HelperFunctionsService (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService)2 HelperFunctionSpecification (eu.esdihumboldt.cst.functions.groovy.helper.spec.impl.HelperFunctionSpecification)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Splitter (com.google.common.base.Splitter)1 ExtensionUtil (de.fhg.igd.eclipse.util.extension.ExtensionUtil)1 ALogger (de.fhg.igd.slf4jplus.ALogger)1 ALoggerFactory (de.fhg.igd.slf4jplus.ALoggerFactory)1 ContextAwareHelperFunction (eu.esdihumboldt.cst.functions.groovy.helper.ContextAwareHelperFunction)1 HelperContext (eu.esdihumboldt.cst.functions.groovy.helper.HelperContext)1 Specification (eu.esdihumboldt.cst.functions.groovy.helper.spec.Specification)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 ExecutionContext (eu.esdihumboldt.hale.common.align.transformation.function.ExecutionContext)1 ServiceProvider (eu.esdihumboldt.hale.common.core.service.ServiceProvider)1 TreePathFilteredTree (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree)1 TreePathPatternFilter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter)1 TreePathProviderAdapter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter)1 Field (java.lang.reflect.Field)1