Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a project type on Netbeans Platform?

Is there a way to know the type of a selected project? I would like to do some specific actions depending of the project type like a J2SE project.

Below is the only way that I found to do that:

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;

}}
like image 689
Fabio Avatar asked Jun 11 '10 14:06

Fabio


People also ask

Where can I find NetBeans Projects?

In NetBeans, select "File" from the menu bar, then "Open project..." and select the location where the file was saved from RobotBuilder. The project will be opened and you will see it in the "Projects" tab on the left side of the NetBeans window.

Where is project structure in NetBeans?

The project contains all of your sources and project metadata, such as the project's Ant build script. The project opens in the IDE. You can view its logical structure in the Projects window (Ctrl-1) and its file structure in the Files window (Ctrl-2).

What is a project in NetBeans?

A project type is a NetBeans Platform term for a grouping of folders and files that is treated as a single unit. Treating related folders and files as a single unit makes working with them easier for the end user.


1 Answers

simple new -> action -> conditionaly enabled (Project) and it is all.

 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
}
}

Jirka

like image 93
user1722245 Avatar answered Oct 23 '22 10:10

user1722245