Author: adietish
Date: 2010-12-06 10:18:53 -0500 (Mon, 06 Dec 2010)
New Revision: 27191
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/LoadingCloudViewElement.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElementCategoryElement.java
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
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java
Log:
[JBIDE-7819] fixing missing children in tree
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElement.java 2010-12-06
13:38:34 UTC (rev 27190)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElement.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -46,16 +46,22 @@
if (!initialized.get()) {
DeltaCloud cloud = (DeltaCloud) getElement();
CVCloudElementCategoryElement instances = new CVInstancesCategoryElement(cloud,
viewer);
- addChild(instances);
+ addCategory(instances);
CVCloudElementCategoryElement images = new CVImagesCategoryElement(cloud, viewer);
- addChild(images);
+ addCategory(images);
}
initialized.set(true);
return super.getChildren();
}
+ private void addCategory(CVCloudElementCategoryElement categoryElement) {
+ children.add(categoryElement);
+ }
+
@Override
public IPropertySource getPropertySource() {
return new CloudPropertySource(getElement());
}
+
+
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElementCategoryElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElementCategoryElement.java 2010-12-06
13:38:34 UTC (rev 27190)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElementCategoryElement.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -22,6 +22,7 @@
public CVCloudElementCategoryElement(Object element, TreeViewer viewer) {
super(element, viewer);
+ addCloudElementListener(getCloud());
}
@Override
@@ -29,6 +30,22 @@
return true;
}
+ @Override
+ public Object[] getChildren() {
+ if (!initialized.get()) {
+ setLoadingIndicator();
+ asyncGetCloudElements();
+ initialized.set(true);
+ }
+ return super.getChildren();
+ }
+
+ private void setLoadingIndicator() {
+ children.add(new LoadingCloudViewElement(getViewer()));
+ }
+
+ protected abstract void asyncGetCloudElements();
+
protected void addChildren(Object[] modelElements) {
if (modelElements.length > CVNumericFoldingElement.FOLDING_SIZE) {
addFoldedChildren(modelElements);
@@ -67,4 +84,14 @@
protected DeltaCloud getCloud() {
return (DeltaCloud) getElement();
}
+
+ @Override
+ protected void dispose() {
+ removeCloudElementListener(getCloud());
+ }
+
+ protected abstract void addCloudElementListener(DeltaCloud cloud);
+
+ protected abstract void removeCloudElementListener(DeltaCloud cloud);
+
}
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-06
13:38:34 UTC (rev 27190)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImagesCategoryElement.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -31,21 +31,14 @@
public CVImagesCategoryElement(Object element, TreeViewer viewer) {
super(element, viewer);
- DeltaCloud cloud = getCloud();
- cloud.addImageListListener(this);
}
public String getName() {
return CVMessages.getString(IMAGE_CATEGORY_NAME);
}
- @Override
- public synchronized Object[] getChildren() {
- if (!initialized.get()) {
- new GetImagesCommand(getCloud()).execute();
- initialized.set(true);
- }
- return super.getChildren();
+ protected void asyncGetCloudElements() {
+ new GetImagesCommand(getCloud()).execute();
}
@Override
@@ -64,6 +57,7 @@
initialized.set(false);
DeltaCloudImage[] images = filter(newImages);
addChildren(images);
+// refresh();
} catch (DeltaCloudException e) {
// TODO: internationalize strings
ErrorUtils.handleError(
@@ -76,17 +70,32 @@
// refresh();
}
+ // private void refresh() {
+ // getViewer().getControl().getDisplay().asyncExec(new Runnable() {
+ //
+ // @Override
+ // public void run() {
+ // getViewer().refresh(this, true);
+ // }
+ // });
+ // }
+
public DeltaCloudImage[] filter(DeltaCloudImage[] images) throws DeltaCloudException {
DeltaCloud cloud = (DeltaCloud) getElement();
IImageFilter f = cloud.getImageFilter();
return f.filter(images).toArray(new DeltaCloudImage[images.length]);
}
- @Override
- protected void dispose() {
- DeltaCloud cloud = (DeltaCloud) getElement();
+ protected void addCloudElementListener(DeltaCloud cloud) {
if (cloud != null) {
+ cloud.addImageListListener(this);
+ }
+ }
+
+ protected void removeCloudElementListener(DeltaCloud cloud) {
+ if (cloud != null) {
cloud.removeImageListListener(this);
}
}
+
}
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-06
13:38:34 UTC (rev 27190)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstancesCategoryElement.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -31,21 +31,14 @@
public CVInstancesCategoryElement(Object element, TreeViewer viewer) {
super(element, viewer);
- DeltaCloud cloud = (DeltaCloud) getElement();
- cloud.addInstanceListListener(this);
}
public String getName() {
return CVMessages.getString(INSTANCE_CATEGORY_NAME);
}
- @Override
- public Object[] getChildren() {
- if (!initialized.get()) {
- new GetInstancesCommand(getCloud()).execute();
- initialized.set(true);
- }
- return super.getChildren();
+ protected void asyncGetCloudElements() {
+ new GetInstancesCommand(getCloud()).execute();
}
@Override
@@ -86,10 +79,14 @@
return f.filter(instances).toArray(new DeltaCloudInstance[instances.length]);
}
- @Override
- protected void dispose() {
- DeltaCloud cloud = (DeltaCloud) getElement();
+ protected void addCloudElementListener(DeltaCloud cloud) {
if (cloud != null) {
+ cloud.addInstanceListListener(this);
+ }
+ }
+
+ protected void removeCloudElementListener(DeltaCloud cloud) {
+ if (cloud != null) {
cloud.removeInstanceListListener(this);
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java 2010-12-06
13:38:34 UTC (rev 27190)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -25,8 +25,6 @@
*/
public class CVRootElement extends CloudViewElement implements ICloudManagerListener {
- private boolean initialized;
-
public CVRootElement(TreeViewer viewer) {
super(DeltaCloudManager.getDefault(), viewer); //$NON-NLS-1$
DeltaCloudManager.getDefault().addCloudManagerListener(this);
@@ -34,7 +32,7 @@
@Override
public String getName() {
- return "root";
+ return "root"; //$NON-NLS-1$
}
@Override
@@ -45,27 +43,24 @@
@Override
public Object[] getChildren() {
- if (!initialized) {
+ if (!initialized.get()) {
DeltaCloudManager m = DeltaCloudManager.getDefault();
- m.removeCloudManagerListener(this);
try {
- addChildren(m.getClouds());
+ addClouds(m.getClouds());
} catch (DeltaCloudException e) {
// TODO: internationalize strings
- ErrorUtils.handleError("Error", "Could not get all clouds", e,
Display.getDefault().getActiveShell());
+ ErrorUtils.handleError("Error", "Could not get clouds", e,
Display.getDefault().getActiveShell());
} finally {
- initialized = true;
- m.addCloudManagerListener(this);
+ initialized.set(true);
}
}
return super.getChildren();
}
- private void addChildren(DeltaCloud[] clouds) {
- for (int i = 0; i < clouds.length; ++i) {
- DeltaCloud cloud = clouds[i];
+ private void addClouds(DeltaCloud[] clouds) {
+ for (DeltaCloud cloud : clouds) {
CVCloudElement e = new CVCloudElement(cloud, cloud.getName(), getViewer());
- addChild(e);
+ children.add(e);
}
}
@@ -77,17 +72,9 @@
public void cloudsChanged(int type) {
DeltaCloudManager m = DeltaCloudManager.getDefault();
try {
- m.removeCloudManagerListener(this);
DeltaCloud[] clouds = m.getClouds();
- addChildren(clouds);
- initialized = true;
- m.addCloudManagerListener(this);
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- getViewer().refresh(this, false);
- }
- });
+ addClouds(clouds);
+ initialized.set(true);
} catch (DeltaCloudException e) {
// TODO: internationalize strings
ErrorUtils.handleError(
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewElement.java 2010-12-06
13:38:34 UTC (rev 27190)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewElement.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -32,13 +32,13 @@
private TreeViewer viewer;
private Object element;
private CloudViewElement parent;
- private Collection<CloudViewElement> children;
+ protected Collection<CloudViewElement> children =
+ Collections.synchronizedCollection(new ArrayList<CloudViewElement>());
protected AtomicBoolean initialized = new AtomicBoolean();
public CloudViewElement(Object element, TreeViewer viewer) {
this.element = element;
this.viewer = viewer;
- children = Collections.synchronizedCollection(new
ArrayList<CloudViewElement>());
initDisposeListener(viewer);
}
@@ -47,7 +47,7 @@
public Object[] getChildren() {
return children.toArray();
}
-
+
protected void clearChildren() {
children.clear();
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java 2010-12-06
13:38:34 UTC (rev 27190)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -57,6 +57,7 @@
TreeViewer viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER);
viewer.setContentProvider(new CloudViewContentProvider());
viewer.setLabelProvider(new CloudViewLabelProvider());
+ viewer.setUseHashlookup(true);
viewer.setInput(new CVRootElement(viewer));
viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
getSite().setSelectionProvider(viewer);
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/LoadingCloudViewElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/LoadingCloudViewElement.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/LoadingCloudViewElement.java 2010-12-06
15:18:53 UTC (rev 27191)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.ui.views;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.views.properties.IPropertySource;
+
+/**
+ * A tree element that shows the user that the tree is currently loading
+ * elements
+ */
+public class LoadingCloudViewElement extends CloudViewElement {
+ protected LoadingCloudViewElement(TreeViewer viewer) {
+ super(null, viewer);
+ }
+
+ @Override
+ public IPropertySource getPropertySource() {
+ // no property source for this element
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ // TODO: internationalize strings
+ return "Loading...";
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/LoadingCloudViewElement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain