[go: up one dir, main page]

Skip to main content


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 #541506] Mon, 21 June 2010 12:20 Go to next message
Xavier Coulon is currently offline Xavier CoulonFriend
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 Wink

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.getTreePathFromItem(AbstractTreeViewer.java:2866)
	at org.eclipse.jface.viewers.AbstractTreeViewer.internalGetWidgetToSelect(AbstractTreeViewer.java:1679)
	at org.eclipse.jface.viewers.AbstractTreeViewer.internalExpand(AbstractTreeViewer.java:1574)
	at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToWidget(AbstractTreeViewer.java:2463)
	at org.eclipse.ui.navigator.CommonViewer.setSelectionToWidget(CommonViewer.java:451)
	at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToWidget(AbstractTreeViewer.java:2900)
	at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1399)
	at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:402)
	at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1353)
	at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1482)
	at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:548)
	at org.eclipse.ui.navigator.CommonViewer.refresh(CommonViewer.java:358)
	at org.eclipse.ui.navigator.CommonViewer.refresh(CommonViewer.java:515)
	at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1414)
	at org.bytesparadise.tools.jaxrs.ui.cnf.ContentProvider.resourceChanged(ContentProvider.java:103)
	at org.eclipse.core.internal.events.NotificationManager$2.run(NotificationManager.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.broadcastChanges(NotificationManager.java:149)
	at org.eclipse.core.internal.resources.Workspace.broadcastBuildEvent(Workspace.java:297)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.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 #541508 is a reply to message #541506] Mon, 21 June 2010 12:27 Go to previous messageGo to next message
Cameron Ross is currently offline Cameron RossFriend
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 #541562 is a reply to message #541508] Mon, 21 June 2010 14:46 Go to previous message
Xavier Coulon is currently offline Xavier CoulonFriend
Messages: 58
Registered: July 2009
Member
Hello Cameron,

Thank you, it works great !

Regards,

Xavier
Previous Topic:how to modify existing plugin
Next Topic:[CommonNavigator] Programmatically / Automatically refresh non-resource content
Goto Forum:
  


Current Time: Thu Dec 12 18:41:50 GMT 2024

Powered by FUDForum. Page generated in 0.04131 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top