org.netbeans.api.progress.BaseProgressUtils Java Examples
The following examples show how to use
org.netbeans.api.progress.BaseProgressUtils.
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: ProjectPropertiesSupport.java From netbeans with Apache License 2.0 | 6 votes |
@NbBundle.Messages("ProjectPropertiesSupport.project.metadata.saving=Saving project metadata...") private static void saveTestSources(final PhpProject project, final String propertyName, final File testDir) { BaseProgressUtils.showProgressDialogAndRun(new Runnable() { @Override public void run() { // XXX reference helper // relativize text path File projectDirectory = FileUtil.toFile(project.getProjectDirectory()); String testPath = PropertyUtils.relativizeFile(projectDirectory, testDir); if (testPath == null) { // path cannot be relativized => use absolute path (any VCS can be hardly use, of course) testPath = testDir.getAbsolutePath(); } PhpProjectProperties.save(project, Collections.singletonMap(propertyName, testPath), Collections.<String, String>emptyMap()); } }, Bundle.ProjectPropertiesSupport_project_metadata_saving()); }
Example #2
Source File: PhpExecutable.java From netbeans with Apache License 2.0 | 6 votes |
/** * Debug this executable with the given execution descriptor and optional output processor factory, <b>blocking but not blocking the UI thread</b> * (it displays progress dialog if it is running in it). * @param startFile the start file * @param executionDescriptor execution descriptor to be used (never controllable) * @param outProcessorFactory output processor factory to be used, can be {@code null} * @return exit code of the process or {@code null} if any error occured * @throws ExecutionException if any error occurs * @see #debug(FileObject) * @see #debug(FileObject, ExecutionDescriptor) * @since 0.28 */ @NbBundle.Messages("PhpExecutable.debug.progress=Debugging...") @CheckForNull public Integer debug(@NonNull final FileObject startFile, @NonNull final ExecutionDescriptor executionDescriptor, @NullAllowed final ExecutionDescriptor.InputProcessorFactory2 outProcessorFactory) throws ExecutionException { if (!EventQueue.isDispatchThread()) { return debugInternal(startFile, executionDescriptor, outProcessorFactory); } // ui thread final AtomicReference<Integer> executionResult = new AtomicReference<>(); final AtomicReference<ExecutionException> executionException = new AtomicReference<>(); BaseProgressUtils.showProgressDialogAndRun(new Runnable() { @Override public void run() { try { executionResult.set(debugInternal(startFile, executionDescriptor, outProcessorFactory)); } catch (ExecutionException ex) { executionException.set(ex); } } }, Bundle.PhpExecutable_debug_progress()); if (executionException.get() != null) { throw executionException.get(); } return executionResult.get(); }
Example #3
Source File: CustomizerGeneral.java From netbeans with Apache License 2.0 | 6 votes |
@NbBundle.Messages({ "MSG_ContactingServer=Contacting the server", "MSG_ConnectionFailed=Could not connect to the server. It is either not running or not accessible at the moment." }) private void certificateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_certificateButtonActionPerformed manager.getInstanceProperties().setProperty(WLTrustHandler.TRUST_EXCEPTION_PROPERTY, null); BaseProgressUtils.showProgressDialogAndRun(new Runnable() { @Override public void run() { boolean connected = WLTrustHandler.check(manager.getCommonConfiguration()); if (!connected) { NotifyDescriptor desc = new NotifyDescriptor.Message(Bundle.MSG_ConnectionFailed(), NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(desc); } } }, Bundle.MSG_ContactingServer()); }
Example #4
Source File: OptionsDisplayerImpl.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({"Get_Config_File_Lengthy_Operation=Please wait while getting config file."}) private FileObject doGetConfigFile(final String path) { configFile = null; AtomicBoolean getConfigFileCancelled = new AtomicBoolean(false); BaseProgressUtils.runOffEventDispatchThread(new Runnable() { @Override public void run() { configFile = FileUtil.getConfigFile(path); } }, Bundle.Get_Config_File_Lengthy_Operation(), getConfigFileCancelled, false, 50, 1000); if (getConfigFileCancelled.get()) { log.log(Level.FINE, "Options Dialog - Getting config file for path ''{0}'', cancelled by user.", path); //NOI18N } return configFile; }
Example #5
Source File: PhpExecutable.java From netbeans with Apache License 2.0 | 5 votes |
/** * Run this executable with the given execution descriptor and optional output processor factory, <b>blocking but not blocking the UI thread</b> * (it displays progress dialog if it is running in it). * @param executionDescriptor execution descriptor to be used * @param outProcessorFactory output processor factory to be used, can be {@code null} * @param progressMessage message displayed if the task is running in the UI thread * @return exit code of the process or {@code null} if any error occured * @throws ExecutionException if any error occurs * @see #runAndWait(String) * @see #runAndWait(ExecutionDescriptor, String) * @since 0.28 */ @CheckForNull public Integer runAndWait(@NonNull ExecutionDescriptor executionDescriptor, @NullAllowed ExecutionDescriptor.InputProcessorFactory2 outProcessorFactory, @NonNull final String progressMessage) throws ExecutionException { Parameters.notNull("progressMessage", progressMessage); // NOI18N final Future<Integer> result = run(executionDescriptor, outProcessorFactory); if (result == null) { return null; } final AtomicReference<ExecutionException> executionException = new AtomicReference<>(); if (SwingUtilities.isEventDispatchThread()) { if (!result.isDone()) { try { // let's wait in EDT to avoid flashing dialogs getResult(result, 90L); } catch (TimeoutException ex) { BaseProgressUtils.showProgressDialogAndRun(new Runnable() { @Override public void run() { try { getResult(result); } catch (ExecutionException extEx) { executionException.set(extEx); } } }, progressMessage); } } } if (executionException.get() != null) { throw executionException.get(); } return getResult(result); }
Example #6
Source File: RunTagWizard.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({ "MSG_ReceivingImageInfo=Receiving Image Details", "LBL_Run=Run {0}" }) public void show() { DockerImageDetail info = BaseProgressUtils.showProgressDialogAndRun( new DockerImageInfoRunnable(tag.getImage()), Bundle.MSG_ReceivingImageInfo(), false); List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<>(); panels.add(new RunContainerPropertiesPanel(info)); panels.add(new RunPortBindingsPanel(info)); String[] steps = new String[panels.size()]; for (int i = 0; i < panels.size(); i++) { JComponent c = (JComponent) panels.get(i).getComponent(); // Default step name to component name of panel. steps[i] = c.getName(); c.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i); c.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); c.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true); c.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true); c.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true); } final WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<>(panels)); // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName() wiz.setTitleFormat(new MessageFormat("{0}")); wiz.setTitle(Bundle.LBL_Run(getImage(tag))); if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) { run(tag, wiz); } }
Example #7
Source File: LibraryChooserGUI.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({"LBL_Importing=Importing..."}) private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed final Set<Library> libs = showChooser(LibraryManager.getDefault(), new IgnoreAlreadyImportedLibrariesFilter(), null, false); if (libs != null) { Runnable r = new Runnable() { @Override public void run() { try { final Set<Library> importedLibs = new HashSet<Library>(); for (Library lib : libs) { importedLibs.add(importHandler.importLibrary(lib)); } EventQueue.invokeLater(new Runnable() { @Override public void run() { setRootNode(); selectLibrary(importedLibs); } }); } catch (IOException ex) { Exceptions.printStackTrace(ex); } finally { enableButtons(true); } } }; enableButtons(false); BaseProgressUtils.showProgressDialogAndRun(r, Bundle.LBL_Importing()); } }
Example #8
Source File: ExternalExecutable.java From netbeans with Apache License 2.0 | 5 votes |
/** * Run this executable with the given execution descriptor and optional output processor factory, <b>blocking but not blocking the UI thread</b> * (it displays progress dialog if it is running in it). * @param executionDescriptor execution descriptor to be used * @param outProcessorFactory output processor factory to be used, can be {@code null} * @param progressMessage message displayed if the task is running in the UI thread * @return exit code of the process or {@code null} if any error occured * @throws ExecutionException if any error occurs * @see #runAndWait(String) * @see #runAndWait(ExecutionDescriptor, String) */ @CheckForNull public Integer runAndWait(@NonNull ExecutionDescriptor executionDescriptor, @NullAllowed ExecutionDescriptor.InputProcessorFactory2 outProcessorFactory, @NonNull final String progressMessage) throws ExecutionException { Parameters.notNull("progressMessage", progressMessage); // NOI18N final Future<Integer> result = run(executionDescriptor, outProcessorFactory); if (result == null) { return null; } final AtomicReference<ExecutionException> executionException = new AtomicReference<>(); if (Mutex.EVENT.isReadAccess()) { // Is EDT if (!result.isDone()) { try { // let's wait in EDT to avoid flashing dialogs getResult(result, 90L); } catch (TimeoutException ex) { BaseProgressUtils.showProgressDialogAndRun(new Runnable() { @Override public void run() { try { getResult(result); } catch (ExecutionException extEx) { executionException.set(extEx); } } }, progressMessage); } } } if (executionException.get() != null) { throw executionException.get(); } return getResult(result); }
Example #9
Source File: ExternalExecutable.java From minifierbeans with Apache License 2.0 | 5 votes |
/** * Run this executable with the given execution descriptor and optional output processor factory, <b>blocking but not blocking the UI thread</b> * (it displays progress dialog if it is running in it). * @param executionDescriptor execution descriptor to be used * @param outProcessorFactory output processor factory to be used, can be {@code null} * @param progressMessage message displayed if the task is running in the UI thread * @return exit code of the process or {@code null} if any error occured * @throws ExecutionException if any error occurs * @see #runAndWait(String) * @see #runAndWait(ExecutionDescriptor, String) */ @CheckForNull public Integer runAndWait(@NonNull ExecutionDescriptor executionDescriptor, @NullAllowed ExecutionDescriptor.InputProcessorFactory2 outProcessorFactory, @NonNull final String progressMessage) throws ExecutionException { Parameters.notNull("progressMessage", progressMessage); // NOI18N final Future<Integer> result = run(executionDescriptor, outProcessorFactory); if (result == null) { return null; } final AtomicReference<ExecutionException> executionException = new AtomicReference<ExecutionException>(); if (Mutex.EVENT.isReadAccess()) { // Is EDT if (!result.isDone()) { try { // let's wait in EDT to avoid flashing dialogs getResult(result, 90L); } catch (TimeoutException ex) { BaseProgressUtils.showProgressDialogAndRun(new Runnable() { @Override public void run() { try { getResult(result); } catch (ExecutionException extEx) { executionException.set(extEx); } } }, progressMessage); } } } if (executionException.get() != null) { throw executionException.get(); } return getResult(result); }
Example #10
Source File: SaveProductAction.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
static Boolean saveProduct(Product product) { Assert.notNull(product.getFileLocation()); final File file = product.getFileLocation(); if (file.isFile() && !file.canWrite()) { Dialogs.showWarning(Bundle.CTL_SaveProductActionName(), MessageFormat.format("The product\n" + "''{0}''\n" + "exists and cannot be overwritten, because it is read only.\n" + "Please choose another file or remove the write protection.", file.getPath()), null); return false; } SnapApp.getDefault().setStatusBarMessage(MessageFormat.format("Writing product ''{0}'' to {1}...", product.getDisplayName(), file)); boolean incremental = true; WriteProductOperation operation = new WriteProductOperation(product, incremental); BaseProgressUtils.runOffEventThreadWithProgressDialog(operation, Bundle.CTL_SaveProductActionName(), operation.getProgressHandle(), true, 50, 1000); SnapApp.getDefault().setStatusBarMessage(""); return operation.getStatus(); }
Example #11
Source File: StopExecutionAction.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected void doPerformAction(ActionEvent evt, JTextComponent target, ShellSession session) { BaseProgressUtils.runOffEventDispatchThread(session::stopExecutingCode, Bundle.LBL_AttemptingStop(), new AtomicBoolean(false), false, 100, 2000); }
Example #12
Source File: FixUsesAction.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void actionPerformed(ActionEvent evt, final JTextComponent target) { if (target != null) { final int caretPosition = target.getCaretPosition(); final AtomicBoolean cancel = new AtomicBoolean(); final AtomicReference<ImportData> importData = new AtomicReference<>(); final UserTask task = new UserTask() { @Override public void run(ResultIterator resultIterator) throws Exception { Result parserResult = resultIterator.getParserResult(); if (parserResult instanceof PHPParseResult) { if (cancel.get()) { return; } final ImportData data = computeUses((PHPParseResult) parserResult, caretPosition); if (cancel.get()) { return; } if (data.shouldShowUsesPanel) { if (!cancel.get()) { importData.set(data); } } else { performFixUses((PHPParseResult) parserResult, data, data.getDefaultVariants(), isRemoveUnusedUses()); } } } }; BaseProgressUtils.runOffEventDispatchThread(new Runnable() { @Override public void run() { try { ParserManager.parse(Collections.singleton(Source.create(target.getDocument())), task); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } } }, Bundle.LongName(), cancel, false); if (importData.get() != null && !cancel.get()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showFixUsesDialog(target, importData.get()); } }); } } }
Example #13
Source File: CakePHP3GoToAction.java From cakephp3-netbeans with Apache License 2.0 | 4 votes |
@Override public final void actionPerformed(ActionEvent event, final JTextComponent textComponent) { Document document = textComponent.getDocument(); if (document == null) { return; } final FileObject fileObject = NbEditorUtilities.getFileObject(document); if (fileObject == null) { return; } PhpModule phpModule = PhpModule.Factory.forFileObject(fileObject); if (phpModule == null) { return; } if (!CakePHP3Module.isCakePHP(phpModule)) { return; } // only php files String mimeType = fileObject.getMIMEType(FileUtils.PHP_MIME_TYPE); // NOI18N if (!FileUtils.PHP_MIME_TYPE.equals(mimeType)) { return; } final AtomicBoolean cancel = new AtomicBoolean(); CakePHP3GoToStatusFactory factory = CakePHP3GoToStatusFactory.getInstance(); final CakePHP3GoToStatus status = factory.create(fileObject, textComponent.getCaretPosition()); final List<GoToItem> defaultItems = new ArrayList<>(); BaseProgressUtils.runOffEventDispatchThread(new Runnable() { @Override public void run() { status.scan(); defaultItems.addAll(getGoToItems(status)); } }, "CakePHP3 Go To", cancel, false); // show popup try { Rectangle rectangle = textComponent.modelToView(textComponent.getCaretPosition()); final Point point = new Point(rectangle.x, rectangle.y + rectangle.height); SwingUtilities.convertPointToScreen(point, textComponent); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { String title = getPopupTitle(); if (title == null) { title = ""; // NOI18N } PopupUtil.showPopup(new GoToPopup(title, defaultItems, status), title, point.x, point.y, true, 0); } }); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } }
Example #14
Source File: SubsetByGeometryAction.java From snap-examples with GNU General Public License v3.0 | 4 votes |
private void createSubset() { // Get current view showing a product's band final ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView(); if (view == null) { return; } final FigureSelection selection = getCurrentFigureSelection(); // Get the geometry of the selection ShapeFigure geometry = null; if (selection.getFigureCount() > 0) { Figure figure = selection.getFigure(0); if (figure instanceof ShapeFigure) { geometry = (ShapeFigure) figure; } } if (geometry == null) { Dialogs.showError(Bundle.CTL_SubsetByGeometryAction_DialogTitle(), ERR_MSG_BASE + "There is no geometry defined in the current selection."); return; } Product subset; try { Product product = view.getProduct(); String productName = product.getName(); ProductSubsetDef subsetDef = new ProductSubsetDef(); subsetDef.setRegion(geometry.getBounds().getBounds()); subset = ProductSubsetBuilder.createProductSubset(product, subsetDef, productName + "_subset", "Subset of " + productName); } catch (IOException e) { Dialogs.showError(Bundle.CTL_SubsetByGeometryAction_DialogTitle(), ERR_MSG_BASE + "An I/O error occurred:\n" + e.getMessage()); return; } Preferences preferences = SnapApp.getDefault().getPreferences(); ProductFileChooser fc = new ProductFileChooser(new File(preferences.get(ProductOpener.PREFERENCES_KEY_LAST_PRODUCT_DIR, "."))); fc.setDialogType(JFileChooser.SAVE_DIALOG); fc.setSubsetEnabled(true); fc.addChoosableFileFilter(new DimapFileFilter()); fc.setProductToExport(subset); int returnVal = fc.showSaveDialog(SnapApp.getDefault().getMainFrame()); File newFile = fc.getSelectedFile(); if (returnVal != JFileChooser.APPROVE_OPTION || newFile == null) { // cancelled return; } WriteProductOperation operation = new WriteProductOperation(subset, newFile, ProductIO.DEFAULT_FORMAT_NAME, false); BaseProgressUtils.runOffEventThreadWithProgressDialog(operation, Bundle.CTL_SubsetByGeometryAction_DialogTitle(), operation.getProgressHandle(), true, 50, 1000); }