Author: adietish
Date: 2011-03-15 05:09:27 -0400 (Tue, 15 Mar 2011)
New Revision: 29782
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java
Log:
[JBIDE-7862]
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java 2011-03-15
08:53:22 UTC (rev 29781)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloudelements/AbstractCloudElementTableView.java 2011-03-15
09:09:27 UTC (rev 29782)
@@ -13,6 +13,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.core.runtime.IAdaptable;
@@ -241,7 +242,7 @@
}
protected abstract ITableContentAndLabelProvider<CLOUDELEMENT>
getContentAndLabelProvider();
-
+
private void setViewerInput(DeltaCloud cloud) {
viewer.setInput(cloud);
}
@@ -306,9 +307,10 @@
return clouds[cloudIndex];
}
- private void createColumns(ITableContentAndLabelProvider<CLOUDELEMENT> provider,
TableColumnLayout tableLayout, Table table) {
+ private void createColumns(ITableContentAndLabelProvider<CLOUDELEMENT> provider,
TableColumnLayout tableLayout,
+ Table table) {
Columns<CLOUDELEMENT> columns = provider.getColumns();
-
+
for (int i = 0; i < columns.getSize(); ++i) {
Column<CLOUDELEMENT> c = columns.getColumn(i);
TableColumn tc = new TableColumn(table, SWT.NONE);
@@ -364,43 +366,59 @@
DeltaCloud[] clouds = getClouds();
final int index = getCloudIndex(cloud, clouds);
Display.getDefault().syncExec(new Runnable() {
-
+
@Override
public void run() {
if (index >= 0) {
int selectionIndex = currentCloudSelector.getSelectionIndex();
currentCloudSelector.removeModifyListener(currentCloudModifyListener);
- currentCloudSelector.setItem(index, cloud.getName());
+ /*
+ * @see [JBIDE-7862]
+ * setting all items seems necessary so that the combo uses the space needed to
display the largest cloud name.
+ * If you just replace the item that was renamed, the combo will not shrink (it
would only get larger if needed).
+ */
+ currentCloudSelector.setItems(getSelectorItems(cloud, index));
currentCloudSelector.select(selectionIndex);
currentCloudSelector.addModifyListener(currentCloudModifyListener);
}
container.layout(true, true);
-
}
+
+ private String[] getSelectorItems(final DeltaCloud cloud, final int index) {
+ List<String> names = new
ArrayList<String>(Arrays.asList(currentCloudSelector.getItems()));
+ names.set(index, cloud.getName());
+ return names.toArray(new String[names.size()]);
+ }
});
}
- public void cloudsChanged(int type, DeltaCloud cloud) {
- DeltaCloud[] clouds = getClouds();
- switch (type) {
- case IDeltaCloudManagerListener.REMOVE_EVENT:
- onCloudRemoved(cloud, clouds);
- break;
- default:
- }
-
- int index = getCloudIndex(currentCloud, clouds);
- String[] cloudNames = toCloudNames(clouds);
- setCloudSelectorItems(cloudNames, currentCloudSelector);
+ public void cloudsChanged(final int type, final DeltaCloud cloud) {
+ viewer.getControl().getDisplay().syncExec(new Runnable() {
- if (cloudNames.length > 0) {
- currentCloudSelector.setText(cloudNames[index]);
- setViewerInput(currentCloud);
- } else {
- currentCloudSelector.setText("");
- setViewerInput(null);
+ @Override
+ public void run() {
+ DeltaCloud[] clouds = getClouds();
+ switch (type) {
+ case IDeltaCloudManagerListener.REMOVE_EVENT:
+ onCloudRemoved(cloud, clouds);
+ break;
+ default:
+ }
+
+ int index = getCloudIndex(currentCloud, clouds);
+ String[] cloudNames = toCloudNames(clouds);
+ setCloudSelectorItems(cloudNames, currentCloudSelector);
+
+ if (cloudNames.length > 0) {
+ currentCloudSelector.setText(cloudNames[index]);
+ setViewerInput(currentCloud);
+ } else {
+ currentCloudSelector.setText("");
+ setViewerInput(null);
+ }
+ container.layout(true, true);
}
- container.layout(true, true);
+ });
}
private void onCloudRemoved(DeltaCloud cloud, DeltaCloud[] clouds) {