白玉成的专栏

Eclipse,让我欢喜让我忧!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  17 随笔 :: 0 文章 :: 6 评论 :: 0 Trackbacks
1. 编写自己的nature:
package com.byc.natures;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;


/**
 * 
 * 
@author Bai Yucheng 2008-4-28
 * 
 
*/

public class MyProjectNature implements IProjectNature {
 
private IProject project;

 
public void configure() throws CoreException {
  
//do nothing
 }


 
public void deconfigure() throws CoreException {
  
//do nothing
 }


 
public IProject getProject() {
  
return project;
 }


 
public void setProject(IProject iproject) {
  project 
= iproject;
 }


}



2. 添加扩展点:org.eclipse.core.resources.natures,设置class属性为我们的nature

<extension
      
id="com.byc.MyProjectNature"
      name
="Project Nature"
      point
="org.eclipse.core.resources.natures">
   
<runtime>
      
<run
            
class="com.byc.natures.MyProjectNature">
      
</run>
   
</runtime>
</extension>


3. 在新建工程的向导中添加我们的nature,添加方法为:

private void addProjectNature(IProject project) throws CoreException {
   
if (!project.hasNature(PROJECT_NATURE)) {
   
try {
    IProjectDescription description 
= project.getDescription();
    String[] natures 
= description.getNatureIds();
    String[] newNatures 
= new String[natures.length + 1];
    System.arraycopy(natures, 
0, newNatures, 0, natures.length);
    newNatures[natures.length] 
= PROJECT_NATURE;
    description.setNatureIds(newNatures);
    project.setDescription(description, 
null);
   }
 catch (CoreException e) {
    e.printStackTrace();
   }

  }

 }
posted on 2008-11-25 22:57 白玉成 阅读(435) 评论(0)  编辑  收藏 所属分类: Eclipse

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


网站导航: