use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.
the class PropertyEntityDialog method getObjectFromSelection.
/**
* @see EntityDialog#getObjectFromSelection(ISelection)
*/
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
return (EntityDefinition) element;
}
}
if (!selection.isEmpty() && selection instanceof ITreeSelection) {
// create property definition w/ default contexts
TreePath path = ((ITreeSelection) selection).getPaths()[0];
// get parent type
TypeDefinition type = ((PropertyDefinition) path.getFirstSegment()).getParentType();
// determine definition path
List<ChildContext> defPath = new ArrayList<ChildContext>();
for (int i = 0; i < path.getSegmentCount(); i++) {
defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
}
// TODO check if property entity definition is applicable?
return new PropertyEntityDefinition(type, defPath, ssid, parentType.getFilter());
}
return null;
}
use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.
the class UnpopulatedPropertiesFilter method select.
/**
* @see ViewerFilter#select(Viewer, Object, Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (ps != null) {
if (element instanceof TreePath) {
element = ((TreePath) element).getLastSegment();
}
if (element instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) element;
if (filterOnlyPopulatedTypes) {
TypeEntityDefinition type = AlignmentUtil.getTypeEntity(entityDef);
int typeCount = ps.getPopulation(type).getOverallCount();
if (typeCount == 0 || typeCount == Population.UNKNOWN) {
// all
return true;
}
}
if (!entityDef.getPropertyPath().isEmpty() && // only filter properties
ps.hasPopulation(entityDef.getSchemaSpace())) {
// only filter if there is a population
Population pop = ps.getPopulation(entityDef);
return pop != null && pop.getOverallCount() != 0;
}
}
}
return true;
}
use of org.eclipse.jface.viewers.TreePath in project linuxtools by eclipse.
the class NewProjectCreationPage method getSelectedWorkingSet.
/**
* Try our best to set the working sets field to something sensible based on the
* current selection.
*/
private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
if (!(selection instanceof ITreeSelection)) {
return EMPTY_WORKING_SET_ARRAY;
}
ITreeSelection treeSelection = (ITreeSelection) selection;
if (treeSelection.isEmpty()) {
return EMPTY_WORKING_SET_ARRAY;
}
List<?> elements = treeSelection.toList();
if (elements.size() == 1) {
Object element = elements.get(0);
TreePath[] paths = treeSelection.getPathsFor(element);
if (paths.length != 1 || paths[0].getSegmentCount() == 0) {
return EMPTY_WORKING_SET_ARRAY;
}
Object candidate = paths[0].getSegment(0);
if (!(candidate instanceof IWorkingSet)) {
return EMPTY_WORKING_SET_ARRAY;
}
IWorkingSet workingSetCandidate = (IWorkingSet) candidate;
if (!workingSetCandidate.isAggregateWorkingSet()) {
return new IWorkingSet[] { workingSetCandidate };
}
return EMPTY_WORKING_SET_ARRAY;
}
ArrayList<IWorkingSet> result = new ArrayList<>();
for (Object element : elements) {
if (element instanceof IWorkingSet && !((IWorkingSet) element).isAggregateWorkingSet()) {
result.add((IWorkingSet) element);
}
}
if (!result.isEmpty()) {
return result.toArray(new IWorkingSet[result.size()]);
} else {
return EMPTY_WORKING_SET_ARRAY;
}
}
use of org.eclipse.jface.viewers.TreePath in project linuxtools by eclipse.
the class CModelLabelsTest method checkLabelProvider.
private static void checkLabelProvider(CachegrindFile file) {
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
TreeViewer viewer = view.getViewer();
TreePath path = new TreePath(new Object[] { view.getOutputs()[0], file });
checkLabelProvider(viewer, path, file);
}
use of org.eclipse.jface.viewers.TreePath in project linuxtools by eclipse.
the class DoubleClickTest method testDoubleClickFunction.
@Test
public void testDoubleClickFunction() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testDoubleClickFunction");
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
CachegrindOutput output = view.getOutputs()[0];
// $NON-NLS-1$
CachegrindFile file = getFileByName(output, "cpptest.cpp");
// $NON-NLS-1$
CachegrindFunction func = getFunctionByName(file, "main");
TreePath path = new TreePath(new Object[] { output, file, func });
doDoubleClick(path);
// check file in editor
IEditorPart editor = checkFile(file);
// check line number
ITextEditor textEditor = (ITextEditor) editor;
ISelection selection = textEditor.getSelectionProvider().getSelection();
TextSelection textSelection = (TextSelection) selection;
// zero-indexed
int line = textSelection.getStartLine() + 1;
int expectedLine = ((IFunction) func.getModel()).getSourceRange().getStartLine();
assertEquals(expectedLine, line);
}
Aggregations