use of org.eclipse.jface.viewers.TreePath in project knime-core by knime.
the class WorkflowGroupSelectionDialog method pathToTreeSelection.
/**
* @param path the path of a resource
* @return the selection to be passed to a tree in order to select the
* resource denoted by the given path
*/
public static IStructuredSelection pathToTreeSelection(final IPath path) {
if (path != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource r = root.findMember(path);
if (r != null && !r.equals(root)) {
IContainer c = r.getParent();
if (r instanceof IContainer) {
c = (IContainer) r;
}
String[] segments = c.getFullPath().segments();
Object[] treePathSegments = new Object[segments.length];
// find all parents in order to create the path segments
int i = 1;
while (c.getParent() != null) {
treePathSegments[treePathSegments.length - i] = c;
c = c.getParent();
i++;
}
TreePath treePath = new TreePath(treePathSegments);
return new TreeSelection(treePath);
}
}
// default: return empty selection
return new TreeSelection();
}
use of org.eclipse.jface.viewers.TreePath in project erlide_eclipse by erlang.
the class ConsolePageParticipant method getShowInContext.
@Override
public ShowInContext getShowInContext() {
final IProcess process = getProcess();
if (process == null) {
return null;
}
final IDebugTarget target = process.getAdapter(IDebugTarget.class);
ISelection selection = null;
if (target == null) {
selection = new TreeSelection(new TreePath(new Object[] { DebugPlugin.getDefault().getLaunchManager(), process.getLaunch(), process }));
} else {
selection = new TreeSelection(new TreePath(new Object[] { DebugPlugin.getDefault().getLaunchManager(), target.getLaunch(), target }));
}
return new ShowInContext(null, selection);
}
use of org.eclipse.jface.viewers.TreePath in project abstools by abstools.
the class NavigatorUtils method openEditor.
/**
* Opens the file in an editor that corresponds to the given
* TreeSelection. Only the first element of the selection will be
* taken into account.
*
* @param ts TreeSelection that is used as a base to find an appropriate editor
* @throws PartInitException - if the editor could not be opened for highlighting
*/
public static void openEditor(TreeSelection ts) throws PartInitException {
if (!ts.equals(TreeSelection.EMPTY)) {
TreePath path = ts.getPaths()[0];
IProject project = getProject(path);
if (project != null) {
if (path.getLastSegment() instanceof InternalASTNode<?>) {
InternalASTNode<?> node = (InternalASTNode<?>) path.getLastSegment();
openAndHighlightEditor(node);
} else if (path.getLastSegment() instanceof ModulePath) {
ModulePath mp = (ModulePath) path.getLastSegment();
if (mp.hasModuleWithDecls()) {
InternalASTNode<ModuleDecl> moduleDecl = mp.getModuleDecl();
openAndHighlightEditor(moduleDecl);
}
} else if (path.getLastSegment() instanceof PackageAbsFile) {
openABSEditorForFile((PackageAbsFile) path.getLastSegment());
}
}
}
}
use of org.eclipse.jface.viewers.TreePath in project abstools by abstools.
the class NewABSFileWizard method getProjectSelectionFromModulePath.
private IStructuredSelection getProjectSelectionFromModulePath(IStructuredSelection sel) {
ModulePath mp = getLastModulePathElement(sel);
if (mp != null) {
AbsNature nature = mp.getNature();
IProject project = nature.getProject();
Set<InternalASTNode<ModuleDecl>> modulesForPrefix = mp.getModulesForPrefix();
// Get first the of element in the HashSet
InternalASTNode<ModuleDecl> m = modulesForPrefix.isEmpty() ? null : modulesForPrefix.iterator().next();
List<IResource> folders = new ArrayList<IResource>();
folders.add(project);
if (m != null) {
CompilationUnit compilationUnit = m.getASTNode().getCompilationUnit();
IPath path = new Path(compilationUnit.getFileName());
path = path.makeRelativeTo(project.getLocation());
for (int i = 0; i < path.segmentCount() - 1; i++) {
folders.add(project.getFolder(path.segment(i)));
}
}
TreePath treePath = new TreePath(folders.toArray());
TreeSelection treeSelection = new TreeSelection(new TreePath[] { treePath });
return treeSelection;
}
return sel;
}
use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class AnnotationOrderedListsDialog method getConceptElements.
private List<String> getConceptElements() {
DataModelMainPage page = parentPage;
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
List<String> childNames = new ArrayList<String>();
XSDElementDeclaration decl = null;
if (selection.getFirstElement() instanceof XSDElementDeclaration) {
decl = (XSDElementDeclaration) selection.getFirstElement();
// childNames = Util.getChildElementNames(decl.getElement());
} else if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
XSDComponent xSDCom = null;
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation) {
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
break;
}
}
decl = (XSDElementDeclaration) xSDCom.getContainer();
}
try {
childNames = Util.getChildElementNames(decl.getName(), decl);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return childNames;
}
Aggregations