工程展示ProjectExplorer之覆寫JavaElement

1.1   基本項

(1)     ContentProvider實現IPipelinedTreeContentProvider2

(2)     工程中存在.classpath文件。

 

1.2      編輯器修改後刷新視圖節點

在編輯器的doSave()中刷新文件夾或文件

    public void doSave(IProgressMonitor progressMonitor)

    {

       

        if (getEditorInput() instanceofIFileEditorInput)

        {

            refreshServiceFileNode(((IFileEditorInput)getEditorInput()).getFile());

        }

    }

private void refreshServiceFileNode(IFile file)

    {

        IViewPart exploreViewer = CommonUIUtil.findView("org.eclipse.ui.navigator.ProjectExplorer", false);//$NON-NLS-1$

        if (null != exploreViewer && (exploreViewer instanceof ProjectExplorer))

        {

            ProjectExplorer projExplore= (ProjectExplorer)exploreViewer;

            boolean expanded = projExplore.getCommonViewer()

                    .getExpandedState(file);

            projExplore.getCommonViewer().refresh(file);

            if (expanded)

            {

                projExplore.getCommonViewer().expandToLevel(file, 1);

            }

 

        }

        IViewPart exploreViewer = CommonUIUtil.findView("org.eclipse.jdt.ui.PackageExplorer", false);//$NON-NLS-1$

        if (null != exploreViewer

                && (exploreViewer instanceof PackageExplorerPart))

        {

           

            PackageExplorerPart packagePart= (PackageExplorerPart)exploreViewer;

            packagePart.refresh(new StructuredSelection(folder));

      

        }

 

        else

        {

            Log.warning(ServiceDefineUiPlugin.getPlugin().getPluginID(),

                    IStatus.WARNING,

                    Messages.RegistryUiUtil_Get_ViewPart_Failed);

        }

    }

1.3      覆寫JavaElement

getPipelinedChildren中先對工程中的javaelement進行清除。

private void cleanJavaContribution(Set theCurrentChildren)

    {

        IJavaElement element = null;

        for (Iterator iter = theCurrentChildren.iterator(); iter.hasNext();)

        {

            Object child = iter.next();

            if (child instanceof IResource

                    && ((element = JavaCore.create((IResource)child))!= null)

                    && element.exists())

            {

                iter.remove();

            }

            else if (child instanceof IJavaElement)

            {

                iter.remove();

            }

            else if (INTERNAL_CONTAINER_CLASS != null

                    && INTERNAL_CONTAINER_CLASS.isInstance(child))

            {

                iter.remove();

            }

        }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章