Java Code Examples for org.netbeans.api.project.Project#getLookup()

The following examples show how to use org.netbeans.api.project.Project#getLookup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoverageSideBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void runAction(String action) {
    Project project = getProject();
    if (project != null) {
        Lookup lookup = project.getLookup();
        if (fileForDocument != null) {
            try {
                DataObject dobj = DataObject.find(fileForDocument);
                lookup = dobj.getLookup();
            } catch (DataObjectNotFoundException ex) {
                Exceptions.printStackTrace(ex);
            }
        }

        ActionProvider provider = project.getLookup().lookup(ActionProvider.class);
        if (provider != null) {
            if (provider.isActionEnabled(action, lookup)) {
                provider.invokeAction(action, lookup);
            }
        }
    }
}
 
Example 2
Source File: WebLogicDDVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void setProject(final Project project) {
    this.project = project;

    // get j2ee module provider
    // get list of config files for this module type
    // figure out which ones exist already
    // 
    Lookup lookup = project.getLookup();
    J2eeModuleProvider provider = lookup.lookup(J2eeModuleProvider.class);
    J2eeModule j2eeModule = provider.getJ2eeModule();
    sunDDFileName = getConfigFileName(j2eeModule,
            org.netbeans.modules.glassfish.eecommon.api.Utils.getInstanceReleaseID(provider));

    // Calculate location:
    sunDDFile = (sunDDFileName != null) ? j2eeModule.getDeploymentConfigurationFile(sunDDFileName) : null;
    sunDDLocation = (sunDDFile != null) ? sunDDFile.getParentFile() : null;
    
    // initialize visual components
    textFileName.setText(sunDDFileName); // NOI18N
    textProjectName.setText(ProjectUtils.getInformation(project).getDisplayName());

    File projectFolder = FileUtil.toFile(project.getProjectDirectory());
    textLocation.setText((sunDDLocation != null) ? getRelativePath(sunDDLocation, projectFolder) : null);
    // only fill 'created file' in if location is valid.
    textCreatedFile.setText((sunDDLocation != null) ? getRelativePath(sunDDFile, projectFolder) : null);
}
 
Example 3
Source File: ActionsUtilTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCanBeReclaimed() throws Exception {
    Project prj1 = new DummyProject();
    Project prj2 = new DummyProject();
    Lookup projects = new TestProxyLookup(new Lookup[] {
        prj1.getLookup(),
        prj2.getLookup(),
    });
    
    ActionsUtil.getProjectsFromLookup(projects, null);
    
    WeakReference<?> ref1 = new WeakReference<Object>(prj1);
    WeakReference<?> ref2 = new WeakReference<Object>(prj2);
    WeakReference<?> lookup = new WeakReference<Object>(projects);
    
    prj1 = null;
    prj2 = null;
    projects = null;
    
    assertGC("the projects can be reclaimed", ref1);
    assertGC("the projects can be reclaimed", ref2);
    assertGC("the lookup can be reclaimed", lookup);
}
 
Example 4
Source File: GlassfishConfiguration.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** !PW FIXME web free form project does not implement J2eeModulePrvoider so
 *  this method will fail for that project type.  This method is used for:
 *
 *  * Getting the server instance id => install location for determining
 *    server version.
 *  * Getting the deployment manager => accessing the ResourceConfigurator
 *    and CMP Mapper (V2 only).
 *
 */
protected J2eeModuleProvider getProvider(File file) {
    J2eeModuleProvider provider = null;
    if (file != null) {
        file = FileUtil.normalizeFile(file);
        FileObject fo = FileUtil.toFileObject(file);
        if (fo != null) {
            Project project = FileOwnerQuery.getOwner(fo);
            if (project != null) {
                org.openide.util.Lookup lookup = project.getLookup();
                provider = lookup.lookup(J2eeModuleProvider.class);
            }
        } else {
            File parent = file.getParentFile();
            if (parent != null) {
                provider = getProvider(parent);
            }
        }
    }
    return provider;
}
 
