tableViewer.setInput with monitor - java

I have a Table viewer with 3 columns and several rows (>4000).
When call tableviewer.setInput(myList) it takes forever and i'm ok with that but i wanted to implement a monitor so that the user can know what's going on but i have no idea how to start or where to call the monitor. Any help will be appreciated.

I assume that you are using SWT/JFace (you are not saying explicitly, but from the code snippet I guess you do).
Did you think about using SWT.VIRTUAL for you table?
Have a look at the TableViewer JavaDoc and the the ILazyContentProvider JavaDoc.
If you can't or don't want to use virtual tables, there's no easy way I know of to display a progress bar while performing setInput(), because setInput() has to be called from the UI thread and will block until finished. So there's not really a way of updating the UI while waiting for setInput to return (not if you don't implement the viewer and the setInput method yourself, at least)...

Related

Xamarin c# Loader example?

This problem is for Xamarin Android C# , but if someone can help in java I'm sure I can convert the code over ..
I'm trying to get some sort of automatic notification on a db that data has been inserted / deleted / etc.
There is outside apps that have access to the db in question, that insert / etc..
I've tried a file observer but it misses most of the inserts.
I've tried using content observer but it never fires a onchange
I've tried using the content observer inside a cursor but no onchange happens either.
(if I understand correctly they will only fire if I register a change occurred which is what I don't want)
Now I've discovered that loaders might be a solution..
They seem to have their own observer that fires when the data changes.
If this is also not an answer then perhaps a database trigger of some kind to notify my app the data was modified ?
I really need guidance here.. no idea how to properly implement a loader..
or if the content observer can be sufficient somehow with some sort of auto trigger as such..
OK, So!
The reason that file Observer was missing db inserts is because a SQLite DB is actually a 2 - 3 file object .. if you watch "Example.DB" then you can miss insert that can happen on Example.DB-shm or Example.DB-wal..
The fix to this, and its not a great fix, is to instead watch the folder ..
doing this will catch all inserts/deletes ..
The problem with this is that it will cause multiple OnChange() 's to execute..
So when coding a file observer like this, you have to either call the stopwatch() while you process the call and switch it on afterwards
OR
Have a "Global Variable" (C# guys are gonna swear at me for calling it that)
or static var
that lets the app know that you are already busy on the event so don't execute the code till the previous call has been completed ..

rJava startMainLoop() function kills Java operations

I've developed an interface that allows a user to load and manipulate data. The GUI is developed in Java and all the computational stuff is done in the background by R, linking the two with jri. The idea is that the user doesn't have to have any knowledge of R to use it, it's all options and buttons. However, i'd like to give the user the option to write some code if necessary. So here is my problem:
If I use the following code to start the Rengine and not let the user interact via console, everything works fine:
Rengine re=new Rengine(null, false, new TextConsole());
But if I use this:
Rengine re=new Rengine(null, true, new TextConsole());
The functionality of the gui doesnt work. I tried using the
re.startMainLoop();
function after the data was loaded. I was able to manipulate the data from the comand line in R, for example I could make a new variable from a column of the data loaded:
newVariable<-data$column1
But yet again, I couldn't use the gui anymore. Has anyone got any ideas or explainations as to why this is?
Thanks in advance,
Aran
Fundamentally, if REPL is not running, R is simply used via eval calls from your code. You have control at all times, except during the actual evaluation. That is the most common use, because you can do pretty much anything that way.
The moment you enable the event loop (REPL), you have to implement the callback methods that are used by the loop. By design R surrenders the control only by calling the rReadConsole callback which you have to implement. The example TextConsole works only as a demo, it uses blocking call (readLine()) to wait so you definitely don't want to use that in your GUI. You'll have to implement all callbacks correspondingly to react to your GUI's elements (wait in ReadConsole for your GUI to wake it up from a separate thread, dispatch WriteConsole to your elements etc.). You can have a look at JGR how it's done properly. Unless you are really building a general purpose R GUI, I wouldn't go into that trouble ...
(PS: please use stats-rosuda-devel mailing list for rJava/JRI questions - you get answers much faster)

JTable wait indicator

I have java applet with JTable. Due to lots of data and poor network bandwidth it takes lots of time to perform any operation like load the table or change it.
I'm thinking about adding sort of activity indicator to let user know that his request is processing.
Before i use JProgressBar, I'd like to know whether there are other options like ajax activity flower.
The easiest way would be setting a (not animated) WAIT_CURSOR
// Setting cursor for any Component:
component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
doProcessing();
component.setCursor(Cursor.getDefaultCursor());
see http://www.catalysoft.com/articles/busyCursor.html
For an animated cursor see:
http://book.javanb.com/swing-hacks/swinghacks-chp-12-sect-2.html
SwingWorker was designed for this, as suggested in this example. In particular, "Note that it safe to mutate the tableModel from inside the process method because it is invoked on the Event Dispatch Thread."—publish()
You can use JBusyComponent for this. Just wrap your Table or the Scrollpane in the JBusyComponent. But remember to load the data outside the event dispatch thread. For this you can use the SwingWorker as suggested in the other answer. JBusyComponent already provides a BusySwingWorker for this.

background process using thread

I want to continuously check a table in the database to see whether a new row has been added to it. This runs as a back ground process. I think a thread should be used for this task. but I have no idea how to write the code. Can somebody help me with this please?
Well, you're not really giving us much to go on here.
You might find it easier to use a database trigger, which will fire some code whenever a specified action occurs (e.g. insertion of new data). You will need to look up details for your specific database.
I just realised that you have probably already tried to use triggers and failed: sql trigger not work as expected. Either approach will work, but I would prefer keeping everything in the DB and avoiding external processes if possible.
What should happen if an insert occurs but your process has died for some reason?
Oracle can now communicate to Java via listener. So if you register for some event, your Java listener will receive that event from the database.

java: any way to detect changes in display configuration?

One of my coworkers would like my Swing app to adapt correctly to the removal of a 2nd display monitor.
Is there any way to get notification of this, other than polling to repeatedly compute virtual bounds? (per the code sample in http://download.oracle.com/javase/6/docs/api/java/awt/GraphicsConfiguration.html)
Hum, tricky one. Because GraphicsConfiguration class won't give us any listeners, I'll have only a couple of alternatives:
(If Windows) Use a JNI interface to
Windows to detect display settings
change and forward them to Java.
This would be the
SystemEvents::DisplaySettingsChanged
Event.
Create a simple polling Thread -
timer that retrieves the result of
Toolkit.getDefaultToolkit().getScreenSize()
as you've already stated before.

Categories