Search in sources :

Example 11 with TreePath

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();
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 12 with TreePath

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);
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) ShowInContext(org.eclipse.ui.part.ShowInContext) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) IDebugTarget(org.eclipse.debug.core.model.IDebugTarget) IProcess(org.eclipse.debug.core.model.IProcess)

Example 13 with TreePath

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());
            }
        }
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) IProject(org.eclipse.core.resources.IProject) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile)

Example 14 with TreePath

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;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) TreePath(org.eclipse.jface.viewers.TreePath) IPath(org.eclipse.core.runtime.IPath) ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) Path(org.eclipse.core.runtime.Path) ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) IPath(org.eclipse.core.runtime.IPath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) IResource(org.eclipse.core.resources.IResource)

Example 15 with TreePath

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;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5