Example 5
Source File: PayaraDDVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void setProject(final Project project) {
    this.project = project;

    // get list of config files for this module type
    // figure out which ones exist already
    // 
    Lookup lookup = project.getLookup();
    J2eeModuleProvider provider = lookup.lookup(J2eeModuleProvider.class);
    J2eeModule j2eeModule = provider.getJ2eeModule();
    payaraDDFileName = getConfigFileName(j2eeModule,provider.getServerInstanceID());

    // Calculate location:
    payaraDDLocation = j2eeModule.getDeploymentConfigurationFile(WEB_XML).getParentFile();
    payaraDDFile = new File(payaraDDLocation, payaraDDFileName);
    
    // initialize visual components
    textFileName.setText(payaraDDFileName); // NOI18N
    textProjectName.setText(ProjectUtils.getInformation(project).getDisplayName());

    File projectFolder = FileUtil.toFile(project.getProjectDirectory());
    textLocation.setText((payaraDDLocation != null) ? getRelativePath(payaraDDLocation, projectFolder) : null);
    // only fill 'created file' in if location is valid.
    textCreatedFile.setText((payaraDDLocation != null) ? getRelativePath(payaraDDFile, projectFolder) : null);
}
 
Example 6
Source File: PayaraConfiguration.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** !PW FIXME web free form project does not implement J2eeModulePrvoider so
 *  this method will fail for that project type.  This method is used for:
 *
 *  * Getting the server instance id => install location for determining
 *    server version.
 *  * Getting the deployment manager => accessing the ResourceConfigurator
 *    and CMP Mapper (V2 only).
 *
 */
protected J2eeModuleProvider getProvider(File file) {
    J2eeModuleProvider provider = null;
    if (file != null) {
        file = FileUtil.normalizeFile(file);
        FileObject fo = FileUtil.toFileObject(file);
        if (fo != null) {
            Project project = FileOwnerQuery.getOwner(fo);
            if (project != null) {
                org.openide.util.Lookup lookup = project.getLookup();
                provider = lookup.lookup(J2eeModuleProvider.class);
            }
        } else {
            File parent = file.getParentFile();
            if (parent != null) {
                provider = getProvider(parent);
            }
        }
    }
    return provider;
}
 
Example 7
Source File: SunDDVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void setProject(final Project project) {
    this.project = project;

    // get j2ee module provider
    // get list of config files for this module type
    // figure out which ones exist already
    // 
    Lookup lookup = project.getLookup();
    J2eeModuleProvider provider = (J2eeModuleProvider) lookup.lookup(J2eeModuleProvider.class);
    J2eeModule j2eeModule = provider.getJ2eeModule();
    sunDDFileName = getConfigFileName(j2eeModule,provider.getServerInstanceID());

    // Calculate location:
    sunDDFile = (sunDDFileName != null) ? j2eeModule.getDeploymentConfigurationFile(sunDDFileName) : null;
    sunDDLocation = (sunDDFile != null) ? sunDDFile.getParentFile() : null;
    
    // initialize visual components
    textFileName.setText(sunDDFileName); // NOI18N
    textProjectName.setText(ProjectUtils.getInformation(project).getDisplayName());

    File projectFolder = FileUtil.toFile(project.getProjectDirectory());
    textLocation.setText((sunDDLocation != null) ? getRelativePath(sunDDLocation, projectFolder) : null);
    // only fill 'created file' in if location is valid.
    textCreatedFile.setText((sunDDLocation != null) ? getRelativePath(sunDDFile, projectFolder) : null);
}
 
Example 8
Source File: CssStylesPanelProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an action provider for the specified {@code FileObject}.
 *
 * @return {@code ActionProvider} for the specified {@code FileObject}.
 */
