Search in sources :

Example 11 with IWrappedResource

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;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) IProject(org.eclipse.core.resources.IProject)

Example 12 with IWrappedResource

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);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) IEditorInput(org.eclipse.ui.IEditorInput)

Example 13 with IWrappedResource

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;
}
Also used : IWorkspace(org.eclipse.core.resources.IWorkspace) IResource(org.eclipse.core.resources.IResource) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 14 with IWrappedResource

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"));
    }
}
Also used : PythonNature(org.python.pydev.plugin.nature.PythonNature) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) FileStub(org.python.pydev.shared_core.resource_stubs.FileStub) File(java.io.File) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) HashSet(java.util.HashSet)

Example 15 with IWrappedResource

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;
}
Also used : IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource)

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