Author: xcoulon
Date: 2012-02-10 09:59:45 -0500 (Fri, 10 Feb 2012)
New Revision: 38603
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
Log:
OPEN - issue JBIDE-10528: Improve OpenShift UI
https://issues.jboss.org/browse/JBIDE-10528
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-02-10
14:45:55 UTC (rev 38602)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-02-10
14:59:45 UTC (rev 38603)
@@ -95,7 +95,7 @@
private Button useExistingAppBtn = null;
public ApplicationConfigurationWizardPage(IWizard wizard,
OpenShiftExpressApplicationWizardModel wizardModel) {
- super("Application Configuration", "Configure the application you want
to create.",
+ super("Application Configuration", "Configure the application you
want\nto create or import.",
"Application configuration", wizard);
this.pageModel = new ApplicationConfigurationWizardPageModel(wizardModel);
}
@@ -111,19 +111,17 @@
private Composite createApplicationSelectionGroup(Composite container,
DataBindingContext dbc) {
Composite existingAppSelectionGroup = new Composite(container, SWT.NONE);
// projectGroup.setText("Project");
- GridDataFactory.fillDefaults()
- .align(SWT.LEFT, SWT.CENTER).align(SWT.FILL, SWT.CENTER).grab(true, false)
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).align(SWT.FILL,
SWT.CENTER).grab(true, false)
.applyTo(existingAppSelectionGroup);
- GridLayoutFactory.fillDefaults()
- .numColumns(3).margins(6, 6).applyTo(existingAppSelectionGroup);
+ GridLayoutFactory.fillDefaults().numColumns(3).margins(6,
6).applyTo(existingAppSelectionGroup);
// existing app checkbox
useExistingAppBtn = new Button(existingAppSelectionGroup, SWT.CHECK);
- useExistingAppBtn.setText("Use the existing application");
+ useExistingAppBtn.setText("Use existing application");
useExistingAppBtn.setToolTipText("Select an existing application or uncheck to
create a new one.");
useExistingAppBtn.setFocus();
- GridDataFactory.fillDefaults()
- .span(1, 1).align(SWT.FILL, SWT.CENTER).grab(false,
false).applyTo(useExistingAppBtn);
+ GridDataFactory.fillDefaults().span(1, 1).align(SWT.FILL, SWT.CENTER).grab(false,
false)
+ .applyTo(useExistingAppBtn);
final IObservableValue useExistingAppObservable = BeanProperties.value(
ApplicationConfigurationWizardPageModel.PROPERTY_USE_EXISTING_APPLICATION).observe(pageModel);
final ISWTObservableValue useExistingAppBtnSelection =
WidgetProperties.selection().observe(useExistingAppBtn);
@@ -131,22 +129,20 @@
// existing app name
final Text existingAppNameText = new Text(existingAppSelectionGroup, SWT.BORDER);
- GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true,
false).applyTo(existingAppNameText);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true,
false)
+ .applyTo(existingAppNameText);
final IObservableValue existingAppNameModelObservable = BeanProperties.value(
ApplicationConfigurationWizardPageModel.PROPERTY_EXISTING_APPLICATION_NAME).observe(pageModel);
- final ISWTObservableValue existingAppNameTextObservable =
- WidgetProperties.text(SWT.Modify).observe(existingAppNameText);
+ final ISWTObservableValue existingAppNameTextObservable =
WidgetProperties.text(SWT.Modify).observe(
+ existingAppNameText);
ValueBindingBuilder.bind(existingAppNameTextObservable).to(existingAppNameModelObservable).in(dbc);
if (pageModel.getExistingApplicationName() != null) {
existingAppNameText.setText(pageModel.getExistingApplicationName());
}
// enable the app name text when the model state is set to 'use existing
// app'
- ValueBindingBuilder
- .bind(WidgetProperties.enabled().observe(existingAppNameText))
- .notUpdating(useExistingAppObservable)
- .in(dbc);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(existingAppNameText))
+ .notUpdating(useExistingAppObservable).in(dbc);
// move focus to the project name text control when choosing the 'Use an
// existing project' option.
useExistingAppBtn.addSelectionListener(new SelectionAdapter() {
@@ -165,12 +161,12 @@
.applyTo(browseAppsButton);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(browseAppsButton))
.notUpdating(useExistingAppObservable).in(dbc);
- final IObservableValue existingAppValidityObservable = BeanProperties.value(
- ApplicationConfigurationWizardPageModel.PROPERTY_EXISTING_APPLICATION_NAME).observe(pageModel);
+ // observe the list of application, get notified once they have been loaded
+ final IObservableValue existingAppsObservable = BeanProperties.value(
+ ApplicationConfigurationWizardPageModel.PROPERTY_EXISTING_APPLICATIONS).observe(pageModel);
- final ApplicationToSelectNameValidator existingProjectValidator =
- new ApplicationToSelectNameValidator(
- existingAppValidityObservable, existingAppNameTextObservable,
existingAppNameModelObservable);
+ final ApplicationToSelectNameValidator existingProjectValidator = new
ApplicationToSelectNameValidator(
+ useExistingAppBtnSelection, existingAppNameTextObservable, existingAppsObservable);
dbc.addValidationStatusProvider(existingProjectValidator);
ControlDecorationSupport.create(existingProjectValidator, SWT.LEFT | SWT.TOP);
@@ -179,14 +175,14 @@
private void createContentAssist(final Text existingAppNameText) {
ControlDecoration dec = new ControlDecoration(existingAppNameText, SWT.TOP |
SWT.LEFT);
- FieldDecoration contentProposalFieldIndicator =
- FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
+ FieldDecoration contentProposalFieldIndicator =
FieldDecorationRegistry.getDefault().getFieldDecoration(
+ FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
dec.setImage(contentProposalFieldIndicator.getImage());
dec.setDescriptionText("Auto-completion is enabled when you start typing a project
name.");
dec.setShowOnlyOnFocus(true);
- AutoCompleteField adapter =
- new AutoCompleteField(existingAppNameText, new TextContentAdapter(), new String[]
{});
+ AutoCompleteField adapter = new AutoCompleteField(existingAppNameText, new
TextContentAdapter(),
+ new String[] {});
adapter.setProposals(getApplicationNames());
}
@@ -237,33 +233,24 @@
applicationNameLabel.setText("Name:");
GridDataFactory.fillDefaults().align(SWT.FILL,
SWT.CENTER).applyTo(applicationNameLabel);
Text applicationNameText = new Text(container, SWT.BORDER);
- GridDataFactory.fillDefaults()
- .grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(applicationNameText);
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL,
SWT.FILL).applyTo(applicationNameText);
UIUtils.selectAllOnFocus(applicationNameText);
final IObservableValue applicationNameModelObservable = BeanProperties.value(
ApplicationConfigurationWizardPageModel.PROPERTY_APPLICATION_NAME).observe(pageModel);
final ISWTObservableValue applicationNameTextObservable =
WidgetProperties.text(SWT.Modify).observe(
applicationNameText);
dbc.bindValue(applicationNameTextObservable, applicationNameModelObservable);
- IObservableValue useExistingObservable =
- BeanProperties.value(ApplicationConfigurationWizardPageModel.PROPERTY_USE_EXISTING_APPLICATION)
- .observe(pageModel);
- ValueBindingBuilder
- .bind(WidgetProperties.enabled().observe(applicationNameText))
- .notUpdating(useExistingObservable)
- .converting(new InvertingBooleanConverter())
- .in(dbc);
+ IObservableValue useExistingObservable = BeanProperties.value(
+ ApplicationConfigurationWizardPageModel.PROPERTY_USE_EXISTING_APPLICATION).observe(pageModel);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(applicationNameText))
+ .notUpdating(useExistingObservable).converting(new
InvertingBooleanConverter()).in(dbc);
- final IObservableValue applicationNameStatusObservable = BeanProperties.value(
- ApplicationConfigurationWizardPageModel.PROPERTY_APPLICATION_NAME_STATUS).observe(pageModel);
-
Label applicationTypeLabel = new Label(container, SWT.NONE);
applicationTypeLabel.setText("Type:");
- GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.CENTER).span(1, 1).applyTo(applicationTypeLabel);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1,
1).applyTo(applicationTypeLabel);
Combo cartridgesCombo = new Combo(container, SWT.BORDER | SWT.READ_ONLY);
- GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true, false).applyTo(cartridgesCombo);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true,
false)
+ .applyTo(cartridgesCombo);
fillCartridgesCombo(dbc, cartridgesCombo);
final ISWTObservableValue cartridgesComboObservable =
WidgetProperties.selection().observe(cartridgesCombo);
final IObservableValue selectedCartridgeModelObservable = BeanProperties.value(
@@ -271,65 +258,49 @@
dbc.bindValue(cartridgesComboObservable, selectedCartridgeModelObservable,
new UpdateValueStrategy().setConverter(new StringToCartridgeConverter()),
new UpdateValueStrategy().setConverter(new CartridgeToStringConverter()));
- ValueBindingBuilder
- .bind(WidgetProperties.enabled().observe(cartridgesCombo))
- .notUpdating(useExistingObservable)
- .converting(new InvertingBooleanConverter())
- .in(dbc);
-
- final ApplicationToCreateInputValidator applicationInputValidator =
- new ApplicationToCreateInputValidator(applicationNameTextObservable,
cartridgesComboObservable);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(cartridgesCombo))
+ .notUpdating(useExistingObservable).converting(new
InvertingBooleanConverter()).in(dbc);
+ final ISWTObservableValue useExistingAppBtnSelection =
WidgetProperties.selection().observe(useExistingAppBtn);
+
+ final ApplicationToCreateInputValidator applicationInputValidator = new
ApplicationToCreateInputValidator(useExistingAppBtnSelection,
+ applicationNameTextObservable, cartridgesComboObservable);
dbc.addValidationStatusProvider(applicationInputValidator);
/*
- * final ApplicationToSelectNameValidator applicationNameValidator = new
- * ApplicationToSelectNameValidator(us applicationNameStatusObservable,
- * applicationNameTextObservable);
+ * final ApplicationToSelectNameValidator applicationNameValidator = new
ApplicationToSelectNameValidator(us
+ * applicationNameStatusObservable, applicationNameTextObservable);
* dbc.addValidationStatusProvider(applicationNameValidator);
- * ControlDecorationSupport.create(applicationNameValidator, SWT.LEFT |
- * SWT.TOP);
+ * ControlDecorationSupport.create(applicationNameValidator, SWT.LEFT | SWT.TOP);
*/
// embeddable cartridges
Group cartridgesGroup = new Group(container, SWT.NONE);
cartridgesGroup.setText("Embeddable Cartridges");
- GridDataFactory.fillDefaults()
- .grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(cartridgesGroup);
- GridLayoutFactory.fillDefaults()
- .numColumns(2).margins(6, 6).applyTo(cartridgesGroup);
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2,
1).applyTo(cartridgesGroup);
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(cartridgesGroup);
Composite tableContainer = new Composite(cartridgesGroup, SWT.NONE);
- GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.FILL).grab(true, true).span(1, 2).hint(400,
250).applyTo(tableContainer);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(1,
2).hint(400, 250)
+ .applyTo(tableContainer);
this.viewer = createTable(tableContainer);
- ValueBindingBuilder
- .bind(WidgetProperties.enabled().observe(viewer.getTable()))
- .notUpdating(useExistingObservable)
- .converting(new InvertingBooleanConverter())
- .in(dbc);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(viewer.getTable()))
+ .notUpdating(useExistingObservable).converting(new
InvertingBooleanConverter()).in(dbc);
Button checkAllButton = new Button(cartridgesGroup, SWT.PUSH);
checkAllButton.setText("&Select All");
- GridDataFactory.fillDefaults()
- .hint(110, SWT.DEFAULT).grab(false, false).align(SWT.FILL,
SWT.TOP).applyTo(checkAllButton);
+ GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).grab(false,
false).align(SWT.FILL, SWT.TOP)
+ .applyTo(checkAllButton);
checkAllButton.addSelectionListener(onCheckAll());
- ValueBindingBuilder
- .bind(WidgetProperties.enabled().observe(checkAllButton))
- .notUpdating(useExistingObservable)
- .converting(new InvertingBooleanConverter())
- .in(dbc);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(checkAllButton)).notUpdating(useExistingObservable)
+ .converting(new InvertingBooleanConverter()).in(dbc);
Button uncheckAllButton = new Button(cartridgesGroup, SWT.PUSH);
uncheckAllButton.setText("&Deselect All");
- GridDataFactory.fillDefaults()
- .hint(110, SWT.DEFAULT).grab(false, true).align(SWT.FILL,
SWT.TOP).applyTo(uncheckAllButton);
+ GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).grab(false, true).align(SWT.FILL,
SWT.TOP)
+ .applyTo(uncheckAllButton);
uncheckAllButton.addSelectionListener(onUncheckAll());
- ValueBindingBuilder
- .bind(WidgetProperties.enabled().observe(uncheckAllButton))
- .notUpdating(useExistingObservable)
- .converting(new InvertingBooleanConverter())
- .in(dbc);
+ ValueBindingBuilder.bind(WidgetProperties.enabled().observe(uncheckAllButton))
+ .notUpdating(useExistingObservable).converting(new
InvertingBooleanConverter()).in(dbc);
// bottom filler
Composite spacer = new Composite(container, SWT.NONE);
- GridDataFactory.fillDefaults()
- .span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(spacer);
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true,
true).applyTo(spacer);
// enabling the group if the 'use existing application' checkbox state
// is 'false' (unchecked)
@@ -337,9 +308,7 @@
this.useExistingAppBtn);
final ISWTObservableValue createApplicationGroupEnabled =
WidgetProperties.enabled().observe(container);
- ValueBindingBuilder
- .bind(createApplicationGroupEnabled).notUpdatingParticipant()
- .to(useExistinAppBtnObservable)
+ ValueBindingBuilder.bind(createApplicationGroupEnabled).notUpdatingParticipant().to(useExistinAppBtnObservable)
.converting(new InvertingBooleanConverter()).in(dbc);
// dbc.bindValue(useExistinAppBtnObservable,
@@ -592,12 +561,11 @@
}
/**
- * Viewer element comparer based on #equals(). The default implementation in
- * CheckboxTableViewer compares elements based on instance identity.
+ * Viewer element comparer based on #equals(). The default implementation in
CheckboxTableViewer compares elements
+ * based on instance identity.
* <p>
- * We need this since the available cartridges (item listed in the viewer)
- * are not the same instance as the ones in the embedded application (items
- * to check in the viewer).
+ * We need this since the available cartridges (item listed in the viewer) are not the
same instance as the ones in
+ * the embedded application (items to check in the viewer).
*/
private static class EqualityComparer implements IElementComparer {
@@ -623,11 +591,11 @@
@Override
protected void onPageActivated(final DataBindingContext dbc) {
- // This is needed for some strange freezing issues when
+ // This is needed for some strange freezing issues when
// launching the wizard from the console view. The UI seems to freeze
new Thread() {
public void run() {
- Display.getDefault().asyncExec(new Runnable() {
+ Display.getDefault().asyncExec(new Runnable() {
public void run() {
onPageActivated2(dbc);
}
@@ -635,6 +603,7 @@
}
}.start();
}
+
protected void onPageActivated2(final DataBindingContext dbc) {
try {
WizardUtils.runInWizard(new Job("Loading existing applications...") {
@@ -688,32 +657,44 @@
class ApplicationToSelectNameValidator extends MultiValidator {
- private final IObservableValue existingAppValidityObservable;
+ private final ISWTObservableValue useExistingAppBtnbservable;
private final ISWTObservableValue existingAppNameTextObservable;
- private final IObservableValue existingAppNameModelObservable;
+ private final IObservableValue existingAppsObservable;
- public ApplicationToSelectNameValidator(IObservableValue
existingAppValidityObservable,
- ISWTObservableValue existingAppNameTextObservable, IObservableValue
existingAppNameModelObservable) {
- this.existingAppValidityObservable = existingAppValidityObservable;
+ public ApplicationToSelectNameValidator(ISWTObservableValue
useExistingAppBtnbservable,
+ ISWTObservableValue existingAppNameTextObservable, IObservableValue
existingAppsObservable) {
+ this.useExistingAppBtnbservable = useExistingAppBtnbservable;
this.existingAppNameTextObservable = existingAppNameTextObservable;
- this.existingAppNameModelObservable = existingAppNameModelObservable;
+ this.existingAppsObservable = existingAppsObservable;
}
@Override
protected IStatus validate() {
- /*
- * final IStatus applicationNameStatus = (IStatus)
- * applicationNameStatusObservable.getValue(); if
- * (applicationNameStatus != null) { return applicationNameStatus; }
- */
- return ValidationStatus.ok();
+ final boolean useExistingApp = (Boolean) useExistingAppBtnbservable.getValue();
+ final String appName = (String) existingAppNameTextObservable.getValue();
+ @SuppressWarnings("unchecked")
+ final List<IApplication> existingApps = (List<IApplication>)
existingAppsObservable.getValue();
+ if (!useExistingApp) {
+ return ValidationStatus.ok();
+ }
+ if (existingApps != null) {
+ for (IApplication application : pageModel.getExistingApplications()) {
+ if (application.getName().equalsIgnoreCase(appName)) {
+ return ValidationStatus.ok();
+ }
+ }
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "The application '" + appName + "' does not exist.");
+ }
+ return new Status(IStatus.CANCEL, OpenShiftUIActivator.PLUGIN_ID,
+ "Select an existing OpenShift application.");
+
+
}
/*
* (non-Javadoc)
- *
- * @see
- * org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
*/
@Override
public IObservableList getTargets() {
@@ -726,23 +707,33 @@
class ApplicationToCreateInputValidator extends MultiValidator {
- private final ISWTObservableValue applicationNameTextObservable,
cartridgesComboObservable;
+ private final ISWTObservableValue useExistingAppBtnbservable;
+ private final ISWTObservableValue applicationNameTextObservable;
+ private final ISWTObservableValue cartridgesComboObservable;
- public ApplicationToCreateInputValidator(ISWTObservableValue
applicationNameTextObservable,
+ public ApplicationToCreateInputValidator(ISWTObservableValue
useExistingAppBtnbservable,
+ ISWTObservableValue applicationNameTextObservable,
ISWTObservableValue cartridgesComboObservable) {
+ this.useExistingAppBtnbservable = useExistingAppBtnbservable;
this.applicationNameTextObservable = applicationNameTextObservable;
this.cartridgesComboObservable = cartridgesComboObservable;
}
@Override
protected IStatus validate() {
- if (!pageModel.getUseExistingApplication()) {
- final String applicationName = (String) applicationNameTextObservable.getValue();
- final String applicationType = (String) cartridgesComboObservable.getValue();
- if (applicationName == null || applicationName.isEmpty() || applicationType == null
- || applicationType.isEmpty()) {
- return ValidationStatus
- .cancel("Please enter a name and select a type for the OpenShift application
you want to create.");
+ final String applicationName = (String) applicationNameTextObservable.getValue();
+ final boolean useExistingApp = (Boolean) useExistingAppBtnbservable.getValue();
+ if (useExistingApp) {
+ return ValidationStatus.ok();
+ }
+ if (!applicationName.matches("\\S+")) {
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "The application name must not contain spaces.");
+ }
+ for (IApplication application : pageModel.getExistingApplications()) {
+ if (application.getName().equalsIgnoreCase(applicationName)) {
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "An application with the same name already exists on OpenShift.");
}
}
return ValidationStatus.ok();
@@ -750,9 +741,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.eclipse.core.databinding.validation.MultiValidator#getTargets()
+ * @see org.eclipse.core.databinding.validation.MultiValidator#getTargets()
*/
@Override
public IObservableList getTargets() {
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-02-10
14:45:55 UTC (rev 38602)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-02-10
14:59:45 UTC (rev 38603)
@@ -15,8 +15,6 @@
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.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -34,21 +32,20 @@
public class ApplicationConfigurationWizardPageModel extends ObservableUIPojo {
public static final String PROPERTY_USE_EXISTING_APPLICATION =
"useExistingApplication";
- public static final String PROPERTY_EXISTING_APPLICATION_NAME =
"existingApplication";
+ public static final String PROPERTY_EXISTING_APPLICATION_NAME =
"existingApplicationName";
public static final String PROPERTY_CARTRIDGES = "cartridges";
public static final String PROPERTY_EMBEDDABLE_CARTRIDGES =
"embeddableCartridges";
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
public static final String PROPERTY_APPLICATION_NAME = "applicationName";
- public static final String PROPERTY_APPLICATION_NAME_STATUS =
"applicationNameStatus";
+ public static final String PROPERTY_EXISTING_APPLICATIONS =
"existingApplications";
-
private final OpenShiftExpressApplicationWizardModel wizardModel;
- private List<IApplication> existingApplications = new
ArrayList<IApplication>();
+ // start with a null value as a marker of non-initialized state (used during first pass
validation)
+ private List<IApplication> existingApplications = null;
private List<ICartridge> cartridges = new ArrayList<ICartridge>();
private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
private String applicationName;
- private IStatus applicationNameStatus;
private ICartridge selectedCartridge;
private String selectedApplicationName;
private boolean useExistingApplication;
@@ -56,9 +53,9 @@
public ApplicationConfigurationWizardPageModel(OpenShiftExpressApplicationWizardModel
wizardModel) {
this.wizardModel = wizardModel;
setUseExistingApplication(wizardModel.isExistingApplication());
- setExistingApplicationName(wizardModel.getApplication() != null ?
wizardModel.getApplication().getName() : null);
+ setExistingApplicationName(wizardModel.getApplication() != null ?
wizardModel.getApplication().getName() : null);
}
-
+
/**
* @return the wizardModel
*/
@@ -67,10 +64,10 @@
}
public IUser getUser() {
-// return wizardModel.getUser();
+ // return wizardModel.getUser();
return OpenShiftUIActivator.getDefault().getUser();
}
-
+
public List<IApplication> getApplications() throws OpenShiftException {
IUser user = getUser();
if (user == null) {
@@ -78,38 +75,33 @@
}
return user.getApplications();
}
-
+
public boolean getUseExistingApplication() {
return this.useExistingApplication;
}
-
+
public void setUseExistingApplication(boolean useExistingApplication) {
wizardModel.setUseExistingApplication(useExistingApplication);
- firePropertyChange(PROPERTY_USE_EXISTING_APPLICATION, this.useExistingApplication,
this.useExistingApplication = useExistingApplication);
+ firePropertyChange(PROPERTY_USE_EXISTING_APPLICATION, this.useExistingApplication,
+ this.useExistingApplication = useExistingApplication);
}
-
public String getExistingApplicationName() {
return selectedApplicationName;
}
public void setExistingApplicationName(String applicationName) {
- for(IApplication application : getExistingApplications()) {
- if(application.getName().equals(applicationName)) {
- wizardModel.setApplication(application);
- }
- }
- firePropertyChange(PROPERTY_EXISTING_APPLICATION_NAME, this.selectedApplicationName,
this.selectedApplicationName = applicationName);
+ firePropertyChange(PROPERTY_EXISTING_APPLICATION_NAME, this.selectedApplicationName,
+ this.selectedApplicationName = applicationName);
}
-
public void loadExistingApplications() throws OpenShiftException {
IUser user = getUser();
if (user != null) {
setExistingApplications(user.getApplications());
}
}
-
+
/**
* @return the existingApplications
*/
@@ -118,14 +110,16 @@
}
/**
- * @param existingApplications the existingApplications to set
+ * @param existingApplications
+ * the existingApplications to set
*/
public void setExistingApplications(List<IApplication> existingApplications) {
- this.existingApplications = existingApplications;
+ firePropertyChange(PROPERTY_EXISTING_APPLICATIONS, this.existingApplications,
+ this.existingApplications = existingApplications);
}
public void loadCartridges() throws OpenShiftException {
-// setCartridges(wizardModel.getUser().getCartridges());
+ // setCartridges(wizardModel.getUser().getCartridges());
setCartridges(OpenShiftUIActivator.getDefault().getUser().getCartridges());
}
@@ -144,11 +138,11 @@
public void setSelectedCartridge(ICartridge cartridge) {
wizardModel.setApplicationCartridge(cartridge);
firePropertyChange(PROPERTY_SELECTED_CARTRIDGE, selectedCartridge,
this.selectedCartridge = cartridge);
- //validateApplicationName();
+ // validateApplicationName();
}
public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException {
-// List<IEmbeddableCartridge> cartridges =
wizardModel.getUser().getEmbeddableCartridges();
+ // List<IEmbeddableCartridge> cartridges =
wizardModel.getUser().getEmbeddableCartridges();
List<IEmbeddableCartridge> cartridges =
OpenShiftUIActivator.getDefault().getUser().getEmbeddableCartridges();
setEmbeddableCartridges(cartridges);
return cartridges;
@@ -157,39 +151,12 @@
public void setApplicationName(String applicationName) {
wizardModel.setApplicationName(applicationName);
firePropertyChange(PROPERTY_APPLICATION_NAME, this.applicationName,
this.applicationName = applicationName);
- validateApplicationName();
}
public String getApplicationName() {
return this.applicationName;
}
- public void setApplicationNameStatus(IStatus applicationNameStatus) {
- firePropertyChange(PROPERTY_APPLICATION_NAME_STATUS, this.applicationNameStatus,
- this.applicationNameStatus = applicationNameStatus);
- }
-
- public IStatus getApplicationNameStatus() {
- return this.applicationNameStatus;
- }
-
- public IStatus validateApplicationName() {
- IStatus status = Status.OK_STATUS;
- final String applicationName = getApplicationName();
- if (!applicationName.matches("\\S+")) {
- status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "The application name must not contain spaces.");
- }
- for(IApplication application : getExistingApplications()) {
- if(application.getName().equalsIgnoreCase(applicationName)) {
- status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "An application with the same name already exists on OpenShift.");
- }
- }
- setApplicationNameStatus(status);
- return status;
- }
-
public void setEmbeddableCartridges(List<IEmbeddableCartridge> cartridges) {
firePropertyChange(PROPERTY_EMBEDDABLE_CARTRIDGES, this.embeddableCartridges,
this.embeddableCartridges = cartridges);
@@ -205,7 +172,7 @@
public boolean hasApplication(ICartridge cartridge) {
try {
-// return wizardModel.getUser().hasApplication(cartridge);
+ // return wizardModel.getUser().hasApplication(cartridge);
return getUser().hasApplication(cartridge);
} catch (OpenShiftException e) {
OpenShiftUIActivator.log(OpenShiftUIActivator