2010-06-11 15 views
8

¿Hay alguna manera de conocer el tipo de proyecto seleccionado? Me gustaría hacer algunas acciones específicas dependiendo del tipo de proyecto, como un proyecto J2SE.¿Cómo puedo obtener un tipo de proyecto en la plataforma Netbeans?

a continuación es la única manera que he encontrado para hacer esto:

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; 

}} 

Respuesta

2

sencilla nuevo -> acción -> conditionaly activado (Proyecto) y es todo.

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

Cuestiones relacionadas