DevFaqGetProjectForFileInEditor

How to get the project for the actual file in the editor?

  • get the project from the lookup of the active TopComponent AND/OR
  • get the project from the lookup of the active DataObject
Project p = TopComponent.getRegistry().getActivated().getLookup().lookup(Project.class);
if (p == null) {
    DataObject dob = TopComponent.getRegistry().getActivated().getLookup().lookup(DataObject.class);
    if (dob != null) {
       FileObject fo = dob.getPrimaryFile();
       p = FileOwnerQuery.getOwner(fo);
       ...

Taken from platform-dev mailing list / Tim Boudreau

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo