Java 类org.eclipse.ui.navigator.PipelinedShapeModification 实例源码

项目:Eclipse-Postfix-Code-Completion    文件:JavaNavigatorContentProvider.java   
/**
 * Converts the shape modification to use Java elements.
 *
 *
 * @param modification
 *            the shape modification to convert
 * @return returns true if the conversion took place
 */
private boolean convertToJavaElements(PipelinedShapeModification modification) {
    Object parent = modification.getParent();
    // As of 3.3, we no longer re-parent additions to IProject.
    if (parent instanceof IContainer) {
        IJavaElement element = JavaCore.create((IContainer) parent);
        if (element != null && element.exists()) {
            // we don't convert the root
            if( !(element instanceof IJavaModel) && !(element instanceof IJavaProject))
                modification.setParent(element);
            return convertToJavaElements(modification.getChildren());

        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaNavigatorContentProvider.java   
/**
 * Converts the shape modification to use Java elements.
 *
 *
 * @param modification
 *            the shape modification to convert
 * @return returns true if the conversion took place
 */
private boolean convertToJavaElements(PipelinedShapeModification modification) {
    Object parent = modification.getParent();
    // As of 3.3, we no longer re-parent additions to IProject.
    if (parent instanceof IContainer) {
        IJavaElement element = JavaCore.create((IContainer) parent);
        if (element != null && element.exists()) {
            // we don't convert the root
            if( !(element instanceof IJavaModel) && !(element instanceof IJavaProject))
                modification.setParent(element);
            return convertToJavaElements(modification.getChildren());

        }
    }
    return false;
}
项目:Pydev    文件:PythonModelProviderTest.java   
/**
 * 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"));
    }
}
项目:Pydev    文件:PydevPackageExplorer.java   
/**
 * @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;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaNavigatorContentProvider.java   
public PipelinedShapeModification interceptAdd(PipelinedShapeModification addModification) {

        Object parent= addModification.getParent();

        if (parent instanceof IJavaProject) {
            addModification.setParent(((IJavaProject)parent).getProject());
        }

        if (parent instanceof IWorkspaceRoot) {
            deconvertJavaProjects(addModification);
        }

        convertToJavaElements(addModification);
        return addModification;
    }
项目:Eclipse-Postfix-Code-Completion    文件:JavaNavigatorContentProvider.java   
private void deconvertJavaProjects(PipelinedShapeModification modification) {
    Set<IProject> convertedChildren = new LinkedHashSet<IProject>();
    for (Iterator<IAdaptable> iterator = modification.getChildren().iterator(); iterator.hasNext();) {
        Object added = iterator.next();
        if(added instanceof IJavaProject) {
            iterator.remove();
            convertedChildren.add(((IJavaProject)added).getProject());
        }
    }
    modification.getChildren().addAll(convertedChildren);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaNavigatorContentProvider.java   
public PipelinedShapeModification interceptAdd(PipelinedShapeModification addModification) {

        Object parent= addModification.getParent();

        if (parent instanceof IJavaProject) {
            addModification.setParent(((IJavaProject)parent).getProject());
        }

        if (parent instanceof IWorkspaceRoot) {
            deconvertJavaProjects(addModification);
        }

        convertToJavaElements(addModification);
        return addModification;
    }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaNavigatorContentProvider.java   
private void deconvertJavaProjects(PipelinedShapeModification modification) {
    Set<IProject> convertedChildren = new LinkedHashSet<IProject>();
    for (Iterator<IAdaptable> iterator = modification.getChildren().iterator(); iterator.hasNext();) {
        Object added = iterator.next();
        if(added instanceof IJavaProject) {
            iterator.remove();
            convertedChildren.add(((IJavaProject)added).getProject());
        }
    }
    modification.getChildren().addAll(convertedChildren);
}
项目:Pydev    文件:PythonModelProviderTest.java   
/**
 * Test if setting the project root as a source folder will return an object from the python model.
 */
public void testProjectIsRoot2() throws Exception {
    String pythonpathLoc = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot";
    final HashSet<String> pythonPathSet = new HashSet<String>();
    pythonPathSet.add(pythonpathLoc);

    PythonNature nature = createNature(pythonPathSet);

    WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub();
    project = new ProjectStub(new File(pythonpathLoc), nature);
    provider = new PythonModelProvider();
    FolderStub folder = new FolderStub(project,
            new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source"));

    workspaceRootStub.addChild(project);
    project.setParent(workspaceRootStub);

    HashSet<Object> folders = new HashSet<Object>();
    folders.add(folder);
    PipelinedShapeModification addModification = new PipelinedShapeModification(project, folders);
    addModification.setParent(project);
    provider.interceptAdd(addModification);

    assertEquals(1, addModification.getChildren().size());
    //it should've been wrapped
    assertTrue(addModification.getChildren().iterator().next() instanceof IWrappedResource);
}
项目:Pydev    文件:PythonModelProviderTest.java   
public void testAddSourceFolderToSourceFolder() throws Exception {
    final HashSet<String> pythonPathSet = new HashSet<String>();
    pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
    String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";

    File f = new File(source2Folder);
    if (f.exists()) {
        f.delete();
    }

    pythonPathSet.add(source2Folder); //still not created!
    PythonNature nature = createNature(pythonPathSet);

    project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
    provider = new PythonModelProvider();
    Object[] children1 = provider.getChildren(project);
    assertEquals(1, children1.length);
    assertTrue(children1[0] instanceof PythonSourceFolder);

    Set set = new HashSet();

    f.mkdir();
    try {
        FolderStub source2FolderFile = new FolderStub(project, f);
        set.add(source2FolderFile);
        provider.interceptAdd(new PipelinedShapeModification(project, set));

        assertEquals(1, set.size());
        assertTrue(set.iterator().next() instanceof PythonSourceFolder);
    } finally {
        f.delete();
    }
}
项目:Pydev    文件:PythonModelProvider.java   
/**
 * This method intercepts some addition to the tree and converts its elements to python
 * elements.
 *
 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptAdd(org.eclipse.ui.navigator.PipelinedShapeModification)
 */
@Override
public PipelinedShapeModification interceptAdd(PipelinedShapeModification addModification) {
    if (DEBUG) {
        System.out.println("interceptAdd");
    }
    convertToPythonElementsAddOrRemove(addModification, true);
    return addModification;
}
项目:Pydev    文件:PythonModelProvider.java   
@Override
public PipelinedShapeModification interceptRemove(PipelinedShapeModification removeModification) {
    if (DEBUG) {
        System.out.println("interceptRemove");
    }
    convertToPythonElementsAddOrRemove(removeModification, false);
    return removeModification;
}
项目:Pydev    文件:PythonModelProvider.java   
/**
 * Helper for debugging the things we have in a modification
 */
private void debug(String desc, PipelinedShapeModification modification) {
    System.out.println("\nDesc:" + desc);
    Object parent = modification.getParent();
    System.out.println("Parent:" + parent);
    System.out.println("Children:");
    for (Object o : modification.getChildren()) {
        System.out.println(o);
    }
}
项目:n4js    文件:N4JSProjectExplorerContentProvider.java   
@Override
public PipelinedShapeModification interceptAdd(final PipelinedShapeModification anAddModification) {
    return null;
}
项目:n4js    文件:N4JSProjectExplorerContentProvider.java   
@Override
public PipelinedShapeModification interceptRemove(final PipelinedShapeModification aRemoveModification) {
    return null;
}
项目:jsbuild-eclipse    文件:NavigatorJSBuildFileContentProvider.java   
@Override
public PipelinedShapeModification interceptAdd(
        PipelinedShapeModification paramPipelinedShapeModification) {
    return paramPipelinedShapeModification;
}
项目:jsbuild-eclipse    文件:NavigatorJSBuildFileContentProvider.java   
@Override
public PipelinedShapeModification interceptRemove(
        PipelinedShapeModification paramPipelinedShapeModification) {
    return paramPipelinedShapeModification;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaSynchronizationContentProvider.java   
/**
 * {@inheritDoc}
 */
public PipelinedShapeModification interceptAdd(final PipelinedShapeModification modification) {
    convertToJavaElements(modification);
    return modification;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaSynchronizationContentProvider.java   
/**
 * {@inheritDoc}
 */
public PipelinedShapeModification interceptRemove(final PipelinedShapeModification modification) {
    convertToJavaElements(modification);
    return modification;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaNavigatorContentProvider.java   
public PipelinedShapeModification interceptRemove(
        PipelinedShapeModification removeModification) {
    deconvertJavaProjects(removeModification);
    convertToJavaElements(removeModification.getChildren());
    return removeModification;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaSynchronizationContentProvider.java   
/**
 * {@inheritDoc}
 */
public PipelinedShapeModification interceptAdd(final PipelinedShapeModification modification) {
    convertToJavaElements(modification);
    return modification;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaSynchronizationContentProvider.java   
/**
 * {@inheritDoc}
 */
public PipelinedShapeModification interceptRemove(final PipelinedShapeModification modification) {
    convertToJavaElements(modification);
    return modification;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaNavigatorContentProvider.java   
public PipelinedShapeModification interceptRemove(
        PipelinedShapeModification removeModification) {
    deconvertJavaProjects(removeModification);
    convertToJavaElements(removeModification.getChildren());
    return removeModification;
}
项目:Pydev    文件:PythonModelProviderTest.java   
public void testFolderToSourceFolder() throws Exception {
    final HashSet<String> pythonPathSet = new HashSet<String>();
    pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
    String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";

    File f = new File(source2Folder);
    File f1 = new File(f, "childFolder");

    if (f1.exists()) {
        f1.delete();
    }
    if (f.exists()) {
        f.delete();
    }

    pythonPathSet.add(source2Folder); //still not created!
    PythonNature nature = createNature(pythonPathSet);

    project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
    provider = new PythonModelProvider();
    Object[] children1 = provider.getChildren(project);
    assertEquals(1, children1.length);
    assertTrue("Found: " + children1[0], children1[0] instanceof PythonSourceFolder);

    f.mkdir();
    f1.mkdir();
    try {
        FolderStub source2FolderFile = new FolderStub(project, f);
        FolderStub source2FolderChild = new FolderStub(project, source2FolderFile, f1);

        Set set = new HashSet();
        set.add(source2FolderChild);
        provider.interceptAdd(new PipelinedShapeModification(source2FolderFile, set));

        assertEquals(1, set.size());
        PythonFolder c = (PythonFolder) set.iterator().next();
        PythonSourceFolder sourceFolder = c.getSourceFolder();
        assertTrue(sourceFolder instanceof PythonSourceFolder);

        set.clear();
        set.add(source2FolderChild);
        provider.interceptAdd(new PipelinedShapeModification(source2FolderFile, set));
    } finally {
        f1.delete();
        f.delete();
    }
}
项目:Pydev    文件:PythonModelProviderTest.java   
public void testFolderToSourceFolder2() throws Exception {
    final HashSet<String> pythonPathSet = new HashSet<String>();
    pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
    String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";

    File f = new File(source2Folder);
    File f1 = new File(f, "childFolder");
    File f2 = new File(f1, "rechildFolder");

    if (f2.exists()) {
        f2.delete();
    }

    if (f1.exists()) {
        f1.delete();
    }
    if (f.exists()) {
        f.delete();
    }

    pythonPathSet.add(source2Folder); //still not created!
    PythonNature nature = createNature(pythonPathSet);

    project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
    provider = new PythonModelProvider();
    Object[] children1 = provider.getChildren(project);
    assertEquals(1, children1.length);
    assertTrue("Expected source folder. Received: " + children1[0], children1[0] instanceof PythonSourceFolder);

    f.mkdir();
    f1.mkdir();
    f2.mkdir();
    try {
        FolderStub source2FolderFile = new FolderStub(project, f);
        FolderStub source2FolderChild = new FolderStub(project, source2FolderFile, f1);
        FolderStub source2FolderReChild = new FolderStub(project, source2FolderChild, f2);

        Set set = new HashSet();
        set.add(source2FolderReChild);
        provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));

        assertEquals(1, set.size());
        PythonFolder c = (PythonFolder) set.iterator().next();
        PythonSourceFolder sourceFolder = c.getSourceFolder();
        assertTrue(sourceFolder instanceof PythonSourceFolder);

        set.clear();
        set.add(source2FolderChild);
        provider.interceptRemove(new PipelinedShapeModification(source2FolderFile, set));
        assertTrue(set.iterator().next() instanceof PythonFolder);
        //            System.out.println(set);

        set.clear();
        set.add(source2FolderReChild);
        provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
        assertTrue(set.iterator().next() instanceof PythonFolder);
        //            System.out.println(set);

        set.clear();
        set.add(source2FolderChild);
        provider.interceptRemove(new PipelinedShapeModification(source2FolderFile, set));
        assertTrue(set.iterator().next() instanceof PythonFolder);
        //            System.out.println(set);

        set.clear();
        set.add(source2FolderReChild);
        provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
        assertTrue(set.iterator().next() instanceof PythonFolder);
        //            System.out.println(set);

    } finally {
        f2.delete();
        f1.delete();
        f.delete();
    }
}