public int cancelAllRequests() { synchronized (LOCK) { int count = cancelAllRequests(myRequests); cancelAllRequests(myPendingRequests); return count; } }
public void propertyChange(final PropertyChangeEvent e) { if (myAlarm.getActiveRequestCount() == 0) { myInitialFocusedWindow = (Window) e.getOldValue(); final MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath(); if (selectedPath.length == 0) { // there is no visible popup return; } Component firstComponent = null; for (final MenuElement menuElement : selectedPath) { final Component component = menuElement.getComponent(); if (component instanceof JMenuBar) { firstComponent = component; break; } else if (component instanceof JPopupMenu) { firstComponent = ((JPopupMenu) component).getInvoker(); break; } } if (firstComponent == null) { return; } final Window window = SwingUtilities.getWindowAncestor(firstComponent); if (window != myInitialFocusedWindow) { // focused window doesn't have popup return; } } myLastFocusedWindow = (Window) e.getNewValue(); myAlarm.cancelAllRequests(); myAlarm.addRequest(myClearSelectedPathRunnable, 150); }
private void scrollToSelectedElement() { if (myAutoscrollFeedback) { myAutoscrollFeedback = false; return; } StructureViewFactoryImpl structureViewFactory = (StructureViewFactoryImpl) StructureViewFactoryEx.getInstance(myProject); if (!structureViewFactory.getState().AUTOSCROLL_FROM_SOURCE) { return; } myAutoscrollAlarm.cancelAllRequests(); myAutoscrollAlarm.addRequest( new Runnable() { public void run() { if (myAbstractTreeBuilder == null) { return; } try { selectViewableElement(); } catch (IndexNotReadyException ignore) { } } }, 1000); }
private void addUpdatingRequest() { if (myRefreshingAlarm.isDisposed()) { return; } myRefreshingAlarm.cancelAllRequests(); myRefreshingAlarm.addRequest(myUpdateRequest, REFRESH_INTERVAL_MS); }
@Override public void initialize() { try { base.initialize(); } catch (Exception ignore) { } myDisposable = Disposer.newDisposable(); Application application = ApplicationManager.getApplication(); if (application != null) { Disposer.register(application, myDisposable); } myMnemonicAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, myDisposable); IdeEventQueue.getInstance() .addDispatcher( e -> { if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ALT) { myAltPressed = e.getID() == KeyEvent.KEY_PRESSED; myMnemonicAlarm.cancelAllRequests(); final Component focusOwner = IdeFocusManager.findInstance().getFocusOwner(); if (focusOwner != null) { myMnemonicAlarm.addRequest(() -> repaintMnemonics(focusOwner, myAltPressed), 10); } } return false; }, myDisposable); }
private synchronized void addCommand(LogCommand command) { if (!myAlarm.isDisposed()) { myLog.add(command); myAlarm.cancelAllRequests(); myAlarm.addRequest(myFlushLogRunnable, 100L); } }
public void fireBreakpointChanged(Breakpoint breakpoint) { breakpoint.reload(); breakpoint.updateUI(); RequestManagerImpl.updateRequests(breakpoint); if (myAllowMulticasting) { // can be invoked from non-AWT thread myAlarm.cancelAllRequests(); final Runnable runnable = new Runnable() { @Override public void run() { myAlarm.addRequest( new Runnable() { @Override public void run() { myDispatcher.getMulticaster().breakpointsChanged(); } }, 100); } }; if (ApplicationManager.getApplication().isDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable); } } }
public synchronized void stop() { if (myOriginal.isRunning()) { myOriginal.stop(); } else { myStartupAlarm.cancelAllRequests(); } // needed only for correct assertion of !progress.isRunning() in // ApplicationImpl.runProcessWithProgressSynchroniously final Semaphore semaphore = new Semaphore(); semaphore.down(); SwingUtilities.invokeLater( new Runnable() { public void run() { semaphore.waitFor(); if (myDialog != null) { // System.out.println("myDialog.destroyProcess()"); myDialog.close(DialogWrapper.OK_EXIT_CODE); myDialog = null; } } }); super.stop(); // should be last to not leaveModal before closing the dialog semaphore.up(); }
public void dispose() { myDisposed = true; cancelAllRequests(); if (myThreadToUse == ThreadToUse.OWN_THREAD) { myExecutorService.getQueue().clear(); myExecutorService.shutdown(); } }
private void hideHint() { myUpdateAlarm.cancelAllRequests(); if (myPopup.isVisible()) { myPopup.setVisible(false); repaintKeyItem(); } myKey = null; }
private void scheduleUpdate(int delay) { myAlarm.cancelAllRequests(); UpdateRequest updateRequest = new UpdateRequest(); if (isTestingMode) { ApplicationManager.getApplication().invokeLater(updateRequest); } else { myAlarm.addRequest(updateRequest, delay); } }
synchronized void stopProcess(boolean toRestartAlarm) { if (!allowToInterrupt) throw new RuntimeException("Cannot interrupt daemon"); cancelUpdateProgress(toRestartAlarm, "by Stop process"); myAlarm.cancelAllRequests(); boolean restart = toRestartAlarm && !myDisposed && myInitialized; if (restart) { myAlarm.addRequest(myUpdateRunnable, mySettings.AUTOREPARSE_DELAY); } }
private void scheduleUpdate() { myAlarm.cancelAllRequests(); myAlarm.addRequest( new Runnable() { @Override public void run() { fireStateChanged(); } }, ArrangementConstants.TEXT_UPDATE_DELAY_MILLIS); }
@Override public void dispose() { myDisposed = true; cancelAllRequests(); if (myThreadToUse == ThreadToUse.POOLED_THREAD) { myExecutorService.shutdown(); } else if (myThreadToUse == ThreadToUse.OWN_THREAD) { myExecutorService.shutdown(); ((ThreadPoolExecutor) myExecutorService).getQueue().clear(); } }
private void updatePanel() { myAlarm.cancelAllRequests(); if (!areValid()) return; repaint(); setToolTipText(myErrorStripeRenderer.getTooltipMessage()); if (!isHighlightingFinished()) { addUpdateRequest(); } }
@Override public void dispose() { synchronized (lock) { isDisposed = true; ToolTipManager.sharedInstance().unregisterComponent(myTree); myModelTracker.removeListener(this); myUpdateAlarm.cancelAllRequests(); if (myUsagePreviewPanel != null) { UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS = ((Splitter) myUsagePreviewPanel.getParent()).getProportion(); myUsagePreviewPanel = null; } } }
private void updateFileIconLater(VirtualFile file) { myFilesToUpdateIconsFor.add(file); myIconUpdaterAlarm.cancelAllRequests(); myIconUpdaterAlarm.addRequest( () -> { if (myManager.getProject().isDisposed()) return; for (VirtualFile file1 : myFilesToUpdateIconsFor) { updateFileIconImmediately(file1); } myFilesToUpdateIconsFor.clear(); }, 200, ModalityState.stateForComponent(this)); }
private void updateLater() { myUpdateAlarm.cancelAllRequests(); myUpdateAlarm.addRequest( new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; PsiDocumentManager.getInstance(myProject).commitAllDocuments(); updateImmediately(); } }, 300); }
public boolean startIfNotStarted(final int refreshInterval) { final boolean refreshIntervalChanged = (refreshInterval > 0) && refreshInterval != myRefreshInterval; if (refreshIntervalChanged) { mySimpleAlarm.cancelAllRequests(); } if (refreshInterval > 0) { myRefreshInterval = refreshInterval; } final boolean wasSet = myActive.compareAndSet(false, true); if (wasSet || refreshIntervalChanged) { mySimpleAlarm.addRequest(myRunnable, myRefreshInterval); } return wasSet; }
private void setStructureViewSelection(@NotNull final String propertyName) { if (myStructureViewComponent.isDisposed()) { return; } JTree tree = myStructureViewComponent.getTree(); if (tree == null) { return; } Object root = tree.getModel().getRoot(); if (AbstractTreeUi.isLoadingChildrenFor(root)) { mySelectionChangeAlarm.cancelAllRequests(); mySelectionChangeAlarm.addRequest( new Runnable() { @Override public void run() { mySelectionChangeAlarm.cancelAllRequests(); setStructureViewSelection(propertyName); } }, 500); return; } Stack<TreeElement> toCheck = ContainerUtilRt.newStack(); toCheck.push(myStructureViewComponent.getTreeModel().getRoot()); while (!toCheck.isEmpty()) { TreeElement element = toCheck.pop(); PsiElement value = element instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement) element).getValue() : null; if (value instanceof IProperty && propertyName.equals(((IProperty) value).getUnescapedKey())) { myStructureViewComponent.select(value, true); selectionChanged(); return; } else { for (TreeElement treeElement : element.getChildren()) { toCheck.push(treeElement); } } } }
private void rebuild( final boolean updateText, @Nullable final Runnable runnable, final boolean requestFocus, final int delayMillis) { myUpdateAlarm.cancelAllRequests(); final Runnable request = new Runnable() { public void run() { ApplicationManager.getApplication() .executeOnPooledThread( new Runnable() { public void run() { if (updateText) { final String text = myCurrentScope != null ? myCurrentScope.getText() : null; SwingUtilities.invokeLater( new Runnable() { public void run() { try { myIsInUpdate = true; myPatternField.setText(text); } finally { myIsInUpdate = false; } } }); } try { if (!myProject.isDisposed()) { updateTreeModel(requestFocus); } } catch (ProcessCanceledException e) { return; } if (runnable != null) { runnable.run(); } } }); } }; myUpdateAlarm.addRequest(request, delayMillis); }
@Override public void run() { LOG.debug("-- (event, expected=" + myAccept + ")"); if (!myAccept) return; myAlarm.cancelAllRequests(); myAlarm.addRequest( new Runnable() { @Override public void run() { myAccept = false; LOG.debug("** waiting finished"); synchronized (myWaiter) { myWaiter.notifyAll(); } } }, INTER_RESPONSE_DELAY); }
public void stateChanged() { livePreviewAlarm.cancelAllRequests(); final Editor editor1 = getEditor(); if (editor1 == null) return; cleanUp(); injectActivityWatcher(); pattern = patternController.buildPattern(); livePreviewAlarm.addRequest( new Runnable() { @Override public void run() { if (patternController != null) { update(editor1); } } }, USER_ACTIVITY_PAUSE); }
private void runQuery() { if (getRootPane() == null) return; Set<InlineProgressIndicator> indicators = getCurrentInlineIndicators(); if (indicators.isEmpty()) return; for (InlineProgressIndicator each : indicators) { each.updateProgress(); } myQueryAlarm.cancelAllRequests(); myQueryAlarm.addRequest( new Runnable() { @Override public void run() { runQuery(); } }, 2000); }
private void onTextChange() { if (!myIsInUpdate) { myUpdateAlarm.cancelAllRequests(); myTextChanged = true; final String text = myPatternField.getText(); myCurrentScope = new InvalidPackageSet(text); try { if (!StringUtil.isEmpty(text)) { myCurrentScope = PackageSetFactory.getInstance().compile(text); } myErrorMessage = null; } catch (Exception e) { myErrorMessage = e.getMessage(); showErrorMessage(); } rebuild(false); } else if (!invalidScopeInside(myCurrentScope)) { myErrorMessage = null; } }
protected void handleSelectionChange(final KeyType selected, final boolean processIfUnfocused) { if (!ApplicationManager.getApplication().isDispatchThread()) { return; } myUpdateAlarm.cancelAllRequests(); if (selected == null) { hideHint(); return; } if (!selected.equals(myKey)) { hideHint(); } myUpdateAlarm.addRequest( new Runnable() { @Override public void run() { doHandleSelectionChange(selected, processIfUnfocused); } }, 10); }
private void scheduleTimeoutCheck() { final Ref<Long> nextTime = Ref.create(Long.MAX_VALUE); synchronized (myLock) { if (myTimeoutHandlers.isEmpty()) return; myTimeoutHandlers.forEachValue( new TObjectProcedure<TimeoutHandler>() { public boolean execute(TimeoutHandler handler) { nextTime.set(Math.min(nextTime.get(), handler.myLastTime)); return true; } }); } final int delay = (int) (nextTime.get() - System.currentTimeMillis() + 100); LOG.debug("schedule timeout check in " + delay + "ms"); if (delay > 10) { myTimeoutAlarm.cancelAllRequests(); myTimeoutAlarm.addRequest(() -> checkTimeout(), delay); } else { checkTimeout(); } }
private void processFileEditorChange(@Nullable final Editor newEditor) { toolWindowUpdateAlarm.cancelAllRequests(); toolWindowUpdateAlarm.addRequest( new Runnable() { @Override public void run() { if (project.isDisposed() || !project.isOpen()) { return; } if (toolWindow == null) { if (newEditor == null) { return; } initToolWindow(); // idea inspection bug //noinspection ConstantConditions assert toolWindow != null; } VirtualFile psiFile = newEditor == null ? null : FileDocumentManager.getInstance().getFile(newEditor.getDocument()); if (psiFile == null) { return; } final boolean doRender = !Comparing.equal(toolWindowForm.getFile(), psiFile); if (doRender) { toolWindowForm.setFile(psiFile); } if (toolWindowVisible) { render(true, true); } } }, 300); }
public void updateInBackground( FindModel findModel, final boolean allowedToChangedEditorSelection) { final int stamp = mySearchResults.getStamp(); myLivePreviewAlarm.cancelAllRequests(); if (findModel == null) return; final boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode(); final FindModel copy = new FindModel(); copy.copyFrom(findModel); Runnable request = new Runnable() { @Override public void run() { mySearchResults.updateThreadSafe(copy, allowedToChangedEditorSelection, null, stamp); } }; if (unitTestMode) { request.run(); } else { myLivePreviewAlarm.addRequest(request, myUserActivityDelay); } }
public IdeTooltip show(final IdeTooltip tooltip, boolean now, final boolean animationEnabled) { myAlarm.cancelAllRequests(); hideCurrent(null, null, null); myQueuedComponent = tooltip.getComponent(); myQueuedTooltip = tooltip; myShowRequest = new Runnable() { @Override public void run() { if (myShowRequest == null) { return; } if (myQueuedComponent != tooltip.getComponent() || !tooltip.getComponent().isShowing()) { hideCurrent(null, null, null, animationEnabled); return; } if (tooltip.beforeShow()) { show(tooltip, null, animationEnabled); } else { hideCurrent(null, null, null, animationEnabled); } } }; if (now) { myShowRequest.run(); } else { myAlarm.addRequest( myShowRequest, myShowDelay ? tooltip.getShowDelay() : tooltip.getInitialReshowDelay()); } return tooltip; }