Search in sources :

Example 1 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class PlaybackDebugger method startWhenFrameActive.

private void startWhenFrameActive() {
    myLog.setText(null);
    addInfo("Waiting for IDE frame activation", -1, MESSAGE_COLOR, 0);
    myRunner = new PlaybackRunner(myCodeEditor.getText(), this, false, true, false);
    VirtualFile file = pathToFile();
    if (file != null) {
        VirtualFile scriptDir = file.getParent();
        if (scriptDir != null) {
            myRunner.setScriptDir(new File(scriptDir.getPresentableUrl()));
        }
    }
    new Thread("playback debugger") {

        @Override
        public void run() {
            new WaitFor(60000) {

                @Override
                protected boolean condition() {
                    return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow() instanceof IdeFrame || myRunner == null;
                }
            };
            if (myRunner == null) {
                message(null, "Script stopped", -1, Type.message, true);
                return;
            }
            message(null, "Starting script...", -1, Type.message, true);
            TimeoutUtil.sleep(1000);
            if (myRunner == null) {
                message(null, "Script stopped", -1, Type.message, true);
                return;
            }
            final PlaybackRunner runner = myRunner;
            myRunner.run().doWhenProcessed(() -> {
                if (runner == myRunner) {
                    SwingUtilities.invokeLater(() -> myRunner = null);
                }
            });
        }
    }.start();
}
Also used : PlaybackRunner(com.intellij.openapi.ui.playback.PlaybackRunner) WaitFor(com.intellij.util.WaitFor) File(java.io.File) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 2 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class FindManagerTest method testFindString.

public void testFindString() throws InterruptedException {
    FindModel findModel = FindManagerTestUtils.configureFindModel("done");
    String text = "public static class MyClass{\n/*done*/\npublic static void main(){}}";
    FindResult findResult = myFindManager.findString(text, 0, findModel);
    assertTrue(findResult.isStringFound());
    findModel = new FindModel();
    findModel.setStringToFind("done");
    findModel.setWholeWordsOnly(false);
    findModel.setFromCursor(true);
    findModel.setGlobal(true);
    findModel.setMultipleFiles(false);
    findModel.setProjectScope(true);
    findResult = myFindManager.findString(text, 40, findModel);
    assertFalse(findResult.isStringFound());
    findModel = new FindModel();
    findModel.setStringToFind("done");
    findModel.setWholeWordsOnly(false);
    findModel.setFromCursor(true);
    findModel.setGlobal(true);
    findModel.setMultipleFiles(false);
    findModel.setProjectScope(true);
    findModel.setForward(false);
    findResult = myFindManager.findString(text, 40, findModel);
    assertTrue(findResult.isStringFound());
    findModel = new FindModel();
    findModel.setStringToFind("done");
    findModel.setWholeWordsOnly(true);
    findModel.setFromCursor(false);
    findModel.setGlobal(true);
    findModel.setMultipleFiles(false);
    findModel.setProjectScope(true);
    findResult = myFindManager.findString(text, 0, findModel);
    assertTrue(findResult.isStringFound());
    findModel = new FindModel();
    findModel.setStringToFind("don");
    findModel.setWholeWordsOnly(true);
    findModel.setFromCursor(false);
    findModel.setGlobal(true);
    findModel.setMultipleFiles(false);
    findModel.setProjectScope(true);
    final FindResult[] findResultArr = new FindResult[1];
    Thread thread = findInNewThread(findModel, myFindManager, text, 0, findResultArr);
    new WaitFor(30 * 1000) {

        @Override
        protected boolean condition() {
            return findResultArr[0] != null;
        }
    }.assertCompleted();
    assertFalse(findResultArr[0].isStringFound());
    thread.join();
}
Also used : WaitFor(com.intellij.util.WaitFor)

Example 3 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class PsiEventsTest method testMakeFileReadOnly.

public void testMakeFileReadOnly() throws Exception {
    FileManager fileManager = myPsiManager.getFileManager();
    VirtualFile file = createChildData(myPrjDir1, "a.txt");
    PsiFile psiFile = fileManager.findFile(file);
    final EventsTestListener listener = new EventsTestListener();
    myPsiManager.addPsiTreeChangeListener(listener, getTestRootDisposable());
    ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Object, IOException>) () -> {
        ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true);
        return null;
    });
    final String expected = "beforePropertyChange writable\n" + "propertyChanged writable\n";
    new WaitFor(500) {

        @Override
        protected boolean condition() {
            return expected.equals(listener.getEventsString());
        }
    }.assertCompleted(listener.getEventsString());
    ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Object, IOException>) () -> {
        ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false);
        return null;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WaitFor(com.intellij.util.WaitFor) IOException(java.io.IOException)

Example 4 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class MergingUpdateQueueTest method waitForExecution.

private static void waitForExecution(final MyQueue queue) {
    queue.onTimer();
    new WaitFor(5000) {

        @Override
        protected boolean condition() {
            return queue.wasExecuted();
        }
    }.assertCompleted();
}
Also used : WaitFor(com.intellij.util.WaitFor)

Example 5 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class TreeUiTest method assertReleaseDuringBuilding.

private void assertReleaseDuringBuilding(final String actionAction, final Object actionElement, Runnable buildAction) throws Exception {
    buildStructure(myRoot);
    myElementUpdateHook = new ElementUpdateHook() {

        @Override
        public void onElementAction(String action, Object element) {
            if (!element.toString().equals(actionElement.toString()))
                return;
            Runnable runnable = () -> {
                myReadyRequest = true;
                Disposer.dispose(getBuilder());
            };
            if (actionAction.equals(action)) {
                if (getBuilder().getUi().isPassthroughMode()) {
                    runnable.run();
                } else {
                    //noinspection SSBasedInspection
                    SwingUtilities.invokeLater(runnable);
                }
            }
        }
    };
    buildAction.run();
    boolean released = new WaitFor(1000) {

        @Override
        protected boolean condition() {
            return getBuilder().getUi() == null;
        }
    }.isConditionRealized();
    assertTrue(released);
}
Also used : WaitFor(com.intellij.util.WaitFor)

Aggregations

WaitFor (com.intellij.util.WaitFor)8 PlaybackRunner (com.intellij.openapi.ui.playback.PlaybackRunner)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IdeFrame (com.intellij.openapi.wm.IdeFrame)1 THashSet (gnu.trove.THashSet)1 File (java.io.File)1 IOException (java.io.IOException)1 TestOnly (org.jetbrains.annotations.TestOnly)1