9910

单飞

   :: 首页 :: 联系 :: 聚合  :: 管理
    public static ToolsProject getDefaultProject()throws Exception{
        
if(instance!= null){
            
return instance;
        }

        IWorkspaceRoot root 
= ResourcesPlugin.getWorkspace().getRoot();
        IProject prj 
= root.getProject("DefaultProject");
        
if (!prj.exists()) {
            
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
            
final IProjectDescription desc = workspace.newProjectDescription(prj.getName());
            desc.setNatureIds(
new String[] "com.test.tools" });
            desc.setComment(
"TOOLS");
            prj.create(desc, 
null);
            prj.open(IResource.BACKGROUND_REFRESH, 
null);
        }

        ToolsProject prject 
= new ToolsProject();
        prject.setPrject(prj);
        
return prject;
    }

IContainer container = (IContainer) resource;
            
final IFile file = container.getFile(new Path(sName + "/" + "s" + ".xml"));
            ensureFolder((IFolder) file.getParent());


InputStream stream 
= openContentStream(siteName);
            
if (file.exists()) {
                file.setContents(stream, 
truetrue, monitor);
            }
 else {
                file.create(stream, 
true, monitor);
            }


stream.close();

private InputStream openContentStream(String siteName) {
        Site site 
= new Site();
        site.setName(siteName);
        XStream xstream 
= new XStream(new DomDriver());
                String xml 
= xstream.toXML(site);
        
return new ByteArrayInputStream(xml.getBytes());
    }

创建目录 mkdirs
public static void ensureFolder(IFolder folder) throws CoreException {
        IContainer parent 
= folder.getParent();
        
if (parent instanceof IFolder) {
            ensureFolder((IFolder) parent);
        }

        
if (!folder.exists()) {
            folder.create(
truefalsenull);
        }


    }



删除目录
dFolder.delete(
truenull);


监听到资源发生变化

private void hookResourceListener() {
        IWorkspace workspace 
= ResourcesPlugin.getWorkspace();
        IResourceChangeListener listener 
= new IResourceChangeListener() {
            
public void resourceChanged(IResourceChangeEvent event) {
                viewer.refresh();
            }

        }
;
        workspace.addResourceChangeListener(listener);
    }
posted on 2009-04-02 13:49 单飞 阅读(714) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: