Author: adietish
Date: 2010-12-04 06:28:21 -0500 (Sat, 04 Dec 2010)
New Revision: 27175
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
Log:
[JBIDE-7688] first implementation that loads elements in a background task
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java 2010-12-03
20:05:27 UTC (rev 27174)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementTableView.java 2010-12-04
11:28:21 UTC (rev 27175)
@@ -13,10 +13,6 @@
import java.util.ArrayList;
import java.util.List;
-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.jface.action.IMenuManager;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ColumnWeightData;
@@ -90,7 +86,7 @@
return;
}
- removeListener(currentCloud);
+// removeListener(currentCloud);
AbstractCloudElementTableView.this.currentCloud = getCurrentCloud(index,
getClouds());
if (currentCloud != null) {
@@ -100,7 +96,7 @@
@Override
public void run() {
setViewerInput(currentCloud);
- addListener(currentCloud);
+// addListener(currentCloud);
}
});
}
@@ -118,15 +114,15 @@
}
};
- private Job viewerInputJob = new Job("") {
+// private Job viewerInputJob = new Job("") {
+//
+// @Override
+// protected IStatus run(IProgressMonitor monitor) {
+//
+// return Status.OK_STATUS;
+// }
+// };
- @Override
- protected IStatus run(IProgressMonitor monitor) {
-
- return Status.OK_STATUS;
- }
- };
-
public AbstractCloudElementTableView() {
lastSelectedCloudPref = new TextPreferenceValue(getSelectedCloudPrefsKey(),
Activator.getDefault());
}
@@ -156,15 +152,8 @@
protected abstract String getSelectedCloudPrefsKey();
- protected abstract void addListener(DeltaCloud cloud);
-
- protected abstract void removeListener(DeltaCloud cloud);
-
@Override
public void dispose() {
- for (DeltaCloud cloud : getClouds()) {
- removeListener(cloud);
- }
DeltaCloudManager.getDefault().removeCloudManagerListener(this);
super.dispose();
}
@@ -191,7 +180,7 @@
currentCloud = getCurrentCloud(currentCloudSelector.getSelectionIndex(), clouds);
- addListener(currentCloud);
+// addListener(currentCloud);
setViewerInput(currentCloud);
setFilterLabelVisible(currentCloud, filterLabel);
@@ -406,27 +395,8 @@
*/
protected abstract void refreshToolbarCommandStates();
- public void listChanged(final DeltaCloud cloud, final CLOUDELEMENT[] cloudChildren) {
- // Run following under Display thread since this can be
- // triggered by a non-display thread notifying listeners.
- if (cloud != null
- && currentCloud != null
- && cloud.getName().equals(currentCloud.getName())) {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- // does not add identical instance twice
- addListener(cloud);
- setViewerInput(cloud);
- refreshToolbarCommandStates();
- }
- });
- }
- }
-
@Override
public void setFocus() {
viewer.getControl().setFocus();
}
-
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-03
20:05:27 UTC (rev 27174)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-04
11:28:21 UTC (rev 27175)
@@ -10,16 +10,23 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
-import java.util.Arrays;
-import java.util.Collection;
+import java.text.MessageFormat;
+import org.eclipse.core.runtime.Assert;
+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.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.ICloudElementFilter;
import org.jboss.tools.deltacloud.core.IDeltaCloudElement;
+import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.ErrorUtils;
/**
@@ -32,26 +39,13 @@
public abstract class AbstractCloudElementViewLabelAndContentProvider<CLOUDELEMENT
extends IDeltaCloudElement> extends
BaseLabelProvider implements ITableContentAndLabelProvider {
+ private DeltaCloud currentCloud;
private ICloudElementFilter<CLOUDELEMENT> localFilter;
+ private TableViewer viewer;
@Override
public Object[] getElements(Object input) {
- Object[] elements = new Object[] {};
- if (input instanceof DeltaCloud) {
- DeltaCloud cloud = (DeltaCloud) input;
- try {
- CLOUDELEMENT[] cloudElements = getCloudElements(cloud);
- ICloudElementFilter<CLOUDELEMENT> filter = getCloudFilter(cloud);
- elements = filter(filter, cloudElements).toArray();
- } catch (DeltaCloudException e) {
- // TODO: internationalize strings
- ErrorUtils.handleError(
- "Error",
- "Could not display elements for cloud " + cloud.getName(),
- e, Display.getDefault().getActiveShell());
- }
- }
- return elements;
+ return new Object[] {};
}
public void setFilter(ICloudElementFilter<CLOUDELEMENT> filter) {
@@ -59,26 +53,100 @@
}
@Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
+ if (!(newInput instanceof DeltaCloud)) {
+ return;
+ }
+ Assert.isTrue(viewer instanceof TableViewer);
+ this.viewer = (TableViewer) viewer;
+ removeListener(currentCloud);
+ this.currentCloud = (DeltaCloud) newInput;
+ addListener(currentCloud);
+ // TODO internationalize strings
+ final String workTitle = MessageFormat.format("Loading elements of cloud
\"{0}\"", currentCloud.getName());
+ new Job(workTitle) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ monitor.beginTask(workTitle, IProgressMonitor.UNKNOWN);
+ /*
+ * trigger load of elements, data will get in through
+ * notification (#listChanged)
+ */
+ getCloudElements(currentCloud);
+ monitor.done();
+ return Status.OK_STATUS;
+ } catch (DeltaCloudException e) {
+ return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
+ MessageFormat.format("Could not get elements of cloud
\"{0}\"", currentCloud.getName()), e);
+ }
+ }
+
+ }.schedule();
}
- protected Collection<CLOUDELEMENT> filter(ICloudElementFilter<CLOUDELEMENT>
filter, CLOUDELEMENT[] cloudElements)
- throws DeltaCloudException {
- if (filter == null && cloudElements != null) {
- return Arrays.asList(cloudElements);
- } else {
- return filter.filter(cloudElements);
+ public void listChanged(final DeltaCloud cloud, final CLOUDELEMENT[] cloudElements) {
+ if (isCurrentCloud(cloud)) {
+ addToViewer(cloudElements);
}
}
+ private boolean isCurrentCloud(final DeltaCloud cloud) {
+ return cloud != null
+ && currentCloud != null
+ && cloud.getName().equals(currentCloud.getName());
+ }
+
+ private void addToViewer(final CLOUDELEMENT[] cloudElements) {
+ viewer.getControl().getDisplay().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ Object[] elements = filter(getFilter(currentCloud), cloudElements);
+ viewer.add(elements);
+ } catch (DeltaCloudException e) {
+ // TODO: internationalize strings
+ ErrorUtils.handleError(
+ "Error",
+ "Could not get elements of clouds " + currentCloud.getName(),
+ e, Display.getDefault().getActiveShell());
+
+ }
+ }
+ });
+ }
+
private ICloudElementFilter<CLOUDELEMENT> getFilter(DeltaCloud cloud) {
if (localFilter != null) {
return localFilter;
} else {
- return getFilter(cloud);
+ return getCloudFilter(cloud);
}
}
+ protected Object[] filter(ICloudElementFilter<CLOUDELEMENT> filter, CLOUDELEMENT[]
cloudElements)
+ throws DeltaCloudException {
+ if (cloudElements == null) {
+ return new Object[] {};
+ }
+ if (filter == null) {
+ return cloudElements;
+ } else {
+ return filter.filter(cloudElements).toArray();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ removeListener(currentCloud);
+ }
+
+ protected abstract void addListener(DeltaCloud cloud);
+
+ protected abstract void removeListener(DeltaCloud cloud);
+
protected abstract ICloudElementFilter<CLOUDELEMENT> getCloudFilter(DeltaCloud
cloud);
protected abstract CLOUDELEMENT[] getCloudElements(DeltaCloud cloud) throws
DeltaCloudException;
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-12-03
20:05:27 UTC (rev 27174)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-12-04
11:28:21 UTC (rev 27175)
@@ -12,7 +12,6 @@
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
-import org.jboss.tools.deltacloud.core.IImageListListener;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
/**
@@ -23,7 +22,7 @@
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public class ImageView extends AbstractCloudElementTableView<DeltaCloudImage>
implements IImageListListener {
+public class ImageView extends AbstractCloudElementTableView<DeltaCloudImage> {
//implements IImageListListener {
@Override
protected String getSelectedCloudPrefsKey() {
@@ -44,20 +43,4 @@
protected void refreshToolbarCommandStates() {
// do nothing
}
-
- @Override
- protected void addListener(DeltaCloud currentCloud) {
- if (currentCloud != null) {
- currentCloud.removeImageListListener(this);
- currentCloud.addImageListListener(this);
- }
- }
-
- @Override
- protected void removeListener(DeltaCloud currentCloud) {
- if (currentCloud != null) {
- currentCloud.removeImageListListener(this);
- currentCloud.addImageListListener(this);
- }
- }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java 2010-12-03
20:05:27 UTC (rev 27174)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java 2010-12-04
11:28:21 UTC (rev 27175)
@@ -19,12 +19,14 @@
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
import org.jboss.tools.deltacloud.core.ICloudElementFilter;
+import org.jboss.tools.deltacloud.core.IImageListListener;
/**
* @author Jeff Johnston
* @author André Dietisheim
*/
-public class ImageViewLabelAndContentProvider extends
AbstractCloudElementViewLabelAndContentProvider<DeltaCloudImage> implements
ITableContentAndLabelProvider {
+public class ImageViewLabelAndContentProvider extends
AbstractCloudElementViewLabelAndContentProvider<DeltaCloudImage>
+ implements ITableContentAndLabelProvider, IImageListListener {
public enum Column {
NAME(0, 20),
@@ -95,4 +97,17 @@
return cloud.getImages();
}
+ @Override
+ protected void addListener(DeltaCloud currentCloud) {
+ if (currentCloud != null) {
+ currentCloud.addImageListListener(this);
+ }
+ }
+
+ @Override
+ protected void removeListener(DeltaCloud currentCloud) {
+ if (currentCloud != null) {
+ currentCloud.removeImageListListener(this);
+ }
+ }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-12-03
20:05:27 UTC (rev 27174)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-12-04
11:28:21 UTC (rev 27175)
@@ -14,7 +14,6 @@
import org.eclipse.ui.services.IEvaluationService;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-import org.jboss.tools.deltacloud.core.IInstanceListListener;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
/**
@@ -25,7 +24,7 @@
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public class InstanceView extends AbstractCloudElementTableView<DeltaCloudInstance>
implements IInstanceListListener {
+public class InstanceView extends AbstractCloudElementTableView<DeltaCloudInstance>
{
protected String getSelectedCloudPrefsKey() {
return IDeltaCloudPreferenceConstants.LAST_CLOUD_INSTANCE_VIEW;
@@ -50,19 +49,4 @@
evaluationService.requestEvaluation("org.jboss.tools.deltacloud.ui.commands.canReboot");
evaluationService.requestEvaluation("org.jboss.tools.deltacloud.ui.commands.canDestroy");
}
-
-
- protected void addListener(DeltaCloud currentCloud) {
- if (currentCloud != null) {
- currentCloud.removeInstanceListListener(this);
- currentCloud.addInstanceListListener(this);
- }
- }
-
- protected void removeListener(DeltaCloud currentCloud) {
- if (currentCloud != null) {
- currentCloud.removeInstanceListListener(this);
- currentCloud.addInstanceListListener(this);
- }
- }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-12-03
20:05:27 UTC (rev 27174)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceViewLabelAndContentProvider.java 2010-12-04
11:28:21 UTC (rev 27175)
@@ -21,6 +21,7 @@
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.core.ICloudElementFilter;
+import org.jboss.tools.deltacloud.core.IInstanceListListener;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
/**
@@ -28,7 +29,7 @@
* @author Andre Dietisheim
*/
public class InstanceViewLabelAndContentProvider extends
- AbstractCloudElementViewLabelAndContentProvider<DeltaCloudInstance> implements
ITableContentAndLabelProvider {
+ AbstractCloudElementViewLabelAndContentProvider<DeltaCloudInstance> implements
ITableContentAndLabelProvider, IInstanceListListener {
public enum Column {
NAME(0, 20),
@@ -125,4 +126,18 @@
return cloud.getInstances();
}
+ @Override
+ protected void addListener(DeltaCloud currentCloud) {
+ if (currentCloud != null) {
+ currentCloud.addInstanceListListener(this);
+ }
+ }
+
+ @Override
+ protected void removeListener(DeltaCloud currentCloud) {
+ if (currentCloud != null) {
+ currentCloud.removeInstanceListListener(this);
+ }
+ }
+
}