Search in sources :

Example 1 with LabelAndImage

use of org.python.pydev.navigator.LabelAndImage in project Pydev by fabioz.

the class PydevPackageExplorer method tryToReveal.

/**
 * This is the method that actually tries to reveal some item in the tree.
 *
 * It will go through the pipeline to see if the actual object to reveal has been replaced in the replace pipeline.
 */
public boolean tryToReveal(Object element) {
    element = getPythonModelElement(element);
    if (element instanceof PydevZipFileStorage) {
        pythonLinkHelper.setCommonViewer(this.getCommonViewer());
        PydevZipFileStorage pydevZipFileStorage = (PydevZipFileStorage) element;
        IStructuredSelection externalFileSelectionInTree = pythonLinkHelper.findExternalFileSelection(pydevZipFileStorage.zipFile);
        if (externalFileSelectionInTree != null && !externalFileSelectionInTree.isEmpty()) {
            Object firstElement = externalFileSelectionInTree.getFirstElement();
            if (firstElement instanceof TreeNode) {
                TreeNode treeNode = (TreeNode) firstElement;
                // Ok, got to the zip file, let's try to find the path below it...
                String zipPath = pydevZipFileStorage.zipPath;
                List<String> split = StringUtils.split(zipPath, '/');
                for (String string : split) {
                    List<TreeNode> children = treeNode.getChildren();
                    for (TreeNode<LabelAndImage> child : children) {
                        if (string.equals(child.getData().label)) {
                            treeNode = child;
                            // Goes on to the next substring...
                            break;
                        }
                    }
                }
                if (revealAndVerify(new StructuredSelection(treeNode))) {
                    return true;
                }
            } else {
                Log.log("Expected a TreeNode. Found: " + firstElement);
                // Just go on to show the zip, not the internal contents...
                if (revealAndVerify(externalFileSelectionInTree)) {
                    return true;
                }
            }
        }
    } else if (element instanceof File) {
        pythonLinkHelper.setCommonViewer(this.getCommonViewer());
        IStructuredSelection externalFileSelectionInTree = pythonLinkHelper.findExternalFileSelection((File) element);
        if (externalFileSelectionInTree != null && !externalFileSelectionInTree.isEmpty()) {
            if (revealAndVerify(externalFileSelectionInTree)) {
                return true;
            }
        }
    }
    // null is checked in the revealAndVerify function
    if (revealAndVerify(element)) {
        return true;
    }
    // if it is a wrapped resource that we couldn't show, try to reveal as a resource...
    if (element instanceof IAdaptable && !(element instanceof IResource)) {
        IAdaptable adaptable = (IAdaptable) element;
        IResource resource = adaptable.getAdapter(IResource.class);
        if (resource != null) {
            if (revealAndVerify(resource)) {
                return true;
            }
        }
    }
    return false;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) LabelAndImage(org.python.pydev.navigator.LabelAndImage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TreeNode(org.python.pydev.shared_core.structure.TreeNode) PydevZipFileStorage(org.python.pydev.shared_ui.editor_input.PydevZipFileStorage) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 2 with LabelAndImage

use of org.python.pydev.navigator.LabelAndImage in project Pydev by fabioz.

the class AbstractFilter method getName.

protected String getName(Object element) {
    if (element instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) element;
        Object adapted = adaptable.getAdapter(IResource.class);
        if (adapted instanceof IResource) {
            IResource resource = (IResource) adapted;
            return resource.getName();
        }
    } else if (element instanceof TreeNode) {
        TreeNode treeNode = (TreeNode) element;
        Object data = treeNode.getData();
        if (data instanceof LabelAndImage) {
            return ((LabelAndImage) data).label;
        }
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) TreeNode(org.python.pydev.shared_core.structure.TreeNode) LabelAndImage(org.python.pydev.navigator.LabelAndImage) IResource(org.eclipse.core.resources.IResource)

Aggregations

IResource (org.eclipse.core.resources.IResource)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 LabelAndImage (org.python.pydev.navigator.LabelAndImage)2 TreeNode (org.python.pydev.shared_core.structure.TreeNode)2 File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 PydevZipFileStorage (org.python.pydev.shared_ui.editor_input.PydevZipFileStorage)1