So I have an SWT thread, an eclipse plugin that consists of a simple view myView
, with a JPanel myJPanel
and a JTree myJTree
embedded into it. With a listener on the Swing thread, when the selection change on my JTree it refresh JPanel into the Swing thread.
Simplified code version of my myView
:
public class myView extends ViewPart {
public java.awt.Frame myFrame;
@Override
public void createPartControl(Composite parent) {
Composite myComposite = new Composite(parent, SWT.EMBEDDED);
myFrame = SWT_AWT.new_Frame(myComposite);
myFrame.add(myJPanel);
myFrame.repaint();
myFrame.revalidate();
//same kind of code for Jtree -> myJTreeFrame
}
What I want to do is to refresh myFrame
from the Swing thread, when the listener of myJTree
has to refresh myJPanel
I thought about this :
public void valueChanged(TreeSelectionEvent e) {
// some code that refresh myJPanel
Display.getDefault().asyncExec(
new Runnable() {
public void run() {
try {
myView view = (viewMap4j)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView( "pluginProject.myView");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
view.myFrame.repaint();
view.myFrame.revalidate();
}
});
}
But I get this error with librairies : No exception of type PartInitException can be thrown; an exception type must be a subclass of Throwable
My question is : How to access to an object from my SWT thread (here myView
) in a Swing thread?
and any ideas to make it work in this specific example?
This did the trick, it gave me access to myView
where I could find myFrame
to refresh it from the JTree listener :
PlatformUI.getWorkbench().getDisplay().asyncExec(
new Runnable() {
public void run() {
try {
myView view =null;
view = (myView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("pluginProject.myView");
view.reloadMyFrame();
} catch (CoreException e) {
e.printStackTrace();
}
}
});