Author: rob.stryker(a)jboss.com
Date: 2012-02-09 08:10:55 -0500 (Thu, 09 Feb 2012)
New Revision: 38549
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleContentProvider.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleLabelProvider.java
Log:
Adds a loading... child in the viewer to prevent workspace freezes.
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleContentProvider.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleContentProvider.java 2012-02-09
12:38:39 UTC (rev 38548)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleContentProvider.java 2012-02-09
13:10:55 UTC (rev 38549)
@@ -1,7 +1,6 @@
package org.jboss.tools.openshift.express.internal.ui.viewer;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.TimeUnit;
+import java.util.ArrayList;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -9,7 +8,9 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Display;
import org.jboss.tools.openshift.express.internal.core.console.UserModel;
import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
@@ -19,6 +20,8 @@
public class OpenShiftExpressConsoleContentProvider implements ITreeContentProvider {
+ private StructuredViewer viewer;
+
@Override
public void dispose() {
// TODO Auto-generated method stub
@@ -27,56 +30,110 @@
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ this.viewer = (StructuredViewer)viewer;
}
+
+ public static class LoadingStub {
+ public LoadingStub() {
+ }
+ }
+ // Keep track of what's loading and what's finished
+ private ArrayList<IUser> loadedUsers = new ArrayList<IUser>();
+ private ArrayList<IUser> loadingUsers = new ArrayList<IUser>();
+
@Override
public Object[] getElements(final Object parentElement) {
if(parentElement instanceof IWorkspaceRoot) {
return UserModel.getDefault().getUsers();
}
if( parentElement instanceof UserModel ) {
- return ((UserModel)parentElement).getUsers();
+ IUser[] users = ((UserModel)parentElement).getUsers();
+ return users;
}
- final ArrayBlockingQueue<Object[]> queue = new
ArrayBlockingQueue<Object[]>(1);
- try {
- Job job = new Job("Loading OpenShift Express User information...") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- // TODO Auto-generated method stub
- monitor.beginTask("Loading OpenShift Express information...",
IProgressMonitor.UNKNOWN);
- monitor.worked(1);
- try {
- if (parentElement instanceof OpenShiftExpressConsoleContentCategory) {
- queue.offer(new Object[] { ((OpenShiftExpressConsoleContentCategory)
parentElement).getUser() });
- }
- if (parentElement instanceof IUser) {
- queue.offer(((IUser) parentElement).getApplications().toArray());
- }
- if (parentElement instanceof IApplication) {
- queue.offer(((IApplication) parentElement).getEmbeddedCartridges().toArray());
- }
- // .... the actual work is done here...
- } catch (OpenShiftException e) {
- Logger.error("Unable to retrieve OpenShift Express information", e);
- } finally {
- monitor.done();
- }
- return Status.OK_STATUS;
+ if( parentElement instanceof IUser ) {
+ if( !loadedUsers.contains(parentElement)) {
+ if( !loadingUsers.contains(parentElement)) {
+ // Load the data
+ launchLoadingUserJob((IUser)parentElement);
}
- };
- job.setPriority(Job.LONG);
- job.schedule();
- //job.join();
- return queue.poll(10, TimeUnit.SECONDS);
- } catch (Exception e) {
- Logger.error("Failed to load OpenShit Express account information", e);
+ // return a stub object that says loading...
+ return new Object[]{new LoadingStub()};
+ }
}
+ return getChildrenFor(parentElement, false);
+ }
- return null;
+ // Force the children to load completely
+ private void getChildrenFor(Object[] parentElements) {
+ for( int i = 0; i < parentElements.length; i++ ) {
+ getChildrenFor(parentElements[i], true);
+ }
}
-
+
+ // Get the children without the protection of a "loading..." situation
+ private Object[] getChildrenFor(Object parentElement, boolean recurse) {
+ // .... the actual work is done here...
+ Object[] children = new Object[0];
+ try {
+ if (parentElement instanceof OpenShiftExpressConsoleContentCategory) {
+ IUser user = ((OpenShiftExpressConsoleContentCategory) parentElement).getUser();
+ children = new Object[] { user };
+ }
+ if (parentElement instanceof IUser) {
+ children = ((IUser) parentElement).getApplications().toArray();
+ }
+ if (parentElement instanceof IApplication) {
+ children = ((IApplication) parentElement).getEmbeddedCartridges().toArray();
+ }
+
+ if( recurse ) {
+ getChildrenFor(children);
+ }
+ } catch (OpenShiftException e) {
+ Logger.error("Unable to retrieve OpenShift Express information", e);
+ }
+ return children;
+ }
+
+ private void launchLoadingUserJob(final IUser user) {
+ Job job = new Job("Loading OpenShift Express User information...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Loading OpenShift Express information...",
IProgressMonitor.UNKNOWN);
+ monitor.worked(1);
+ // Get the actual children, with the delay
+ loadingUsers.add(user);
+ getChildrenFor(user, true);
+
+ loadedUsers.add(user);
+ loadingUsers.remove(user);
+
+ // refresh the parent object in the viewer when finished
+ try {
+ Thread.sleep(10000);
+ } catch(InterruptedException ie) {
+
+ }
+ refreshViewerObject(user);
+ 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[] getChildren(Object parentElement) {
return getElements(parentElement);
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleLabelProvider.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleLabelProvider.java 2012-02-09
12:38:39 UTC (rev 38548)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleLabelProvider.java 2012-02-09
13:10:55 UTC (rev 38549)
@@ -1,12 +1,13 @@
package org.jboss.tools.openshift.express.internal.ui.viewer;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
+import
org.jboss.tools.openshift.express.internal.ui.viewer.OpenShiftExpressConsoleContentProvider.LoadingStub;
import com.openshift.express.client.IApplication;
import com.openshift.express.client.IEmbeddableCartridge;
@@ -88,6 +89,10 @@
styledString.setStyle(0, message.length(), StyledString.DECORATIONS_STYLER);
return new StyledString(message);
}
+
+ if( element instanceof LoadingStub) {
+ return new StyledString("Loading...");
+ }
return null;
}
Show replies by date