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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations