Author: adietish
Date: 2010-11-18 12:23:32 -0500 (Thu, 18 Nov 2010)
New Revision: 26728
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/ImageView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java
Log:
[JBIDE-7628] removed explicit loading of the clouds (is now done implicitly by the first
caller of #getClouds())
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-18 17:17:46
UTC (rev 26727)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-18 17:23:32
UTC (rev 26728)
@@ -1,5 +1,17 @@
2010-11-18 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java
(performFinish):
+ [JBIDE-7628] moved saveClouds() to try block so that its errors are reported
+ * src/org/jboss/tools/deltacloud/ui/views/ImageView.java (getClouds):
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceView.java (getClouds):
+ [JBIDE-7628] removed explicit loading of the clouds (is now done implicitly by the first
caller of #getClouds()) -> added exception handling
+ * src/org/jboss/tools/deltacloud/ui/views/DeltaCloudView.java (cloudsChanged):
+ [JBIDE-7628] renamed notification method (to better reflect what it notifies)
+ * src/org/jboss/tools/deltacloud/ui/views/CVRootElement.java (CVRootElement):
+ [JBIDE-7628] removed explicit loading of the clouds (is now done implicitly by the first
caller of #getClouds())
+ (getChildren):
+ (cloudsChanged):
+ [JBIDE-7628] getClouds() can throw DeltaCloudException now (since it may trigger cloud
loading) -> added proper exception catching & reporting
* src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java (execute):
[JBIDE-7625] added error reporting
* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java
(performTest):
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-11-18
17:17:46 UTC (rev 26727)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/ImageView.java 2010-11-18
17:23:32 UTC (rev 26728)
@@ -38,12 +38,14 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
import org.jboss.tools.deltacloud.core.ICloudManagerListener;
import org.jboss.tools.deltacloud.core.IImageFilter;
import org.jboss.tools.deltacloud.core.IImageListListener;
import org.jboss.tools.deltacloud.ui.Activator;
+import org.jboss.tools.deltacloud.ui.ErrorUtils;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
import org.osgi.service.prefs.Preferences;
@@ -67,18 +69,12 @@
private ImageViewLabelAndContentProvider contentProvider;
- private ImageView parentView;
-
- public ImageView() {
- parentView = this;
- }
-
private ModifyListener cloudModifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if (currCloud != null) {
- currCloud.removeImageListListener(parentView);
+ currCloud.removeImageListListener(ImageView.this);
}
int index = cloudSelector.getSelectionIndex();
if (index >= 0) {
@@ -92,7 +88,7 @@
@Override
public void run() {
viewer.setInput(currCloud);
- currCloud.addImageListListener(parentView);
+ currCloud.addImageListListener(ImageView.this);
viewer.refresh();
}
@@ -155,7 +151,8 @@
cloudSelectorLabel.setText(CVMessages.getString(CLOUD_SELECTOR_LABEL));
cloudSelector = new Combo(container, SWT.BORDER | SWT.READ_ONLY);
- initializeCloudSelector();
+ clouds = getClouds();
+ initializeCloudSelector(clouds);
cloudSelector.addModifyListener(cloudModifyListener);
// Following is a kludge so that on Linux the Combo is read-only but
// has a white background.
@@ -187,9 +184,9 @@
getSite().setSelectionProvider(viewer);
if (currCloud != null) {
- currCloud.removeImageListListener(parentView);
+ currCloud.removeImageListListener(this);
viewer.setInput(currCloud);
- currCloud.addImageListListener(parentView);
+ currCloud.addImageListListener(this);
IImageFilter filter = currCloud.getImageFilter();
filterLabel.setVisible(!filter.toString().equals(IImageFilter.ALL_STRING));
}
@@ -224,7 +221,7 @@
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
"org.jboss.tools.deltacloud.ui.viewer");
hookContextMenu();
hookSelection();
-
+
DeltaCloudManager.getDefault().addCloudManagerListener(this);
}
@@ -266,9 +263,8 @@
viewer.getTable().setFocus();
}
- private void initializeCloudSelector() {
+ private void initializeCloudSelector(DeltaCloud[] clouds) {
int defaultIndex = 0;
- clouds = DeltaCloudManager.getDefault().getClouds();
String[] cloudNames = new String[clouds.length];
// If we have saved the last cloud used from a previous session,
// default to using that cloud to start unless it no longer exists
@@ -286,10 +282,10 @@
}
}
- public void changeEvent(int type) {
+ public void cloudsChanged(int type) {
String currName = null;
int currIndex = 0;
- clouds = DeltaCloudManager.getDefault().getClouds();
+ clouds = getClouds();
if (currCloud != null) {
currName = currCloud.getName();
currIndex = cloudSelector.getSelectionIndex();
@@ -325,14 +321,29 @@
@Override
public void run() {
// TODO Auto-generated method stub
- currCloud.removeImageListListener(parentView);
+ currCloud.removeImageListListener(ImageView.this);
viewer.setInput(finalList);
- currCloud.addImageListListener(parentView);
+ currCloud.addImageListListener(ImageView.this);
viewer.refresh();
}
});
}
}
+
+ private DeltaCloud[] getClouds() {
+ DeltaCloud[] clouds = new DeltaCloud[]{};
+ try {
+ clouds = DeltaCloudManager.getDefault().getClouds();
+ } catch (DeltaCloudException e) {
+ // TODO: internationalize strings
+ ErrorUtils.openErrorDialog(
+ "Error",
+ "Could not get all clouds",
+ e, Display.getDefault().getActiveShell());
+ }
+ return clouds;
+ }
+
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-11-18
17:17:46 UTC (rev 26727)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-11-18
17:23:32 UTC (rev 26728)
@@ -38,21 +38,20 @@
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.services.IEvaluationService;
import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
import org.jboss.tools.deltacloud.core.ICloudManagerListener;
import org.jboss.tools.deltacloud.core.IInstanceFilter;
import org.jboss.tools.deltacloud.core.IInstanceListListener;
import org.jboss.tools.deltacloud.ui.Activator;
+import org.jboss.tools.deltacloud.ui.ErrorUtils;
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
import org.osgi.service.prefs.Preferences;
public class InstanceView extends ViewPart implements ICloudManagerListener,
IInstanceListListener {
- /**
- * The ID of the view as specified by the extension.
- */
public static final String ID =
"org.jboss.tools.deltacloud.ui.views.InstanceView";
private final static String CLOUD_SELECTOR_LABEL = "CloudSelector.label";
//$NON-NLS-1$
@@ -149,7 +148,7 @@
layout.marginWidth = 0;
container.setLayout(layout);
- clouds = DeltaCloudManager.getDefault().getClouds();
+ clouds = getClouds();
createCloudSelector();
initCloudSelector(getLastSelectedCloud(), cloudSelector, clouds);
@@ -163,7 +162,7 @@
currCloud = getCurrentCloud(cloudSelector.getSelectionIndex(), clouds);
- initCurrentCloud(currCloud, viewer);
+ addInstanceListener(currCloud, viewer);
setFilterLabelVisible(currCloud, filterLabel);
Point p1 = cloudSelectorLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
@@ -196,10 +195,24 @@
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
"org.jboss.tools.deltacloud.ui.viewer");
hookContextMenu(viewer.getTable());
getSite().setSelectionProvider(viewer);
-
+
DeltaCloudManager.getDefault().addCloudManagerListener(this);
}
+ private DeltaCloud[] getClouds() {
+ DeltaCloud[] clouds = new DeltaCloud[]{};
+ try {
+ clouds = DeltaCloudManager.getDefault().getClouds();
+ } catch (DeltaCloudException e) {
+ // TODO: internationalize strings
+ ErrorUtils.openErrorDialog(
+ "Error",
+ "Could not get all clouds",
+ e, Display.getDefault().getActiveShell());
+ }
+ return clouds;
+ }
+
private void setFilterLabelVisible(DeltaCloud currentCloud, Label filterLabel) {
if (currentCloud == null) {
filterLabel.setVisible(false);
@@ -210,11 +223,11 @@
filterLabel.setVisible(!filter.toString().equals(IInstanceFilter.ALL_STRING));
}
- private void initCurrentCloud(DeltaCloud currentCloud, Viewer viewer) {
+ private void addInstanceListener(DeltaCloud currentCloud, Viewer viewer) {
if (currentCloud != null) {
currentCloud.removeInstanceListListener(this);
+ currentCloud.addInstanceListListener(this);
viewer.setInput(currentCloud);
- currentCloud.addInstanceListListener(this);
}
}
@@ -301,14 +314,14 @@
}
}
- public void changeEvent(int type) {
+ public void cloudsChanged(int type) {
String currName = null;
int currIndex = 0;
if (currCloud != null) {
currName = currCloud.getName();
currIndex = cloudSelector.getSelectionIndex();
}
- clouds = DeltaCloudManager.getDefault().getClouds();
+ clouds = getClouds();
String[] cloudNames = new String[clouds.length];
int index = 0;
for (int i = 0; i < clouds.length; ++i) {
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java 2010-11-18
17:17:46 UTC (rev 26727)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard2.java 2010-11-18
17:23:32 UTC (rev 26728)
@@ -124,25 +124,18 @@
String memory = mainPage.getMemoryProperty();
String storage = mainPage.getStorageProperty();
String keyname = mainPage.getKeyName();
- String name = null;
+ String name = getName();
// Save persistent settings for this particular cloud
cloud.setLastImageId(imageId);
cloud.setLastKeyname(keyname);
- DeltaCloudManager.getDefault().saveClouds();
Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
- try {
- name = URLEncoder.encode(mainPage.getInstanceName(), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } //$NON-NLS-1$
-
boolean result = false;
String errorMessage = WizardMessages.getString(DEFAULT_REASON);
try {
+ DeltaCloudManager.getDefault().saveClouds();
boolean dontShowDialog =
prefs.getBoolean(IDeltaCloudPreferenceConstants.DONT_CONFIRM_CREATE_INSTANCE,
false);
if (!dontShowDialog) {
@@ -187,4 +180,13 @@
return result;
}
+ private String getName() {
+ try {
+ return URLEncoder.encode(mainPage.getInstanceName(), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // TODO: implement proper handling
+ return "";
+ } //$NON-NLS-1$
+ }
+
}