Updating the status message dynamically of an eclipse rcp application by using a worker thread
Tech-Today

Updating the status message dynamically of an eclipse rcp application by using a worker thread


Objective:
-To create an eclipse application that will dynamically update the action bar's status message from a worker thread. Updating a part of the screen in another thread is a good practice, since it will not make your screen blink, also the screen will not look like it hanged.

Requirements:
-eclipse-rcp (eclipse.org)

1.) create a new eclipse-rcp project with a view
2.) create a new class which will implement a Runnable interface (worker thread), name it StatusUpdater
public class StatusUpdater implements Runnable {
private ViewPart1 view;

public StatusUpdater(ViewPart1 view) {
this.view = view;
}

@Override
public void run() {
int i = 0;
while(true) {
view.updateStatus("Counter: "+i);
i++;
try {
Thread.sleep(1000);
} catch(InterruptedException e) {

}
}
}
}
What you should notice:
-the constructor has a ViewPart1 parameter (which will be the only view that we defined)
-view.updateStatus is a method in the ViewPart1

Going back into the ViewPart1 class
1.) in the createPartControl method, we will instantiate our StatusUpdater class
public void createPartControl(Composite parent) {
Thread t = new Thread(new StatusUpdater(this));
t.start();
}

And finally the updateStatus method
 public void updateStatus(final String s) {
final IActionBars bars = getViewSite().getActionBars();
//not Display.getCurrent() and new Display(), both will throw exception
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
bars.getStatusLineManager().setMessage(s);
}
});
}




- How To Monitor The Data Source Connections And Sql Queries In Jboss
To allow us to debug our jboss server for possible connection leaks, wrong sql queries normally we do 2 changes: 1.) In persistence.xml, set hibernate.show_sql to true 2.) In jboss's standalone.xml, we set the hibernate logger to DEBUG <logger...

- Add Eclipse-rcp's Views Short List, Perspective Short List In The Org.eclipse.ui.menus Plugin Via Dynamic Compoundcontributionitem Class
Recently, I've encountered a problem wherein I wanted to display the eclipse-rcp's list of view, perspective etc using the extension org.eclipse.ui.menus. The problem can easily solved by the ApplicationActionBarAdvisor, see the code below: private...

- Open A View In The Eclipse-rcp's Extension Tab Using The Showviewhandler Class
Let's do this quick. 1.) Create a new HelloWorld Plug-in Project and name it CommandParameter. 2.) Open the plugin.xml and click the Extensions tab. 3.) In the All Extensions tab click the Add button and under the Extension Point Filter: search "view"....

- Execute An Eclipse-rcp Command And Open An Eclipse-rcp View In Code
Objective: 1.) To execute an eclipse rcp command in code 2.) To open an eclipse rcp view in command Most of the time you will just use the extension tab in the plugin.xml but for those who chose to implement in code here's how they're done: Solution:...

- Eclipse-rcp Shows A Blank Perspective When Adding View Dynamically And Overriding The Applicationworkbenchadvisor's Initialize Method
How to recreate the problem: 1.) create a new Hello World plugin project in eclipse rcp 2.) add extension org.eclipse.ui.views in plugin.xml->Extensions 3.) right click the extension and select New->view 4.) enter an id and a class name 5.) right...



Tech-Today








.