【问题标题】:How can I get a project type on Netbeans Platform?如何在 Netbeans 平台上获取项目类型?
【发布时间】:2010-06-11 14:22:25
【问题描述】:

有没有办法知道所选项目的类型?我想根据项目类型(如 J2SE 项目)执行一些特定操作。

以下是我发现的唯一方法:

public final class MyAction extends CookieAction { 

@Override 
public boolean isEnabled() { 
  if(this.getActivatedNodes() == null || this.getActivatedNodes().length != 1) { 
        return false; 
    } 

    Lookup lookup = this.getActivatedNodes()[0].getLookup(); 

    // gets the selected project 
    Project currentProject = lookup.lookup(Project.class); 

    // checks if the selected project is a J2SE Project or a Maven Project 
    if(currentProject != null && (currentProject.getClass().getSimpleName().equals("J2SEProject") 
            || currentProject.getClass().getSimpleName().equals("NbMavenProjectImpl"))) { 
        return true; 
    } 

    return false;

}}

【问题讨论】:

    标签: java netbeans netbeans-platform


    【解决方案1】:

    简单的新 -> 操作 -> 有条件地启用(项目),这就是全部。

     package project.action;
    
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import org.netbeans.api.project.Project;
    
    import org.openide.awt.ActionRegistration;
    import org.openide.awt.ActionReference;
    import org.openide.awt.ActionReferences;
    import org.openide.awt.ActionID;
    import org.openide.util.NbBundle.Messages;
    
    @ActionID(category = "Build",
    id = "project.action.SomeAction")
    @ActionRegistration(displayName = "#CTL_SomeAction")
    @ActionReferences({
        @ActionReference(path = "Menu/File", position = 0)
    })
    @Messages("CTL_SomeAction=SomeAction")
    public final class SomeAction implements ActionListener {
    
    private final Project context;
    
    public SomeAction(Project context) { // this is enable !!
        this.context = context;
    }
    
    public void actionPerformed(ActionEvent ev) {
        // TODO use context
    }
    }
    

    吉尔卡

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      相关资源
      最近更新 更多