Java Code Examples for org.netbeans.api.progress.ProgressHandle#progress()
The following examples show how to use
org.netbeans.api.progress.ProgressHandle#progress() .
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: GoogleSearchProviderImpl.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
private List<MavenDependencyInfo> downloadGoogleIndex(int connectTimeout, int readTimeout) { ProgressHandle handle = ProgressHandle.createHandle("Goodle index download"); List<MavenDependencyInfo> tmp = new ArrayList<>(); handle.start(); GoogleMasterIndex googleMasterIndex = readGoogleMasterIndex(connectTimeout, readTimeout); if (googleMasterIndex != null) { handle.switchToDeterminate(googleMasterIndex.getGroups().size()); int step = 0; Map<String, String> groups = googleMasterIndex.getGroups(); for (Map.Entry<String, String> entry : groups.entrySet()) { final String group = entry.getKey(); final String url = entry.getValue(); GoogleGroupIndex googleGroupIndex = readGoogleGroupIndex(group, url, connectTimeout, readTimeout); tmp.addAll(googleGroupIndex.getArtifacts()); handle.progress(step++); } } handle.finish(); return tmp; }
Example 2
Source File: GradleProjectCache.java From netbeans with Apache License 2.0 | 6 votes |
@Messages({ "# {0} - The project name", "LBL_Loading=Loading {0}" }) @Override public GradleProject call() throws Exception { tokenSource = GradleConnector.newCancellationTokenSource(); final ProgressHandle handle = ProgressHandle.createHandle(Bundle.LBL_Loading(ctx.previous.getBaseProject().getName()), this); ProgressListener pl = (ProgressEvent pe) -> { handle.progress(pe.getDescription()); }; handle.start(); try { return loadGradleProject(ctx, tokenSource.token(), pl); } catch (Throwable ex) { LOG.log(WARNING, ex.getMessage(), ex); throw ex; } finally { handle.finish(); } }
Example 3
Source File: UpdateUnitProviderImpl.java From netbeans with Apache License 2.0 | 6 votes |
/** Make refresh of content of the provider. The content can by read from * a cache. The <code>force</code> parameter forces reading content from * remote server. * * @param force if true then forces to reread the content from server * @return true if refresh succeed * @throws java.io.IOException when any network problem is encountered */ public boolean refresh (ProgressHandle handle, boolean force) throws IOException { boolean res = false; if (handle != null) { handle.progress (NbBundle.getMessage (UpdateUnitProviderImpl.class, "UpdateUnitProviderImpl_FormatCheckingForUpdates", getDisplayName ())); } final UpdateProvider updateProvider = getUpdateProvider(); updateProvider.refresh (force); if (force) { // store time of the last check AutoupdateSettings.setLastCheck (new Date ()); AutoupdateSettings.setLastCheck (updateProvider.getName(),new Date ()); } // don't remember update units while refreshing the content UpdateManagerImpl.getInstance().clearCache (); return res; }
Example 4
Source File: ProgressAPICompatTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testExtractDetailLabel() throws Exception { Method m = InternalHandle.class.getMethod("extractDetailLabel"); assertEquals("Returns JLabel", JLabel.class, m.getReturnType()); InternalHandle ih = new InternalHandle("foo", null, true); final JLabel jl = (JLabel)m.invoke(ih); final ProgressHandle ph = ih.createProgressHandle(); ph.start(1); ph.progress("bar", 1); // the progress is not updated immediately; wait a little (no suitable event listener); // label gets initialized in AWT, wait for the pending EDT queue items Thread.sleep(1000); SwingUtilities.invokeAndWait(new Runnable() { public void run() { assertEquals("bar", jl.getText()); }}); }
Example 5
Source File: AnalyzerTopComponent.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Void run(ProgressHandle handle) { handle.switchToDeterminate(fixes.size()); int clock = 0; for (FixDescription f : fixes) { if (cancel.get()) break; try { f.implement(); } catch (Exception ex) { Exceptions.printStackTrace(ex); } finally { handle.progress(++clock); } } handle.finish(); return null; }
Example 6
Source File: WebSocketEndpointIterator.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Set<?> instantiate( ProgressHandle handle ) throws IOException { handle.start(); handle.progress(NbBundle.getMessage(WebSocketEndpointIterator.class, "TXT_GenerateEndpoint")); // NOI18N FileObject targetFolder = Templates.getTargetFolder(getWizard()); String name = Templates.getTargetName(getWizard()); FileObject endpoint = GenerationUtils.createClass(targetFolder, name, null ); generateEndpoint(endpoint); handle.finish(); return Collections.singleton(endpoint); }
Example 7
Source File: ExistingWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Set instantiate(ProgressHandle handle) throws IOException { try { handle.start(2); handle.progress(1); RequestProcessor.getDefault().post(new Runnable() { @Override public void run() { tryOpenProject(); } }); return Collections.EMPTY_SET; } finally { handle.finish(); } }
Example 8
Source File: NewJ2SEModularProjectWizardIterator.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Set<FileObject> instantiate (ProgressHandle handle) throws IOException { final WizardDescriptor myWiz = this.wiz; if (myWiz == null) { LOG.warning("The uninitialize called before instantiate."); //NOI18N return Collections.emptySet(); } handle.start (3); Set<FileObject> resultSet = new HashSet<>(); File dirF = (File)myWiz.getProperty("projdir"); //NOI18N if (dirF == null) { throw new NullPointerException ("projdir == null, props:" + myWiz.getProperties()); //NOI18N } dirF = FileUtil.normalizeFile(dirF); String name = (String)myWiz.getProperty("name"); //NOI18N JavaPlatform platform = (JavaPlatform)myWiz.getProperty("javaPlatform"); //NOI18N handle.progress (NbBundle.getMessage (NewJ2SEModularProjectWizardIterator.class, "LBL_NewJ2SEModuleProjectWizardIterator_WizardProgress_CreatingProject"), 1); J2SEModularProjectGenerator.createProject(dirF, name, platform); handle.progress (2); FileObject dir = FileUtil.toFileObject(dirF); // Returning FileObject of project diretory. // Project will be open and set as main final Integer ind = (Integer) myWiz.getProperty(PROP_NAME_INDEX); if (ind != null) { WizardSettings.setNewProjectCount(ind); } resultSet.add (dir); handle.progress (NbBundle.getMessage (NewJ2SEModularProjectWizardIterator.class, "LBL_NewJ2SEModuleProjectWizardIterator_WizardProgress_PreparingToOpen"), 3); dirF = (dirF != null) ? dirF.getParentFile() : null; if (dirF != null && dirF.exists()) { ProjectChooser.setProjectsFolder (dirF); } SharableLibrariesUtils.setLastProjectSharable(false); return resultSet; }
Example 9
Source File: RunOffEDTImplTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String run(ProgressHandle handle) { handle.switchToDeterminate(5); for (int i= 0; i < 5; i++) { handle.progress("Job " + i, i); } return "Done"; }
Example 10
Source File: AdHocGroup.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void findProjects(Set<Project> projects, ProgressHandle h, int start, int end) { List<String> paths = projectPaths(); for (String path : paths) { Project p = projectForPath(path); if (p != null) { if (h != null) { h.progress(progressMessage(p), start += ((end - start) / paths.size())); } projects.add(p); } } }
Example 11
Source File: ImportBlueprintEarWizardIterator.java From netbeans with Apache License 2.0 | 5 votes |
/** <strong>Package private for unit test only</strong>. */ static Set<FileObject> testableInstantiate(final String platformName, final String sourceLevel, final Profile j2eeProfile, final File dirF, final File srcF, final String serverInstanceID, final String name, final Map<FileObject, ModuleType> userModules, ProgressHandle handle, String librariesDefinition) throws IOException { EarProjectGenerator.importProject(dirF, srcF, name, j2eeProfile, serverInstanceID, platformName, sourceLevel, userModules, librariesDefinition); if (handle != null) { handle.progress(2); } FileObject dir = FileUtil.toFileObject(dirF); // remember last used server UserProjectSettings.getDefault().setLastUsedServer(serverInstanceID); Set<FileObject> resultSet = new HashSet<FileObject>(); resultSet.add(dir); NewEarProjectWizardIterator.setProjectChooserFolder(dirF); if (handle != null) { handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3); } // Returning set of FileObject of project diretory. // Project will be open and set as main return resultSet; }
Example 12
Source File: InstanceNode.java From visualvm with GNU General Public License v2.0 | 5 votes |
private static ChangeListener setProgress(final ProgressHandle pHandle) { final BoundedRangeModel progress = HeapProgress.getProgress(); ChangeListener cl = new ChangeListener() { public void stateChanged(ChangeEvent e) { pHandle.progress(progress.getValue()); } }; progress.addChangeListener(cl); return cl; }
Example 13
Source File: DefaultSuiteProjectOperationsImplementation.java From netbeans with Apache License 2.0 | 5 votes |
private static int performDeleteOnProject(Project project, List<FileObject> toDelete ,ProgressHandle handle, int done) throws IOException { handle.progress(NbBundle.getMessage(DefaultSuiteProjectOperationsImplementation.class, "LBL_Progress_Cleaning_Project")); ProjectOperations.notifyDeleting(project); handle.progress(++done); for (FileObject f : toDelete) { handle.progress(NbBundle.getMessage(DefaultSuiteProjectOperationsImplementation.class, "LBL_Progress_Deleting_File", FileUtil.getFileDisplayName(f))); if (f != null && f.isValid()) { f.delete(); } handle.progress(++done); } FileObject projectFolder = project.getProjectDirectory(); projectFolder.refresh(); // #190983 if (!projectFolder.isValid()) { LOG.log(Level.WARNING, "invalid project folder: {0}", projectFolder); } else if (projectFolder.getChildren().length == 0) { projectFolder.delete(); } else { LOG.log(Level.WARNING, "project folder {0} was not empty: {1}", new Object[] {projectFolder, Arrays.asList(projectFolder.getChildren())}); } ProjectOperations.notifyDeleted(project); return done; }
Example 14
Source File: InstanceNode.java From netbeans with Apache License 2.0 | 5 votes |
private static ChangeListener setProgress(final ProgressHandle pHandle) { final BoundedRangeModel progress = HeapProgress.getProgress(); ChangeListener cl = new ChangeListener() { public void stateChanged(ChangeEvent e) { pHandle.progress(progress.getValue()); } }; progress.addChangeListener(cl); return cl; }
Example 15
Source File: SampledCPUSnapshot.java From netbeans with Apache License 2.0 | 5 votes |
private void initSamples() throws IOException { SamplesInputStream stream = new SamplesInputStream(npssFile.getInputStream()); int samplesGuess = (int)(npssFile.getSize()/130); ProgressHandle ph = ProgressHandle.createSystemHandle("Computing snapshot samples", null); ph.start(samplesGuess); for(ThreadsSample s = stream.readSample(); s != null; s = stream.readSample()) { samples++; lastTimestamp = s.getTime(); if (samples < samplesGuess) { ph.progress(samples); } } ph.finish(); }
Example 16
Source File: BasicProjectWizardIterator.java From nb-springboot with Apache License 2.0 | 5 votes |
@Override public Set<FileObject> instantiate(ProgressHandle handle) throws IOException { handle.start(4); Set<FileObject> resultSet = new LinkedHashSet<>(); File fDir = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); fDir.mkdirs(); handle.progress(1); FileObject foDir = FileUtil.toFileObject(fDir); FileObject template = URLMapper.findFileObject(getClass().getResource("BasicSpringbootProject.zip")); unZipFile(template.getInputStream(), foDir); handle.progress(2); // create nbactions.xml file createNbActions(foDir); // clear non project cache ProjectManager.getDefault().clearNonProjectCache(); // Always open top dir as a project: resultSet.add(foDir); // open pom.xml file final FileObject foPom = foDir.getFileObject("pom.xml"); if (foPom != null) { resultSet.add(foPom); } handle.progress(3); // trigger download of dependencies Project prj = ProjectManager.getDefault().findProject(foDir); if (prj != null) { final NbMavenProject mvn = prj.getLookup().lookup(NbMavenProject.class); if (mvn != null) { mvn.downloadDependencyAndJavadocSource(false); } } // remember folder for creation of new projects File parent = fDir.getParentFile(); if (parent != null && parent.exists()) { ProjectChooser.setProjectsFolder(parent); } handle.finish(); return resultSet; }
Example 17
Source File: InitializrProjectWizardIterator.java From nb-springboot with Apache License 2.0 | 4 votes |
@Override public Set<FileObject> instantiate(ProgressHandle handle) throws IOException { handle.start(4); Set<FileObject> resultSet = new LinkedHashSet<>(); File dirF = FileUtil.normalizeFile((File) wiz.getProperty(WIZ_PROJ_LOCATION)); dirF.mkdirs(); FileObject foDir = FileUtil.toFileObject(dirF); // prepare service invocation params String bootVersion = ((NamedItem) wiz.getProperty(WIZ_BOOT_VERSION)).getId(); String mvnGroup = (String) wiz.getProperty(WIZ_GROUP); String mvnArtifact = (String) wiz.getProperty(WIZ_ARTIFACT); String mvnVersion = (String) wiz.getProperty(WIZ_VERSION); String mvnName = (String) wiz.getProperty(WIZ_NAME); String mvnDesc = (String) wiz.getProperty(WIZ_DESCRIPTION); String packaging = ((NamedItem) wiz.getProperty(WIZ_PACKAGING)).getId(); String pkg = (String) wiz.getProperty(WIZ_PACKAGE); String lang = ((NamedItem) wiz.getProperty(WIZ_LANGUAGE)).getId(); String javaVersion = ((NamedItem) wiz.getProperty(WIZ_JAVA_VERSION)).getId(); String deps = (String) wiz.getProperty(WIZ_DEPENDENCIES); handle.progress(1); try { // invoke initializr webservice InputStream stream = InitializrService.getInstance().getProject(bootVersion, mvnGroup, mvnArtifact, mvnVersion, mvnName, mvnDesc, packaging, pkg, lang, javaVersion, deps); handle.progress(2); // unzip response unZipFile(stream, foDir, (boolean) wiz.getProperty(WIZ_REMOVE_MVN_WRAPPER)); handle.progress(3); // parse pom.xml final FileObject foPom = foDir.getFileObject("pom.xml"); // manage run/debug trough maven plugin if ((boolean) wiz.getProperty(WIZ_USE_SB_MVN_PLUGIN)) { // create nbactions.xml file with custom maven actions configuration createNbActions(bootVersion, pkg, mvnName, foDir); } // clear non project cache ProjectManager.getDefault().clearNonProjectCache(); // Always open top dir as a project: resultSet.add(foDir); // open pom.xml file resultSet.add(foPom); // trigger download of dependencies Project prj = ProjectManager.getDefault().findProject(foDir); if (prj != null) { final NbMavenProject mvn = prj.getLookup().lookup(NbMavenProject.class); if (mvn != null) { mvn.downloadDependencyAndJavadocSource(false); } } // remember folder for creation of new projects File parent = dirF.getParentFile(); if (parent != null && parent.exists()) { ProjectChooser.setProjectsFolder(parent); } // remember used deps final Preferences prefs = BootDependenciesPanel.depsCountPrefNode(); String[] splitDeps = deps.split(","); // add to counts in prefs for (String depName : splitDeps) { prefs.putInt(depName, prefs.getInt(depName, 0) + 1); } } catch (Exception ex) { Exceptions.printStackTrace(ex); } handle.finish(); return resultSet; }
Example 18
Source File: NbDownloader.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public void downloadFully(URL url, File target, @Nullable String checksum, ProgressIndicator indicator) throws IOException { if (target.exists() && checksum != null) { if (checksum.equals(Downloader.hash(new BufferedInputStream(new FileInputStream(target)), target.length(), indicator))) { return; } } // We don't use the settings here explicitly, since HttpRequests picks up the network settings from studio directly. indicator.logInfo("Downloading " + url); indicator.setText("Downloading..."); indicator.setSecondaryText(url.toString()); ProgressHandle handle = ProgressHandle.createHandle("Downloading " + url); try { URLConnection connection = url.openConnection(); if (connection instanceof HttpsURLConnection) { ((HttpsURLConnection) connection).setInstanceFollowRedirects(true); ((HttpsURLConnection) connection).setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.3.1)"); ((HttpsURLConnection) connection).setRequestProperty("Accept-Charset", "UTF-8"); ((HttpsURLConnection) connection).setDoOutput(true); ((HttpsURLConnection) connection).setDoInput(true); } connection.setConnectTimeout(3000); connection.connect(); int contentLength = connection.getContentLength(); if (contentLength < 1) { throw new FileNotFoundException(); } handle.start(contentLength); OutputStream dest = new FileOutputStream(target); InputStream in = connection.getInputStream(); int count; int done = 0; byte data[] = new byte[BUFFER_SIZE]; while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) { done += count; handle.progress(done); dest.write(data, 0, count); } dest.close(); in.close(); } finally { handle.finish(); } }
Example 19
Source File: ClientSideProjectWizardIterator.java From netbeans with Apache License 2.0 | 4 votes |
@NbBundle.Messages({ "ClientSideProjectWizardIterator.progress.creatingProject=Creating project", "ClientSideProjectWizardIterator.error.noSources=<html>Source folder cannot be created.<br><br>Use <i>Resolve Project Problems...</i> action to repair the project.", "ClientSideProjectWizardIterator.error.noSiteRoot=<html>Site Root folder cannot be created.<br><br>Use <i>Resolve Project Problems...</i> action to repair the project.", }) @Override public Set<FileObject> instantiate(ProgressHandle handle) throws IOException { handle.start(); handle.progress(Bundle.ClientSideProjectWizardIterator_progress_creatingProject()); Set<FileObject> files = new LinkedHashSet<>(); File projectDirectory = FileUtil.normalizeFile((File) wizardDescriptor.getProperty(Wizard.PROJECT_DIRECTORY)); String name = (String) wizardDescriptor.getProperty(Wizard.NAME); if (!projectDirectory.isDirectory() && !projectDirectory.mkdirs()) { throw new IOException("Cannot create project directory"); //NOI18N } FileObject dir = FileUtil.toFileObject(projectDirectory); CommonProjectHelper projectHelper = ClientSideProjectUtilities.setupProject(dir, name); // Always open top dir as a project: files.add(dir); ClientSideProject project = (ClientSideProject) FileOwnerQuery.getOwner(projectHelper.getProjectDirectory()); Pair<FileObject, FileObject> folders = wizard.instantiate(files, handle, wizardDescriptor, project); FileObject sources = folders.first(); FileObject siteRoot = folders.second(); if (sources != null) { // main file FileObject mainFile = sources.getFileObject("main.js"); // NOI18N if (mainFile != null) { files.add(mainFile); } } else if (wizard.hasSources()) { errorOccured(Bundle.ClientSideProjectWizardIterator_error_noSources()); } if (siteRoot != null) { // index file FileObject indexFile = siteRoot.getFileObject("index", "html"); // NOI18N if (indexFile != null) { files.add(indexFile); } } else if (wizard.hasSiteRoot()) { errorOccured(Bundle.ClientSideProjectWizardIterator_error_noSiteRoot()); } File parent = projectDirectory.getParentFile(); if (parent != null && parent.exists()) { ProjectChooser.setProjectsFolder(parent); } handle.finish(); wizard.logUsage(wizardDescriptor, dir, sources, siteRoot); return files; }
Example 20
Source File: BindingCustomizer.java From netbeans with Apache License 2.0 | 4 votes |
private void importDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importDataButtonActionPerformed final DataImporter importer = Lookup.getDefault().lookup(DataImporter.class); if (importer != null) { final Future<RADComponent> task = importer.importData(bindingComponent.getFormModel()); if (task != null) { final ProgressHandle handle = ProgressHandleFactory.createHandle(null, (Cancellable)null); JComponent handlePanel = panelForHandle(handle); handle.start(); handle.progress(FormUtils.getBundleString("MSG_BindingCustomizer_Importing")); // NOI18N String cancelString = FormUtils.getBundleString("MSG_BindingCustomizer_Cancel"); // NOI18N DialogDescriptor dd = new DialogDescriptor( handlePanel, FormUtils.getBundleString("MSG_BindingCustomizer_Please_Wait"), // NOI18N true, new Object[] {cancelString}, cancelString, DialogDescriptor.DEFAULT_ALIGN, null, null); final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd); new Thread(new Runnable() { @Override public void run() { try { final RADComponent data = task.get(); EventQueue.invokeLater(new Runnable() { @Override public void run() { if (data != null) { // refresh source components combo fillSourceComponentsCombo(); sourceCombo.setSelectedItem(data.getName()); } dialog.setVisible(false); handle.finish(); } }); } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.INFO, ex.getMessage(), ex); } } }).start(); dialog.setVisible(true); } } }