Author: adietish
Date: 2010-12-02 09:33:09 -0500 (Thu, 02 Dec 2010)
New Revision: 27098
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
Log:
[JBIDE-7789] fixed NPE when invalid cloud is selected in combo. images was NULL
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-02 14:21:09
UTC (rev 27097)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-02 14:33:09
UTC (rev 27098)
@@ -1,5 +1,8 @@
2010-12-02 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java
+ (inputChanged):
+ [JBIDE-7789] fixed NPE when invalid cloud is selected in combo. images was NULL
* src/org/jboss/tools/deltacloud/ui/views/CVCloudElement.java (getChildren):
[JBIDE-7780] synchronized children initialisation
* src/org/jboss/tools/deltacloud/ui/views/CloudViewElement.java (getName):
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-02
14:21:09 UTC (rev 27097)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageViewLabelAndContentProvider.java 2010-12-02
14:33:09 UTC (rev 27098)
@@ -26,12 +26,13 @@
/**
* @author Jeff Johnston
+ * @author André Dietisheim
*/
public class ImageViewLabelAndContentProvider extends BaseLabelProvider implements
ITableContentAndLabelProvider {
private DeltaCloud cloud;
private IImageFilter localFilter;
- private DeltaCloudImage[] images = new DeltaCloudImage[]{};
+ private DeltaCloudImage[] images = new DeltaCloudImage[] {};
public enum Column {
NAME(0, 20),
@@ -73,6 +74,9 @@
@Override
public Object[] getElements(Object inputElement) {
+ if (images == null) {
+ return new DeltaCloudImage[] {};
+ }
return images;
}
@@ -85,36 +89,48 @@
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (newInput != null) {
- if (newInput instanceof DeltaCloudImage[]) {
- images = filter((DeltaCloudImage[]) newInput);
- } else if (newInput instanceof DeltaCloud){
- cloud = (DeltaCloud) newInput;
- try {
- images = filter(cloud.getImages());
- } catch (Exception e) {
- ErrorUtils.handleError(
- "Error",
- "Could not display images for cloud " + cloud.getName(),
- e, Display.getDefault().getActiveShell());
- }
+ if (newInput instanceof DeltaCloud) {
+ this.cloud = (DeltaCloud) newInput;
}
+ this.images = filter(cloud, getImages(newInput));
}
}
+ private DeltaCloudImage[] getImages(Object newInput) {
+ DeltaCloudImage[] images = new DeltaCloudImage[] {};
+ if (newInput instanceof DeltaCloudImage[]) {
+ images = ((DeltaCloudImage[]) newInput);
+ } else if (newInput instanceof DeltaCloud) {
+ cloud = (DeltaCloud) newInput;
+ try {
+ return cloud.getImages();
+ } catch (Exception e) {
+ ErrorUtils.handleError(
+ "Error",
+ "Could not display images for cloud " + cloud.getName(),
+ e, Display.getDefault().getActiveShell());
+ }
+
+ }
+ return images;
+ }
+
// Allow override of filter for Finding Images
public void setFilter(IImageFilter filter) {
this.localFilter = filter;
}
- private DeltaCloudImage[] filter(DeltaCloudImage[] input) {
+ private DeltaCloudImage[] filter(DeltaCloud cloud, DeltaCloudImage[] input) {
ArrayList<DeltaCloudImage> array = new ArrayList<DeltaCloudImage>();
IImageFilter f = localFilter;
- if (localFilter == null)
+ if (localFilter == null && cloud != null) {
f = cloud.getImageFilter();
+ }
for (int i = 0; i < input.length; ++i) {
DeltaCloudImage image = input[i];
- if (f.isVisible(image))
+ if (f != null && f.isVisible(image)) {
array.add(image);
+ }
}
return array.toArray(new DeltaCloudImage[array.size()]);
}
Show replies by date