Author: xcoulon
Date: 2012-02-09 10:36:34 -0500 (Thu, 09 Feb 2012)
New Revision: 38561
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java
Log:
Fixed -
https://issues.jboss.org/browse/JBIDE-10836
AssertionFailedException: null argument when updating project configuration
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2012-02-09
15:25:29 UTC (rev 38560)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2012-02-09
15:36:34 UTC (rev 38561)
@@ -19,10 +19,11 @@
import java.util.Map;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.internal.ui.util.CoreUtility;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
@@ -34,7 +35,6 @@
import org.jboss.tools.ws.jaxrs.core.pubsub.Subscriber;
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
-@SuppressWarnings("restriction")
public class UriMappingsContentProvider implements ITreeContentProvider, Subscriber { //
,
private TreeViewer viewer;
@@ -49,32 +49,36 @@
}
@Override
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ @Override
public Object[] getChildren(final Object parentElement) {
if (parentElement instanceof IProject) {
+ final IProject project = (IProject) parentElement;
+ if(!uriPathTemplateCategories.containsKey(project)) {
+ UriPathTemplateCategory uriPathTemplateCategory = new UriPathTemplateCategory(this,
project);
+ uriPathTemplateCategories.put(project, uriPathTemplateCategory);
+ }
+ Logger.debug("Displaying the UriPathTemplateCategory for project
'{}'", project.getName());
+ return new Object[] { uriPathTemplateCategories.get(project) };
+ }
+ if (parentElement instanceof UriPathTemplateCategory) {
+
long startTime = new Date().getTime();
- final IProject project = (IProject) parentElement;
+ final UriPathTemplateCategory uriPathTemplateCategory = (UriPathTemplateCategory)
parentElement;
+ final IProject project = uriPathTemplateCategory.getProject();
try {
- if (!uriPathTemplateCategories.containsKey(project)) {
- if (JaxrsMetamodelLocator.get(project) == null) {
- Logger.debug("JAX-RS Metamodel needs to be built for project '" +
project.getName() + "'");
- Job buildJob = CoreUtility.getBuildJob(project);
- buildJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
- buildJob.schedule();
- Logger.debug("Displaying a temporary node in the viewer while the metamodel is
being built...");
- //return new Object[] { new WaitWhileBuildingElement() };
- }
- else {
- // edge case: if the metamodel was built but no category was initialized yet.
- Logger.debug("Adding a UriPathTemplateCategory for project {} (case #2)",
project.getName());
- UriPathTemplateCategory uriPathTemplateCategory = new UriPathTemplateCategory(this,
project);
- uriPathTemplateCategories.put(project, uriPathTemplateCategory);
- }
+ if (JaxrsMetamodelLocator.get(project) == null) {
+ launchLoadingMetamodelJob(uriPathTemplateCategory);
+ // return a stub object that says loading...
+ Logger.debug("Displaying the 'Loading...' stub for project
'{}'", project.getName());
+ return new Object[]{new LoadingStub()};
}
-
- Logger.debug("Displaying the UriPathTemplateCategory for project
'{}'", project.getName());
- return new Object[] { uriPathTemplateCategories.get(project) };
- } catch (CoreException e) {
- Logger.error("Failed to retrieve JAX-RS Metamodel in project '" +
project.getName() + "'", e);
+ return uriPathTemplateCategory.getChildren();
+ } catch(CoreException e) {
+ Logger.error("Failed to retrieve JAX-RS Metamodel for project '" +
project.getName() + "'", e);
} finally {
long endTime = new Date().getTime();
Logger.debug("JAX-RS Metamodel UI for project '" + project.getName() +
"' refreshed in "
@@ -85,10 +89,37 @@
return ((ITreeContentProvider) parentElement).getChildren(parentElement);
}
Logger.debug("*** No children for parent of type '{}' ***",
parentElement.getClass().getName());
-
+
return null;
}
+ private void launchLoadingMetamodelJob(final UriPathTemplateCategory
uriPathTemplateCategory) {
+ final IProject project = uriPathTemplateCategory.getProject();
+ Job job = new Job("Loading JAX-RS metamodel for project '" +
project.getName() + "'...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Loading JAX-RS metamodel for project '" +
project.getName() + "'...",
+ IProgressMonitor.UNKNOWN);
+ monitor.worked(1);
+
+ refreshViewerObject(uriPathTemplateCategory);
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+ };
+ job.setPriority(Job.LONG);
+ job.schedule();
+ }
+
+ private void refreshViewerObject(final Object object) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ viewer.refresh(object);
+ }
+ });
+ }
+
@Override
public Object getParent(Object element) {
return null;
@@ -96,10 +127,9 @@
@Override
public boolean hasChildren(Object element) {
- if(element instanceof IProject) {
+ if (element instanceof IProject) {
return true;
- } else
- if (element instanceof ITreeContentProvider) {
+ } else if (element instanceof ITreeContentProvider) {
return ((ITreeContentProvider) element).hasChildren(element);
}
Logger.debug("Element {} has not children", element.getClass().getName());
@@ -107,11 +137,6 @@
}
@Override
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
- @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
this.viewer = (TreeViewer) viewer;
}
@@ -158,7 +183,8 @@
public void run() {
if (viewer != null) {
TreePath[] treePaths = viewer.getExpandedTreePaths();
- Logger.debug("*** Refreshing the viewer at target level: {} (viewer busy: {})
***", target, viewer.isBusy());
+ Logger.debug("*** Refreshing the viewer at target level: {} (viewer busy: {})
***", target,
+ viewer.isBusy());
viewer.refresh();
viewer.setExpandedTreePaths(treePaths);
Logger.debug("*** Refreshing the viewer... done ***");
@@ -176,5 +202,10 @@
public String getId() {
return "UI";
}
+
+ public static class LoadingStub {
+ public LoadingStub() {
+ }
+ }
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java 2012-02-09
15:25:29 UTC (rev 38560)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java 2012-02-09
15:36:34 UTC (rev 38561)
@@ -22,6 +22,7 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
import org.jboss.tools.ws.jaxrs.ui.JBossJaxrsUIPlugin;
+import org.jboss.tools.ws.jaxrs.ui.cnf.UriMappingsContentProvider.LoadingStub;
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
/** @author xcoulon */
@@ -53,9 +54,9 @@
}
} else if (element instanceof UriPathTemplateMethodMappingElement) {
return JBossJaxrsUIPlugin.getDefault().createImage("servlet_mapping.gif");
- } else if (element instanceof WaitWhileBuildingElement) {
+ } else if (element instanceof LoadingStub) {
return JBossJaxrsUIPlugin.getDefault().createImage("systemprocess.gif");
- }
+ }
return null;
}
@@ -163,8 +164,8 @@
.append("(...)");
return new StyledString(sb.toString());
}
- if (element instanceof WaitWhileBuildingElement) {
- String message = "Building RESTful Web Services...";
+ if (element instanceof LoadingStub) {
+ String message = "Loading...";
StyledString styledString = new StyledString(message);
styledString.setStyle(0, message.length(), StyledString.DECORATIONS_STYLER);
return new StyledString(message);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java 2012-02-09
15:25:29 UTC (rev 38560)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java 2012-02-09
15:36:34 UTC (rev 38561)
@@ -74,6 +74,13 @@
return project;
}
+ /**
+ * @return the project
+ */
+ public final IProject getProject() {
+ return project;
+ }
+
@Override
public boolean hasChildren(Object element) {
try {
@@ -120,4 +127,8 @@
parent.refreshContent(project);
}
+ public Object[] getChildren() {
+ return getChildren(this);
+ }
+
}
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java 2012-02-09
15:25:29 UTC (rev 38560)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java 2012-02-09
15:36:34 UTC (rev 38561)
@@ -1,15 +0,0 @@
-/**
- *
- */
-package org.jboss.tools.ws.jaxrs.ui.cnf;
-
-
-/**
- * ElementKind displayed while the project's metamodel is built in background.
- *
- * @author xcoulon
- *
- */
-public class WaitWhileBuildingElement {
-
-}