简体   繁体   English

我在NetBeans平台上开发插件时如何调用打开的项目窗口?

[英]How it is possible to call open project window when i develop plugin in netbeans platform?

I develop plugin to netbeans IDE and i would like to determinate user to select a open projects in netbeans IDE in some action: How it is possible to call this window and get some reason from user action on it?: 我开发了netbeans IDE的插件,我想确定用户是否可以通过以下操作在netbeans IDE中选择一个打开的项目:如何调用此窗口并从用户对它的操作中获得某些原因?

在此处输入图片说明

I am not really sure what you want to achieve, but you may take a look on the following code: 我不确定您要实现什么,但是您可以看一下以下代码:

Lookup gLookup = Utilities.actionsGlobalContext();
Project currentlySelectedProject = gLookup.lookup(Project.class);
// do something with the project, e.g., print out its name
System.out.println(ProjectUtils.getInformation(currentlySelectedProject).getDisplayName());

This code gives you currently selected project in the projects window of NetBeans IDE (therefore the project has to be already open to get it). 该代码为您提供了当前在NetBeans IDE的“项目”窗口中选择的项目(因此必须已打开该项目才能获得它)。 If you need to follow changes to it, you can add a listener for it: 如果您需要对其进行更改,则可以为其添加一个侦听器:

Lookup.Result<Project> globalResultOBJ = gLookup.lookup(new Lookup.Template(Project.class));
LookupListener globalListenerOBJ = new LookupListener() {
    @Override
    public void resultChanged(LookupEvent le) {
        currentlySelectedProject = genlokup.lookup(Project.class);
        // again you can do something with newly selected project
        System.out.println(ProjectUtils.getInformation(currentlySelectedProject).getDisplayName());
    }
};
globalResultOBJ.addLookupListener(globalListenerOBJ);

This codes will give you access to currently selected project. 此代码可让您访问当前选定的项目。 Is that what you need or dou you want explicitly ask the user to open a new project? 是您需要的还是您要明确要求用户打开一个新项目的? Meaning, that you want to programmatically open the run the Open project action? 意味着要以编程方式打开运行“打开项目”操作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM