use of org.python.pydev.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class PythonTypePropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IFile iFile = null;
if (receiver instanceof IWrappedResource) {
IWrappedResource wrappedResource = (IWrappedResource) receiver;
Object actualObject = wrappedResource.getActualObject();
if (actualObject instanceof IProject) {
return true;
} else if (actualObject instanceof IFile) {
iFile = (IFile) actualObject;
}
}
if (receiver instanceof IAdaptable) {
IAdaptable iAdaptable = (IAdaptable) receiver;
iFile = iAdaptable.getAdapter(IFile.class);
}
if (iFile != null) {
if (CorePlugin.markAsPyDevFileIfDetected(iFile)) {
return true;
}
}
return false;
}
use of org.python.pydev.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class PythonLinkHelper method activateEditor.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
if (aSelection == null || aSelection.isEmpty()) {
return;
}
Object firstElement = aSelection.getFirstElement();
// if it is a python element, let's first get the actual object for finding the editor
if (firstElement instanceof IWrappedResource) {
IWrappedResource resource = (IWrappedResource) firstElement;
firstElement = resource.getActualObject();
}
// and now, if it is really a file...
if (firstElement instanceof IFile) {
// ok, let's check if the active editor is already the selection, because although the findEditor(editorInput) method
// may return an editor for the correct file, we may have multiple editors for the same file, and if the current
// editor is already correct, we don't want to change it
// @see bug: https://sourceforge.net/tracker/?func=detail&atid=577329&aid=2037682&group_id=85796
IEditorPart activeEditor = aPage.getActiveEditor();
if (activeEditor != null) {
IEditorInput editorInput = activeEditor.getEditorInput();
IFile currFile = (IFile) editorInput.getAdapter(IFile.class);
if (currFile != null && currFile.equals(firstElement)) {
// the current editor is already the active editor.
return;
}
}
// if we got here, the active editor is not a match, so, let's find one and show it.
IEditorPart editor = null;
IEditorInput fileInput = new FileEditorInput((IFile) firstElement);
if ((editor = aPage.findEditor(fileInput)) != null) {
aPage.bringToTop(editor);
}
}
}
use of org.python.pydev.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class PythonBaseModelProvider method inputChanged.
/*
* (non-Javadoc) Method declared on IContentProvider.
*/
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
super.inputChanged(viewer, oldInput, newInput);
this.viewer = (CommonViewer) viewer;
// whenever the input changes, we must reconfigure the top level choice
topLevelChoice.init(aConfig, this.viewer);
IWorkspace[] oldWorkspace = null;
IWorkspace[] newWorkspace = null;
// get the old
if (oldInput instanceof IWorkspace) {
oldWorkspace = new IWorkspace[] { (IWorkspace) oldInput };
} else if (oldInput instanceof IResource) {
oldWorkspace = new IWorkspace[] { ((IResource) oldInput).getWorkspace() };
} else if (oldInput instanceof IWrappedResource) {
IWrappedResource iWrappedResource = (IWrappedResource) oldInput;
Object actualObject = iWrappedResource.getActualObject();
if (actualObject instanceof IResource) {
IResource iResource = (IResource) actualObject;
oldWorkspace = new IWorkspace[] { iResource.getWorkspace() };
}
} else if (oldInput instanceof IWorkingSet) {
IWorkingSet oldWorkingSet = (IWorkingSet) oldInput;
oldWorkspace = getWorkspaces(oldWorkingSet);
}
// and the new
if (newInput instanceof IWorkspace) {
newWorkspace = new IWorkspace[] { (IWorkspace) newInput };
} else if (newInput instanceof IResource) {
newWorkspace = new IWorkspace[] { ((IResource) newInput).getWorkspace() };
} else if (newInput instanceof IWrappedResource) {
IWrappedResource iWrappedResource = (IWrappedResource) newInput;
Object actualObject = iWrappedResource.getActualObject();
if (actualObject instanceof IResource) {
IResource iResource = (IResource) actualObject;
newWorkspace = new IWorkspace[] { iResource.getWorkspace() };
}
} else if (newInput instanceof IWorkingSet) {
IWorkingSet newWorkingSet = (IWorkingSet) newInput;
newWorkspace = getWorkspaces(newWorkingSet);
}
// now, let's treat the workspace
if (oldWorkspace != null) {
for (IWorkspace workspace : oldWorkspace) {
workspace.removeResourceChangeListener(this);
}
}
if (newWorkspace != null) {
for (IWorkspace workspace : newWorkspace) {
workspace.addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
}
}
this.input = newWorkspace;
}
use of org.python.pydev.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class PythonModelProviderTest method testInterceptAdd.
/**
* Test if intercepting an add deep within the pythonpath structure will correctly return an object
* from the python model.
*/
public void testInterceptAdd() throws Exception {
PythonNature nature = createNature(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source/python");
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature);
file = new FileStub(project, new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source/python/pack1/pack2/mod2.py"));
provider = new PythonModelProvider();
HashSet<Object> files = new HashSet<Object>();
files.add(file);
files.add(null);
files.add("string");
provider.interceptAdd(new PipelinedShapeModification(file.getParent(), files));
assertEquals(2, files.size());
for (Object wrappedResource : files) {
assertTrue((wrappedResource instanceof IWrappedResource && ((IWrappedResource) wrappedResource).getActualObject() == file) || wrappedResource.equals("string"));
}
}
use of org.python.pydev.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class PyResourceDropAdapterAssistant method getActual.
/**
* This is the main change (wherever it had a target, it tries to get the actual wrapped resource -- if it is wrapped)
*/
private Object getActual(Object target) {
if (target instanceof IWrappedResource) {
IWrappedResource resource = (IWrappedResource) target;
target = resource.getActualObject();
}
return target;
}
Aggregations