Search in sources :

Example 1 with IWrappedResource

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

the class CustomizationCommons method getContainerFromObject.

public static IContainer getContainerFromObject(Object receiver) {
    if (receiver instanceof IWrappedResource) {
        IWrappedResource wrappedResource = (IWrappedResource) receiver;
        Object actualObject = wrappedResource.getActualObject();
        if (actualObject instanceof IContainer) {
            return (IContainer) actualObject;
        }
    }
    if (receiver instanceof IContainer) {
        return (IContainer) receiver;
    }
    return null;
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource)

Example 2 with IWrappedResource

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

the class PyPackageStateSaver method getCompletPath.

/**
 * This method will get the complete path in the tree for a resource (or wrapped resource)
 */
private ArrayList<Object> getCompletPath(Object resource) {
    // cannot have more than 100 levels... ok? (this is just a 'safeguard')
    int max = 100;
    int i = 0;
    ArrayList<Object> ret = new ArrayList<Object>();
    ret.add(0, resource);
    while (true) {
        i++;
        if (i > max) {
            Log.log("Could not get the structure for: " + resource);
            // something strange happened...
            return new ArrayList<Object>();
        } else if (resource instanceof IProject || resource instanceof IWorkspaceRoot || resource instanceof IWorkingSet) {
            break;
        } else if (resource instanceof IWrappedResource) {
            IWrappedResource w = (IWrappedResource) resource;
            resource = w.getParentElement();
            if (resource == null) {
                break;
            }
            ret.add(0, resource);
        } else if (resource instanceof IResource) {
            IResource r = (IResource) resource;
            resource = r.getParent();
            if (resource == null) {
                break;
            }
            ret.add(0, resource);
        }
    }
    return ret;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) IWorkingSet(org.eclipse.ui.IWorkingSet) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) IResource(org.eclipse.core.resources.IResource)

Example 3 with IWrappedResource

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

the class PyPropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (expectedValue == null) {
        return false;
    }
    if ("open".equals(property)) {
        if (receiver instanceof PythonProjectSourceFolder) {
            PythonProjectSourceFolder pythonProjectSourceFolder = (PythonProjectSourceFolder) receiver;
            IResource actualObject = pythonProjectSourceFolder.getActualObject();
            if (actualObject instanceof IProject) {
                return ((IProject) actualObject).isOpen() == toBoolean(expectedValue);
            }
        }
    } else if ("name".equals(property)) {
        if (receiver instanceof IWrappedResource) {
            IWrappedResource wrappedResource = (IWrappedResource) receiver;
            IResource resource = (IResource) wrappedResource.getAdapter(IResource.class);
            if (resource != null) {
                return expectedValue.toString().equals(resource.getName());
            }
        }
    }
    return false;
}
Also used : PythonProjectSourceFolder(org.python.pydev.navigator.elements.PythonProjectSourceFolder) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource)

Example 4 with IWrappedResource

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

the class PydevPackageExplorer method getPythonModelElement.

/**
 * @param element the element that should be gotten as an element from the pydev model
 * @return a pydev element or the same element passed as a parameter.
 */
private Object getPythonModelElement(Object element) {
    if (element instanceof IWrappedResource) {
        return element;
    }
    INavigatorPipelineService pipelineService = this.getNavigatorContentService().getPipelineService();
    if (element instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) element;
        IFile file = adaptable.getAdapter(IFile.class);
        if (file != null) {
            HashSet<Object> files = new ContributorTrackingSet((NavigatorContentService) this.getNavigatorContentService());
            files.add(file);
            pipelineService.interceptAdd(new PipelinedShapeModification(file.getParent(), files));
            if (files.size() > 0) {
                element = files.iterator().next();
            }
        }
    }
    return element;
}
Also used : INavigatorPipelineService(org.eclipse.ui.navigator.INavigatorPipelineService) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) ContributorTrackingSet(org.eclipse.ui.internal.navigator.ContributorTrackingSet) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource)

Example 5 with IWrappedResource

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

the class PythonLabelProvider method getImage.

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
 */
@Override
public Image getImage(Object element) {
    if (element instanceof PythonProjectSourceFolder) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PROJECT_SOURCE_FOLDER_ICON));
    }
    if (element instanceof PythonSourceFolder) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.SOURCE_FOLDER_ICON));
    }
    if (element instanceof PythonFolder) {
        PythonFolder folder = (PythonFolder) element;
        IFolder actualObject = folder.getActualObject();
        if (actualObject != null) {
            if (checkIfValidPackageFolder(folder)) {
                return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.FOLDER_PACKAGE_ICON));
            }
        }
        return provider.getImage(actualObject);
    }
    if (element instanceof PythonNode) {
        PythonNode node = (PythonNode) element;
        return node.entry.getImage();
    }
    if (element instanceof IWrappedResource) {
        IWrappedResource resource = (IWrappedResource) element;
        Object actualObject = resource.getActualObject();
        if (actualObject instanceof IFile) {
            IFile iFile = (IFile) actualObject;
            final String name = iFile.getName();
            if (name.indexOf('.') == -1) {
                try {
                    if (CorePlugin.markAsPyDevFileIfDetected(iFile)) {
                        if (FileTypesPreferences.isCythonFile(name)) {
                            return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
                        }
                        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PY_FILE_ICON));
                    }
                } catch (Exception e) {
                // Ignore
                }
            }
            if (FileTypesPreferences.isCythonFile(name)) {
                return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
            }
            if (name.startsWith("__init__.") && PythonPathHelper.isValidSourceFile(name)) {
                return ImageCache.asImage(PyTitlePreferencesPage.getInitIcon());
            } else {
                IProject project = iFile.getProject();
                try {
                    if (project.hasNature(PythonNature.DJANGO_NATURE_ID)) {
                        String djangoModulesHandling = PyTitlePreferencesPage.getDjangoModulesHandling();
                        if (djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_SHOW_PARENT_AND_DECORATE || djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_DECORATE) {
                            if (PyTitlePreferencesPage.isDjangoModuleToDecorate(name)) {
                                return ImageCache.asImage(PyTitlePreferencesPage.getDjangoModuleIcon(name));
                            }
                        }
                    }
                } catch (CoreException e) {
                    Log.log(e);
                }
            }
        }
        return provider.getImage(actualObject);
    }
    if (element instanceof ProjectConfigError) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.ERROR));
    }
    if (element instanceof TreeNode<?>) {
        TreeNode<?> treeNode = (TreeNode<?>) element;
        LabelAndImage data = (LabelAndImage) treeNode.getData();
        return ImageCache.asImage(data.image);
    }
    if (element instanceof IFile) {
        IFile iFile = (IFile) element;
        String name = iFile.getName();
        if (FileTypesPreferences.isCythonFile(name)) {
            return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
        }
    }
    if (element instanceof IProject) {
        IProject project = (IProject) element;
        if (!project.isOpen()) {
            return null;
        }
        IMarker[] markers;
        try {
            markers = project.findMarkers(PythonBaseModelProvider.PYDEV_PACKAGE_EXPORER_PROBLEM_MARKER, true, 0);
        } catch (CoreException e1) {
            Log.log(e1);
            return null;
        }
        if (markers == null || markers.length == 0) {
            return null;
        }
        // We have errors: make them explicit.
        if (projectWithError == null) {
            synchronized (lock) {
                // the other enters the lock, it does not need to recalculated).
                if (projectWithError == null) {
                    // Note on double-checked locking idiom: http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html.
                    // (would not work as expected on java 1.4)
                    Image image = provider.getImage(element);
                    try {
                        DecorationOverlayIcon decorationOverlayIcon = new DecorationOverlayIcon(image, ImageCache.asImageDescriptor(SharedUiPlugin.getImageCache().getDescriptor(UIConstants.ERROR_SMALL)), IDecoration.BOTTOM_LEFT);
                        projectWithError = decorationOverlayIcon.createImage();
                    } catch (Exception e) {
                        Log.log("Unable to create error decoration for project icon.", e);
                        projectWithError = image;
                    }
                }
            }
        }
        return projectWithError;
    }
    if (element instanceof IWorkingSet) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.WORKING_SET));
    }
    return null;
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) IFile(org.eclipse.core.resources.IFile) PythonNode(org.python.pydev.navigator.elements.PythonNode) PythonFolder(org.python.pydev.navigator.elements.PythonFolder) ProjectConfigError(org.python.pydev.navigator.elements.ProjectConfigError) PythonProjectSourceFolder(org.python.pydev.navigator.elements.PythonProjectSourceFolder) Image(org.eclipse.swt.graphics.Image) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) TreeNode(org.python.pydev.shared_core.structure.TreeNode) IMarker(org.eclipse.core.resources.IMarker) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) IWorkingSet(org.eclipse.ui.IWorkingSet) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IWrappedResource (org.python.pydev.navigator.elements.IWrappedResource)19 IProject (org.eclipse.core.resources.IProject)8 IResource (org.eclipse.core.resources.IResource)7 IFile (org.eclipse.core.resources.IFile)6 PythonSourceFolder (org.python.pydev.navigator.elements.PythonSourceFolder)6 IContainer (org.eclipse.core.resources.IContainer)5 IWorkingSet (org.eclipse.ui.IWorkingSet)5 PythonNature (org.python.pydev.plugin.nature.PythonNature)5 HashSet (java.util.HashSet)4 IFolder (org.eclipse.core.resources.IFolder)4 PipelinedShapeModification (org.eclipse.ui.navigator.PipelinedShapeModification)4 LinkedHashSet (java.util.LinkedHashSet)3 PythonFolder (org.python.pydev.navigator.elements.PythonFolder)3 PythonProjectSourceFolder (org.python.pydev.navigator.elements.PythonProjectSourceFolder)3 TreeNode (org.python.pydev.shared_core.structure.TreeNode)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2