private static ActionProvider actionProviderForFileObject(FileObject fileObject) {
    ActionProvider provider = null;
    Project project = FileOwnerQuery.getOwner(fileObject);
    if (project != null) {
        Lookup lkp = project.getLookup();
        provider = lkp.lookup(ActionProvider.class);
    }
    return provider;
}
 
Example 9
Source File: ProjectConvertors.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Lookup findDelegate() {
    if (closed) {
        return null;
    }
    final Project currentOwner = getNonConvertorOwner(projectDirectory);
    return currentOwner == null ?
            null :
            currentOwner.getLookup();
}
 
Example 10
Source File: SignApkAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    if (activatedNodes.length != 1) {
        return;
    }
    Project owner = activatedNodes[0].getLookup().lookup(Project.class);
    if (owner != null) {
        KeystoreConfiguration keystoreConfiguration = owner.getLookup().lookup(KeystoreConfiguration.class);
        if (keystoreConfiguration != null) {
            if (keystoreConfiguration.getCurrentKeystoreConfiguration().isAsk() || !keystoreConfiguration.getCurrentKeystoreConfiguration().isValid()) {
                ApkSigningConfigPanel signingConfigPanel = new ApkSigningConfigPanel(null, owner.getLookup());
                DialogDescriptor dialogDescriptor = new DialogDescriptor(signingConfigPanel, "Generate Signed APK", true, signingConfigPanel);
                DialogDisplayer.getDefault().notify(dialogDescriptor);
            }
            if (keystoreConfiguration.getCurrentKeystoreConfiguration().isValid()) {
                try {
                    List<String> tasks = new ArrayList<>();
                    if (keystoreConfiguration.getCurrentKeystoreConfiguration().isApkRelease()) {
                        tasks.add("assembleRelease");
                    }
                    if (keystoreConfiguration.getCurrentKeystoreConfiguration().isApkDebug()) {
                        tasks.add("assembleDebug");
                    }
                    ApkUtils.gradleSignApk(owner, "", tasks, keystoreConfiguration, FileUtil.toFile(owner.getProjectDirectory()));
                } catch (Exception ex) {
                    Exceptions.printStackTrace(ex);
                }
            } else {
                InputOutput io = owner.getLookup().lookup(InputOutput.class);
                if (io != null) {
                    io.show(ImmutableSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE));
                    io.getOut().print("\n\r");
                    io.getOut().print("\u001B[31mKeystore setting is not valid!\u001B[30m\n\r");
                    io.getOut().print("\n\r");
                }
            }
        }
    }

}
 
Example 11
Source File: SourceFileMap.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a source file map for the module, or null if none can be identified.
 *
 * @param source A non-null source file (java, descriptor or dbschema) to establish mapping context.
 * @return SourceFileMap for the project, may return <code>null</code>
 */
public static final SourceFileMap findSourceMap(FileObject source) {
    Project owner = FileOwnerQuery.getOwner(source);
    if (owner != null) {
        Lookup l = owner.getLookup();
        J2eeModuleProvider projectModule = (J2eeModuleProvider) l.lookup(J2eeModuleProvider.class);
        if (projectModule != null) {
            return projectModule.getSourceFileMap();
        }
    }
    return null;
}
 
Example 12
Source File: Util.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static String getBaseName(Project project) {
        String baseName;
        Lookup lookup = project.getLookup();
        J2eeModuleProvider provider = (J2eeModuleProvider) lookup.lookup(J2eeModuleProvider.class);
        String id = provider.getServerInstanceID();
        if (Utils.useGlassfishPrefix(id)) // NOI18N
            baseName = "glassfish-resources"; // NOI18N
        else
            baseName = "sun-resources"; // NOI18N
        return baseName;

}
 
Example 13
Source File: ResourcesHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static private J2eeModuleProvider getProvider(Project project) {
    J2eeModuleProvider provider = null;
    if (project != null) {
        org.openide.util.Lookup lookup = project.getLookup();
        provider = lookup.lookup(J2eeModuleProvider.class);
    }
    return provider;
}
 
