use of org.eclipse.jface.viewers.TreePath 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 org.eclipse.jface.viewers.TreePath in project hale by halestudio.
the class TypeStructureTray method createTargetSample.
/**
* Create sample code for populating the target property.
*
* @param selection the selection in the tree viewer
* @param types the types serving as input
* @return the sample code
*/
protected String createTargetSample(ISelection selection, Collection<? extends TypeDefinition> types) {
ITreeSelection treeSel = (ITreeSelection) selection;
TreePath[] paths = treeSel.getPaths();
if (paths != null && paths.length > 0) {
// XXX for now only use the first path
TreePath path = paths[0];
DefinitionGroup parent;
int startIndex = 0;
List<PathTree> properties;
// determine parent type
if (path.getFirstSegment() instanceof TypeDefinition) {
// XXX not supported yet
return null;
} else {
// types are not in the tree, single type must be root
parent = types.iterator().next();
// build PathTrees from tree paths
properties = PathTree.createPathTrees(Arrays.asList(paths), startIndex);
}
StringBuilder example = new StringBuilder();
example.append(GroovyConstants.BINDING_TARGET);
example.append(" {\n");
int indentCount = 1;
for (PathTree tree : properties) {
InstanceBuilderCode.appendBuildProperties(example, indentCount, tree, parent, BUILDER_USE_BRACKETS);
}
example.append("}");
return example.toString();
}
return GroovyConstants.BINDING_TARGET + " = {}";
}
use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.
the class TypeStructureTray method createSourceSample.
/**
* Create sample code for accessing a source property.
*
* @param selection the selection in the tree viewer
* @param types the types serving as input
* @return the sample code or <code>null</code>
*/
protected String createSourceSample(ISelection selection, Collection<? extends TypeDefinition> types) {
ITreeSelection treeSel = (ITreeSelection) selection;
TreePath[] paths = treeSel.getPaths();
if (paths != null && paths.length > 0) {
StringBuilder result = null;
for (TreePath path : paths) {
String examples = createSourceSample(path, types);
if (examples != null) {
if (result == null) {
result = new StringBuilder();
}
result.append(examples);
}
}
if (result != null) {
return result.toString();
}
return null;
}
return null;
}
use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.
the class InstanceValidationReportDetailsContentProvider method inputChanged.
/**
* @see ITreePathContentProvider#inputChanged(Viewer, Object, Object)
*/
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
childCache.clear();
messages.clear();
limitedPaths.clear();
if (newInput instanceof Collection<?>) {
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
TreePath emptyPath = new TreePath(new Object[0]);
for (Object o : (Collection<?>) newInput) {
if (o instanceof InstanceValidationMessage) {
InstanceValidationMessage message = ((InstanceValidationMessage) o);
Set<Object> baseTypes = childCache.get(emptyPath);
if (baseTypes == null) {
baseTypes = new HashSet<Object>();
childCache.put(emptyPath, baseTypes);
}
// XXX maybe expand messages with SSID?
TypeDefinition typeDef = null;
if (message.getType() != null) {
typeDef = ss.getSchemas(SchemaSpaceID.TARGET).getType(message.getType());
}
// use typeDef if available, QName otherwise
Object use = typeDef == null ? message.getType() : typeDef;
if (use == null) {
// fall-back to generic category
use = "General";
}
baseTypes.add(use);
messages.put(new TreePath(new Object[] { use }), message);
}
}
}
}
use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.
the class InstanceValidationReportDetailsPage method getValidSelection.
/**
* Returns a valid instance selection for the current selection of the tree
* viewer. Returns <code>null</code> if there is none.
*
* @return a valid instance selection for the current selection of the tree
* viewer or <code>null</code>
*/
private InstanceSelection getValidSelection() {
ISelection viewerSelection = treeViewer.getSelection();
if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty())
return null;
ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
// XXX use all paths
TreePath firstPath = treeSelection.getPaths()[0];
// instead of first
// only?
InstanceValidationMessage firstMessage;
Iterator<InstanceValidationMessage> restIter;
if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
restIter = Iterators.emptyIterator();
} else {
Collection<InstanceValidationMessage> messages = contentProvider.getMessages(treeSelection.getPaths()[0]);
if (messages.isEmpty())
// shouldn't happen, but doesn't really matter
return null;
restIter = messages.iterator();
firstMessage = restIter.next();
}
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
// check first message for valid instance reference
if (firstMessage.getInstanceReference() == null || is.getInstance(firstMessage.getInstanceReference()) == null)
return null;
Set<InstanceReference> references = new HashSet<InstanceReference>();
references.add(firstMessage.getInstanceReference());
while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());
return new DefaultInstanceSelection(references.toArray());
}
Aggregations