Wicket 1.4 periodic component state update using AJAX - wicket

I have a link that should fire some process on the server and go inactive, then it should monitor this process at the background, and when it will be finished, link should be updated. All these actions should be done with the aid of AJAX.
Example of link transformation: Bake a cake -> Baking a cake -> Load baked cake
This workflow could be done within onClick method of AjaxLink, but it will block another AJAX requests, and will go down on long processing time.

One option here is to use AbstractAjaxTimerBehavior to poll server status regularly and update the label accordingly
/* Create stopped timer */
AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
#Override
protected void onTimer(AjaxRequestTarget target) {
if (serverIsReady()) {
/* Stop timer */
this.stop(target);
/* Update UI */
label.setDefaultModel("Load baked cake");
target.add(label);
}
}
});
link.add(timer);
timer.stop();
/* Create triggering event behaviour */
link.add(new AjaxEventBehavior("onclick") {
#Override
protected void onEvent(AjaxRequestTarget target) {
/* Update UI */
label.setDefaultModel("Baking a cake");
target.add(label);
/* Start timer */
timer.restart(target); /* It seems this method doesn't exist in Wicket 1.4 */
}
});

Related

How do I make the Scoreboard on the side not be visible when the Debug HUD is open?

I'm working on a 1.16.5 Minecraft client-side mod and I am trying to get the scoreboard to be invisible when the Debug HUD is visible. I have a basic mixin to the scoreboard's rendering function but I need to be able to check for whether the DebugHud is visible or not.
Code:
#Mixin(InGameHud.class)
public class MScoreboardHUD {
#Inject(at = #At("HEAD"), method = "renderScoreboardSidebar")
private void init(CallbackInfo info) {
// soon
}
}
Answer
Using MinecraftClient.options.debugEnabled will tell you whether the F3 menu is active.
Final Code
This uses client as the MinecraftClient object, and info.cancel() to cancel the scoreboard render
#Mixin(InGameHud.class)
public class MScoreboardHUD {
#Inject(at = #At("HEAD"), method = "renderScoreboardSidebar")
private void init(CallbackInfo info) {
if (client.options.debugEnabled) {
info.cancel();
}
}
}

Loader during Unity IAP Callback

I want to put loader in between dialog boxes come up for the purchase. What is the way for this?
Because when game player press Buy button, he should require to wait for 5 to 10 second depends on internet speed and server response and this process happed 2 to 3 times because multiple dialogs come up within screen.
So in this case, may be player can leave the screen. I want to put the loader so that game player realise that some processing is running in background, he required to wait for some time.
At present I was following completely this code for Unity IAP setup.
Integrating Unity IAP In Your Game
I assume this is for mobile platform but even if its not still the following can be considered:
Simple solution is to create a full screen Image (UI/Panel) object in your UI to block clicks. I would use Animator component (with triggers) to display this panel in front of other UI when there is a background process running.
public class Loader : MonoBehaviour
{
public static Loader Instance;
Animator m_Animator;
public bool Loading {get; private set;}
void Awake()
{
Instance = this; // However make sure there is only one object containing this script in the scene all time.
}
void Start()
{
//This gets the Animator, which should be attached to the GameObject you are intending to animate.
m_Animator = gameObject.GetComponent<Animator>();
Loading = false;
}
public void Show()
{
Loading = true;
m_Animator.SetBool("Loading", Loading); // this will show the panel.
}
public void Hide()
{
Loading = false;
m_Animator.SetBool("Loading", Loading); // this will hide the panel.
}
}
Then in any script which manipulates UI:
public void BuyButtonClicked()
{
Loader.Instance.Show();
// process time taking stuff
Loader.Instance.Hide();
}
You can also create any kind of loading animation as child of panel object using simple images and animation tool inside Unity (for example rotating animation (use fidget spinner, its cool)).
And in case of Android where user have option to leave screen by pressing OS back button you can prevent going back by checking if any loading is in progress by following example:
// code for back button
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
BackButtonPressed();
}
}
void BackButtonPressed()
{
if(Loader.Instance.Loading)
return;
// use back button event. (For example to leave screen)
}
Hope this helps ;)

vTaskDelay never return

