Compile Single programmatically

View: New views
2 Messages — Rating Filter:   Alert me  

Compile Single programmatically

by buhman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I'm developing on an application that is based on a Netbeans Module Suite (v6.0) and I'd need to know one thing:

I'm using the NB Java Editor in my application, and I need to compile this file. A project folder with the build.xml and the property files exists. The compiling itself is yet done by a  workaround that uses a Robot and invokes VK_F9...(COMPILE_SINGLE) which is very, very poor - I know - but it works..

Now I wanted to change this and I was looking for the appropriate Action or Action Handler class that invokes this compiling process in the NB sources with the additionaly features such as the output to the output window, the markups in the code a. s. o. ... but I could not find it. What I found was the following:

        org.openide.nodes.Node[] activatedNodes = WindowManager.getDefault().getRegistry().getActivatedNodes();

        for (int i = 0; i < activatedNodes.length; i++) {
             org.openide.nodes.Node n = activatedNodes[i];
             Project project = (Project)n.getValue("Project"); // NOI18N
             Item item = (Item)n.getValue("Item"); // NOI18N
       
             ActionProvider ap = (ActionProvider)project.getLookup().lookup(ActionProvider.class);
       
              if (ap != null)
                    ap.invokeAction(ActionProvider.COMMAND_COMPILE_SINGLE,
                                             Lookups.fixed(new Object[] {project, n}));
    }

But this code causes a NullPointerException as the Project object is null and now I don't know further...

I'm sure that there's an easy way to realize this, has anyone an idea?

Thanks in Advance!!

Daniel





Re: Compile Single programmatically

by Jesse Glick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

daniel.kroeger@... wrote:
>              Project project = (Project)n.getValue("Project"); // NOI18N

Node.getValue() is completely unused. I think you mean

   Project project = n.getLookup().lookup(Project.class);
   if (project != null) ...

This will only work on project nodes. For file nodes, you would need to
find the DataObject in lookup; if present, get its primaryFile, then use
FileOwnerQuery to find the project it is part of (if any).

>              Item item = (Item)n.getValue("Item"); // NOI18N

I have no idea what this is supposed to be. Delete it.

>               if (ap != null)

&& ap.supportsAction(AP.C_C_S)

> Lookups.fixed(new Object[] {project, n})

n.getLookup()