public PhpNewClassDialog(@NotNull Project project, @Nullable PsiDirectory directory) { super(project); this.myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); Disposer.register(this.getDisposable(), new Disposable() { public void dispose() { PhpNewClassDialog.this.myAlarm.cancelAllRequests(); PhpNewClassDialog.this.myDisposed = true; } }); this.myProperties = new Properties(); this.myProject = project; this.myDirectory = directory; init(); }
public ContentChooser(Project project, String title, boolean useIdeaEditor, boolean allowMultipleSelections) { super(project, true); myProject = project; myUseIdeaEditor = useIdeaEditor; myAllowMultipleSelections = allowMultipleSelections; myUpdateAlarm = new Alarm(getDisposable()); mySplitter = new JBSplitter(true, 0.3f); mySplitter.setSplitterProportionKey(getDimensionServiceKey() + ".splitter"); myList = new JBList(new CollectionListModel<Item>()); myList.setExpandableItemsEnabled(false); setOKButtonText(CommonBundle.getOkButtonText()); setTitle(title); init(); }
public void waitProcess(final ProcessHandler processHandler) { Alarm alarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, getTestRootDisposable()); final boolean[] isRunning = {true}; alarm.addRequest(new Runnable() { @Override public void run() { boolean b; synchronized (isRunning) { b = isRunning[0]; } if (b) { processHandler.destroyProcess(); LOG.error("process was running over " + myTimeout / 1000 + " seconds. Interrupted. "); } } }, myTimeout); processHandler.waitFor(); synchronized (isRunning) { isRunning[0] = false; } alarm.dispose(); }
public void waitFor(Runnable r) { Alarm alarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, getTestRootDisposable()); final Thread thread = Thread.currentThread(); final boolean[] isRunning = {true}; alarm.addRequest(new Runnable() { @Override public void run() { boolean b; synchronized (isRunning) { b = isRunning[0]; } if (b) { thread.interrupt(); LOG.error("test was running over " + myTimeout / 1000 + " seconds. Interrupted. "); } } }, myTimeout); r.run(); synchronized (isRunning) { isRunning[0] = false; } Thread.interrupted(); }
@Override public void applicationActivated(final IdeFrame ideFrame) { final Runnable processClipboard = new Runnable() { @Override public void run() { final String clipboard = AnalyzeStacktraceUtil.getTextInClipboard(); if (clipboard != null && clipboard.length() < MAX_STACKTRACE_SIZE && !clipboard.equals(stacktrace)) { stacktrace = clipboard; final Project project = ideFrame.getProject(); if (project != null && isStacktrace(stacktrace)) { final UnscrambleDialog dialog = new UnscrambleDialog(project); dialog.createNormalizeTextAction().actionPerformed(null); dialog.doOKAction(); } } } }; if (Patches.SLOW_GETTING_CLIPBOARD_CONTENTS) { //IDEA's clipboard is synchronized with the system clipboard on frame activation so we need to postpone clipboard processing new Alarm().addRequest(processClipboard, 300); } else { processClipboard.run(); } }
private static void pollDeployments(final ServerConnection connection) { connection.computeDeployments(new Runnable() { @Override public void run() { new Alarm().addRequest(new Runnable() { @Override public void run() { if (connection == ServerConnectionManager.getInstance().getConnection(connection.getServer())) { pollDeployments(connection); } } }, POLL_DEPLOYMENTS_DELAY, ModalityState.any()); } }); }
public AbstractTreeUpdater(@NotNull AbstractTreeBuilder treeBuilder) { myTreeBuilder = treeBuilder; final JTree tree = myTreeBuilder.getTree(); final JComponent component = tree instanceof TreeTableTree ? ((TreeTableTree)tree).getTreeTable() : tree; myUpdateQueue = new MergingUpdateQueue("UpdateQueue", 300, component.isShowing(), component) { @Override protected Alarm createAlarm(@NotNull Alarm.ThreadToUse thread, Disposable parent) { return new Alarm(thread, parent) { @Override protected boolean isEdt() { return AbstractTreeUpdater.this.isEdt(); } }; } }; myUpdateQueue.setRestartTimerOnAdd(false); final UiNotifyConnector uiNotifyConnector = new UiNotifyConnector(component, myUpdateQueue); Disposer.register(this, myUpdateQueue); Disposer.register(this, uiNotifyConnector); }
@Override public void addNotify() { super.addNotify(); final String key = "toolwindow.stripes.buttons.info.shown"; if (UISettings.getInstance().HIDE_TOOL_STRIPES && !PropertiesComponent.getInstance().isTrueValue(key)) { PropertiesComponent.getInstance().setValue(key, String.valueOf(true)); final Alarm alarm = new Alarm(); alarm.addRequest(new Runnable() { @Override public void run() { GotItMessage.createMessage(UIBundle.message("tool.window.quick.access.title"), UIBundle.message( "tool.window.quick.access.message")) .setDisposable(ToolWindowsWidget.this) .show(new RelativePoint(ToolWindowsWidget.this, new Point(10, 0)), Balloon.Position.above); Disposer.dispose(alarm); } }, 20000); } }
void updateStatus(Configurable configurable) { myFilter.updateSpotlight(configurable == null); if (myBanner != null) { myBanner.setProject(myTreeView.findConfigurableProject(configurable)); myBanner.setText(myTreeView.getPathNames(configurable)); } if (myEditor != null) { ConfigurationException exception = myFilter.myContext.getErrors().get(configurable); myEditor.getApplyAction().setEnabled(!myFilter.myContext.getModified().isEmpty()); myEditor.getResetAction().setEnabled(myFilter.myContext.isModified(configurable) || exception != null); myEditor.setError(exception); myEditor.revalidate(); } if (configurable != null) { new Alarm().addRequest(new Runnable() { @Override public void run() { if (!myDisposed && mySpotlightPainter != null) { mySpotlightPainter.updateNow(); } } }, 300); } }
public ControlledCycle(final Project project, final Getter<Boolean> callback, @NotNull final String name, final int refreshInterval) { myRefreshInterval = (refreshInterval <= 0) ? ourRefreshInterval : refreshInterval; myActive = new AtomicBoolean(false); myRunnable = new Runnable() { boolean shouldBeContinued = true; public void run() { if (! myActive.get() || project.isDisposed()) return; try { shouldBeContinued = callback.get(); } catch (ProcessCanceledException e) { return; } catch (RuntimeException e) { LOG.info(e); } if (! shouldBeContinued) { myActive.set(false); } else { mySimpleAlarm.addRequest(myRunnable, myRefreshInterval); } } }; mySimpleAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project); }
public VcsAnnotationLocalChangesListenerImpl(Project project, final ProjectLevelVcsManager vcsManager) { myLock = new Object(); myUpdateStuff = createUpdateStuff(); myUpdater = new ZipperUpdater(ApplicationManager.getApplication().isUnitTestMode() ? 10 : 300, Alarm.ThreadToUse.POOLED_THREAD, project); myConnection = project.getMessageBus().connect(); myLocalFileSystem = LocalFileSystem.getInstance(); VcsAnnotationRefresher handler = createHandler(); myDirtyPaths = new HashSet<String>(); myDirtyChanges = new HashMap<String, VcsRevisionNumber>(); myDirtyFiles = new HashSet<VirtualFile>(); myFileAnnotationMap = MultiMap.createSet(); myVcsManager = vcsManager; myVcsKeySet = new HashSet<VcsKey>(); myConnection.subscribe(VcsAnnotationRefresher.LOCAL_CHANGES_CHANGED, handler); }
private void addItemToLookup(CompletionResult item) { if (!myLookup.addItem(item.getLookupElement(), item.getPrefixMatcher())) { return; } myCount++; if (myCount == 1) { new Alarm(Alarm.ThreadToUse.SHARED_THREAD, this).addRequest(new Runnable() { @Override public void run() { myFreezeSemaphore.up(); } }, 300); } myQueue.queue(myUpdate); }
private void fixMouseCheaters() { myLookup.getComponent().addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { final ActionCallback done = IdeFocusManager.getInstance(myProject).requestFocus(myLookup.getEditor().getContentComponent(), true); IdeFocusManager.getInstance(myProject).typeAheadUntil(done); new Alarm(myLookup).addRequest(new Runnable() { @Override public void run() { if (!done.isDone()) { done.setDone(); } } }, 300, myModalityState); } }); }
void setCalculating(final boolean calculating) { Runnable setVisible = new Runnable() { @Override public void run() { myIconPanel.setVisible(myLookup.isCalculating()); } }; if (myLookup.isCalculating()) { new Alarm(myLookup).addRequest(setVisible, 100, myModalityState); } else { setVisible.run(); } if (calculating) { myProcessIcon.resume(); } else { myProcessIcon.suspend(); } }
public ProjectListBuilder(final Project project, final CommanderPanel panel, final AbstractTreeStructure treeStructure, final Comparator comparator, final boolean showRoot) { super(project, panel.getList(), panel.getModel(), treeStructure, comparator, showRoot); myList.setCellRenderer(new ColoredCommanderRenderer(panel)); myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, myProject); myPsiTreeChangeListener = new MyPsiTreeChangeListener(); PsiManager.getInstance(myProject).addPsiTreeChangeListener(myPsiTreeChangeListener); myFileStatusListener = new MyFileStatusListener(); FileStatusManager.getInstance(myProject).addFileStatusListener(myFileStatusListener); myCopyPasteListener = new MyCopyPasteListener(); CopyPasteManager.getInstance().addContentChangedListener(myCopyPasteListener); buildRoot(); }
public void saveToFile() { final String oldText = myDocument.getText(); final String newText = IpnbParser.newDocumentText(this); if (newText == null) return; if (oldText.equals(newText)) { new Alarm().addRequest(new MySynchronizeRequest(), 10, ModalityState.stateForComponent(this)); return; } try { final ReplaceInfo replaceInfo = findFragmentToChange(oldText, newText); if (replaceInfo.getStartOffset() != -1) { myDocument.replaceString(replaceInfo.getStartOffset(), replaceInfo.getEndOffset(), replaceInfo.getReplacement()); } } catch (Exception e) { myDocument.replaceString(0, oldText.length(), newText); } }
public QuickFixManager(@Nullable final GuiEditor editor, @NotNull final T component, @NotNull final JViewport viewPort) { myEditor = editor; myComponent = component; myAlarm = new Alarm(); myShowHintRequest = new MyShowHintRequest(this); (new VisibilityWatcherImpl(this, component)).install(myComponent); myComponent.addFocusListener(new FocusListenerImpl(this)); // Alt+Enter new ShowHintAction(this, component); viewPort.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { updateIntentionHintPosition(viewPort); } }); }
public RootsToWorkingCopies(final SvnVcs vcs) { myProject = vcs.getProject(); myQueue = new BackgroundTaskQueue(myProject, "SVN VCS roots authorization checker"); myLock = new Object(); myRootMapping = new HashMap<VirtualFile, WorkingCopy>(); myUnversioned = new HashSet<VirtualFile>(); myVcs = vcs; myRechecker = new Runnable() { public void run() { final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(myProject).getRootsUnderVcs(myVcs); synchronized (myLock) { clear(); for (VirtualFile root : roots) { addRoot(root); } } } }; myZipperUpdater = new ZipperUpdater(200, Alarm.ThreadToUse.POOLED_THREAD, myProject); }
protected final void initValidation() { myValidationAlarm.cancelAllRequests(); final Runnable validateRequest = new Runnable() { @Override public void run() { if (myDisposed) return; final ValidationInfo result = doValidate(); if (result == null) { clearProblems(); } else { reportProblem(result); } if (!myDisposed) { initValidation(); } } }; if (getValidationThreadToUse() == Alarm.ThreadToUse.SWING_THREAD) { myValidationAlarm.addRequest(validateRequest, myValidationDelay, ModalityState.current()); } else { myValidationAlarm.addRequest(validateRequest, myValidationDelay); } }
public MergingUpdateQueue(@NonNls String name, int mergingTimeSpan, boolean isActive, @Nullable JComponent modalityStateComponent, @Nullable Disposable parent, @Nullable JComponent activationComponent, @NotNull Alarm.ThreadToUse thread) { myMergingTimeSpan = mergingTimeSpan; myModalityStateComponent = modalityStateComponent; myName = name; myPassThrough = ApplicationManager.getApplication().isUnitTestMode(); myExecuteInDispatchThread = thread == Alarm.ThreadToUse.SWING_THREAD; myWaiterForMerge = createAlarm(thread, myExecuteInDispatchThread ? null : this); if (isActive) { showNotify(); } if (parent != null) { Disposer.register(parent, this); } if (activationComponent != null) { setActivationComponent(activationComponent); } }
public EncodingPanel(@NotNull final Project project) { super(project); update = new Alarm(this); myComponent = new TextPanel() { @Override protected void paintComponent(@NotNull final Graphics g) { super.paintComponent(g); if (actionEnabled && getText() != null) { final Rectangle r = getBounds(); final Insets insets = getInsets(); AllIcons.Ide.Statusbar_arrows.paintIcon(this, g, r.width - insets.right - AllIcons.Ide.Statusbar_arrows.getIconWidth() - 2, r.height / 2 - AllIcons.Ide.Statusbar_arrows.getIconHeight() / 2); } } }; new ClickListener() { @Override public boolean onClick(MouseEvent e, int clickCount) { update(); showPopup(e); return true; } }.installOn(myComponent); myComponent.setBorder(WidgetBorder.INSTANCE); }
public static void showHintPopup(final ConfigurableSearchTextField searchField, final JBPopup[] activePopup, final Alarm showHintAlarm, final Consumer<String> selectConfigurable, final Project project) { for (JBPopup aPopup : activePopup) { if (aPopup != null) { aPopup.cancel(); } } final JBPopup popup = createPopup(searchField, activePopup, showHintAlarm, selectConfigurable, project, 0); //no selection if (popup != null) { popup.showUnderneathOf(searchField); searchField.requestFocusInWindow(); } activePopup[0] = popup; activePopup[1] = null; }
public AutoTestManager(Project project) { myDocumentWatcher = new DelayedDocumentWatcher(project, new Alarm(Alarm.ThreadToUse.SWING_THREAD, project), AUTOTEST_DELAY, new Consumer<VirtualFile[]>() { @Override public void consume(VirtualFile[] files) { for (Content content : myEnabledDescriptors) { runAutoTest(content); } } }, new Condition<VirtualFile>() { @Override public boolean value(VirtualFile file) { // Vladimir.Krivosheev — I don't know, why AutoTestManager checks it, but old behavior is preserved return FileEditorManager.getInstance(myDocumentWatcher.getProject()).isFileOpen(file); } }); }
public VcsAnnotationLocalChangesListenerImpl(Project project, final ProjectLevelVcsManager vcsManager) { myProject = project; myLock = new Object(); myUpdateStuff = createUpdateStuff(); myUpdater = new ZipperUpdater(ApplicationManager.getApplication().isUnitTestMode() ? 10 : 300, Alarm.ThreadToUse.POOLED_THREAD, project); myConnection = myProject.getMessageBus().connect(); myLocalFileSystem = LocalFileSystem.getInstance(); myHandler = createHandler(); myDirtyPaths = new HashSet<String>(); myDirtyChanges = new HashMap<String, VcsRevisionNumber>(); myDirtyFiles = new HashSet<VirtualFile>(); myFileAnnotationMap = new MultiMap<VirtualFile, FileAnnotation>() { @Override protected Collection<FileAnnotation> createCollection() { return new HashSet<FileAnnotation>(1); } }; myVcsManager = vcsManager; myVcsKeySet = new HashSet<VcsKey>(); myConnection.subscribe(VcsAnnotationRefresher.LOCAL_CHANGES_CHANGED, myHandler); }
public synchronized void addItem(final CompletionResult item) { if (!isRunning()) return; ProgressManager.checkCanceled(); final boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode(); if (!unitTestMode) { LOG.assertTrue(!ApplicationManager.getApplication().isDispatchThread()); } LOG.assertTrue(myParameters.getPosition().isValid()); myItemSorters.put(item.getLookupElement(), (CompletionSorterImpl)item.getSorter()); myLookup.addItem(item.getLookupElement(), item.getPrefixMatcher()); myCount++; if (myCount == 1) { new Alarm(Alarm.ThreadToUse.SHARED_THREAD, this).addRequest(new Runnable() { @Override public void run() { myFreezeSemaphore.up(); } }, 300); } myQueue.queue(myUpdate); }
@NotNull private static PsiFile getInjectedFileIfAny(@NotNull final Editor editor, @NotNull final Project project, int offset, @NotNull PsiFile psiFile, @NotNull final Alarm alarm) { Document document = editor.getDocument(); // when document is committed, try to highlight braces in injected lang - it's fast if (!PsiDocumentManager.getInstance(project).isUncommited(document)) { final PsiElement injectedElement = InjectedLanguageUtil.findInjectedElementNoCommit(psiFile, offset); if (injectedElement != null /*&& !(injectedElement instanceof PsiWhiteSpace)*/) { final PsiFile injected = injectedElement.getContainingFile(); if (injected != null) { return injected; } } } else { PsiDocumentManager.getInstance(project).performForCommittedDocument(document, new Runnable() { @Override public void run() { if (!project.isDisposed() && !editor.isDisposed()) { BraceHighlighter.updateBraces(editor, alarm); } } }); } return psiFile; }
private void fixMouseCheaters() { getComponent().addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { final ActionCallback done = IdeFocusManager.getInstance(myProject).requestFocus(myEditor.getContentComponent(), true); IdeFocusManager.getInstance(myProject).typeAheadUntil(done); new Alarm(LookupImpl.this).addRequest(new Runnable() { @Override public void run() { if (!done.isDone()) { done.setDone(); } } }, 300, myModalityState); } }); }
public void setCalculating(final boolean calculating) { myCalculating = calculating; Runnable setVisible = new Runnable() { @Override public void run() { myIconPanel.setVisible(myCalculating); } }; if (myCalculating) { new Alarm(this).addRequest(setVisible, 100, myModalityState); } else { setVisible.run(); } if (calculating) { myProcessIcon.resume(); } else { myProcessIcon.suspend(); } }
public SimpleEditorPreview(final ColorAndFontOptions options, final ColorSettingsPage page, final boolean navigatable) { myOptions = options; myPage = page; String text = page.getDemoText(); HighlightsExtractor extractant2 = new HighlightsExtractor(page.getAdditionalHighlightingTagToDescriptorMap()); myHighlightData = extractant2.extractHighlights(text); int selectedLine = -1; myEditor = (EditorEx)FontEditorPreview.createPreviewEditor(extractant2.cutDefinedTags(text), 10, 3, selectedLine, myOptions, false); FontEditorPreview.installTrafficLights(myEditor); myBlinkingAlarm = new Alarm().setActivationComponent(myEditor.getComponent()); if (navigatable) { addMouseMotionListener(myEditor, page.getHighlighter(), myHighlightData, false); CaretListener listener = new CaretListener() { @Override public void caretPositionChanged(CaretEvent e) { navigate(myEditor, true, e.getNewPosition(), page.getHighlighter(), myHighlightData, false); } }; myEditor.getCaretModel().addCaretListener(listener); } }
private GitRootScanner(@NotNull Project project) { myRootProblemNotifier = GitRootProblemNotifier.getInstance(project); StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() { @Override public void run() { myProjectIsInitialized = true; scanIfReady(); } }); final MessageBus messageBus = project.getMessageBus(); messageBus.connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this); messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this); messageBus.connect().subscribe(ProjectTopics.PROJECT_ROOTS, this); myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project); }
protected final void initValidation() { myValidationAlarm.cancelAllRequests(); final Runnable validateRequest = () -> { if (myDisposed) return; List<ValidationInfo> result = doValidateAll(); if (!result.isEmpty()) { installErrorPainter(); } myErrorPainter.setValidationInfo(result); updateErrorInfo(result); if (!myDisposed) { initValidation(); } }; if (getValidationThreadToUse() == Alarm.ThreadToUse.SWING_THREAD) { // null if headless JRootPane rootPane = getRootPane(); myValidationAlarm.addRequest(validateRequest, myValidationDelay, ApplicationManager.getApplication() == null ? null : rootPane == null ? ModalityState.current() : ModalityState.stateForComponent(rootPane)); } else { myValidationAlarm.addRequest(validateRequest, myValidationDelay); } }