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

下面列出了怎么用org.eclipse.ui.navigator.PipelinedShapeModification的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * 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;
}
 
源代码2 项目: 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"));
    }
}
 
源代码3 项目: 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;
}
 
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;
	}
 
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);
}
 
源代码6 项目: 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);
}
 
源代码7 项目: 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();
    }
}
 
源代码8 项目: 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");
    }
    final Map<PythonNature, Set<String>> natureToSourcePathSet = new HashMap<>();
    convertToPythonElementsAddOrRemove(addModification, true, natureToSourcePathSet);
    return addModification;
}
 
源代码9 项目: Pydev   文件: PythonModelProvider.java
@Override
public PipelinedShapeModification interceptRemove(PipelinedShapeModification removeModification) {
    if (DEBUG) {
        System.out.println("interceptRemove");
    }
    final Map<PythonNature, Set<String>> natureToSourcePathSet = new HashMap<>();
    convertToPythonElementsAddOrRemove(removeModification, false, natureToSourcePathSet);
    return removeModification;
}
 
源代码10 项目: 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);
    }
}
 
源代码11 项目: n4js   文件: N4JSProjectExplorerContentProvider.java
@Override
public PipelinedShapeModification interceptAdd(final PipelinedShapeModification anAddModification) {
	return null;
}
 
源代码12 项目: n4js   文件: N4JSProjectExplorerContentProvider.java
@Override
public PipelinedShapeModification interceptRemove(final PipelinedShapeModification aRemoveModification) {
	return null;
}
 
源代码13 项目: xds-ide   文件: ProjectExplorerContentProvider.java
@Override
public PipelinedShapeModification interceptAdd(
        PipelinedShapeModification anAddModification) {
	anAddModification.getChildren().clear();
    return anAddModification;
}
 
源代码14 项目: xds-ide   文件: ProjectExplorerContentProvider.java
@Override
public PipelinedShapeModification interceptRemove(
        PipelinedShapeModification aRemoveModification) {
    return aRemoveModification;
}
 
源代码15 项目: tracecompass   文件: TmfNavigatorContentProvider.java
@Override
public PipelinedShapeModification interceptAdd(PipelinedShapeModification anAddModification) {
    return anAddModification;
}
 
源代码16 项目: tracecompass   文件: TmfNavigatorContentProvider.java
@Override
public PipelinedShapeModification interceptRemove(PipelinedShapeModification aRemoveModification) {
    return null;
}
 
/**
 * {@inheritDoc}
 */
public PipelinedShapeModification interceptAdd(final PipelinedShapeModification modification) {
	convertToJavaElements(modification);
	return modification;
}
 
/**
 * {@inheritDoc}
 */
public PipelinedShapeModification interceptRemove(final PipelinedShapeModification modification) {
	convertToJavaElements(modification);
	return modification;
}
 
public PipelinedShapeModification interceptRemove(
		PipelinedShapeModification removeModification) {
	deconvertJavaProjects(removeModification);
	convertToJavaElements(removeModification.getChildren());
	return removeModification;
}
 
源代码20 项目: 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();
    }
}
 
源代码21 项目: 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();
    }
}
 
源代码22 项目: Pydev   文件: PythonModelProvider.java
/**
 * Converts the shape modification to use Python elements.
 * @param natureToSourcePathSet
 *
 * @param modification: the shape modification to convert
 * @param isAdd: boolean indicating whether this convertion is happening in an add operation
 */
@SuppressWarnings("unchecked")
private void convertToPythonElementsAddOrRemove(PipelinedShapeModification modification, boolean isAdd,
        Map<PythonNature, Set<String>> natureToSourcePathSet) {
    if (DEBUG) {
        debug("Before", modification);
    }
    Object parent = modification.getParent();
    if (parent instanceof IContainer) {
        IContainer parentContainer = (IContainer) parent;
        Object pythonParent = getResourceInPythonModel(parentContainer, true);

        if (pythonParent instanceof IWrappedResource) {
            IWrappedResource parentResource = (IWrappedResource) pythonParent;
            modification.setParent(parentResource);
            wrapChildren(parentResource, parentResource.getSourceFolder(), modification.getChildren(), isAdd,
                    natureToSourcePathSet);

        } else if (pythonParent == null) {

            Object parentInWrap = parentContainer;
            PythonSourceFolder sourceFolderInWrap = null;

            //this may happen when a source folder is added or some element that still doesn't have it's parent in the model...
            //so, we have to get the parent's parent until we actually 'know' that it is not in the model (or until we run
            //out of parents to try)
            //the case in which we reproduce this is Test 1 (described in the class)
            FastStack<Object> found = new FastStack<Object>(20);
            while (true) {

                //add the current to the found
                if (parentContainer == null) {
                    break;
                }

                found.push(parentContainer);
                if (parentContainer instanceof IProject) {
                    //we got to the project without finding any part of a python model already there, so, let's see
                    //if any of the parts was actually a source folder (that was still not added)
                    tryCreateModelFromProject((IProject) parentContainer, found, natureToSourcePathSet);
                    //and now, if it was created, try to convert it to the python model (without any further add)
                    convertToPythonElementsUpdateOrRefresh(modification.getChildren());
                    return;
                }

                Object p = getResourceInPythonModel(parentContainer, true);

                if (p instanceof IWrappedResource) {
                    IWrappedResource wrappedResource = (IWrappedResource) p;
                    sourceFolderInWrap = wrappedResource.getSourceFolder();

                    while (found.size() > 0) {
                        Object f = found.pop();
                        if (f instanceof IResource) {
                            //no need to create it if it's already in the model!
                            Object child = sourceFolderInWrap.getChild((IResource) f);
                            if (child != null && child instanceof IWrappedResource) {
                                wrappedResource = (IWrappedResource) child;
                                continue;
                            }
                        }
                        //creating is enough to add it to the model
                        if (f instanceof IFile) {
                            wrappedResource = new PythonFile(wrappedResource, (IFile) f, sourceFolderInWrap);
                        } else if (f instanceof IFolder) {
                            wrappedResource = new PythonFolder(wrappedResource, (IFolder) f, sourceFolderInWrap);
                        }
                    }
                    parentInWrap = wrappedResource;
                    break;
                }

                parentContainer = parentContainer.getParent();
            }

            wrapChildren(parentInWrap, sourceFolderInWrap, modification.getChildren(), isAdd,
                    natureToSourcePathSet);
        }

    } else if (parent == null) {
        wrapChildren(null, null, modification.getChildren(), isAdd, natureToSourcePathSet);
    }

    if (DEBUG) {
        debug("After", modification);
    }
}
 
 类所在包
 类方法
 同包方法