Re: project conversion questions

Tomas Zezula <[email protected]> Fri, 25 Jul 2003 09:06:40 +0200
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Organization Sun Microsystems
Message-ID <[email protected]>
On Thu, 2003-07-24 at 17:03, Peter Wisnovsky wrote:
>  > the Java core module (java/src) does not define any API and from this
>  > reason it does not export any public packages.
>  > Dependence on the JavaDataObject is not desired, this class is going to
>  > be removed in the NetBeans 4.0.
>  > The ProjectMember, EnvironmentProvier and Look should replace all the
>  > DataObejcts in the NB 4.0.
>  > Is it not enough for your module to test if the (ProjectMember or Node)
>  > has certain object in its lookup?
> 
> Well, I need to 1) determine efficiently if the selected node of a
> NodeAction represents a Java class, and 2) be able to get from the
> selected nodes provided to a NodeAction down to the SourceElement of
> the Java object. Is there a new way to do this now?
> 
> Thanks,
> 
> Peter
> 
Yes, it is possible
1)
Either as Svata has written before:

[assuming (1) means "represents java source file, rather than java
class]
1a) node.getLookup().lookup(ProjectMember.class).getOriginal() -> 
FileObject, you can check for mimetype, extension, ...
+ check that the node is indeed a project member...

1a) node.getLookup().lookup(SourceCookie.Editor.class) != null

[assuming (1) means "node represents a java class"]
node.getLookup().lookup(ClassElement.class);

1b) node.getLookup().lookup(SourceCookie.class).getSource() ?

or,
if the action is added to the node representing a java file by your
module, you have to create Look which adds the action and add this Look
to the composite look for Java mime type.
This also ensures that the Node you get in the Action represents a java
file.

2)
On the node in the action you have to look for Source cookie,

public void performAction (Node[] nodes) {
	for (int i=0; i<nodes.length(); i++) {
		SourceCookie sc = (SourceCookie)
 			nodes[i].getLookup().lookup(SourceCookie.class);
		SourceElement se = sc.getSource ();
		doSomething (se);
	}
}


> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>