Author: adietish
Date: 2010-12-22 15:32:48 -0500 (Wed, 22 Dec 2010)
New Revision: 27694
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/cloudelements/AbstractCloudElementTableView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementViewLabelAndContentProvider.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/ImageViewLabelAndContentProvider.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/InstanceViewLabelAndContentProvider.java
Log:
[JBIDE-7959] now null is accepted to clear table view (needed when disconnecting last
cloud), now handling case where current cloud is being removed
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-22 19:31:11
UTC (rev 27693)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-22 20:32:48
UTC (rev 27694)
@@ -1,5 +1,13 @@
2010-12-22 adietisheim <adietisheim@adietisheim-thinkpad>
+ *
src/org/jboss/tools/deltacloud/ui/views/cloudelements/InstanceViewLabelAndContentProvider.java
(asyncAddCloudElements):
+ *
src/org/jboss/tools/deltacloud/ui/views/cloudelements/ImageViewLabelAndContentProvider.java
(asyncAddCloudElements):
+ *
src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementViewLabelAndContentProvider.java
(inputChanged):
+ *
src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java
+ (setViewerInput):
+ (cloudsChanged):
+ [JBIDE-7959] now null is accepted to clear table view (needed when disconnecting last
cloud)
+ [JBIDE-7959] now handling case where current cloud is being removed
* src/org/jboss/tools/deltacloud/ui/views/cloudelements/InstanceView.java
(addPropertyChangeListener):
[JBIDE-7959] added guard to avoid NPE when adding property change listener to current
cloud
* src/org/jboss/tools/internal/deltacloud/ui/wizards/ProfilePage.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java 2010-12-22
19:31:11 UTC (rev 27693)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java 2010-12-22
20:32:48 UTC (rev 27694)
@@ -80,7 +80,7 @@
private TextPreferenceValue lastSelectedCloudPref;
private Composite container;
- private ModifyListener cloudCloudModifyListener = new ModifyListener() {
+ private ModifyListener currentCloudModifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
@@ -114,7 +114,8 @@
// only
DeltaCloud cloud = UIUtils.getFirstAdaptedElement(selection, DeltaCloud.class);
if (isNewCloud(cloud)) {
- currentCloudSelector.select(getCloudIndex(cloud, getClouds()));
+ int index = getCloudIndex(cloud, getClouds());
+ currentCloudSelector.select(index);
}
}
};
@@ -240,9 +241,7 @@
protected abstract ITableContentAndLabelProvider getContentAndLabelProvider();
private void setViewerInput(DeltaCloud cloud) {
- if (currentCloud != null) {
- viewer.setInput(currentCloud);
- }
+ viewer.setInput(cloud);
}
/**
@@ -273,7 +272,9 @@
private int getCloudIndex(String cloudName, DeltaCloud[] clouds) {
int index = 0;
- if (cloudName != null && clouds.length > 0) {
+ if (cloudName != null
+ && cloudName.length() > 0
+ && clouds.length > 0) {
for (int i = 0; i < clouds.length; i++) {
DeltaCloud cloud = clouds[i];
if (cloudName != null && cloudName.equals(cloud.getName())) {
@@ -322,7 +323,7 @@
currentCloudSelectorLabel.setText(CVMessages.getString(CLOUD_SELECTOR_LABEL));
this.currentCloudSelector = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
- currentCloudSelector.addModifyListener(cloudCloudModifyListener);
+ currentCloudSelector.addModifyListener(currentCloudModifyListener);
// Following is a kludge so that on Linux the Combo is read-only but
// has a white background.
currentCloudSelector.addVerifyListener(new VerifyListener() {
@@ -341,10 +342,10 @@
protected abstract String getViewID();
private void initCloudSelector(String cloudNameToSelect, Combo cloudSelector,
DeltaCloud[] clouds) {
- if (clouds.length > 0
- && cloudNameToSelect != null && cloudNameToSelect.length() > 0) {
- cloudSelector.setItems(toCloudNames(clouds));
- cloudSelector.select(getCloudIndex(cloudNameToSelect, clouds));
+ if (clouds.length > 0) {
+ setCloudSelectorItems(toCloudNames(clouds), cloudSelector);
+ int index = getCloudIndex(cloudNameToSelect, clouds);
+ cloudSelector.select(index);
}
}
@@ -361,29 +362,26 @@
int index = getCloudIndex(cloud, clouds);
if (index >= 0) {
int selectionIndex = currentCloudSelector.getSelectionIndex();
- currentCloudSelector.removeModifyListener(cloudCloudModifyListener);
+ currentCloudSelector.removeModifyListener(currentCloudModifyListener);
currentCloudSelector.setItem(index, cloud.getName());
currentCloudSelector.select(selectionIndex);
- currentCloudSelector.addModifyListener(cloudCloudModifyListener);
+ currentCloudSelector.addModifyListener(currentCloudModifyListener);
}
container.layout(true, true);
}
public void cloudsChanged(int type, DeltaCloud cloud) {
+ DeltaCloud[] clouds = getClouds();
switch (type) {
- case IDeltaCloudManagerListener.ADD_EVENT:
- addPropertyChangeListener(cloud);
- break;
case IDeltaCloudManagerListener.REMOVE_EVENT:
- removePropertyChangeListener(cloud);
+ onCloudRemoved(cloud, clouds);
break;
+ default:
}
-
- DeltaCloud[] clouds = getClouds();
- int index = getCloudIndex(currentCloud, getClouds());
+
+ int index = getCloudIndex(currentCloud, clouds);
String[] cloudNames = toCloudNames(clouds);
setCloudSelectorItems(cloudNames, currentCloudSelector);
- this.currentCloud = getCloud(index, clouds);
if (cloudNames.length > 0) {
currentCloudSelector.setText(cloudNames[index]);
@@ -395,6 +393,13 @@
container.layout(true, true);
}
+ private void onCloudRemoved(DeltaCloud cloud, DeltaCloud[] clouds) {
+ if (cloud == currentCloud) {
+ removePropertyChangeListener(cloud);
+ this.currentCloud = getCloud(0, clouds);
+ }
+ }
+
protected void addPropertyChangeListener(DeltaCloud cloud) {
if (cloud != null) {
cloud.addPropertyChangeListener(DeltaCloud.PROP_NAME, this);
@@ -418,9 +423,9 @@
}
private void setCloudSelectorItems(String[] cloudNames, Combo cloudSelector) {
- cloudSelector.removeModifyListener(cloudCloudModifyListener);
+ cloudSelector.removeModifyListener(currentCloudModifyListener);
cloudSelector.setItems(cloudNames);
- cloudSelector.addModifyListener(cloudCloudModifyListener);
+ cloudSelector.addModifyListener(currentCloudModifyListener);
}
/**
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-22
19:31:11 UTC (rev 27693)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementViewLabelAndContentProvider.java 2010-12-22
20:32:48 UTC (rev 27694)
@@ -36,16 +36,17 @@
private DeltaCloud currentCloud;
private ICloudElementFilter<CLOUDELEMENT> localFilter;
private TableViewer viewer;
-
+
@Override
public Object[] getElements(Object input) {
/*
* items are added in asynchronous manner.
*
* @see #inputChanged
+ *
* @see #asyncAddCloudElements
*/
- return new Object[]{};
+ return new Object[] {};
}
public void setFilter(ICloudElementFilter<CLOUDELEMENT> filter) {
@@ -54,7 +55,7 @@
@Override
public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
- if (!(newInput instanceof DeltaCloud)) {
+ if (!(newInput instanceof DeltaCloud || newInput != null)) {
return;
}
Assert.isLegal(viewer instanceof TableViewer);
@@ -64,7 +65,7 @@
addPropertyChangeListener(currentCloud);
asyncAddCloudElements(currentCloud);
}
-
+
protected void updateCloudElements(CLOUDELEMENT[] elements, DeltaCloud cloud) {
if (isCurrentCloud(cloud)) {
addToViewer(elements);
@@ -83,7 +84,7 @@
@Override
public void run() {
try {
- viewer.refresh();
+ clearTableViewer();
Object[] elements = filter(getFilter(currentCloud), cloudElements);
viewer.add(elements);
} catch (DeltaCloudException e) {
@@ -128,6 +129,10 @@
}
}
+ protected void clearTableViewer() {
+ viewer.refresh();
+ }
+
protected abstract ICloudElementFilter<CLOUDELEMENT> getCloudFilter(DeltaCloud
cloud);
protected abstract void asyncAddCloudElements(DeltaCloud cloud);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/ImageViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/ImageViewLabelAndContentProvider.java 2010-12-22
19:31:11 UTC (rev 27693)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/ImageViewLabelAndContentProvider.java 2010-12-22
20:32:48 UTC (rev 27694)
@@ -100,15 +100,19 @@
@Override
protected void asyncAddCloudElements(final DeltaCloud cloud) {
+ if (cloud == null) {
+ clearTableViewer();
+ return;
+ }
new AbstractCloudElementJob(
MessageFormat.format("Get images from cloud {0}", cloud.getName()), cloud,
CLOUDELEMENT.IMAGES) {
@Override
protected IStatus doRun(IProgressMonitor monitor) throws DeltaCloudException {
try {
- addToViewer(cloud.getImages());;
+ addToViewer(cloud.getImages());
return Status.OK_STATUS;
- } catch(DeltaCloudException e) {
+ } catch (DeltaCloudException e) {
throw e;
}
}
@@ -123,12 +127,12 @@
updateCloudElements(images, cloud);
}
}
-
+
@Override
public void addPropertyChangeListener(DeltaCloud cloud) {
cloud.addPropertyChangeListener(DeltaCloud.PROP_IMAGES, this);
}
-
+
protected DeltaCloudImage[] getCloudElements(DeltaCloud cloud) throws
DeltaCloudException {
return cloud.getImages();
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/InstanceViewLabelAndContentProvider.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/InstanceViewLabelAndContentProvider.java 2010-12-22
19:31:11 UTC (rev 27693)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/InstanceViewLabelAndContentProvider.java 2010-12-22
20:32:48 UTC (rev 27694)
@@ -125,6 +125,10 @@
@Override
protected void asyncAddCloudElements(final DeltaCloud cloud) {
+ if (cloud == null) {
+ clearTableViewer();
+ return;
+ }
new AbstractCloudElementJob(
MessageFormat.format("Get instances from cloud {0}", cloud.getName()),
cloud, CLOUDELEMENT.INSTANCES) {
@@ -132,7 +136,6 @@
protected IStatus doRun(IProgressMonitor monitor) throws DeltaCloudException {
try {
addToViewer(cloud.getInstances());
- ;
return Status.OK_STATUS;
} catch (DeltaCloudException e) {
throw e;