public void testMakeFileReadOnly() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); PsiFile psiFile = fileManager.findFile(file); final EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true); final String expected = "beforePropertyChange writable\n" + "propertyChanged writable\n"; new WaitFor(500){ @Override protected boolean condition() { return expected.equals(listener.getEventsString()); } }.assertCompleted(listener.getEventsString()); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false); }
void hideTree() throws Exception { Assert.assertFalse(getMyBuilder().myWasCleanedUp); invokeLaterIfNeeded(new Runnable() { @Override public void run() { getBuilder().getUi().deactivate(); } }); final WaitFor waitFor = new WaitFor() { @Override protected boolean condition() { return getMyBuilder().myWasCleanedUp || myCancelRequest != null; } }; if (myCancelRequest != null) { throw new Exception(myCancelRequest); } waitFor.assertCompleted("Tree cleanup was not performed. isCancelledReadyState=" + getBuilder().getUi().isCancelledReady()); Assert.assertTrue(getMyBuilder().myWasCleanedUp); }
@Override protected void tearDown() throws Exception { invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (getBuilder() != null) { Disposer.dispose(getBuilder()); } } }); new WaitFor(6000) { @Override protected boolean condition() { return getBuilder() == null || getBuilder().getUi() == null; } }; super.tearDown(); }
private void assertCallbackOnce(final TreeAction action) { final int[] notifyCount = new int[1]; final boolean[] done = new boolean[1]; invokeLaterIfNeeded(new Runnable() { @Override public void run() { action.run(new Runnable() { @Override public void run() { notifyCount[0]++; done[0] = true; } }); } }); new WaitFor(2000) { @Override protected boolean condition() { return done[0] && getMyBuilder().getUi().isReady(); } }; assertTrue(done[0]); assertEquals(1, notifyCount[0]); }
public void do_not_make_instance_start_date_earlier(){ final CloudInstanceUserData data = new CloudInstanceUserData("aaa", "bbbb", "localhost", 10000l, "profileDescr", Collections.<String, String>emptyMap()); final VmwareCloudInstance instance = myImage.startNewInstance(data); new WaitFor(5 * 1000){ @Override protected boolean condition() { return instance.getStatus() == InstanceStatus.RUNNING; } }; FakeVirtualMachine fakeVM = FakeModel.instance().getVirtualMachine(instance.getName()); final Calendar calendarInstance = Calendar.getInstance(); calendarInstance.set(2001, 1, 1); fakeVM.setBootTime(calendarInstance); calendarInstance.set(2001, 1, 1); final Calendar instance2 = Calendar.getInstance(); instance2.set(2002, 1, 1); assertTrue(instance.getStartedTime().after(instance2.getTime())); }
public void sync_start_stop_instance_status() throws RemoteException { final VmwareCloudImage img1 = getImageByName("image1"); assertEquals(1, img1.getInstances().size()); final VmwareCloudInstance inst1 = img1.getInstances().iterator().next(); assertEquals(InstanceStatus.STOPPED, inst1.getStatus()); startNewInstanceAndWait("image1"); assertEquals(InstanceStatus.RUNNING, inst1.getStatus()); FakeModel.instance().getVirtualMachine("image1").shutdownGuest(); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.STOPPED; } }.assertCompleted("Should have caught the stopped status"); FakeModel.instance().getVirtualMachine("image1").powerOnVM_Task(null); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.RUNNING; } }.assertCompleted("Should have caught the running status"); }
public void sync_clone_status() throws RemoteException { final VmwareCloudImage img1 = getImageByName("image_template"); assertEquals(0, img1.getInstances().size()); final VmwareCloudInstance inst = startNewInstanceAndWait("image_template"); assertEquals(InstanceStatus.RUNNING, inst.getStatus()); FakeModel.instance().getVirtualMachine(inst.getName()).shutdownGuest(); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.STOPPED; } }.assertCompleted("Should have caught the stopped status"); FakeModel.instance().getVirtualMachine(inst.getName()).powerOnVM_Task(null); new WaitFor(3000){ protected boolean condition() { return img1.getInstances().iterator().next().getStatus() == InstanceStatus.RUNNING; } }.assertCompleted("Should have caught the running status"); }
public void check_same_datacenter() throws InterruptedException { FakeModel.instance().addDatacenter("dc2"); FakeModel.instance().addFolder("cf2").setParent("dc2", Datacenter.class); FakeModel.instance().addResourcePool("rp2").setParentFolder("cf2"); FakeModel.instance().addVM("image3").setParentFolder("cf"); updateClientParameters(CloudProfileUtil.collectionFromJson( "[{sourceVmName:'image1', behaviour:'START_STOP'}," + "{sourceVmName:'image2',snapshot:'snap*',folder:'cf',pool:'rp',maxInstances:3,behaviour:'ON_DEMAND_CLONE'}," + "{sourceVmName:'image_template', snapshot:'" + VmwareConstants.CURRENT_STATE + "',folder:'cf',pool:'rp',maxInstances:3,behaviour:'FRESH_CLONE'}, " + "{sourceVmName:'image3',snapshot:'" + VmwareConstants.CURRENT_STATE + "'," + "folder:'cf2',pool:'rp2',maxInstances:3,behaviour:'ON_DEMAND_CLONE'}]", PROJECT_ID)); recreateClient(); final CloudInstanceUserData userData = createUserData("image3_agent"); final VmwareCloudInstance vmwareCloudInstance = myClient.startNewInstance(getImageByName("image3"), userData); new WaitFor(10 * 1000) { @Override protected boolean condition() { return vmwareCloudInstance.getStatus() == InstanceStatus.ERROR && vmwareCloudInstance.getErrorInfo() != null; } }.assertCompleted(); final String msg = vmwareCloudInstance.getErrorInfo().getMessage(); assertContains(msg, "Unable to find folder cf2 in datacenter dc"); }
private void terminateAndDeleteIfNecessary(final boolean shouldBeDeleted, final VmwareCloudInstance instance) throws CheckedCloudException { myClient.terminateInstance(instance); new WaitFor(5*1000){ protected boolean condition() { return instance.getStatus()==InstanceStatus.STOPPED; } }.assertCompleted(); final String name = instance.getName(); final WaitFor waitFor = new WaitFor(10 * 1000) { @Override protected boolean condition() { try { if (shouldBeDeleted) { return (myFakeApi.getAllVMsMap(false).get(name) == null); } else { return myFakeApi.getInstanceDetails(name).getInstanceStatus() == InstanceStatus.STOPPED; } } catch (CheckedCloudException e) { return false; } } }; waitFor.assertCompleted("template clone should be deleted after execution"); }
private VMWareCloudClient recreateClient(final VMWareCloudClient oldClient, final CloudClientParameters parameters, long updateTime, boolean waitForInitialization){ if (oldClient != null) { oldClient.dispose(); } myProfile = VmwareTestUtils.createProfileFromProps(parameters); final VMWareCloudClient newClient = new VMWareCloudClient(myProfile, myFakeApi, myTaskManager, myIdxStorage); final Collection<VmwareCloudImageDetails> images = VMWareCloudClientFactory.parseImageDataInternal(parameters); newClient.populateImagesData(images, updateTime, updateTime); if (waitForInitialization) { new WaitFor(5000) { @Override protected boolean condition() { return newClient.isInitialized(); } }.assertCompleted("Must be initialized"); } return newClient; }
public void testMakeFileReadOnly() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); PsiFile psiFile = fileManager.findFile(file); final EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true); String string = listener.getEventsString(); final String expected = "beforePropertyChange\n" + "propertyChanged\n"; new WaitFor(500){ @Override protected boolean condition() { return expected.equals(listener.getEventsString()); } }.assertCompleted(expected); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false); }
private void assertCallbackOnce(final TreeAction action) { final int[] notifyCount = new int[1]; final boolean[] done = new boolean[1]; invokeLaterIfNeeded(new Runnable() { @Override public void run() { action.run(new Runnable() { @Override public void run() { notifyCount[0]++; done[0] = true; } }); } }); new WaitFor(60000) { @Override protected boolean condition() { return done[0] && getMyBuilder().getUi().isReady(); } }; assertTrue(done[0]); assertEquals(1, notifyCount[0]); }
private void waitForExecution(final MyQueue queue) { queue.onTimer(); new WaitFor(5000) { @Override protected boolean condition() { return queue.wasExecuted(); } }; }
void waitBuilderToCome(final Condition<Object> condition) throws Exception { boolean success = new WaitFor(60000) { @Override protected boolean condition() { final boolean[] ready = {false}; invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { AbstractTreeUi ui = getBuilder().getUi(); if (ui == null) { ready[0] = true; return; } ready[0] = myCancelRequest != null || myReadyRequest || condition.value(null) && ui.isReady(); } }); return ready[0]; } }.isConditionRealized(); if (myCancelRequest != null) { throw new Exception(myCancelRequest); } if (!myReadyRequest) { if (!getBuilder().isDisposed()) { Assert.assertTrue(getBuilder().getUi().getNodeActions().isEmpty()); } } Assert.assertTrue(success); }
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 = new Runnable() { @Override public void run() { 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); }
public void check_can_start_new_instance_limits() throws RemoteException, InterruptedException { final CloudInstanceUserData data = new CloudInstanceUserData("aaa", "bbbb", "localhost", 10000l, "profileDescr", Collections.<String, String>emptyMap()); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); myImage.startNewInstance(data); assertTrue(myImage.canStartNewInstance()); final VmwareCloudInstance instance2Stop = myImage.startNewInstance(data); assertFalse(myImage.canStartNewInstance()); new WaitFor(5*1000){ @Override protected boolean condition() { return instance2Stop.getStatus() == InstanceStatus.RUNNING; } }; final FakeVirtualMachine vm2Stop = FakeModel.instance().getVirtualMachine(instance2Stop.getName()); final String result = vm2Stop.powerOffVM_Task().waitForTask(); assertEquals(Task.SUCCESS, result); instance2Stop.setStatus(InstanceStatus.STOPPED); assertTrue(myImage.canStartNewInstance()); System.setProperty(VmwareConstants.CONSIDER_STOPPED_VMS_LIMIT, "true"); assertFalse(myImage.canStartNewInstance()); System.getProperties().remove(VmwareConstants.CONSIDER_STOPPED_VMS_LIMIT); assertTrue(myImage.canStartNewInstance()); }
public void should_power_off_if_no_guest_tools_avail() throws InterruptedException { final VmwareCloudImage image_template = getImageByName("image_template"); final VmwareCloudInstance instance = startNewInstanceAndWait("image_template"); assertContains(image_template.getInstances(), instance); FakeModel.instance().getVirtualMachine(instance.getName()).disableGuestTools(); myClient.terminateInstance(instance); new WaitFor(2000) { @Override protected boolean condition() { return instance.getStatus() == InstanceStatus.STOPPED && !image_template.getInstances().contains(instance); } }; assertNull(FakeModel.instance().getVirtualMachine(instance.getName())); assertNotContains(image_template.getInstances(), instance); }
public void enforce_change_of_stuck_instance_status() throws RemoteException, ExecutionException, InterruptedException { myStuckTime.set(3*1000); recreateClient(250); final VmwareCloudInstance instance = startNewInstanceAndWait("image1"); FakeModel.instance().getVms().get(instance.getName()).shutdownGuest(); instance.setStatus(InstanceStatus.STOPPING); new WaitFor(6*1000){ @Override protected boolean condition() { return instance.getStatus() == InstanceStatus.STOPPED; } }.assertCompleted("should have changed the status"); }
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 = new Runnable() { @Override public void run() { 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(15000) { @Override protected boolean condition() { return getBuilder().getUi() == null; } }.isConditionRealized(); assertTrue(released); }
private static void waitFor(final Condition<Void> condition) { new WaitFor(10000) { @Override protected boolean condition() { gc(); return condition.value(null); } }.assertCompleted(condition.toString()); }
public void testFindString() { 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]; findInNewThread(findModel, myFindManager, text, 0, findResultArr); new WaitFor(30 *1000){ @Override protected boolean condition() { return findResultArr[0] != null; } }.assertCompleted(); assertFalse(findResultArr[0].isStringFound()); }
public void testDeferredSelection() throws Exception { buildStructure(myRoot, false); final Ref<Boolean> queued = new Ref<Boolean>(false); final Ref<Boolean> intellijSelected = new Ref<Boolean>(false); final Ref<Boolean> jetbrainsSelected = new Ref<Boolean>(false); invokeLaterIfNeeded(new Runnable() { @Override public void run() { try { getBuilder().select(new NodeElement("intellij"), new Runnable() { @Override public void run() { intellijSelected.set(true); } }, true); queued.set(true); } catch (Exception e) { e.printStackTrace(); fail(); } } }); new WaitFor() { @Override protected boolean condition() { return queued.get(); } }; assertTrue(getBuilder().getUi().isIdle()); assertTreeNow("+null\n"); assertNull(((DefaultMutableTreeNode)notNull(getBuilder().getTreeModel()).getRoot()).getUserObject()); invokeLaterIfNeeded(new Runnable() { @Override public void run() { getBuilder().getUi().activate(true); getBuilder().select(new NodeElement("jetbrains"), new Runnable() { @Override public void run() { jetbrainsSelected.set(true); } }, true); } }); waitBuilderToCome(new Condition<Object>() { @Override public boolean value(Object object) { return intellijSelected.get() && jetbrainsSelected.get(); } }); assertTree("-/\n" + " -com\n" + " +[intellij]\n" + " +[jetbrains]\n" + " +org\n" + " +xUnit\n"); }
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(new Runnable() { @Override public void run() { if (runner == myRunner) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { myRunner = null; } }); } } }); } }.start(); }
public void do_not_clear_image_instances_list_on_error() throws ExecutionException, InterruptedException, MalformedURLException { final AtomicBoolean failure = new AtomicBoolean(false); final AtomicLong lastApiCallTime = new AtomicLong(0); myFakeApi = new FakeApiConnector(TEST_SERVER_UUID, PROFILE_ID){ @Override protected <T extends ManagedEntity> Collection<T> findAllEntitiesOld(final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findAllEntitiesOld(instanceType); } @Override protected <T extends ManagedEntity> Map<String, T> findAllEntitiesAsMapOld(final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findAllEntitiesAsMapOld(instanceType); } @Override protected <T extends ManagedEntity> Pair<T,Datacenter> findEntityByIdNameOld(final String name, final Class<T> instanceType) throws VmwareCheckedCloudException { lastApiCallTime.set(System.currentTimeMillis()); if (failure.get()){ throw new VmwareCheckedCloudException("Cannot connect"); } return super.findEntityByIdNameOld(name, instanceType); } }; recreateClient(250); startNewInstanceAndWait("image2"); startNewInstanceAndWait("image2"); startNewInstanceAndWait("image2"); Thread.sleep(5*1000); failure.set(true); final long problemStart = System.currentTimeMillis(); new WaitFor(5*1000){ @Override protected boolean condition() { return myLastRunTime.get() > problemStart; } }.assertCompleted("Should have been checked at least once - delay set to 2 sec"); assertEquals(3, getImageByName("image2").getInstances().size()); }
private VmwareCloudInstance startNewInstanceAndCheck(VMWareCloudClient client, String imageName, Map<String, String> parameters, boolean instanceShouldStart) { final CloudInstanceUserData userData = createUserData(imageName + "_agent", parameters); final VmwareCloudImage image = getImageByName(client, imageName); final Collection<VmwareCloudInstance> runningInstances = image .getInstances() .stream() .filter(i->i.getStatus() == InstanceStatus.RUNNING) .collect(Collectors.toList()); final VmwareCloudInstance vmwareCloudInstance = client.startNewInstance(image, userData); final boolean ready = vmwareCloudInstance.isReady(); System.out.printf("Instance '%s'. Ready: %b%n", vmwareCloudInstance.getName(), ready); final WaitFor waitFor = new WaitFor(2 * 1000) { @Override protected boolean condition() { if (ready) { return vmwareCloudInstance.getStatus() == InstanceStatus.RUNNING; } else { return image .getInstances() .stream() .anyMatch(i->i.getStatus() == InstanceStatus.RUNNING && !runningInstances.contains(i)); } } }; if (instanceShouldStart) { waitFor.assertCompleted(); if (!ready) { final VmwareCloudInstance startedInstance = image .getInstances() .stream() .filter(i -> i.getStatus() == InstanceStatus.RUNNING && !runningInstances.contains(i)).findAny().get(); assertNotNull(startedInstance); return startedInstance; } else { return vmwareCloudInstance; } } else { assertFalse(waitFor.isConditionRealized()); return null; } }
public void testFindString() throws Exception{ FindManager findManager = FindManager.getInstance(myProject); FindModel findModel = new FindModel(); findModel.setStringToFind("done"); findModel.setWholeWordsOnly(false); findModel.setFromCursor(false); findModel.setGlobal(true); findModel.setMultipleFiles(false); findModel.setProjectScope(true); String text = "public static class MyClass{\n/*done*/\npublic static void main(){}}"; FindResult findResult = findManager.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 = findManager.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 = findManager.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 = findManager.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]; findInNewThread(findModel, findManager, text, 0, findResultArr); new WaitFor(30 *1000){ @Override protected boolean condition() { return findResultArr[0] != null; } }.assertCompleted(); assertFalse(findResultArr[0].isStringFound()); }
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() { @Override public void run() { new WaitFor() { @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); try { sleep(1000); } catch (InterruptedException e) {} if (myRunner == null) { message(null, "Script stopped", -1, Type.message, true); return; } final PlaybackRunner runner = myRunner; myRunner.run().doWhenProcessed(new Runnable() { @Override public void run() { if (runner == myRunner) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { myRunner = null; } }); } } }); } }.start(); }