Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » [CommonNavigator] Programmatically / Automatically refresh non-resource content
[CommonNavigator] Programmatically / Automatically refresh non-resource content [message #606140] Mon, 21 June 2010 08:20 Go to next message
Xavier Coulon is currently offline Xavier Coulon
Messages: 58
Registered: July 2009
Member
Hello,

I'm working on a plugin that's aimed at helping Web developpers building RESTFul applications using the JAX-RS spec, within Eclipse ;)

For now, I have a builder that is configured with a facet and that builds an internal JAX-RS "registry", which is stored in the Project's session properties. This "registry" is based on annotations found on classes of the project, so it is not bound to a particular resource.

To display this registry, I added a custom navigatorContent that is associated to the "Project Explorer" viewer.
This works almost fine : when I clean the project, a "full build" is triggered, and the "registry" is initialized and stored in the project. But on the UI side, I cannot programmatically refresh the viewer.

I tried to add a my ITreeContentProvider impl as an IResourceChangeListener for POST_BUILD event as below:
public ContentProvider() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD);
}
, so that when the build is done, I can trigger a viewer.refresh() :
public void resourceChanged(IResourceChangeEvent event) {

((TreeViewer)viewer).refresh();
}


But this approach fails with a SWTException :
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.SWT.error(SWT.java:3770)
at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:355)
at org.eclipse.swt.widgets.Widget.getData(Widget.java:521)
at org.eclipse.jface.viewers.AbstractTreeViewer.getTreePathFrom Item(AbstractTreeViewer.java:2866)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalGetWidg etToSelect(AbstractTreeViewer.java:1679)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalExpand( AbstractTreeViewer.java:1574)
at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToW idget(AbstractTreeViewer.java:2463)
at org.eclipse.ui.navigator.CommonViewer.setSelectionToWidget(C ommonViewer.java:451)
at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToW idget(AbstractTreeViewer.java:2900)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1399)
at org.eclipse.jface.viewers.TreeViewer.preservingSelection(Tre eViewer.java:402)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1353)
at org.eclipse.jface.viewers.StructuredViewer.refresh(Structure dViewer.java:1482)
at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer. java:548)
at org.eclipse.ui.navigator.CommonViewer.refresh(CommonViewer.j ava:358)
at org.eclipse.ui.navigator.CommonViewer.refresh(CommonViewer.j ava:515)
at org.eclipse.jface.viewers.StructuredViewer.refresh(Structure dViewer.java:1414)
at org.bytesparadise.tools.jaxrs.ui.cnf.ContentProvider.resourc eChanged(ContentProvider.java:103)
at org.eclipse.core.internal.events.NotificationManager$2.run(N otificationManager.java:291)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.NotificationManager.notify( NotificationManager.java:285)
at org.eclipse.core.internal.events.NotificationManager.broadca stChanges(NotificationManager.java:149)
at org.eclipse.core.internal.resources.Workspace.broadcastBuild Event(Workspace.java:297)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBu ildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJ ob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


How can I automatically/programmatically refresh the navigator content, since the content is not bound to a particular resource ?

Thank you in advance
Regards,
Xavier
Re: [CommonNavigator] Programmatically / Automatically refresh non-resource content [message #606147 is a reply to message #606140] Mon, 21 June 2010 08:27 Go to previous messageGo to next message
Cameron Ross is currently offline Cameron Ross
Messages: 31
Registered: May 2010
Member
Looks like this is being called on a non-UI thread. Try something like the following:

public void resourceChanged(IResourceChangeEvent event) {
if (Display.getCurrent() != null) {
if (viewer != null)
viewer.refresh();
} else
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (viewer != null)
viewer.refresh();
}});
}

Cameron.
Re: [CommonNavigator] Programmatically / Automatically refresh non-resource content [message #606149 is a reply to message #606147] Mon, 21 June 2010 10:46 Go to previous message
Xavier Coulon is currently offline Xavier Coulon
Messages: 58
Registered: July 2009
Member
Hello Cameron,

Thank you, it works great !

Regards,

Xavier
Previous Topic:[CommonNavigator] Programmatically / Automatically refresh non-resource content
Next Topic:Exported eclipse product doesn't launch
Goto Forum:
  


Current Time: Wed Aug 27 11:04:22 EDT 2014

Powered by FUDForum. Page generated in 0.02441 seconds