My application run on stm32F4 with FreeRTOS V9.0.0 and port files Source\portable\RVDS\ARM_CM4F (imported via RTE Keil).
The main, call some initialization functions, create the task and then call the vTaskStartScheduler.
The task simply call vTaskDelay(1000) which never return. The system is not is fault. The fault report dosen't show any error or problem.
The code is:
int main(void)
{
init_foo1()
init_foo2()
xTaskCreate(aTask, "name",1280, NULL, 6, NULL);
init_foo3();
vTaskStartScheduler();
}
void aTask()
{
vTaskDelay(1000);
bar();
}
What is wrong?
Thanks all
You need to put infinite loop firstly:
Example usage of vTaskDelay function accordinly to documentation:
void vTaskFunction( void * pvParameters )
{
/* Block for 500ms. */
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
for( ;; )
{
/* Simply toggle the LED every 500ms, blocking between each toggle. */
vToggleLED();
vTaskDelay( xDelay );
}
}
Also test the priority in xTaskCreate
UBaseType_t uxPriority

Plugin Development: IResourceChangeListener called more than once on just one change

I am using IResourceChangeListener to listen to changes in resource.
my code is:
public void createPartControl(Composite parent) {
// Graph will hold all other objects
graph = new Graph(parent, SWT.NONE);
// create the graph with the right nodes and connections.
init();
//listen to changes in the resource.
workspace = ResourcesPlugin.getWorkspace();
resourceChangeListener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
//IResourceDelta delta = event.getDelta();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
init();
System.out.println("Something changed!");
}
});
}
};
workspace.addResourceChangeListener(resourceChangeListener);
}
public void dispose() {
workspace.removeResourceChangeListener(resourceChangeListener);
}
But, when I am doing just one change in the resource, and save it, the listener called more than once! (usually twice, but sometimes even 6 times!!!)
I tried to use delta to see if it's called in the project,folder,file..
and I didn't saw differences between the calls (maybe I didn't used it properly).
I found this link, but I didn't found there solution to solve my problem
IResourceChangeListener being called twice with one change
How can I fix my code?
Thanks.
There is nothing you can do in the listener code to change how many resource change events you get. It depends entirely on how the code making the changes is doing the change.
You may find that IResourceDelta.getKind and IResourceDelta.getFlags return different values in the events. Also something getMovedFromPath and getMovedToPath for rename or move operations.
If it is your code doing the change you can use a WorkspaceJob or WorkspaceModifyOperation to do atomic changes to the workspace which will also reduce the number of resource change events.
You might also want to check that your old listeners are being removed correctly.

How to detect the scroll panel is still scrolling or not in GWT?

I need checkpoint to detect the scrollpanel is still scrolling or not. I am sending the server request while scrolling the scroll bar with the delay of 100 milliseconds.
I meant, every 100 milliseconds i am sending the request to server while scrolling. This is fine when i do scroll slowly in the grid. But, when I drag from page top to bottom
I could see there are multiple request is going to server. I want to know is there any flag to delete the long scroll. Please find the code
#Override
public void onScroll(final ScrollEvent scrollEvent)
{
int delay = 100;
super.onScroll(scrollEvent, delay);
}
I am using GWT class com.google.gwt.dom.client.BrowserEvents.ScrollEvent. I need below kind of logic
#Override
public void onScroll(final ScrollEvent scrollEvent)
{
int delay = 100;
if(stillScollbarScrolling) {
return;
} else {
super.onScroll(scrollEvent, delay);
}
}
So, I need to consider last request only as valid request. All the previous requests are invalid. I have logic to cancel all the previous logic. But, I need check point to still scroll bar is scrolling without release the bar.
Please help me..
If I understand you well, you need to cancel repeating scroll events. If so, you can use a Timer to do that.
Once a scroll event occurs you start a timer. If next scroll event is fired you check if a timer is still running. If so, it means that you have a repeating event that should be cancelled. If a timer is not running than it is not a repeating event and a request should be done.
Here is the code:
Timer timer = new Timer() {
#Override
public void run() {
// do nothing...
}
};
#Override
public void onScroll(final ScrollEvent scrollEvent) {
if(timer.isRunning()) {
// timer is running - stop the timer and do nothing (cancel event)
timer.cancel();
}
else
// timer is not running - do request
super.onScroll(scrollEvent);
// restart the timer with 100ms delay
timer.schedule(100);
}
Please, notice that the first scroll event will cause doing the request because the timer is not started yet.