Author: adietish
Date: 2010-12-06 08:38:34 -0500 (Mon, 06 Dec 2010)
New Revision: 27190
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElementCategoryElement.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCategoryElement.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.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/CVCloudElement.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImageElement.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/CVInstanceElement.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/CVNumericFoldingElement.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/CloudViewLabelProvider.java
Log:
[JBIDE-7819]
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudElementFilter.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -35,9 +35,9 @@
private IFieldMatcher nameRule;
private IFieldMatcher idRule;
- public Collection<CLOUDELEMENT> filter() throws DeltaCloudException {
+ public Collection<CLOUDELEMENT> filter(CLOUDELEMENT[] cloudElements) throws
DeltaCloudException {
List<CLOUDELEMENT> filteredElements = new ArrayList<CLOUDELEMENT>();
- for (CLOUDELEMENT cloudElement : getCloudElements()) {
+ for (CLOUDELEMENT cloudElement : cloudElements) {
if (matches(cloudElement)) {
filteredElements.add(cloudElement);
}
@@ -45,8 +45,6 @@
return filteredElements;
}
- protected abstract CLOUDELEMENT[] getCloudElements() throws DeltaCloudException;
-
protected boolean matches(CLOUDELEMENT cloudElement) {
return nameRule.matches(cloudElement.getName())
&& idRule.matches(cloudElement.getId());
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllImageFilter.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -23,7 +23,6 @@
private IFieldMatcher matcher = new AllFieldMatcher();
-
public AllImageFilter(DeltaCloud cloud) {
super(cloud);
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -18,11 +18,6 @@
private IFieldMatcher matcher = new AllFieldMatcher();
@Override
- protected DeltaCloudInstance[] getCloudElements() throws DeltaCloudException {
- return getCloud().getInstances();
- }
-
- @Override
public boolean matches(DeltaCloudInstance instance) {
return true;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ICloudElementFilter.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -35,7 +35,7 @@
+ ALL_MATCHER_EXPRESSION + EXPRESSION_DELIMITER // arch
+ ALL_MATCHER_EXPRESSION; // desc
- public Collection<CLOUDELEMENT> filter() throws DeltaCloudException;
+ public Collection<CLOUDELEMENT> filter(CLOUDELEMENT[] cloudElements) throws
DeltaCloudException;
public void setRules(String ruleString);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -60,9 +60,4 @@
public IFieldMatcher getDescRule() {
return descRule;
}
-
- @Override
- protected DeltaCloudImage[] getCloudElements() throws DeltaCloudException {
- return getCloud().getImages();
- }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -87,9 +87,4 @@
public IFieldMatcher getRealmRule() {
return realmRule;
}
-
- @Override
- protected DeltaCloudInstance[] getCloudElements() throws DeltaCloudException {
- return getCloud().getInstances();
- }
}
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-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -106,7 +106,7 @@
if (filter == null) {
return cloudElements;
} else {
- return filter.filter().toArray();
+ return filter.filter(cloudElements).toArray();
}
}
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCategoryElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCategoryElement.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCategoryElement.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -1,184 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat Inc..
- * All rights reserved. This program and the accompanying materials
- * are 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 Incorporated - initial API and implementation
- *******************************************************************************/
-package org.jboss.tools.deltacloud.ui.views;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.views.properties.IPropertySource;
-import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.core.DeltaCloudImage;
-import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-
-/**
- * @author Jeff Johnston
- * @author Andre Dietisheim
- */
-public abstract class CVCategoryElement extends CloudViewElement {
-
- protected boolean initialized;
- private TreeViewer viewer;
-
- public CVCategoryElement(Object element, TreeViewer viewer) {
- super(element);
- this.viewer = viewer;
- viewer.getControl().addDisposeListener(onDispose());
- }
-
- @Override
- public Object[] getChildren() {
- return super.getChildren();
- }
-
- @Override
- public boolean hasChildren() {
- return true;
- }
-
- protected void addChildren(Object[] modelElements) {
- if (modelElements.length > CVNumericFoldingElement.FOLDING_SIZE) {
- addFoldedChildren(modelElements);
- } else {
- addChildren(getElements(modelElements, 0, modelElements.length));
- }
- }
-
- protected void addFoldedChildren(Object[] modelElements) {
- int min = 0;
- int max = CVNumericFoldingElement.FOLDING_SIZE;
- int length = modelElements.length;
- while (length > CVNumericFoldingElement.FOLDING_SIZE) {
- CVNumericFoldingElement f = new CVNumericFoldingElement(min, max);
- addChild(f);
- f.addChildren(getElements(modelElements, min, max));
- min += CVNumericFoldingElement.FOLDING_SIZE;
- max += CVNumericFoldingElement.FOLDING_SIZE;
- length -= CVNumericFoldingElement.FOLDING_SIZE;
- }
- if (length > 0) {
- CVNumericFoldingElement f = new CVNumericFoldingElement(min, max);
- addChild(f);
- f.addChildren(getElements(modelElements, min, min + length));
- }
- }
-
- protected abstract CloudViewElement[] getElements(Object[] modelElements, int
startIndex, int stopIndex);
-
- @Override
- public IPropertySource getPropertySource() {
- // no property source for cathegories
- return null;
- }
-
- protected Viewer getViewer() {
- return viewer;
- }
-
- protected void refresh() {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- IStructuredSelection oldSelection = (IStructuredSelection) viewer.getSelection();
- ((TreeViewer) viewer).refresh(CVCategoryElement.this, false);
- restoreSelection(oldSelection);
- }
- });
- }
-
- /**
- * This is a workaround:
- *
- * When a change in the list of instances happens, DeltaCloud notifies this
- * class with the list of all instances (@see
- * DeltaCloud#performInstanceAction). This class then removes all children
- * and readds new children with the same DeltaCloudInstance instances.
- *
- * <p>
- * I also tried an alternative approach where I implemented an equals method
- * in CVInstanceElement that returns <code>true</code> if both elements
have
- * the same DeltaCloudInsta instance. The consequence is that the viewer
- * keeps the selection, but is not aware of a change in the underlying
- * items. The consequence is that the context-menu does not change its state
- * (the instance action, that was executed, should disappear) and the
- * properties view does not update either.
- *
- * @param selection
- *
- * @see DeltaCloud#performInstanceAction
- * @see #listChanged
- */
- private void restoreSelection(IStructuredSelection selection) {
- List<?> newSelectedElements = getChildrenWithSameElement(selection.toList());
- if (newSelectedElements != null && newSelectedElements.size() > 0) {
- ISelection newSelection = new StructuredSelection(newSelectedElements);
- viewer.setSelection(newSelection);
- }
- }
-
- /**
- * Returns the children of this category element that have the same elements
- * (#getElement) as the given items. This method is used to restore
- * selection after the {@link CVInstanceElement} or {@link CVImageElement}
- * have been recreated. They still have the same {@link DeltaCloudInstance}
- * or {@link DeltaCloudImage}.
- *
- * @param elementsToMatch
- * the elements to match
- * @return the children with same element
- *
- * @see #CloudViewElement#getElement
- * @see CVInstanceElement
- * @see CVImageElement
- */
- private List<?> getChildrenWithSameElement(List<?> itemsToMatch) {
- if (itemsToMatch == null || itemsToMatch.size() == 0) {
- return Collections.EMPTY_LIST;
- }
- List<Object> children = new ArrayList<Object>();
- for (Object itemToMatch : itemsToMatch) {
- Object elementToMatch = ((CloudViewElement) itemToMatch).getElement();
- if (elementToMatch != null) {
- for (Object child : getChildren()) {
- Object childElement = ((CloudViewElement) child).getElement();
- if (elementToMatch.equals(childElement)) {
- children.add(child);
- }
- }
- }
- }
- return children;
- }
-
- private DisposeListener onDispose() {
- return new DisposeListener() {
-
- @Override
- public void widgetDisposed(DisposeEvent e) {
- dispose();
- }
- };
- }
-
- protected DeltaCloud getCloud() {
- return (DeltaCloud) getElement();
- }
-
- protected abstract void dispose();
-}
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
11:48:52 UTC (rev 27189)
+++
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)
@@ -11,7 +11,6 @@
package org.jboss.tools.deltacloud.ui.views;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.views.properties.IPropertySource;
import org.jboss.tools.deltacloud.core.DeltaCloud;
@@ -22,10 +21,9 @@
public class CVCloudElement extends CloudViewElement {
private TreeViewer viewer;
- private boolean initialized;
public CVCloudElement(Object element, String name, TreeViewer viewer) {
- super(element);
+ super(element, viewer);
this.viewer = viewer;
}
@@ -37,10 +35,6 @@
return "";
}
}
-
- public Viewer getViewer() {
- return viewer;
- }
@Override
public boolean hasChildren() {
@@ -49,14 +43,14 @@
@Override
public synchronized Object[] getChildren() {
- if (!initialized) {
+ if (!initialized.get()) {
DeltaCloud cloud = (DeltaCloud) getElement();
- CVCategoryElement c1 = new CVInstancesCategoryElement(cloud, viewer);
- CVCategoryElement c2 = new CVImagesCategoryElement(cloud, viewer);
- addChild(c1);
- addChild(c2);
+ CVCloudElementCategoryElement instances = new CVInstancesCategoryElement(cloud,
viewer);
+ addChild(instances);
+ CVCloudElementCategoryElement images = new CVImagesCategoryElement(cloud, viewer);
+ addChild(images);
}
- initialized = true;
+ initialized.set(true);
return super.getChildren();
}
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElementCategoryElement.java
(from rev 27185,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCategoryElement.java)
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVCloudElementCategoryElement.java
(rev 0)
+++
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)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are 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 Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.ui.views;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+
+/**
+ * @author Jeff Johnston
+ * @author Andre Dietisheim
+ */
+public abstract class CVCloudElementCategoryElement extends CloudViewElement {
+
+ public CVCloudElementCategoryElement(Object element, TreeViewer viewer) {
+ super(element, viewer);
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return true;
+ }
+
+ protected void addChildren(Object[] modelElements) {
+ if (modelElements.length > CVNumericFoldingElement.FOLDING_SIZE) {
+ addFoldedChildren(modelElements);
+ } else {
+ addChildren(getElements(modelElements, 0, modelElements.length));
+ }
+ }
+
+ protected void addFoldedChildren(Object[] modelElements) {
+ int min = 0;
+ int max = CVNumericFoldingElement.FOLDING_SIZE;
+ int length = modelElements.length;
+ while (length > CVNumericFoldingElement.FOLDING_SIZE) {
+ CVNumericFoldingElement f = new CVNumericFoldingElement(min, max, getViewer());
+ addChild(f);
+ f.addChildren(getElements(modelElements, min, max));
+ min += CVNumericFoldingElement.FOLDING_SIZE;
+ max += CVNumericFoldingElement.FOLDING_SIZE;
+ length -= CVNumericFoldingElement.FOLDING_SIZE;
+ }
+ if (length > 0) {
+ CVNumericFoldingElement f = new CVNumericFoldingElement(min, max, getViewer());
+ addChild(f);
+ f.addChildren(getElements(modelElements, min, min + length));
+ }
+ }
+
+ protected abstract CloudViewElement[] getElements(Object[] modelElements, int
startIndex, int stopIndex);
+
+ @Override
+ public IPropertySource getPropertySource() {
+ // no property source for cathegories
+ return null;
+ }
+
+ protected DeltaCloud getCloud() {
+ return (DeltaCloud) getElement();
+ }
+}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImageElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImageElement.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVImageElement.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.views.properties.IPropertySource;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
@@ -19,8 +20,8 @@
*/
public class CVImageElement extends CloudViewElement {
- public CVImageElement(Object element) {
- super(element);
+ public CVImageElement(Object element, TreeViewer viewer) {
+ super(element, viewer);
}
public String getName() {
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
11:48:52 UTC (rev 27189)
+++
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)
@@ -25,7 +25,7 @@
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public class CVImagesCategoryElement extends CVCategoryElement implements
IImageListListener {
+public class CVImagesCategoryElement extends CVCloudElementCategoryElement implements
IImageListListener {
private static final String IMAGE_CATEGORY_NAME = "ImageCategoryName";
//$NON-NLS-1$
@@ -41,8 +41,9 @@
@Override
public synchronized Object[] getChildren() {
- if (!initialized) {
+ if (!initialized.get()) {
new GetImagesCommand(getCloud()).execute();
+ initialized.set(true);
}
return super.getChildren();
}
@@ -51,7 +52,7 @@
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]);
+ elements[i - startIndex] = new CVImageElement(modelElements[i], getViewer());
}
return elements;
}
@@ -60,8 +61,8 @@
public synchronized void listChanged(DeltaCloud cloud, DeltaCloudImage[] newImages) {
try {
clearChildren();
- initialized = false;
- DeltaCloudImage[] images = filter();
+ initialized.set(false);
+ DeltaCloudImage[] images = filter(newImages);
addChildren(images);
} catch (DeltaCloudException e) {
// TODO: internationalize strings
@@ -70,15 +71,15 @@
MessageFormat.format("Could not get images from cloud \"{0}\"",
cloud.getName()), e,
getViewer().getControl().getShell());
} finally {
- initialized = true;
+ initialized.set(true);
}
// refresh();
}
- public DeltaCloudImage[] filter() throws DeltaCloudException {
+ public DeltaCloudImage[] filter(DeltaCloudImage[] images) throws DeltaCloudException {
DeltaCloud cloud = (DeltaCloud) getElement();
IImageFilter f = cloud.getImageFilter();
- return f.filter().toArray(new DeltaCloudImage[] {});
+ return f.filter(images).toArray(new DeltaCloudImage[images.length]);
}
@Override
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstanceElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstanceElement.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVInstanceElement.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.views.properties.IPropertySource;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
@@ -19,8 +20,8 @@
*/
public class CVInstanceElement extends CloudViewElement {
- public CVInstanceElement(Object element) {
- super(element);
+ public CVInstanceElement(Object element, TreeViewer viewer) {
+ super(element, viewer);
}
public String getName() {
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
11:48:52 UTC (rev 27189)
+++
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)
@@ -25,7 +25,7 @@
* @author Jeff Johnston
* @author Andre Dietisheim
*/
-public class CVInstancesCategoryElement extends CVCategoryElement implements
IInstanceListListener {
+public class CVInstancesCategoryElement extends CVCloudElementCategoryElement implements
IInstanceListListener {
private static final String INSTANCE_CATEGORY_NAME = "InstanceCategoryName";
//$NON-NLS-1$
@@ -41,8 +41,9 @@
@Override
public Object[] getChildren() {
- if (!initialized) {
+ if (!initialized.get()) {
new GetInstancesCommand(getCloud()).execute();
+ initialized.set(true);
}
return super.getChildren();
}
@@ -51,22 +52,23 @@
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]);
+ elements[i - startIndex] = new CVInstanceElement(modelElements[i], getViewer());
}
return elements;
}
protected void addChildrenFor(Object[] modelElements, int startIndex, int stopIndex) {
for (int i = startIndex; i < stopIndex; ++i) {
- addChild(new CVInstanceElement(modelElements[i]));
+ addChild(new CVInstanceElement(modelElements[i], getViewer()));
}
}
@Override
public void listChanged(DeltaCloud cloud, DeltaCloudInstance[] newInstances) {
try {
+ initialized.set(false);
clearChildren();
- final DeltaCloudInstance[] instances = filter();
+ final DeltaCloudInstance[] instances = filter(newInstances);
addChildren(instances);
} catch (DeltaCloudException e) {
// TODO: internationalize strings
@@ -75,13 +77,13 @@
MessageFormat.format("Could not get instanceso from cloud
\"{0}\"", cloud.getName()), e,
getViewer().getControl().getShell());
} finally {
- initialized = true;
+ initialized.set(true);
}
}
- public DeltaCloudInstance[] filter() throws DeltaCloudException {
+ public DeltaCloudInstance[] filter(DeltaCloudInstance[] instances) throws
DeltaCloudException {
IInstanceFilter f = getCloud().getInstanceFilter();
- return f.filter().toArray(new DeltaCloudInstance[] {});
+ return f.filter(instances).toArray(new DeltaCloudInstance[instances.length]);
}
@Override
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVNumericFoldingElement.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVNumericFoldingElement.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CVNumericFoldingElement.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.views.properties.IPropertySource;
/**
@@ -22,8 +23,8 @@
private Object min;
private int max;
- public CVNumericFoldingElement(int min, int max) {
- super(null);
+ public CVNumericFoldingElement(int min, int max, TreeViewer viewer) {
+ super(null, viewer);
this.min = min;
this.max = max;
}
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
11:48:52 UTC (rev 27189)
+++
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)
@@ -26,18 +26,17 @@
public class CVRootElement extends CloudViewElement implements ICloudManagerListener {
private boolean initialized;
- private TreeViewer viewer;
public CVRootElement(TreeViewer viewer) {
- super(DeltaCloudManager.getDefault()); //$NON-NLS-1$
- this.viewer = viewer;
+ super(DeltaCloudManager.getDefault(), viewer); //$NON-NLS-1$
+ DeltaCloudManager.getDefault().addCloudManagerListener(this);
}
@Override
public String getName() {
return "root";
}
-
+
@Override
public IPropertySource getPropertySource() {
// no property source for the root element
@@ -49,31 +48,30 @@
if (!initialized) {
DeltaCloudManager m = DeltaCloudManager.getDefault();
m.removeCloudManagerListener(this);
- DeltaCloud[] clouds = new DeltaCloud[] {};
try {
- clouds = m.getClouds();
+ addChildren(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 all clouds", e,
Display.getDefault().getActiveShell());
+ } finally {
+ initialized = true;
+ m.addCloudManagerListener(this);
}
- for (int i = 0; i < clouds.length; ++i) {
- DeltaCloud cloud = clouds[i];
- CVCloudElement e = new CVCloudElement(cloud, cloud.getName(), viewer);
- addChild(e);
- }
- m.addCloudManagerListener(this);
- initialized = true;
}
return super.getChildren();
}
+ private void addChildren(DeltaCloud[] clouds) {
+ for (int i = 0; i < clouds.length; ++i) {
+ DeltaCloud cloud = clouds[i];
+ CVCloudElement e = new CVCloudElement(cloud, cloud.getName(), getViewer());
+ addChild(e);
+ }
+ }
+
@Override
- protected void finalize() throws Throwable {
+ public void dispose() {
DeltaCloudManager.getDefault().removeCloudManagerListener(this);
- super.finalize();
}
public void cloudsChanged(int type) {
@@ -81,17 +79,13 @@
try {
m.removeCloudManagerListener(this);
DeltaCloud[] clouds = m.getClouds();
- for (int i = 0; i < clouds.length; ++i) {
- DeltaCloud cloud = clouds[i];
- CVCloudElement e = new CVCloudElement(cloud, cloud.getName(), viewer);
- addChild(e);
- }
+ addChildren(clouds);
initialized = true;
m.addCloudManagerListener(this);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- ((TreeViewer) viewer).refresh(this, false);
+ getViewer().refresh(this, false);
}
});
} catch (DeltaCloudException e) {
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
11:48:52 UTC (rev 27189)
+++
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)
@@ -11,9 +11,16 @@
package org.jboss.tools.deltacloud.ui.views;
import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.views.properties.IPropertySource;
/**
@@ -22,50 +29,69 @@
*/
public abstract class CloudViewElement implements IAdaptable {
+ private TreeViewer viewer;
private Object element;
private CloudViewElement parent;
- private List<CloudViewElement> children;
+ private Collection<CloudViewElement> children;
+ protected AtomicBoolean initialized = new AtomicBoolean();
- public abstract IPropertySource getPropertySource();
-
+ public CloudViewElement(Object element, TreeViewer viewer) {
+ this.element = element;
+ this.viewer = viewer;
+ children = Collections.synchronizedCollection(new
ArrayList<CloudViewElement>());
+ initDisposeListener(viewer);
+ }
+
+ public abstract String getName();
+
public Object[] getChildren() {
return children.toArray();
}
-
+
protected void clearChildren() {
children.clear();
}
-
+
public boolean hasChildren() {
return children.size() > 0;
}
-
+
public Object getParent() {
return parent;
}
-
- public void addChild(CloudViewElement e) {
- children.add(e);
- e.setParent(this);
+
+ public void addChild(final CloudViewElement e) {
+ addChildToModel(e);
+ getViewer().getControl().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ getViewer().add(this, e);
+ }
+ });
}
-
- public void addChildren(CloudViewElement[] elements) {
- for(CloudViewElement element : elements) {
- addChild(element);
+
+ public void addChildToModel(CloudViewElement element) {
+ children.add(element);
+ element.setParent(this);
+ }
+
+ public void addChildren(final CloudViewElement[] elements) {
+ for (CloudViewElement element : elements) {
+ addChildToModel(element);
}
+
+ getViewer().getControl().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ getViewer().add(this, elements);
+ }
+ });
}
public void setParent(CloudViewElement e) {
parent = e;
}
-
- public CloudViewElement(Object element) {
- this.element = element;
- children = new ArrayList<CloudViewElement>();
- }
-
- public abstract String getName();
-
+
public Object getElement() {
return element;
}
@@ -79,4 +105,31 @@
}
return null;
}
+
+ public abstract IPropertySource getPropertySource();
+
+ protected TreeViewer getViewer() {
+ return viewer;
+ }
+
+ private void initDisposeListener(Viewer viewer) {
+ final Control control = viewer.getControl();
+ control.getDisplay().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ control.addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ dispose();
+ }
+ });
+ }
+ });
+ }
+
+ protected void dispose() {
+ // nothing to do
+ }
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewLabelProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewLabelProvider.java 2010-12-06
11:48:52 UTC (rev 27189)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/CloudViewLabelProvider.java 2010-12-06
13:38:34 UTC (rev 27190)
@@ -20,7 +20,7 @@
public Image getImage(Object element) {
if (element instanceof CVCloudElement) {
return SWTImagesFactory.get(SWTImagesFactory.IMG_CLOUD);
- } else if (element instanceof CVCategoryElement ||
+ } else if (element instanceof CVCloudElementCategoryElement ||
element instanceof CVNumericFoldingElement) {
return SWTImagesFactory.get(SWTImagesFactory.IMG_FOLDER);
} else if (element instanceof CVInstanceElement) {