Author: adietish
Date: 2011-01-06 04:43:27 -0500 (Thu, 06 Jan 2011)
New Revision: 27941
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudElementCategoryItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/DeltaCloudViewItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImageItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImagesCategoryItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstanceItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstancesCategoryItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/LoadingItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/NumericFoldingItem.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/RootItem.java
Log:
[JBIDE-8052] reimplemented cloud view items
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudElementCategoryItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudElementCategoryItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudElementCategoryItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views.cloud;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.eclipse.jface.viewers.TreeViewer;
@@ -21,8 +22,8 @@
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public abstract class CloudElementCategoryItem<CLOUDELEMENT> extends
DeltaCloudViewItem<DeltaCloud> implements
- PropertyChangeListener {
+public abstract class CloudElementCategoryItem<CLOUDELEMENT> extends
DeltaCloudViewItem<DeltaCloud>
+ implements PropertyChangeListener {
protected CloudElementCategoryItem(DeltaCloud model, DeltaCloudViewItem<?> parent,
TreeViewer viewer) {
super(model, parent, viewer);
@@ -30,23 +31,21 @@
}
@Override
- public boolean hasChildren() {
- return true;
- }
-
- @Override
public Object[] getChildren() {
- if (!initialized.get()) {
- asyncAddCloudElements();
+ if (!areChildrenInitialized()) {
+ asyncLoadCloudElements();
+ setChildrenInitialized(true);
}
return super.getChildren();
}
protected void setLoadingIndicator() {
- children.add(new LoadingItem(this, viewer));
+ clearChildren();
+ addChild(new LoadingItem(this, getViewer()));
+// refresh();
}
- protected abstract void asyncAddCloudElements();
+ protected abstract void asyncLoadCloudElements();
protected void addChildren(CLOUDELEMENT[] modelElements) {
if (modelElements.length > NumericFoldingItem.FOLDING_SIZE) {
@@ -61,7 +60,7 @@
int max = NumericFoldingItem.FOLDING_SIZE;
int length = modelElements.length;
while (length > NumericFoldingItem.FOLDING_SIZE) {
- NumericFoldingItem f = new NumericFoldingItem(min, max, this, viewer);
+ NumericFoldingItem f = new NumericFoldingItem(min, max, this, getViewer());
addChild(f);
f.addChildren(getElements(modelElements, min, max));
min += NumericFoldingItem.FOLDING_SIZE;
@@ -69,22 +68,17 @@
length -= NumericFoldingItem.FOLDING_SIZE;
}
if (length > 0) {
- NumericFoldingItem f = new NumericFoldingItem(min, max, this, viewer);
+ NumericFoldingItem f = new NumericFoldingItem(min, max, this, getViewer());
addChild(f);
f.addChildren(getElements(modelElements, min, min + length));
}
}
protected void onCloudElementsChanged(DeltaCloud cloud, CLOUDELEMENT[] cloudElements)
throws DeltaCloudException {
- try {
- clearChildren();
- initialized.set(false);
- final CLOUDELEMENT[] filteredElements = filter(cloudElements);
- addChildren(filteredElements);
- expand();
- } finally {
- initialized.set(true);
- }
+ clearChildren();
+ addChildren(filter(cloudElements));
+ refresh();
+ expand();
}
protected abstract CLOUDELEMENT[] filter(CLOUDELEMENT[] cloudElements) throws
DeltaCloudException;
@@ -98,4 +92,18 @@
}
protected abstract void addPropertyChangeListener(DeltaCloud cloud);
+
+ protected void removePropertyChangeListener(DeltaCloud cloud) {
+ if (cloud != null) {
+ cloud.removePropertyChangeListener(this);
+ }
+ }
+
+ @Override
+ public abstract void propertyChange(PropertyChangeEvent evt);
+
+ @Override
+ protected void dispose() {
+ removePropertyChangeListener(getModel());
+ }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/CloudItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -11,6 +11,7 @@
package org.jboss.tools.deltacloud.ui.views.cloud;
import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.views.properties.IPropertySource;
@@ -21,13 +22,14 @@
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public class CloudItem extends DeltaCloudViewItem<DeltaCloud> {
+public class CloudItem extends DeltaCloudViewItem<DeltaCloud> implements
PropertyChangeListener {
private TreeViewer viewer;
protected CloudItem(DeltaCloud model, DeltaCloudViewItem<?> parent, TreeViewer
viewer) {
super(model, parent, viewer);
this.viewer = viewer;
+ model.addPropertyChangeListener(DeltaCloud.PROP_NAME, this);
}
public String getName() {
@@ -40,13 +42,13 @@
}
@Override
- public synchronized Object[] getChildren() {
- if (!initialized.get()) {
- DeltaCloud cloud = (DeltaCloud) getModel();
- children.add(new InstancesCategoryItem(cloud, this, viewer));
- children.add(new ImagesCategoryItem(cloud, this, viewer));
+ public Object[] getChildren() {
+ if (!areChildrenInitialized()) {
+ DeltaCloud cloud = getModel();
+ addChild(new InstancesCategoryItem(cloud, this, viewer));
+ addChild(new ImagesCategoryItem(cloud, this, viewer));
+ setChildrenInitialized(true);
}
- initialized.set(true);
return super.getChildren();
}
@@ -57,11 +59,6 @@
@Override
public void propertyChange(PropertyChangeEvent event) {
- viewer.update(this, new String[]{DeltaCloud.PROP_NAME});
+ viewer.update(this, new String[] { DeltaCloud.PROP_NAME });
}
-
- @Override
- protected void addPropertyChangeListener(DeltaCloud cloud) {
- cloud.addPropertyChangeListener(DeltaCloud.PROP_NAME, this);
- }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/DeltaCloudViewItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/DeltaCloudViewItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/DeltaCloudViewItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -10,13 +10,11 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views.cloud;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.TreeViewer;
@@ -26,47 +24,58 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.views.properties.IPropertySource;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
/**
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public abstract class DeltaCloudViewItem<DELTACLOUDITEM> implements IAdaptable,
PropertyChangeListener {
+public abstract class DeltaCloudViewItem<DELTACLOUDITEM> implements IAdaptable {
private DELTACLOUDITEM model;
private DeltaCloudViewItem<?> parent;
- protected List<DeltaCloudViewItem<?>> children =
- Collections.synchronizedList(new ArrayList<DeltaCloudViewItem<?>>());
- protected TreeViewer viewer;
- protected AtomicBoolean initialized = new AtomicBoolean();
+ private List<DeltaCloudViewItem<?>> children = new
ArrayList<DeltaCloudViewItem<?>>();
+ private TreeViewer viewer;
+ private AtomicBoolean initialized = new AtomicBoolean();
+ private Lock childrenLock = new ReentrantLock();
protected DeltaCloudViewItem(DELTACLOUDITEM model, DeltaCloudViewItem<?> parent,
TreeViewer viewer) {
this.model = model;
this.parent = parent;
this.viewer = viewer;
initDisposeListener(viewer);
- addPropertyChangeListener(model);
}
public abstract String getName();
public Object[] getChildren() {
- return children.toArray();
+ try {
+ childrenLock.lock();
+ return children.toArray();
+ } finally {
+ childrenLock.unlock();
+ }
}
protected void clearChildren() {
- getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- viewer.remove(children.toArray());
- children.clear();
- }
- });
+ try {
+ childrenLock.lock();
+ children.clear();
+ } finally {
+ childrenLock.unlock();
+ }
}
public boolean hasChildren() {
- return children.size() > 0;
+ try {
+ childrenLock.lock();
+ if (areChildrenInitialized()) {
+ return children.size() > 0;
+ }
+ return true;
+ } finally {
+ childrenLock.unlock();
+ }
}
public Object getParent() {
@@ -74,45 +83,65 @@
}
public void addChild(final DeltaCloudViewItem<?> element) {
- getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- viewer.add(DeltaCloudViewItem.this, element);
+ try {
+ childrenLock.lock();
+ children.add(element);
+ } finally {
+ childrenLock.unlock();
+ }
+ }
+
+ public void addChildren(final DeltaCloudViewItem<?>[] elements) {
+ try {
+ childrenLock.lock();
+ for (DeltaCloudViewItem<?> element : elements) {
children.add(element);
}
- });
+ } finally {
+ childrenLock.unlock();
+ }
}
- public void addChildren(final DeltaCloudViewItem<?>[] elements) {
- getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- viewer.add(DeltaCloudViewItem.this, elements);
- for (DeltaCloudViewItem<?> element : elements) {
- children.add(element);
+ public void removeChild(final DeltaCloudViewItem<?> element) {
+ try {
+ childrenLock.lock();
+ children.remove(element);
+ } finally {
+ childrenLock.unlock();
+ }
+ }
+
+ protected DeltaCloudViewItem<?> getCloudViewElement(DeltaCloud cloudToMatch) {
+ try {
+ childrenLock.lock();
+ for (DeltaCloudViewItem<?> cloudElement : children) {
+ DeltaCloud cloud = (DeltaCloud) cloudElement.getModel();
+ if (cloudToMatch.equals(cloud)) {
+ return cloudElement;
}
}
- });
+ return null;
+ } finally {
+ childrenLock.unlock();
+ }
}
- public void removeChild(final DeltaCloudViewItem<?> element) {
+ protected void expand() {
getDisplay().syncExec(new Runnable() {
+
@Override
public void run() {
- if (element != null) {
- int index = children.indexOf(element);
- viewer.remove(DeltaCloudViewItem.this, index);
- }
+ viewer.setExpandedState(DeltaCloudViewItem.this, true);
}
});
}
- protected void expand() {
+ protected void refresh() {
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
- viewer.setExpandedState(DeltaCloudViewItem.this, true);
+ viewer.refresh();
}
});
}
@@ -121,6 +150,14 @@
return model;
}
+ protected void setChildrenInitialized(boolean initialized) {
+ this.initialized.set(initialized);
+ }
+
+ protected boolean areChildrenInitialized() {
+ return initialized.get();
+ }
+
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class adapter) {
@@ -154,27 +191,10 @@
return viewer.getControl().getDisplay();
}
- protected void dispose() {
- removePropertyChangeListener(getModel());
+ protected TreeViewer getViewer() {
+ return viewer;
}
- public void propertyChange(PropertyChangeEvent event) {
- // do nothing
+ protected void dispose() {
}
-
- protected void removePropertyChangeListener(DELTACLOUDITEM model) {
- if (model != null) {
- try {
- Method method = model.getClass()
- .getMethod("removePropertyChangeListener",
PropertyChangeListener.class);
- if (method != null) {
- method.invoke(model, this);
- }
- } catch (Exception e) {
- // ignore
- }
- }
- }
-
- protected abstract void addPropertyChangeListener(DELTACLOUDITEM object);
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImageItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImageItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImageItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -45,7 +45,8 @@
}
@Override
- protected void addPropertyChangeListener(DeltaCloudImage object) {
- // do nothing
+ public boolean hasChildren() {
+ return false;
}
+
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImagesCategoryItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImagesCategoryItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/ImagesCategoryItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -43,7 +43,7 @@
}
@Override
- protected void asyncAddCloudElements() {
+ protected void asyncLoadCloudElements() {
setLoadingIndicator();
new AbstractCloudElementJob(
MessageFormat.format("Get images from cloud {0}", getModel().getName()),
getModel(), CLOUDELEMENT.IMAGES) {
@@ -51,11 +51,7 @@
@Override
protected IStatus doRun(IProgressMonitor monitor) throws DeltaCloudException {
try {
- DeltaCloudImage[] images = getCloud().getImages();
- clearChildren();
- addChildren(images);
- initialized.set(true);
- expand();
+ getCloud().getImages();
return Status.OK_STATUS;
} catch(DeltaCloudException e) {
clearChildren();
@@ -69,14 +65,13 @@
protected DeltaCloudViewItem<?>[] getElements(DeltaCloudImage[] modelElements, int
startIndex, int stopIndex) {
DeltaCloudViewItem<?>[] elements = new DeltaCloudViewItem[stopIndex -
startIndex];
for (int i = startIndex; i < stopIndex; ++i) {
- elements[i - startIndex] = new ImageItem(modelElements[i], this, viewer);
+ elements[i - startIndex] = new ImageItem(modelElements[i], this, getViewer());
}
return elements;
}
@Override
public void propertyChange(PropertyChangeEvent event) {
- super.propertyChange(event);
DeltaCloud cloud = (DeltaCloud) event.getSource();
DeltaCloudImage[] newImages = (DeltaCloudImage[]) event.getNewValue();
try {
@@ -86,7 +81,7 @@
ErrorUtils.handleError(
"Error",
MessageFormat.format("Could not display new images from cloud
\"{0}\"", cloud.getName()), e,
- viewer.getControl().getShell());
+ getViewer().getControl().getShell());
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstanceItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstanceItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstanceItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -51,7 +51,7 @@
}
@Override
- protected void addPropertyChangeListener(DeltaCloudInstance object) {
- // do nothing
+ public boolean hasChildren() {
+ return false;
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstancesCategoryItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstancesCategoryItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/InstancesCategoryItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -13,6 +13,7 @@
import java.beans.PropertyChangeEvent;
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;
@@ -43,7 +44,7 @@
}
@Override
- protected void asyncAddCloudElements() {
+ protected void asyncLoadCloudElements() {
setLoadingIndicator();
new AbstractCloudElementJob(
MessageFormat.format("Get instances from cloud {0}", getModel().getName()),
getModel(),
@@ -52,11 +53,7 @@
@Override
protected IStatus doRun(IProgressMonitor monitor) throws DeltaCloudException {
try {
- DeltaCloudInstance[] instances = getCloud().getInstances();
- clearChildren();
- addChildren(instances);
- initialized.set(true);
- expand();
+ getCloud().getInstances();
return Status.OK_STATUS;
} catch (DeltaCloudException e) {
clearChildren();
@@ -71,7 +68,7 @@
protected DeltaCloudViewItem<?>[] getElements(DeltaCloudInstance[] modelElements,
int startIndex, int stopIndex) {
DeltaCloudViewItem<?>[] elements = new DeltaCloudViewItem[stopIndex -
startIndex];
for (int i = startIndex; i < stopIndex; ++i) {
- elements[i - startIndex] = new InstanceItem(modelElements[i], this, viewer);
+ elements[i - startIndex] = new InstanceItem(modelElements[i], this, getViewer());
}
return elements;
}
@@ -83,6 +80,7 @@
@Override
public void propertyChange(PropertyChangeEvent event) {
DeltaCloud cloud = (DeltaCloud) event.getSource();
+ Assert.isTrue(cloud == getModel());
DeltaCloudInstance[] newInstances = (DeltaCloudInstance[]) event.getNewValue();
try {
onCloudElementsChanged(cloud, newInstances);
@@ -91,7 +89,7 @@
ErrorUtils.handleError(
"Error",
MessageFormat.format("Could not display new instances from cloud
\"{0}\"", cloud.getName()), e,
- viewer.getControl().getShell());
+ getViewer().getControl().getShell());
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/LoadingItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/LoadingItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/LoadingItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -30,13 +30,13 @@
}
@Override
+ public boolean hasChildren() {
+ return false;
+ }
+
+ @Override
public String getName() {
// TODO: internationalize strings
return "Loading...";
}
-
- @Override
- protected void addPropertyChangeListener(Object object) {
- // do nothing
- }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/NumericFoldingItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/NumericFoldingItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/NumericFoldingItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -53,10 +53,4 @@
public IPropertySource getPropertySource() {
return null;
}
-
- @Override
- protected void addPropertyChangeListener(Object object) {
- // do nothing
- }
-
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/RootItem.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/RootItem.java 2011-01-06
09:23:46 UTC (rev 27940)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/RootItem.java 2011-01-06
09:43:27 UTC (rev 27941)
@@ -43,7 +43,7 @@
@Override
public Object[] getChildren() {
- if (!initialized.get()) {
+ if (!areChildrenInitialized()) {
DeltaCloudManager m = DeltaCloudManager.getDefault();
try {
addClouds(m.getClouds());
@@ -51,7 +51,7 @@
// TODO: internationalize strings
ErrorUtils.handleError("Error", "Could not get clouds", e,
Display.getDefault().getActiveShell());
} finally {
- initialized.set(true);
+ setChildrenInitialized(true);
}
}
return super.getChildren();
@@ -59,25 +59,11 @@
private void addClouds(DeltaCloud[] clouds) {
for (DeltaCloud cloud : clouds) {
- addCloud(cloud);
+ CloudItem cloudItem = new CloudItem(cloud, this, getViewer());
+ addChild(cloudItem);
}
}
- private void addCloud(DeltaCloud cloud) {
- CloudItem e = new CloudItem(cloud, this, viewer);
- children.add(e);
- }
-
- private DeltaCloudViewItem<?> getCloudViewElement(DeltaCloud cloudToMatch) {
- for (DeltaCloudViewItem<?> cloudElement : children) {
- DeltaCloud cloud = (DeltaCloud) cloudElement.getModel();
- if (cloudToMatch.equals(cloud)) {
- return cloudElement;
- }
- }
- return null;
- }
-
@Override
public void dispose() {
DeltaCloudManager.getDefault().removeCloudManagerListener(this);
@@ -86,16 +72,11 @@
public void cloudsChanged(int type, DeltaCloud cloud) {
switch (type) {
case IDeltaCloudManagerListener.ADD_EVENT:
- addChild(new CloudItem(cloud, this, viewer));
+ addChild(new CloudItem(cloud, this, getViewer()));
break;
case IDeltaCloudManagerListener.REMOVE_EVENT:
removeChild(getCloudViewElement(cloud));
break;
}
}
-
- @Override
- protected void addPropertyChangeListener(DeltaCloudManager object) {
- // do nothing
- }
}