Jface TreeViewer diposed during refresh() - eclipse

what if I do a viewer.refresh() at the same time I close the tree viewer on the UI.
What will happen and how I can handle this situation?

This shouldn't happen in the same time, as UI events (such as close or refresh) are inherently single-threaded - they can happen only one after the other (unless you call refresh inside the dispose, or dispose during refresh, however both of them are hard to justify as normal steps)..
If your question was motivated by an SWT error of widget is disposed, then most likely you have disposed of something previously, but nonetheless called its refresh method - I would look it at that way.

Maybe you have more than one listener and trees around? I would advice to add a disposeListener to the tree and put a breakpoint into it. Then you see when it gets disposed.

Related

Does setState() inherently affect the application performance?

I read that setState affect application performance because it rebuilds the widget tree.
Calling setState notifies the framework that the internal state of
this object has changed in a way that might impact the user interface
in this subtree, which causes the framework to schedule a build for
this State object.
Is this an actual concern for application performance?
Yeah, it may but only if you are calling the function too many times unnecessarily.
What's the best practice?
Try calling it at the end of functionality or only when you need to
update the widget, you can also create multiple subclasses ( stateful
widget), so if you want some changes in a particular area only, then
only that widget will get updated not the entire screen.

does gwt panel clear method un attach event handlers?

in gwt Panel.clear() method clears all child widgets. Does that mean all even handlers associated with those child widgets will be removed or garbage collected as well?
Yes, it will (at least if the child widget cleaned their reference to application-transversal objects like the eventBus and don't hold circular references).
As per this documentation
The core GWT widget
system has a very specific event-handling system that makes it
impossible to trigger a leak.
It will also work in IE, as long as you
don't go straight to JSNI and hook up event handlers yourself (using
things like Event.sinkEvents() is just fine).
Calling Widget.removeEventListener() or
HandlerRegistration.removeHandler() is never necessary (or useful)
for any reason other than that you want to stop
receiving events (this is one reason we tucked removeHandler() into
HandlerRegistration -- most people never need to call it).
and this blog post.
However, removeHandler is required to avoid application-level, java-esque memory
leaks.
If you have a “global” event source, like an always-visible navigation
bar widget or an application-wide EventBus, and you have a transient
event listener, like a presenter listening for events, the presenter’s
event handler will keep it from being garbage collected until the
EventBus is also garbage collected.
So don't worry about widgets or #UIHandler. Just clear the tab and it'll work.
No it will not. You have to call removeHandler(). (eventually)
In this doumcnetation:
>
2 . removeHandler is required to avoid application-level memory leaks.
If you have a “global” event source, like an always-visible navigation
bar widget or an application-wide EventBus, and you have a transient
event listener, like a presenter listening for events, the presenter’s
event handler will keep it from being garbage collected until the
EventBus is also garbage collected.

Finish activity onPause but still be in backstack?

I'm trying to minimize memory usage in my app, and one of the things I'm doing is calling finish() in the onPause method (which I know is not the best way to do things). For the most part, it seems to be working well, but when the user clicks the back button from the next activity, it logically skips over the finished activity and goes back further. Is it possible to have that activity in the back stack and just get recreated if the user presses back?
No. This conclusion comes from the task and backstack documentation as well as the activity documentation and a general understanding of how a stack data structure works.
A stack data strucure only has 2 possible operations push/put, which adds something to the collection, and pop, which removes it. Stacks folow a last in first out model, or LIFO, where by last thing added - in your case an activity - is the first thing removed when pop is called.
Within the android lifecycle activities are generally popped from the stack when the back button is pressed. At that point onDestroy() is called and the activity is removed (you can verify this by overriding the onDestroy() method and logging the results if you want to check). Alternativly you can force onDestroy() to be called by calling finish() as you are. Finishing an activity effectivly does the same thing as pressing back. The activity is destroyed and must be recreated before it can be added to the stack.
For what you're trying to do the stack would have to incorporate some intermediate state in which an activity does not exist but rather something akin to a reference is held that, when moved to the top, would indicate that the corresponding activity should be recreated. Since this is not how the sack works - it only holds activities - that state cannont exist and so the result you are talking about is not possible.
Your Goal is to minimize memory usage,Just make use of activity life cycle, You can do this alternative(if you need)
-Just leave onCreate() method blank.(only do setContentView(layout))
-Override onResume();
-whatever you were doing in onCreate just copy paste to onResume().
-and In onPause(), Recycle your all bitmaps and set them to null(I think you are using Bitmaps thats why you are very cautious about it ). and remove your views.
Now what will happen, when you launch your new activity, onPause() would be called. that will remove your all bitmap and views. and when you come back, onResume() will be call.(onCreate will not be called). and that will again initialize your view and bitmaps.
No, i don't think that is possible. Once you finish the Activity it's gone. You could, however, implement and handle your own stack. On back pressed, you would just start the closed Activity again.

MouseOver and MouseOut events does not get fired by a widget

I have two widgets listening for a MouseOutEvent. Problem is that sometimes this events does not get called on both of the widgeth even if you mouse out of them.
No error is thrown and this is extremely hard to debug.
My understanding is that this event is fired by a browser, so I don't understand why this is not happening. I am registering this event to the widget itself.
Any suggestions will be a great help.
Thanks
Sounds like you might have used addHandler to register to your MouseOverHandler. Widget has two methods for adding event handlers, addDomHandler and addHandler. The first is meant to be used for DomEvents, e.g. MouseOutEvents. It sinks the event on the widget, which means that your listener will get notified (this is only necessary for DomEvents). Those events might not get fired if you do not use addDomHandler to register your handler.

How do you update a JFace Viewer from inside a Job?

Caveat: I'm still struggling with proper MVC in Eclipse plugin development, so if you see anything here that is most likely causing me more pain that I should be enduring, please let me know.
The question:
I have a View with a JFace Tree Viewer and a Table (not a table viewer... that will be changed down the road).
I have an action that is initialized with a reference to the View (this seems terrible to me, but I don't yet know how to do it the right way). When the action is run -- via a button on the view -- the action:
1) gets the Tree Viewer from the View
2) gets the underlying model
3) creates a Job
a) inside the job, loops over the model and does various things to it, including adding additional children into the model
b) uses a function exposed in the view that "clears" the Table in the view
4) adds a JobChangeListener that implements "done()".
a) inside the done() method, it expands the treeviewer via this code:
loadMethodsJob.addJobChangeListener(new JobChangeAdapter(){
public void done(IJobChangeEvent event){
view.enableActions();
view.getTestsViewer().expandAll();
}
});
Inside the Job, whenever I attempt to access the elements in the viewer, I get Invalid Thread Access errors. I believe I understand why I get them when running inside the job, but I'm not sure how to work around them correctly if I can't interact with the widgets in the job change listener. I can get it to work if I wrap every interaction with the widgets in a getDisplay().synchExec(....), but I seem to remember reading that this is not preferable.
I feel like I'm on the cusp of a big leap in understanding with Eclipse SWT, so I appreciate any guidance in getting there.
Any UI component in SWT can be accessed only by a UI thread.
Since the done method of the job runs in a separate non-UI thread, the invalid thread access is fired.
By wrapping every interaction in a Display.syncExec , you are making sure that it runs in the display thread (The UI thread).
There shouldn't be any problem with the above approach.