org.netbeans.api.project.ui.OpenProjects Java Examples
The following examples show how to use
org.netbeans.api.project.ui.OpenProjects.
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: ModulesNodeFactory.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override protected void performAction(Node[] activatedNodes) { for (Node node : activatedNodes) { final FileObject fo = node.getLookup().lookup(FileObject.class); if (fo != null) { RequestProcessor.getDefault().post(new Runnable() { public @Override void run() { Project projectsArray[] = new Project[]{FileOwnerQuery.getOwner(fo)}; OpenProjects.getDefault().open(projectsArray, false, true); RequestProcessor.getDefault().post(new Runnable() { public @Override void run() { ProjectActionUtils.selectAndExpandProject(projectsArray[0]); } }, 500); } }); } } }
Example #2
Source File: ProjectUtilitiesProviderImpl.java From netbeans with Apache License 2.0 | 6 votes |
public ProjectUtilitiesProviderImpl() { OpenProjects.getDefault().addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { synchronized(ProjectUtilitiesProviderImpl.this) { if (!hasListeners()) return; String prop = evt.getPropertyName(); if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(prop) || OpenProjects.PROPERTY_MAIN_PROJECT.equals(prop)) { for (ChangeListener listener : listeners) listener.stateChanged(new ChangeEvent(evt)); } } } }); }
Example #3
Source File: SearchScopeOpenProjects.java From netbeans with Apache License 2.0 | 6 votes |
@Override public SearchInfo getSearchInfo() { Project[] openProjects = OpenProjects.getDefault().getOpenProjects(); if (openProjects.length == 0) { /* * We cannot prevent this situation. The action may be invoked * between moment the last project had been removed and the removal * notice was distributed to the open projects listener (and this * action disabled). This may happen if the the last project * is being removed in another thread than this action was * invoked from. */ return SearchInfoUtils.createEmptySearchInfo(); } if (openProjects.length == 1) { return createSingleProjectSearchInfo(openProjects[0]); } SearchInfo[] prjSearchInfos = new SearchInfo[openProjects.length]; for (int i = 0; i < prjSearchInfos.length; i++) { prjSearchInfos[i] = createSingleProjectSearchInfo(openProjects[i]); } return SearchInfoUtils.createCompoundSearchInfo(prjSearchInfos); }
Example #4
Source File: EarProjectTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testEarProjectIsGCed() throws Exception { // #83128 File prjDirF = new File(getWorkDir(), "testEA"); String name = "Test EnterpriseApplication"; Profile j2eeProfile = Profile.J2EE_14; // creates a project we will use for the import NewEarProjectWizardIteratorTest.generateEARProject(prjDirF, name, j2eeProfile, TestUtil.SERVER_URL, null, null, null, null, null, null); Project earProject = ProjectManager.getDefault().findProject(FileUtil.toFileObject(prjDirF)); EarProjectTest.openProject((EarProject) earProject); Node rootNode = earProject.getLookup().lookup(LogicalViewProvider.class).createLogicalView(); rootNode.getChildren().getNodes(true); // ping Reference<Project> wr = new WeakReference<Project>(earProject); OpenProjects.getDefault().close(new Project[] { earProject }); EarProjectTest.closeProject((EarProject) earProject); rootNode = null; earProject = null; // TimedWeakReference timeout plus some buffer (projectapi.nb) Thread.sleep(15000 + 5000); assertGC("project cannot be garbage collected", wr); }
Example #5
Source File: EvaluatorTest.java From netbeans with Apache License 2.0 | 6 votes |
protected void setUp () throws Exception { super.setUp (); //PreferredCCParser is using SourceUtils.isScanInProgress() to modify behavior; ensure indexing is not running. FileObject prjRoot = FileUtil.toFileObject(new File(System.getProperty("test.dir.src"))); assertNotNull(prjRoot); Project prj = FileOwnerQuery.getOwner(prjRoot); assertNotNull(prj); Project annotationsPrj = FileOwnerQuery.getOwner(prj.getProjectDirectory().getParent().getFileObject("api.annotations.common")); assertNotNull(annotationsPrj); OpenProjects.getDefault().open(new Project[] {annotationsPrj}, false); JavaSource.create(ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY)).runWhenScanFinished(p -> {}, true).get(); System.setProperty("debugger.evaluator2", "true"); JPDASupport.removeAllBreakpoints (); Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src")+ "org/netbeans/api/debugger/jpda/testapps/EvaluatorApp.java"); LineBreakpoint lb = bp.getLineBreakpoints().get(0); source = new URL(lb.getURL()); DebuggerManager.getDebuggerManager ().addBreakpoint (lb); support = JPDASupport.attach ( "org.netbeans.api.debugger.jpda.testapps.EvaluatorApp" ); support.waitState (JPDADebugger.STATE_STOPPED); }
Example #6
Source File: AppClientProvider.java From netbeans with Apache License 2.0 | 6 votes |
private boolean isProjectOpen() { // OpenProjects.getDefault() is null when this method is called upon // IDE startup from the project's impl of ProjectOpenHook if (OpenProjects.getDefault() != null) { Project[] projects = OpenProjects.getDefault().getOpenProjects(); for (int i = 0; i < projects.length; i++) { if (projects[i].equals(project)) { return true; } } return false; } else { // be conservative -- don't know anything about the project // so consider it open return true; } }
Example #7
Source File: ApplicationScopedResourcesUtils.java From netbeans with Apache License 2.0 | 6 votes |
public static boolean isEarChild(Project project) { J2eeModuleProvider childProvider = project.getLookup().lookup(J2eeModuleProvider.class); if (childProvider == null || childProvider instanceof J2eeApplicationProvider) { return false; } // FIXME if the ear is closed it wont find it; is it a problem? Project[] allProjects = OpenProjects.getDefault().getOpenProjects(); for (Project candidate : allProjects) { J2eeApplicationProvider app = candidate.getLookup().lookup(J2eeApplicationProvider.class); if (app != null) { for (J2eeModuleProvider p : app.getChildModuleProviders()) { if (p.equals(childProvider)) { return true; } } } } return false; }
Example #8
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
/** * Open projects with given names located in given folder. * * @param projectNames project names to open * @param dir project's enclosing directory * @throws java.io.IOException when project cannot be opened */ public static void openProjects(File dir, String... projectNames) throws IOException { List<Project> projects = new ArrayList<>(projectNames.length); for (String projectName : projectNames) { File projectsDir = FileUtil.normalizeFile(dir); FileObject projectsDirFO = FileUtil.toFileObject(projectsDir); FileObject projdir = projectsDirFO.getFileObject(projectName); FileObject nbproject = projdir.getFileObject("nbproject"); if (nbproject.getFileObject("private") != null) { for (FileObject ch : nbproject.getFileObject("private").getChildren()) { ch.delete(); } } Project p = ProjectManager.getDefault().findProject(projdir); if (p == null) { throw new IOException("Project is not found " + projectName); } projects.add(p); } OpenProjects.getDefault().open(projects.toArray(new Project[0]), false); }
Example #9
Source File: RESTExplorerPanel.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void addNotify() { super.addNotify(); manager.addPropertyChangeListener(this); Project[] projects = OpenProjects.getDefault().getOpenProjects(); Children rootChildren = new Children.Array(); AbstractNode explorerResourcesRoot = new AbstractNode(rootChildren); List<Node> projectNodeList = new ArrayList<Node>(); for (Project prj : projects) { Node node = factory.createNode(prj); if ( node != null ){ projectNodeList.add(node); } } Node[] projectNodes = new Node[projectNodeList.size()]; projectNodeList.<Node>toArray(projectNodes); rootChildren.add(projectNodes); manager.setRootContext(explorerResourcesRoot); // !PW If we preselect a node, this can go away. descriptor.setValid(false); treeView.requestFocusInWindow(); }
Example #10
Source File: SuiteOperations.java From netbeans with Apache License 2.0 | 6 votes |
private static void close(final Project prj) { Mutex.EVENT.readAccess(new Mutex.Action<Object>() { public Object run() { LifecycleManager.getDefault().saveAll(); Action closeAction = CommonProjectActions.closeProjectAction(); closeAction = closeAction instanceof ContextAwareAction ? ((ContextAwareAction) closeAction).createContextAwareInstance(Lookups.fixed(new Object[] {prj})) : null; if (closeAction != null && closeAction.isEnabled()) { closeAction.actionPerformed(new ActionEvent(prj, -1, "")); // NOI18N } else { //fallback: OpenProjects.getDefault().close(new Project[] {prj}); } return null; } }); }
Example #11
Source File: WSITRefactoringFactory.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean isOnSourceClasspath(FileObject fileObject) { Project project = FileOwnerQuery.getOwner(fileObject); if (project==null) return false; if (OpenProjects.getDefault().isProjectOpen(project)) { SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups( JavaProjectConstants.SOURCES_TYPE_JAVA); for (int j = 0; j < sourceGroups.length; j++) { if (fileObject==sourceGroups[j].getRootFolder()) { return true; } if (FileUtil.isParentOf(sourceGroups[j].getRootFolder(), fileObject)) return true; } return false; } return false; }
Example #12
Source File: MoveClassPanel.java From netbeans with Apache License 2.0 | 6 votes |
public MoveClassPanel(final ChangeListener parent, String startPackage, String headLine, String bypassLine, FileObject f, String newName, boolean toType) { this.fo = f; this.parent = parent; this.newName = newName; this.bypassLine = bypassLine; initComponents(); setCombosEnabled(true); labelHeadLine.setText(headLine); rootComboBox.setRenderer(GROUP_CELL_RENDERER); packageComboBox.setRenderer(PackageView.listRenderer()); projectsComboBox.setRenderer(PROJECT_CELL_RENDERER); typeCombobox.setRenderer(CLASS_CELL_RENDERER); Project fileOwner = fo != null ? FileOwnerQuery.getOwner(fo) : null; project = fileOwner != null ? fileOwner : OpenProjects.getDefault().getOpenProjects()[0]; this.startPackage = startPackage; if(newName != null) { labelHeadLine.setVisible(false); } else { labelNewName.setVisible(false); newNameField.setVisible(false); } this.toType = toType; }
Example #13
Source File: Group.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void run() { OpenProjects.getDefault().addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!projectsLoaded || switchingGroup.get()) { return; } final String propertyName = evt.getPropertyName(); if (propertyName != null) { final Group g = getActiveGroup(); if (g != null) { LOG.log(Level.FINE, "received {0} on {1}", new Object[] {propertyName, g.id}); RequestProcessor.getDefault().post(new Runnable() { @Override public void run() { g.openProjectsEvent(propertyName); } }); } } } }); }
Example #14
Source File: ProjectHelper.java From jeddict with Apache License 2.0 | 6 votes |
public static List<Project> getJavaProjects() { List<Project> list = new ArrayList<>(); Project[] openProjects = OpenProjects.getDefault().getOpenProjects(); if (openProjects != null) { for (Project prj : openProjects) { Sources sources = ProjectUtils.getSources(prj); if (sources == null) { continue; } SourceGroup[] srcGrps = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); if (srcGrps != null && srcGrps.length > 0) { list.add(prj); } } } return list; }
Example #15
Source File: MainProjectManager.java From netbeans with Apache License 2.0 | 6 votes |
@java.lang.SuppressWarnings("LeakingThisInConstructor") private MainProjectManager () { pcs = new PropertyChangeSupport (this); a = ProjectSensitiveActions.projectSensitiveAction ( this, "x", null ); OpenProjects.getDefault().addPropertyChangeListener(this); currentProject = new WeakReference<Project>(OpenProjects.getDefault().getMainProject()); isMainProject = currentProject.get() != null; a.addPropertyChangeListener(this); // I'm listening on it so that I get enable() called. SwingUtilities.invokeLater(new Runnable() { public @Override void run() { a.isEnabled(); } }); }
Example #16
Source File: IDEServicesImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void applyPatch(final File patchFile) { UIUtils.runInAWT(new Runnable() { @Override public void run() { final File context = selectPatchContext(); if (context != null) { RP.post(new Runnable() { @Override public void run() { try { PatchUtils.applyPatch(patchFile, context); Project project = FileOwnerQuery.getOwner(Utilities.toURI(context)); if(project != null && !OpenProjects.getDefault().isProjectOpen(project)) { OpenProjects.getDefault().open(new Project[] {project}, false); } } catch (IOException ex) { LOG.log(Level.INFO, ex.getMessage(), ex); } } }); } } }); }
Example #17
Source File: DefaultClassPathProvider.java From netbeans with Apache License 2.0 | 6 votes |
private void fire() { LOG.log(Level.FINEST, "Request to fire an event"); //NOI18N synchronized (this) { if (task == null) { LOG.log(Level.FINEST, "Scheduled firer task"); //NOI18N final Future<Project[]> becomeProjects = OpenProjects.getDefault().openProjects(); task = RP.create(new Runnable() { @Override public void run() { try { becomeProjects.get(); support.firePropertyChange(PROP_RESOURCES,null,null); LOG.log(Level.FINEST, "Fired an event"); //NOI18N } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } finally { task = null; //Write barrier } } }); task.schedule(0); } } }
Example #18
Source File: DelayScanRegistry.java From netbeans with Apache License 2.0 | 6 votes |
/** * Delays given task if neccessary - e.g. projects are currently openning - and reschedules the task if indexing is running * This method waits for projects to open and thus blocks the current thread. * @param task task to be delayed * @param logger * @param logMessagePrefix * @return true if the task was rescheduled */ public boolean isDelayed (RequestProcessor.Task task, Logger logger, String logMessagePrefix) { boolean rescheduled = false; DelayedScan scan = getRegisteredScan(task); Future<Project[]> projectOpenTask = OpenProjects.getDefault().openProjects(); if (!projectOpenTask.isDone()) { try { projectOpenTask.get(); } catch (Exception ex) { // not interested } } if (IndexingBridge.getInstance().isIndexingInProgress() && (BLOCK_INDEFINITELY || scan.waitingLoops * WAITING_PERIOD < MAX_WAITING_TIME)) { // do not steal disk from openning projects and indexing tasks Level level = ++scan.waitingLoops < 10 ? Level.FINE : Level.INFO; logger.log(level, "{0}: Scanning in progress, trying again in {1}ms", new Object[]{logMessagePrefix, WAITING_PERIOD}); //NOI18N task.schedule(WAITING_PERIOD); // try again later rescheduled = true; } else { scan.waitingLoops = 0; } return rescheduled; }
Example #19
Source File: GroovyProjectUtil.java From netbeans with Apache License 2.0 | 6 votes |
public static boolean isOnSourceClasspath(FileObject fo) { Project project = FileOwnerQuery.getOwner(fo); if (project == null) { return false; } if (OpenProjects.getDefault().isProjectOpen(project)) { for (SourceGroup group : GroovySources.getGroovySourceGroups(ProjectUtils.getSources(project))) { if (group.getRootFolder().equals(fo)) { return true; } if (FileUtil.isParentOf(group.getRootFolder(), fo)) { return true; } } } return false; }
Example #20
Source File: OpenProjectsTrampolineImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange( PropertyChangeEvent e ) { if ( e.getPropertyName().equals( OpenProjectList.PROPERTY_OPEN_PROJECTS ) ) { pchSupport.firePropertyChange( OpenProjects.PROPERTY_OPEN_PROJECTS, e.getOldValue(), e.getNewValue() ); } if ( e.getPropertyName().equals( OpenProjectList.PROPERTY_WILL_OPEN_PROJECTS ) ) { pchSupport.firePropertyChange( OpenProjectList.PROPERTY_WILL_OPEN_PROJECTS, e.getOldValue(), e.getNewValue() ); } if ( e.getPropertyName().equals( OpenProjectList.PROPERTY_MAIN_PROJECT ) ) { pchSupport.firePropertyChange( OpenProjects.PROPERTY_MAIN_PROJECT, e.getOldValue(), e.getNewValue() ); } }
Example #21
Source File: WebProjectWebServicesClientSupport.java From netbeans with Apache License 2.0 | 5 votes |
private boolean isProjectOpened() { // XXX workaround: OpenProjects.getDefault() can be null // when called from ProjectOpenedHook.projectOpened() upon IDE startup if (OpenProjects.getDefault() == null) return true; Project[] projects = OpenProjects.getDefault().getOpenProjects(); for (int i = 0; i < projects.length; i++) { if (projects[i].equals(project)) return true; } return false; }
Example #22
Source File: Installer.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void close() { try { FeatureManager.incrementUnused(OpenProjects.getDefault().getOpenProjects()); FeatureManager.disableUnused(5); } catch (Exception ex) { Exceptions.printStackTrace(ex); } }
Example #23
Source File: AntActionInstance.java From netbeans with Apache License 2.0 | 5 votes |
public @Override boolean isEnabled() { if (proj.getFile() == null) { return false; // cannot run script not on disk } // #21249: if it delegates to a script in a project, enable only if that project is open Element root = proj.getProjectElement(); if (root == null) { return false; // misparse } NodeList nl = root.getElementsByTagName("ant"); // NOI18N if (nl.getLength() == 1) { Element ant = (Element) nl.item(0); String antfile = ant.getAttribute("antfile"); // NOI18N if (antfile.length() == 0) { String dir = ant.getAttribute("dir"); // NOI18N if (dir.length() > 0) { antfile = dir + File.separatorChar + "build.xml"; // NOI18N } } if (antfile.length() > 0) { FileObject fo = FileUtil.toFileObject(new File(antfile)); if (fo != null) { Project owner = FileOwnerQuery.getOwner(fo); if (owner != null) { return Arrays.asList(OpenProjects.getDefault().getOpenProjects()).contains(owner); } } } } return true; }
Example #24
Source File: UpdateAllProjects.java From netbeans with Apache License 2.0 | 5 votes |
private List<UpgradableProject> getListOfUpdatableProjects() { List<UpgradableProject> projs = new ArrayList<UpgradableProject>(); for (Project p : OpenProjects.getDefault().getOpenProjects()) { UpgradableProject up = p.getLookup().lookup(UpgradableProject.class); if (up != null && up.isCreatedFromEclipse()) { projs.add(up); } } return projs; }
Example #25
Source File: ProjectOpenFileImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** * Opens the specified project asynchronously. This method helps to avoid * blocking of the current thread (e.g. AWT thread) on long-time operation * of opening the project. * * @param p the project. */ private void openProject(final Project p) { Runnable r =new Runnable() { @Override public void run() { OpenProjects.getDefault().open(new Project[] {p}, false, true); } }; new Thread(r, "Open " + p).start(); // NOI18N }
Example #26
Source File: BreakpointGroup.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean isDependentOnAnOpened(Project p, Set<Project> openedProjectsCache, Set<Project> closedProjectsCache, Map<Project, Set<? extends Project>> subProjects) { for (Project op : OpenProjects.getDefault().getOpenProjects()) { if (isSubProjectOf(p, op, subProjects, new HashSet<Project>())) { openedProjectsCache.add(p); return true; } } closedProjectsCache.add(p); return false; }
Example #27
Source File: RefactoringUtil.java From netbeans with Apache License 2.0 | 5 votes |
public static boolean isOnSourceClasspath(FileObject fo) { Project p = FileOwnerQuery.getOwner(fo); if (p==null) return false; if (OpenProjects.getDefault().isProjectOpen(p)) { SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (int j = 0; j < gr.length; j++) { if (fo==gr[j].getRootFolder()) return true; if (FileUtil.isParentOf(gr[j].getRootFolder(), fo)) return true; } return false; } return false; }
Example #28
Source File: PersistentSnippetsSupport.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if (!OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName())) { return; } if (!OpenProjects.getDefault().isProjectOpen(project)) { unregister(project); OpenProjects.getDefault().removePropertyChangeListener(this); } }
Example #29
Source File: ShowMembersAtCaretAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean isEnabled() { final JTextComponent tc = EditorRegistry.lastFocusedComponent(); if (tc == null || !tc.isShowing() || getContext(tc) == null) { return false; } return OpenProjects.getDefault().getOpenProjects().length > 0; }
Example #30
Source File: ProjectsRootNodePreferredOpenTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { clearWorkDir(); MockServices.setServices(TestSupport.TestProjectFactory.class); FileObject workDir = FileUtil.toFileObject(getWorkDir()); assertNotNull(workDir); first = new CountDownLatch(1); middle = new CountDownLatch(1); rest = new CountDownLatch(2); List<URL> list = new ArrayList<URL>(); List<ExtIcon> icons = new ArrayList<ExtIcon>(); List<String> names = new ArrayList<String>(); for (int i = 0; i < 10; i++) { FileObject prj = TestSupport.createTestProject(workDir, "prj" + i); URL url = URLMapper.findURL(prj, URLMapper.EXTERNAL); list.add(url); names.add(url.toExternalForm()); icons.add(new ExtIcon()); TestSupport.TestProject tmp = (TestSupport.TestProject)ProjectManager.getDefault ().findProject (prj); assertNotNull("Project found", tmp); CountDownLatch down = i == 0 ? first : (i == 5 ? middle : rest); tmp.setLookup(createLookup(tmp, new TestProjectOpenedHookImpl(down))); } OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); OpenProjects.getDefault().addPropertyChangeListener(this); //compute project root node children in sync mode System.setProperty("test.projectnode.sync", "true"); }