Example 14
Source File: ResourcesHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static private J2eeModuleProvider getProvider(Project project) {
    J2eeModuleProvider provider = null;
    if (project != null) {
        org.openide.util.Lookup lookup = project.getLookup();
        provider = lookup.lookup(J2eeModuleProvider.class);
    }
    return provider;
}
 
Example 15
Source File: J2SEProjectTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Lookup createAdditionalLookup(Lookup lkp) {
    Project p = lkp.lookup(Project.class);
    assertNotNull(p);
    Lookup base = p.getLookup();
    assertNotNull(base);
    final AuxiliaryConfiguration aux = base.lookup(AuxiliaryConfiguration.class);
    assertNotNull(aux);
    return Lookups.singleton(new Callable<AuxiliaryConfiguration>() {
        public AuxiliaryConfiguration call() throws Exception {
            return aux;
        }
    });
}
 
Example 16
Source File: ImportantNodeFactory.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages("LBL_Important=Important Files")
public ImportantFilesNode(Project p) {
    super(new ImportantFilesChildFactory2(p), p.getLookup());
    setDisplayName(Bundle.LBL_Important());
}
 
Example 17
Source File: ProjectFilesNodeFactory.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages("LBL_ProjectFiles=Project Files")
public ProjectFilesNode(Project p) {
    super(new ProjectFilesChildFactory2(p), p.getLookup());
    setDisplayName(Bundle.LBL_ProjectFiles());
}
 
Example 18
Source File: ModulesNodeFactory.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
public ModulesNode(Project project) {
    super(new ModuleChildrens(project), project.getLookup());
    setDisplayName("Modules");
}
 
Example 19
Source File: ProjectFilesNodeFactory.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages("LBL_ProjectFiles=Project Files")
public ProjectFilesNode(Project p) {
    super(new ProjectFilesChildFactory2(p), p.getLookup());
    setDisplayName(Bundle.LBL_ProjectFiles());
}
 
Example 20
Source File: ActionsUtilTest.java    From netbeans with Apache License 2.0 2 votes vote down vote up
public void testCacheUpdatesCorrectly() throws Exception {
    Project prj1 = new DummyProject();
    Project prj2 = new DummyProject();
    TestProxyLookup projects = new TestProxyLookup(new Lookup[] {
        prj1.getLookup(),
        prj2.getLookup(),
    });
    
    Set<Project> bothProjects = new HashSet<Project>(Arrays.asList(prj1, prj2));
    Set<Project> result = new HashSet<Project>(Arrays.asList(ActionsUtil.getProjectsFromLookup(projects, null)));
    
    assertTrue(bothProjects.equals(result));
    
    //make sure cache is somehow updated even after hard GC:
    //and try really hard to reclaim even (potential) SoftReferences:
    boolean wasThrown = false;
    
    try {
        assertGC("", new WeakReference<Object>(o));
    } catch (AssertionFailedError e) {
        //ignore
        wasThrown = true;
    }
    
    assertTrue(wasThrown);
    
    projects.setLookupsOverride(new Lookup[] {prj1.getLookup()});
    
    Set<Project> firstProject = new HashSet<Project>(Arrays.asList(prj1));
    
    result = new HashSet<Project>(Arrays.asList(ActionsUtil.getProjectsFromLookup(projects, null)));
    
    assertTrue(firstProject.equals(result));
    
    projects.setLookupsOverride(new Lookup[] {});
    
    result = new HashSet<Project>(Arrays.asList(ActionsUtil.getProjectsFromLookup(projects, null)));
    
    assertTrue(Collections.EMPTY_SET.equals(result));
    
    projects.setLookupsOverride(new Lookup[] {prj1.getLookup(), prj2.getLookup()});

    result = new HashSet<Project>(Arrays.asList(ActionsUtil.getProjectsFromLookup(projects, null)));
    
    assertTrue(bothProjects.equals(result));
}