org.openide.util.Cancellable Java Examples
The following examples show how to use
org.openide.util.Cancellable.
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: DebuggerTest.java From netbeans with Apache License 2.0 | 6 votes |
private void startDebugging(final SessionId sessionId, File scriptFile) { final ProcessBuilder processBuilder = new ProcessBuilder(new String[]{getPHPInterpreter(), scriptFile.getAbsolutePath()}); processBuilder.directory(scriptFile.getParentFile()); processBuilder.environment().put("XDEBUG_CONFIG", "idekey=" + sessionId.getId()); //NOI18N final DebuggerOptions options = DebuggerOptions.getGlobalInstance(); options.pathMapping = Collections.emptyList(); SessionManager.getInstance().startSession(sessionId, options, new Callable<Cancellable>() { @Override public Cancellable call() throws Exception { processBuilder.start(); return new Cancellable() { @Override public boolean cancel() { return true; } }; } }); }
Example #2
Source File: BaseExecutionService.java From netbeans with Apache License 2.0 | 6 votes |
private void cleanup(final List<InputReaderTask> tasks, final ExecutorService processingExecutor) { boolean interrupted = false; if (processingExecutor != null) { try { AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { processingExecutor.shutdown(); return null; } }); for (Cancellable cancellable : tasks) { cancellable.cancel(); } while (!processingExecutor.awaitTermination(EXECUTOR_SHUTDOWN_SLICE, TimeUnit.MILLISECONDS)) { LOGGER.log(Level.INFO, "Awaiting processing finish"); } } catch (InterruptedException ex) { interrupted = true; } } if (interrupted) { Thread.currentThread().interrupt(); } }
Example #3
Source File: SessionManager.java From netbeans with Apache License 2.0 | 6 votes |
public void startNewSession(Project project, Callable<Cancellable> run, DebugStarter.Properties properties) { assert properties.getStartFile() != null; SessionId sessionId = SessionManager.getSessionId(project); if (sessionId == null) { sessionId = new SessionId(properties.getStartFile(), project); DebuggerOptions options = new DebuggerOptions(); options.debugForFirstPageOnly = properties.isCloseSession(); options.pathMapping = properties.getPathMapping(); options.debugProxy = properties.getDebugProxy(); options.projectEncoding = properties.getEncoding(); startSession(sessionId, options, run); long started = System.currentTimeMillis(); if (!sessionId.isInitialized(true)) { ConnectionErrMessage.showMe(((int) (System.currentTimeMillis() - started) / 1000)); } } }
Example #4
Source File: NetworkSupport.java From netbeans with Apache License 2.0 | 6 votes |
/** * Download the given URL to the target file with showing its progress. * <p> * This method must be called only in a background thread. To cancel the download, interrupt the current thread. * @param url URL to be downloaded * @param target target file * @param displayName display name of the progress * @throws NetworkException if any network error occurs * @throws IOException if any error occurs * @throws InterruptedException if the download is cancelled * @see #download(java.lang.String, java.io.File) * @see #downloadWithProgress(java.lang.String, java.io.File, org.netbeans.api.progress.ProgressHandle) * @since 1.25 */ public static void downloadWithProgress(@NonNull String url, @NonNull File target, @NonNull String displayName) throws NetworkException, IOException, InterruptedException { Parameters.notNull("displayName", displayName); final Thread downloadThread = Thread.currentThread(); ProgressHandle progressHandle = ProgressHandle.createHandle(displayName, new Cancellable() { @Override public boolean cancel() { downloadThread.interrupt(); return true; } }); progressHandle.start(); try { downloadInternal(url, target, progressHandle); } finally { progressHandle.finish(); } }
Example #5
Source File: ProblemComponent.java From netbeans with Apache License 2.0 | 6 votes |
private void showDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showDetailsActionPerformed Container c = this; while (!(c instanceof ParametersPanel)) { c = c.getParent(); } final ParametersPanel parametersPanel = (ParametersPanel) c; Cancellable doCloseParent = new Cancellable() { @Override public boolean cancel() { parametersPanel.cancel.doClick(); return true; } }; ProblemDetails details = problem.getDetails(); if (details != null) { details.showDetails(new CallbackAction(ui), doCloseParent); } }
Example #6
Source File: ExecutionService.java From netbeans with Apache License 2.0 | 6 votes |
private ProgressHandle createProgressHandle(InputOutput inputOutput, String displayName, Cancellable cancellable) { if (!descriptor.showProgress() && !descriptor.showSuspended()) { return null; } ProgressHandle handle = ProgressHandleFactory.createHandle(displayName, cancellable, new ProgressAction(inputOutput)); handle.setInitialDelay(0); handle.start(); handle.switchToIndeterminate(); if (descriptor.showSuspended()) { handle.suspend(NbBundle.getMessage(ExecutionService.class, "Running")); } return handle; }
Example #7
Source File: ProgressAPICompatTest.java From netbeans with Apache License 2.0 | 6 votes |
/** * Check that if a Swing component is extracted, the progress * reports 'customPlaced' = true. * @throws Exception */ public void testHandleIsCustomPlaced() throws Exception { C c = new C(); A a = new A(); Constructor ctor = InternalHandle.class.getConstructor( String.class, Cancellable.class, Boolean.TYPE, Action.class ); InternalHandle h = (InternalHandle)ctor.newInstance("Foobar", c, true, a); ProgressHandle p = h.createProgressHandle(); Method m = InternalHandle.class.getMethod("extractComponent"); JComponent comp = (JComponent)m.invoke(h); assertTrue(h.isCustomPlaced()); }
Example #8
Source File: UpdateHandler.java From netbeans-wakatime with BSD 3-Clause "New" or "Revised" License | 6 votes |
static void refreshSilentUpdateProvider() { UpdateUnitProvider silentUpdateProvider = getSilentUpdateProvider(); if (silentUpdateProvider == null) { // have a problem => cannot continue WakaTime.info("Missing Silent Update Provider => cannot continue."); return ; } try { final String displayName = "Checking for updates to WakaTime plugin..."; silentUpdateProvider.refresh( ProgressHandleFactory.createHandle( displayName, new Cancellable () { @Override public boolean cancel () { return true; } } ), true ); } catch (IOException ex) { // caught a exception WakaTime.error("A problem caught while refreshing Update Centers, cause: " + ex.toString()); } }
Example #9
Source File: ScaleToolModel.java From opensim-gui with Apache License 2.0 | 6 votes |
ScaleToolWorker() throws Exception { updateScaleTool(); progressHandle = ProgressHandleFactory.createHandle("Executing scaling...", new Cancellable() { public boolean cancel() { result = false; finished(); return true; } }); progressHandle.start(); // Crash here processedModel = new Model(unscaledModel); processedModel.setName(scaleTool.getName()); String proposedFilename = unscaledModel.getInputFileName().replace(".osim", "_scaled.osim"); processedModel.setInputFileName(proposedFilename); processedModel.setOriginalModelPathFromModel(unscaledModel); // important to keep track of the original path so bone loading works //processedModel.setup(); setExecuting(true); }
Example #10
Source File: Actions.java From netbeans with Apache License 2.0 | 5 votes |
private ProgressHandle getProgress() { return ProgressHandleFactory.createHandle(NbBundle.getMessage(Actions.class, "LBL_SubmitAllProgress"), new Cancellable() { @Override public boolean cancel() { canceled = true; return canceled; } }); }
Example #11
Source File: ProgressUI.java From netbeans with Apache License 2.0 | 5 votes |
@Override public ProgressHandle createHandle(String displayname, Cancellable c, boolean userInit) { if (userInit) { return ProgressHandleFactory.createHandle(displayname, c, null); } else { return ProgressHandleFactory.createSystemHandle(displayname, c, null); } }
Example #12
Source File: Actions.java From netbeans with Apache License 2.0 | 5 votes |
private ProgressHandle getProgress() { return ProgressHandleFactory.createHandle(NbBundle.getMessage(Actions.class, "LBL_CancelAllProgress"), new Cancellable() { @Override public boolean cancel() { canceled = true; return canceled; } }); }
Example #13
Source File: TaskListTopComponent.java From netbeans with Apache License 2.0 | 5 votes |
private PropertyChangeListener createChangeListener() { return new PropertyChangeListener() { @Override public void propertyChange( PropertyChangeEvent e ) { synchronized( TaskListTopComponent.this ) { if( ((Boolean)e.getNewValue()).booleanValue() ) { if( null == progress ) { progress = ProgressHandleFactory.createHandle( NbBundle.getMessage( TaskListTopComponent.class, "LBL_ScanProgress" ), //NOI18N new Cancellable() { //NOI18N @Override public boolean cancel() { taskManager.abort(); return true; } }); progress.start(); progress.switchToIndeterminate(); } } else { if( null != progress ) progress.finish(); progress = null; } } } }; }
Example #14
Source File: UpdateHandler.java From netbeans-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
static Restarter doInstall(InstallSupport support, Installer installer) throws OperationException { final String displayName = "Installing WakaTime plugin..."; ProgressHandle installHandle = ProgressHandleFactory.createHandle( displayName, new Cancellable () { @Override public boolean cancel () { return true; } } ); return support.doInstall(installer, installHandle); }
Example #15
Source File: UpdateHandler.java From netbeans-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
static UpdateUnitProvider getSilentUpdateProvider() { List<UpdateUnitProvider> providers = UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(true); String oldCodename = "org_wakatime_netbeans_plugin_update_center"; for (UpdateUnitProvider p : providers) { if (p.getName().equals(oldCodename) || p.getName().equals(WakaTime.CODENAME)) { // this is our current plugin try { final String displayName = "Checking for updates to WakaTime plugin..."; p.refresh( ProgressHandleFactory.createHandle( displayName, new Cancellable () { @Override public boolean cancel () { return true; } } ), true ); } catch (IOException ex) { // caught a exception WakaTime.error("A problem caught while refreshing Update Centers, cause: " + ex.toString()); } return p; } } return null; }
Example #16
Source File: UpdateHandler.java From netbeans-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
static Validator doDownload(InstallSupport support) throws OperationException { final String displayName = "Downloading new version of WakaTime plugin..."; ProgressHandle downloadHandle = ProgressHandleFactory.createHandle( displayName, new Cancellable () { @Override public boolean cancel () { return true; } } ); return support.doDownload(downloadHandle, true); }
Example #17
Source File: UpdateHandler.java From netbeans-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
static Installer doVerify(InstallSupport support, Validator validator) throws OperationException { final String displayName = "Validating WakaTime plugin..."; ProgressHandle validateHandle = ProgressHandleFactory.createHandle( displayName, new Cancellable () { @Override public boolean cancel () { return true; } } ); Installer installer = support.doValidate(validator, validateHandle); return installer; }
Example #18
Source File: ProgressTransferListener.java From netbeans with Apache License 2.0 | 5 votes |
/** * Produces a token which may be passed to {@link AggregateProgressFactory#createHandle} * in order to permit progress to be canceled. * If an event is received after a cancel request has been made, {@link ThreadDeath} will * be thrown (which you probably also want to catch and handle gracefully). * Due to AETHER-95, {@link IllegalStateException} with a cause of {@link ThreadDeath} might also be thrown. * Must be called by the same thread as will call {@link #setAggregateHandle} and runs the process. * @return a cancellation token */ public static Cancellable cancellable() { final AtomicBoolean b = new AtomicBoolean(); activeListener().cancel = b; return new Cancellable() { public @Override boolean cancel() { return b.compareAndSet(false, true); } }; }
Example #19
Source File: IKToolModel.java From opensim-gui with Apache License 2.0 | 5 votes |
IKToolWorker() throws Exception { // Give the thread a nudge so that we're not much slower than command line' setPriority(Thread.MAX_PRIORITY); updateIKTool(); // Operate on a copy of the model -- this way if users play with parameters in the GUI it won't affect the model we're actually computing on ikTool.setModel(getOriginalModel()); // Make no motion be currently selected (so model doesn't have extraneous ground forces/experimental markers from // another motion show up on it) MotionsDB.getInstance().clearCurrent(); // Initialize progress bar, given we know the number of frames to process double startTime = ikTool.getStartTime(); double endTime = ikTool.getEndTime(); progressHandle = ProgressHandleFactory.createHandle("Executing inverse kinematics...", new Cancellable() { public boolean cancel() { interrupt(true); SimulationDB.getInstance().fireToolFinish(); return true; } }); // Animation callback will update the display during IK solve animationCallback = new JavaMotionDisplayerCallback(getOriginalModel(),null/* ikTool.getOutputStorage()*/, progressHandle, true); getOriginalModel().addAnalysis(animationCallback); animationCallback.setStepInterval(1); animationCallback.startProgressUsingTime(startTime, endTime); // Do this manouver (there's gotta be a nicer way) to create the object so that C++ owns it and not Java (since // removeIntegCallback in finished() will cause the C++-side callback to be deleted, and if Java owned this object // it would then later try to delete it yet again) interruptingCallback = new InterruptCallback(getOriginalModel()); getOriginalModel().addAnalysis(interruptingCallback); setExecuting(true); SimulationDB.getInstance().fireToolStart(); }
Example #20
Source File: Actions.java From netbeans with Apache License 2.0 | 5 votes |
private ProgressHandle getProgress() { return ProgressHandleFactory.createHandle(NbBundle.getMessage(Actions.class, setAsSeen ? "LBL_MarkSeenAllProgress" : "LBL_MarkUnseenAllProgress"), new Cancellable() { @Override public boolean cancel() { canceled = true; return canceled; } }); }
Example #21
Source File: RegisterDerby.java From netbeans with Apache License 2.0 | 5 votes |
private boolean waitStart(final ExecSupport execSupport, int waitTime) { boolean started = false; final boolean[] forceExit = new boolean[1]; String waitMessage = NbBundle.getMessage(RegisterDerby.class, "MSG_StartingDerby"); ProgressHandle progress = ProgressHandleFactory.createHandle(waitMessage, new Cancellable() { @Override public boolean cancel() { forceExit[0] = true; return execSupport.interruptWaiting(); } }); progress.start(); try { while (!started) { started = execSupport.waitForMessage(waitTime * 1000); if (!started) { if (waitTime > 0 && (!forceExit[0])) { String title = NbBundle.getMessage(RegisterDerby.class, "LBL_DerbyDatabase"); String message = NbBundle.getMessage(RegisterDerby.class, "MSG_WaitStart", waitTime); NotifyDescriptor waitConfirmation = new NotifyDescriptor.Confirmation(message, title, NotifyDescriptor.YES_NO_OPTION); if (DialogDisplayer.getDefault().notify(waitConfirmation) != NotifyDescriptor.YES_OPTION) { break; } } else { break; } } } if (!started) { execSupport.terminate(); LOGGER.log(Level.WARNING, "Derby server failed to start"); // NOI18N } } finally { progress.finish(); } return started; }
Example #22
Source File: RecentSearches.java From netbeans with Apache License 2.0 | 5 votes |
/** * Find action by display name and run it. */ @NbBundle.Messages({ "LBL_SearchingRecentResult=Searching for a Quick Search Item", "MSG_RecentResultNotFound=Recent Quick Search Item was not found."}) private void findAndRunAction() { final AtomicBoolean cancelled = new AtomicBoolean(false); ProgressHandle handle = ProgressHandleFactory.createHandle( Bundle.LBL_SearchingRecentResult(), new Cancellable() { @Override public boolean cancel() { cancelled.set(true); return true; } }); handle.start(); ResultsModel model = ResultsModel.getInstance(); Task evaluate = CommandEvaluator.evaluate( stripHTMLandPackageNames(name), model); RP.post(evaluate); int tries = 0; boolean found = false; while (tries++ < 30 && !cancelled.get()) { if (checkActionWasFound(model, true)) { found = true; break; } else if (evaluate.isFinished()) { found = checkActionWasFound(model, false); break; } } handle.finish(); if (!found && !cancelled.get()) { NotifyDescriptor nd = new NotifyDescriptor.Message( Bundle.MSG_RecentResultNotFound(), NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notifyLater(nd); } }
Example #23
Source File: ActionsManager.java From netbeans with Apache License 2.0 | 5 votes |
private Cancellable getCancellable(Object action) { if (action instanceof Cancellable) { return (Cancellable) action; } try { // Hack because of ActionsProvider$ContextAware: Field delegateField = action.getClass().getDeclaredField("delegate"); // NOI18N delegateField.setAccessible(true); action = delegateField.get(action); if (action instanceof Cancellable) { return (Cancellable) action; } } catch (Exception ex) {} return null; }
Example #24
Source File: ActionsManager.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean cancel() { for (Iterator it = postedActions.iterator(); it.hasNext(); ) { Object action = it.next(); Cancellable c = getCancellable(action); if (c != null) { if (!c.cancel()) { return false; } } else { return false; } } return true; }
Example #25
Source File: Analyzer.java From netbeans with Apache License 2.0 | 5 votes |
public static void process(Lookup context, HintsSettings hintsSettings) { final AtomicBoolean abCancel = new AtomicBoolean(); class Cancel implements Cancellable { public boolean cancel() { abCancel.set(true); return true; } } ProgressHandle h = ProgressHandleFactory.createHandle(NbBundle.getMessage(Analyzer.class, "LBL_AnalyzingJavadoc"), new Cancel()); // NOI18N RP.post(new Analyzer(context, abCancel, h, hintsSettings)); }
Example #26
Source File: QueryController.java From netbeans with Apache License 2.0 | 5 votes |
private void onGotoIssue() { String idText = panel.idTextField.getText().trim(); if(idText == null || idText.trim().equals("") ) { // NOI18N return; } final String id = idText.replaceAll("\\s", ""); // NOI18N final Task[] t = new Task[1]; Cancellable c = new Cancellable() { @Override public boolean cancel() { if(t[0] != null) { return t[0].cancel(); } return true; } }; final ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(QueryController.class, "MSG_Opening", new Object[] {id}), c); // NOI18N t[0] = Bugzilla.getInstance().getRequestProcessor().create(new Runnable() { @Override public void run() { handle.start(); try { openIssue(repository.getIssue(id)); } finally { handle.finish(); } } }); t[0].schedule(0); }
Example #27
Source File: ConfigActionLocal.java From netbeans with Apache License 2.0 | 5 votes |
private void startDebugger(final DebugStarter dbgStarter, final Runnable initDebuggingCode, Cancellable cancellable, final FileObject debuggedFile) { Callable<Cancellable> initDebuggingCallable = Executors.callable(initDebuggingCode, cancellable); // XXX run config DebugStarter.Properties props = new DebugStarter.Properties.Builder() .setStartFile(debuggedFile) .setCloseSession(false) .setPathMapping(ProjectPropertiesSupport.getDebugPathMapping(project)) .setDebugProxy(ProjectPropertiesSupport.getDebugProxy(project)) .setEncoding(ProjectPropertiesSupport.getEncoding(project)) .build(); dbgStarter.start(project, initDebuggingCallable, props); }
Example #28
Source File: J2SEPlatformCustomizer.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({ "TXT_JavadocSearch=Searching Javadoc in {0}" }) private static Collection<? extends URL> findRoot(final File file, final int type) throws MalformedURLException { if (type != CLASSPATH) { final FileObject fo = URLMapper.findFileObject(FileUtil.urlForArchiveOrDir(file)); if (fo != null) { final Collection<FileObject> result = Collections.synchronizedCollection(new ArrayList<FileObject>()); if (type == SOURCES) { final FileObject root = JavadocAndSourceRootDetection.findSourceRoot(fo); if (root != null) { result.add(root); } } else if (type == JAVADOC) { final AtomicBoolean cancel = new AtomicBoolean(); class Task implements ProgressRunnable<Void>, Cancellable { @Override public Void run(ProgressHandle handle) { result.addAll(JavadocAndSourceRootDetection.findJavadocRoots(fo, cancel)); return null; } @Override public boolean cancel() { cancel.set(true); return true; } } final ProgressRunnable<Void> task = new Task(); ProgressUtils.showProgressDialogAndRun(task, Bundle.TXT_JavadocSearch(file.getAbsolutePath()), false); } if (!result.isEmpty()) { return result.stream() .map(FileObject::toURL) .collect(Collectors.toList()); } } } return Collections.singleton(Utilities.toURI(file).toURL()); }
Example #29
Source File: BackendLauncher.java From netbeans with Apache License 2.0 | 5 votes |
synchronized void stop() { if (futureCancellable != null) { try { Cancellable cancellable = futureCancellable.get(); if (cancellable != null) { cancellable.cancel(); } } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } } }
Example #30
Source File: UIInternalHandle.java From netbeans with Apache License 2.0 | 5 votes |
public UIInternalHandle(String displayName, Cancellable cancel, boolean userInitiated, Action view) { super(displayName, cancel, userInitiated); viewAction = view; }