Author: adietish
Date: 2010-12-25 05:36:25 -0500 (Sat, 25 Dec 2010)
New Revision: 27737
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePageModel.java
Log:
[JBIDE-8000] switched to observable pojo that notifies in UI thread only, corrected
binding order (first bind items, then selected item, then enablement)
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-12-25
10:17:25 UTC (rev 27736)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-12-25
10:36:25 UTC (rev 27737)
@@ -10,8 +10,12 @@
*******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.databinding.Binding;
@@ -30,7 +34,9 @@
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
@@ -51,13 +57,16 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudHardwareProfile;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
import org.jboss.tools.deltacloud.core.DeltaCloudKey;
import org.jboss.tools.deltacloud.core.DeltaCloudRealm;
-import org.jboss.tools.deltacloud.core.Driver;
+import org.jboss.tools.deltacloud.core.job.AbstractCloudElementJob;
+import org.jboss.tools.deltacloud.core.job.AbstractCloudElementJob.CLOUDELEMENT;
+import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.MandatoryStringValidator;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.SelectedComboItemValidator;
@@ -139,7 +148,7 @@
super(WizardMessages.getString(NAME));
this.cloud = cloud;
String defaultKeyname = cloud.getLastKeyname();
- model = new NewInstancePageModel(cloud, defaultKeyname, image); //$NON-NLS-1$
+ model = new NewInstancePageModel(defaultKeyname, image); //$NON-NLS-1$
setDescription(WizardMessages.getString(DESCRIPTION));
setTitle(WizardMessages.getString(TITLE));
setImageDescriptor(SWTImagesFactory.DESC_DELTA_LARGE);
@@ -152,6 +161,8 @@
this.container = createWidgets(parent);
setControl(container);
bindWidgets(dbc, container);
+ asyncGetProfiles(model, cloud);
+ asyncGetRealms(model, cloud);
}
private Composite createWidgets(Composite parent) {
@@ -196,9 +207,6 @@
Button keyManageButton = new Button(container, SWT.NULL);
keyManageButton.setText(WizardMessages.getString(MANAGE_BUTTON_LABEL));
keyManageButton.addSelectionListener(manageListener);
- if (Driver.MOCK.equals(cloud.getDriver())) {
- keyManageButton.setEnabled(false);
- }
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(keyManageButton);
Label hardwareLabel = new Label(container, SWT.NULL);
@@ -490,4 +498,40 @@
public NewInstancePageModel getModel() {
return model;
}
+
+ private void asyncGetProfiles(final NewInstancePageModel model, final DeltaCloud cloud)
{
+ // TODO: internationalize strings
+ new AbstractCloudElementJob("Get profiles", cloud, CLOUDELEMENT.PROFILES) {
+ protected IStatus doRun(IProgressMonitor monitor) throws Exception {
+ try {
+ List<DeltaCloudHardwareProfile> profiles =
Arrays.asList(cloud.getProfiles());
+ model.setAllProfiles(profiles);
+ return Status.OK_STATUS;
+ } catch (DeltaCloudException e) {
+ // TODO: internationalize strings
+ return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
+ MessageFormat.format("Could not get profiles from cloud {0}",
cloud.getName()));
+ }
+ }
+ }.schedule();
+ }
+
+ private void asyncGetRealms(final NewInstancePageModel model, final DeltaCloud cloud) {
+ // TODO: internationalize strings
+ new AbstractCloudElementJob("Get realms", cloud, CLOUDELEMENT.REALMS) {
+ protected IStatus doRun(IProgressMonitor monitor) throws Exception {
+ try {
+ List<DeltaCloudRealm> allRealms = new ArrayList<DeltaCloudRealm>();
+ allRealms.addAll(Arrays.asList(cloud.getRealms()));
+ model.setRealms(allRealms);
+ return Status.OK_STATUS;
+ } catch (DeltaCloudException e) {
+ // TODO: internationalize strings
+ return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
+ MessageFormat.format("Could not get realms from cloud {0}",
cloud.getName()));
+ }
+ }
+ }.schedule();
+ }
+
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePageModel.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePageModel.java 2010-12-25
10:17:25 UTC (rev 27736)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePageModel.java 2010-12-25
10:36:25 UTC (rev 27737)
@@ -10,24 +10,13 @@
******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
-import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.jboss.tools.common.log.StatusFactory;
-import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudHardwareProfile;
import org.jboss.tools.deltacloud.core.DeltaCloudImage;
import org.jboss.tools.deltacloud.core.DeltaCloudRealm;
-import org.jboss.tools.deltacloud.core.job.AbstractCloudElementJob;
-import org.jboss.tools.deltacloud.core.job.AbstractCloudElementJob.CLOUDELEMENT;
-import org.jboss.tools.deltacloud.ui.Activator;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.ObservableUIPojo;
/**
@@ -52,7 +41,6 @@
private DeltaCloudImage image;
private String arch;
private String keyname;
- private DeltaCloud cloud;
private DeltaCloudRealm selectedRealm;
private List<DeltaCloudRealm> realms = new ArrayList<DeltaCloudRealm>();
private DeltaCloudHardwareProfile selectedProfile;
@@ -62,12 +50,9 @@
private String storage;
private String memory;
- protected NewInstancePageModel(DeltaCloud cloud, String keyname, DeltaCloudImage image)
{
- this.cloud = cloud;
+ protected NewInstancePageModel(String keyname, DeltaCloudImage image) {
this.keyname = keyname;
this.image = image;
- asyncGetRealms();
- asyncGetProfiles();
}
public String getName() {
@@ -116,16 +101,19 @@
return selectedRealm.getId();
}
- private void setRealms(List<DeltaCloudRealm> realms) {
+ protected void setRealms(List<DeltaCloudRealm> realms) {
getPropertyChangeSupport().firePropertyChange(PROPERTY_REALMS, this.realms, this.realms
= realms);
+ setSelectedRealmIndex(0);
}
public List<DeltaCloudRealm> getRealms() {
return realms;
}
- private void setAllProfiles(List<DeltaCloudHardwareProfile> profiles) {
+ protected void setAllProfiles(List<DeltaCloudHardwareProfile> profiles) {
getPropertyChangeSupport().firePropertyChange(PROP_ALL_PROFILES, this.allProfiles,
this.allProfiles = profiles);
+ setFilteredProfiles(filterProfiles(image, profiles));
+ setSelectedProfileIndex(0);
}
public List<DeltaCloudHardwareProfile> getAllProfiles() {
@@ -201,42 +189,6 @@
return allProfiles.indexOf(selectedProfile);
}
- private void asyncGetRealms() {
- // TODO: internationalize strings
- new AbstractCloudElementJob("Get realms", cloud, CLOUDELEMENT.REALMS) {
- protected IStatus doRun(IProgressMonitor monitor) throws Exception {
- try {
- setRealms(Arrays.asList(cloud.getRealms()));
- setSelectedRealmIndex(0);
- return Status.OK_STATUS;
- } catch (DeltaCloudException e) {
- // TODO: internationalize strings
- return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
- MessageFormat.format("Could not get realms from cloud {0}",
cloud.getName()));
- }
- }
- }.schedule();
- }
-
- private void asyncGetProfiles() {
- // TODO: internationalize strings
- new AbstractCloudElementJob("Get profiles", cloud, CLOUDELEMENT.PROFILES) {
- protected IStatus doRun(IProgressMonitor monitor) throws Exception {
- try {
- List<DeltaCloudHardwareProfile> profiles =
Arrays.asList(cloud.getProfiles());
- setAllProfiles(profiles);
- setFilteredProfiles(filterProfiles(image, profiles));
- setSelectedProfileIndex(0);
- return Status.OK_STATUS;
- } catch (DeltaCloudException e) {
- // TODO: internationalize strings
- return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
- MessageFormat.format("Could not get profiles from cloud {0}",
cloud.getName()));
- }
- }
- }.schedule();
- }
-
public void setCpu(String cpu) {
this.cpu = cpu;
}