Author: adietish
Date: 2010-12-02 09:20:04 -0500 (Thu, 02 Dec 2010)
New Revision: 27096
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
Log:
[JBIDE-7693] remove listener before loading children. children would get added twice
otherwise (model gets new children, notifies view while we are already getting and adding
them.
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java 2010-12-02
14:18:03 UTC (rev 27095)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java 2010-12-02
14:20:04 UTC (rev 27096)
@@ -37,66 +37,42 @@
return CVMessages.getString(IMAGE_CATEGORY_NAME);
}
- private void addImages(DeltaCloudImage[] images) {
- if (images.length > CVNumericFoldingElement.FOLDING_SIZE) {
- int min = 0;
- int max = CVNumericFoldingElement.FOLDING_SIZE;
- int length = images.length;
- while (length > CVNumericFoldingElement.FOLDING_SIZE) {
- CVNumericFoldingElement f = new CVNumericFoldingElement(min, max);
- addChild(f);
- for (int i = min; i < max; ++i) {
- DeltaCloudImage d = images[i];
- CVImageElement element = new CVImageElement(d);
- f.addChild(element);
- }
- min += CVNumericFoldingElement.FOLDING_SIZE;
- max += CVNumericFoldingElement.FOLDING_SIZE;
- length -= CVNumericFoldingElement.FOLDING_SIZE;
- }
- if (length > 0) {
- CVNumericFoldingElement f = new CVNumericFoldingElement(min, max);
- addChild(f);
- for (int i = min; i < min + length; ++i) {
- DeltaCloudImage d = images[i];
- CVImageElement element = new CVImageElement(d);
- f.addChild(element);
- }
- }
- } else {
- for (int i = 0; i < images.length; ++i) {
- DeltaCloudImage d = images[i];
- CVImageElement element = new CVImageElement(d);
- addChild(element);
- }
- }
- }
-
@Override
- public Object[] getChildren() {
+ public synchronized Object[] getChildren() {
if (!initialized) {
DeltaCloud cloud = (DeltaCloud) getElement();
try {
- DeltaCloudImage[] images = filter(cloud.getImages());
cloud.removeImageListListener(this);
- addImages(images);
+ DeltaCloudImage[] images = filter(cloud.getImages());
+ addChildren(images);
initialized = true;
- cloud.addImageListListener(this);
} catch (Exception e) {
ErrorUtils.handleError(
"Error",
"Colud not get images from cloud " + cloud.getName(),
e, getViewer().getControl().getShell());
+ } finally {
+ cloud.addImageListListener(this);
}
}
return super.getChildren();
}
@Override
- public void listChanged(DeltaCloud cloud, DeltaCloudImage[] newImages) {
+ protected CloudViewElement[] getElements(Object[] modelElements, int startIndex, int
stopIndex) {
+ CloudViewElement[] elements = new CloudViewElement[stopIndex - startIndex];
+ for (int i = startIndex; i < stopIndex; ++i) {
+ elements[i - startIndex] = new CVImageElement(modelElements[i]);
+ }
+ return elements;
+ }
+
+ @Override
+ public synchronized void listChanged(DeltaCloud cloud, DeltaCloudImage[] newImages) {
clearChildren();
+ initialized = false;
DeltaCloudImage[] images = filter(newImages);
- addImages(images);
+ addChildren(images);
initialized = true;
// refresh();
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-12-02
14:18:03 UTC (rev 27095)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-12-02
14:20:04 UTC (rev 27096)
@@ -38,40 +38,6 @@
return CVMessages.getString(INSTANCE_CATEGORY_NAME);
}
- private void addInstances(DeltaCloudInstance[] instances) {
- if (instances.length > CVNumericFoldingElement.FOLDING_SIZE) {
- int min = 0;
- int max = CVNumericFoldingElement.FOLDING_SIZE;
- int length = instances.length;
- while (length > CVNumericFoldingElement.FOLDING_SIZE) {
- CVNumericFoldingElement f = new CVNumericFoldingElement(min, max);
- addChild(f);
- for (int i = min; i < max; ++i) {
- DeltaCloudInstance d = instances[i];
- CVInstanceElement element = new CVInstanceElement(d);
- f.addChild(element);
- }
- min += CVNumericFoldingElement.FOLDING_SIZE;
- max += CVNumericFoldingElement.FOLDING_SIZE;
- length -= CVNumericFoldingElement.FOLDING_SIZE;
- }
- if (length > 0) {
- CVNumericFoldingElement f = new CVNumericFoldingElement(min, max);
- addChild(f);
- for (int i = min; i < min + length; ++i) {
- DeltaCloudInstance d = instances[i];
- CVInstanceElement element = new CVInstanceElement(d);
- f.addChild(element);
- }
- }
- } else {
- for (int i = 0; i < instances.length; ++i) {
- DeltaCloudInstance d = instances[i];
- CVInstanceElement element = new CVInstanceElement(d);
- addChild(element);
- }
- }
- }
@Override
public Object[] getChildren() {
@@ -80,25 +46,41 @@
try {
cloud.removeInstanceListListener(this);
DeltaCloudInstance[] instances = filter(cloud.getInstances());
- addInstances(instances);
+ addChildren(instances);
initialized = true;
- cloud.addInstanceListListener(this);
} catch (Exception e) {
// TODO: internationalize strings
ErrorUtils.handleError(
"Error",
"Colud not get instances from cloud " + cloud.getName(),
e, Display.getDefault().getActiveShell());
+ } finally {
+ cloud.addInstanceListListener(this);
}
}
return super.getChildren();
}
@Override
+ protected CloudViewElement[] getElements(Object[] modelElements, int startIndex, int
stopIndex) {
+ CloudViewElement[] elements = new CloudViewElement[stopIndex - startIndex];
+ for (int i = startIndex; i < stopIndex; ++i) {
+ elements[i - startIndex] = new CVInstanceElement(modelElements[i]);
+ }
+ return elements;
+ }
+
+ protected void addChildrenFor(Object[] modelElements, int startIndex, int stopIndex) {
+ for (int i = startIndex; i < stopIndex; ++i) {
+ addChild(new CVInstanceElement(modelElements[i]));
+ }
+ }
+
+ @Override
public void listChanged(DeltaCloud cloud, DeltaCloudInstance[] newInstances) {
clearChildren();
final DeltaCloudInstance[] instances = filter(newInstances);
- addInstances(instances);
+ addChildren(instances);
initialized = true;
// refresh();
}
Show replies by date