In my plugin, I execute a network query, get the result
and show the processing step.
CoreProgressManager.getInstance().runProcessWithProgressSynchronously(Runnable {
//runnable block
CoreProgressManager.getInstance().progressIndicator.text = "Start loading"
val result = MyProvider.getObjects() // this network request
CoreProgressManager.getInstance().progressIndicator.text = "Finish"
result.forEach {
//processing result
CoreProgressManager.getInstance().progressIndicator.text = "Processing is $result"
}
}, taskTitle, true /* canBeCanceled */, project)
Sometimes the query is performed by the network for a long time, and I want to stop working all block (runnable block).
For this, in runProcessWithProgressSynchronously I passed the parameter canBeCanceled = true
and naively thought that IDEA would stop executing my executable block, but this did not happen.
How do I catch the clicking of a Cancel button and stop my runnable block?
You need to periodically call ProgressIndicator.checkCanceled() from your block. This method will throw a ProcessCanceledException if the Cancel button has been pressed.
Related
I want to show a web notification to the user if they left the page open for 10 seconds. I have already taken the notification permission.
Problem here is the notification occurs multiple times even if the user comes back to the page in less than 10 secs. Already use clearTimeout for flushing myVar value....but no luck.....any help!
var myVar;
window.onblur = function myFunction() {
myVar = setTimeout(function () {
var notification = new Notification("XXX page is open in background ");
}, 10000);
clearTimeout(myVar);
};
want to make in such a way that only if user goes out of the page multiple times the notification will trigger everytime....but if he comes back to the page it will not appear..
Well, it could be due to testing. You must realize that window.onblur is triggered each time you leave the page. So if you leave, enter, leave, enter, leave, you will get 3 popups; each event runs independantly.
What you should do is call clearTimeout() in your window.onfocus event; don't forget to clear your myVar variable in both your popup handling code and your onfocus event (and test for it being null or not).
In my application i have a two tab buttons say Tasks and Worklist. Tasks is always loaded. But Worklist button is dynamic and loaded only after some time.
I want to click Tasks button after a certain time. ie, i need to wait for Worklist button and if it exists after a certain time then click the Tasks button. Also if the timeout exceeds and Worklist button is not loaded then i need to click Tasks button.
i cannot use sleep.
Can i use expectationForPredicate and waitForExpectationsWithTimeout. But waitForExpectationsWithTimeout gets failed if the element is not found after timeout. Even if i write
waitForExpectationsWithTimeout(120) { (error) -> Void in
click Tasks button
}
This gives stall on main thread.
I want to click Tasks button only after worklists is loaded. but if worklist is not loaded after some timeout, then also i need to click Tasks button..
Is there any solution. any help.
You can create your own custom Method to handle this:
func waitForElementToExist(
element: XCUIElement,
timeout: Int = 20,
failTestOnFailure: Bool = true)
-> Bool
{
var i = 0
let message = "Timed out while waiting for element: \(element) after \(timeout) seconds"
while !element.exists {
sleep(1)
i += 1
guard i < timeout else {
if failTestOnFailure {
XCTFail(message)
} else {
print(message)
}
return false
}
}
return true
}
you can call the method like:
if waitForElementToExist(taskButton, timeout: 20, failTestOnFailure: false) {
button.tap()
}
Hope this works for you!
I'm new to Groovy and came to Groovy and grails from Java.
I cannot explain this:
boolean boolVar = false
if (boolVar) {
print "ok"
}
but code execution run inside "if" block, nut boolVar is false
debugger session screenshot
I think the screenshot is a bit wrong as you have nothing after the condition so intelliJ highlight this line but it does not execute it, it seems it goes to the block but it does not print the ok, can you show the result of the run window ?
for example add this to your code
boolean boolVar = false
def output = "I start here"
if (boolVar) {
output += "\noops in loop"
println "ok"
}
print output
only I start here is being printed
I'm not sure I get it by 100%, did you try this?
boolean boolVar = false
if (!boolVar) {
println "ok"
}
if(boolVar) and if(boolVar == true) is the same
1.) Remove all breakpoints from your project (Run->View Breakpoints and delete all breakpoints)
2.) Clean the target directory.
3.) Add a new breakpoint at the "print" statement and check if it works now.
I'm having a problem with a variable I'm using to track the status of a user activity. In a GUI I have a button that, on clicking the button launches a second GUI. In that GUI, the user can either complete the activity started in the first GUI or not.
If the user cancels the second GUI, then the idea is to go back to the first GUI, leaving all variables and lists with their current values. If the second GUI completes the activity of the first GUI, then all variables and lists should be reset.
To track this, I have a variable (Boolean complete) initially set to FALSE. In the second GUI, when the "OK" button is clicked (rather than the "Cancel" button), the second GUI calls a method in the first GUI, changing the value of "complete" to TRUE.
To see what the heck is going on, I have System.out.println at several points allowing me to see the value of "complete" along the way. What I see is this:
Launching first GUI - complete = FALSE
Launching second GUI - complete = FALSE
Clicking "OK" in second GUI - complete = TRUE
Second GUI closes itself, returning to complete first GUI activity
First GUI finishes activity with complete = FALSE
I'm assuming it is because I am launching the second GUI with a showandwait, and when the method containing the showandwait begins, the value of "complete" = FALSE. The value changes in the WAIT part of show and wait, then the method continues and that is where I get the value still being FALSE, though it was changed to TRUE.
Here is a summary of the code in question (if you need exact code, it's longer, but I can post on request):
completeButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
try {
System.out.println("b4 calc = " + complete); // complete = FALSE
// all the code to create the calcStage
calcStage.showAndWait(); // second GUI, which calls a method in THIS
// class that changes complete to TRUE. That method
// (in THIS file) also has a println that shows the change.
getComplete(); // tried adding this method to check the value of
// "complete" after the change made by the calcStage
// (which calls a method in this same file)
System.out.println("Complete? " + complete);
// this shows complete = FALSE,
// though in the calcStage it was changed to TRUE
if (salecomplete) {
// code that should reset all variables and lists if the activity was completed
}
}
}
}
The question here is why does the second GUI successfully change the value of "complete", but when I return to the first GUI it still sees complete as FALSE? And how can I get around this?
Try having the controller of the second GUI calling a method in the first GUI's controller to modify that complete variable
For example:
// Code to handle the OK button being pressed
#Override
public void handle(ActionEvent t) {
// Do validation and work
//reference to the first controller object
firstController.setComplete(true);
}
I have a MessageBox being shown in Application Closing/Deactivated methods in Windows Phone 7/8 application. It is used to warn the user for active timer being disabled because app is closing. The App Closing/Deactivated events are perfect for this, because putting logic in all application pages would be a killer - too many pages and paths for navigation. This works just fine - message box displays OK in WP7.
I also know for breaking changes in the API of WP8. There it is clearly stated that MessageBox.Show in Activated and Launching will cause exception.
The problem is that in WP8 the message box does not get shown on app closing. Code is executed without exception, but no message appears.
P.S. I've asked this on MS WP Dev forum but obviously no one knew.
Move the msgBox code from the app closing events and into your main page codebehind. Override the on back key press event and place your code there. This is how it was done on 7.x:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Do you want to exit XXXXX?", "Application Closing", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
{
// Cancel default navigation
e.Cancel = true;
}
}
FYI - On WP8 it looks like you have to dispatch the MsgBox Show to a new thread.
This prompts the user before the app ever actually starts to close in the event model. If the user accepts the back key press is allowed to happen, otherwise its canceled. You are not allowed to override the home button press, it must always go immediately to the home screen. You should look into background agents to persist your timer code through suspend / resume.
Register BackKeyPress event on RootFrame.
RootFrame.BackKeyPress += BackKeyPressed;
private void BackKeyPressed(object sender, CancelEventArgs e)
{
var result = (MessageBox.Show("Do you want to exit XXXXX?", "Application Closing", MessageBoxButton.OKCancel));
if (result == MessageBoxResult.Cancel)
{
// Cancel default navigation
e.Cancel = true;
}
}