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);
}
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();
}
}
}
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);
}
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;
}
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;
}
}
}
}
Aggregations