Author: adietish
Date: 2012-02-15 11:01:31 -0500 (Wed, 15 Feb 2012)
New Revision: 38762
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
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IOpenShiftExpressWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
Log:
[JBIDE-10907] fixing enablement states in application configuration page
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-15
15:57:46 UTC (rev 38761)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-02-15
16:01:31 UTC (rev 38762)
@@ -100,7 +100,14 @@
private Button useExistingAppBtn;
private Text existingAppNameText;
private Button browseAppsButton;
- private Group appConfigurationGroup;
+ private Group newAppConfigurationGroup;
+ private Label newAppNameLabel;
+ private Text newAppNameText;
+ private Label newAppTypeLabel;
+ private Combo newAppCartridgeCombo;
+ private Group newAppEmbeddableCartridgesGroup;
+ private Button checkAllButton;
+ private Button uncheckAllButton;
public ApplicationConfigurationWizardPage(IWizard wizard,
OpenShiftExpressApplicationWizardModel wizardModel) {
super("Setup OpenShift Application", "Select an existing or create a new
OpenShift Express Application.",
@@ -145,8 +152,8 @@
// existing app name
this.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);
IObservableValue existingAppNameTextObservable =
WidgetProperties.text(SWT.Modify).observe(existingAppNameText);
IObservableValue existingAppNameModelObservable =
@@ -222,33 +229,33 @@
}
private void createApplicationConfigurationGroup(Composite parent, DataBindingContext
dbc) {
- this.appConfigurationGroup = new Group(parent, SWT.NONE);
- appConfigurationGroup.setText("New application");
- GridLayoutFactory.fillDefaults().numColumns(2).margins(6,
6).applyTo(appConfigurationGroup);
+ this.newAppConfigurationGroup = new Group(parent, SWT.NONE);
+ newAppConfigurationGroup.setText("New application");
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(6,
6).applyTo(newAppConfigurationGroup);
GridDataFactory.fillDefaults()
- .grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(appConfigurationGroup);
+ .grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(newAppConfigurationGroup);
- IObservableValue useExistingApplication = BeanProperties
- .value(ApplicationConfigurationWizardPageModel.PROPERTY_USE_EXISTING_APPLICATION)
- .observe(pageModel);
+ IObservableValue useExistingApplication =
+ WidgetProperties.selection().observe(useExistingAppBtn);
enableApplicationWidgets(
pageModel.isUseExistingApplication()
- , appConfigurationGroup
+ , newAppConfigurationGroup
, existingAppNameText
, browseAppsButton);
useExistingApplication.addValueChangeListener(
- onUseExistingApplication(appConfigurationGroup, existingAppNameText,
browseAppsButton));
+ onUseExistingApplication(newAppConfigurationGroup, existingAppNameText,
+ browseAppsButton));
- Label applicationNameLabel = new Label(appConfigurationGroup, SWT.NONE);
- applicationNameLabel.setText("Name:");
- GridDataFactory.fillDefaults().align(SWT.FILL,
SWT.CENTER).applyTo(applicationNameLabel);
- Text newApplicationNameText = new Text(appConfigurationGroup, SWT.BORDER);
+ this.newAppNameLabel = new Label(newAppConfigurationGroup, SWT.NONE);
+ newAppNameLabel.setText("Name:");
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(newAppNameLabel);
+ this.newAppNameText = new Text(newAppConfigurationGroup, SWT.BORDER);
GridDataFactory.fillDefaults()
- .grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(newApplicationNameText);
- UIUtils.selectAllOnFocus(newApplicationNameText);
- final ISWTObservableValue applicationNameTextObservable =
- WidgetProperties.text(SWT.Modify).observe(newApplicationNameText);
+ .grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(newAppNameText);
+ UIUtils.selectAllOnFocus(newAppNameText);
+ final IObservableValue applicationNameTextObservable =
+ WidgetProperties.text(SWT.Modify).observe(newAppNameText);
final IObservableValue applicationNameModelObservable =
BeanProperties
.value(ApplicationConfigurationWizardPageModel.PROPERTY_APPLICATION_NAME)
@@ -258,15 +265,15 @@
.to(applicationNameModelObservable)
.in(dbc);
- Label applicationTypeLabel = new Label(appConfigurationGroup, SWT.NONE);
- applicationTypeLabel.setText("Type:");
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1,
1).applyTo(applicationTypeLabel);
- Combo cartridgesCombo = new Combo(appConfigurationGroup, SWT.BORDER | SWT.READ_ONLY);
+ this.newAppTypeLabel = new Label(newAppConfigurationGroup, SWT.NONE);
+ newAppTypeLabel.setText("Type:");
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1,
1).applyTo(newAppTypeLabel);
+ this.newAppCartridgeCombo = new Combo(newAppConfigurationGroup, SWT.BORDER |
SWT.READ_ONLY);
GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true, false).applyTo(cartridgesCombo);
- fillCartridgesCombo(dbc, cartridgesCombo);
+ .align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true,
false).applyTo(newAppCartridgeCombo);
+ fillCartridgesCombo(dbc, newAppCartridgeCombo);
final ISWTObservableValue selectedCartridgeComboObservable =
- WidgetProperties.selection().observe(cartridgesCombo);
+ WidgetProperties.selection().observe(newAppCartridgeCombo);
final IObservableValue selectedCartridgeModelObservable =
BeanProperties.value(NewApplicationWizardPageModel.PROPERTY_SELECTED_CARTRIDGE).observe(pageModel);
ValueBindingBuilder
@@ -289,12 +296,13 @@
new CustomControlDecorationUpdater());
// embeddable cartridges
- Group cartridgesGroup = new Group(appConfigurationGroup, 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);
+ this.newAppEmbeddableCartridgesGroup = new Group(newAppConfigurationGroup, SWT.NONE);
+ newAppEmbeddableCartridgesGroup.setText("Embeddable Cartridges");
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1)
+ .applyTo(newAppEmbeddableCartridgesGroup);
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(6,
6).applyTo(newAppEmbeddableCartridgesGroup);
- Composite tableContainer = new Composite(cartridgesGroup, SWT.NONE);
+ Composite tableContainer = new Composite(newAppEmbeddableCartridgesGroup, SWT.NONE);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).grab(true, true).span(1, 2).hint(400,
250).applyTo(tableContainer);
this.viewer = createTable(tableContainer);
@@ -303,25 +311,26 @@
BeanProperties.set(ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
.observe(pageModel));
- Button checkAllButton = new Button(cartridgesGroup, SWT.PUSH);
+ this.checkAllButton = new Button(newAppEmbeddableCartridgesGroup, SWT.PUSH);
checkAllButton.setText("&Select All");
GridDataFactory.fillDefaults().
hint(110, SWT.DEFAULT).grab(false, false).align(SWT.FILL,
SWT.TOP).applyTo(checkAllButton);
checkAllButton.addSelectionListener(onCheckAll());
- Button uncheckAllButton = new Button(cartridgesGroup, SWT.PUSH);
+ this.uncheckAllButton = new Button(newAppEmbeddableCartridgesGroup, SWT.PUSH);
uncheckAllButton.setText("&Deselect All");
GridDataFactory.fillDefaults()
.hint(110, SWT.DEFAULT).grab(false, true).align(SWT.FILL,
SWT.TOP).applyTo(uncheckAllButton);
uncheckAllButton.addSelectionListener(onUncheckAll());
// bottom filler
- Composite spacer = new Composite(appConfigurationGroup, SWT.NONE);
+ Composite spacer = new Composite(newAppConfigurationGroup, SWT.NONE);
GridDataFactory.fillDefaults()
.span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(spacer);
}
- private IValueChangeListener onUseExistingApplication(final Group
applicationConfigurationGroup,
+ private IValueChangeListener onUseExistingApplication(final Group
+ applicationConfigurationGroup,
final Text applicationNameText, final Button applicationBrowseButton) {
return new IValueChangeListener() {
@@ -331,12 +340,22 @@
if (newValue instanceof Boolean) {
Boolean useExisting = (Boolean) newValue;
if (!useExisting) {
- pageModel.resetExistingApplication();
+ resetExistingApplication();
}
enableApplicationWidgets(
- useExisting, applicationConfigurationGroup, applicationNameText,
applicationBrowseButton);
+ useExisting, applicationConfigurationGroup, applicationNameText,
+ applicationBrowseButton);
}
}
+
+ private void resetExistingApplication() {
+ try {
+ pageModel.resetExistingApplication();
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log(e);
+ }
+
+ }
};
}
@@ -647,7 +666,7 @@
loadOpenshiftResources(dbc);
enableApplicationWidgets(
pageModel.isUseExistingApplication()
- , appConfigurationGroup
+ , newAppConfigurationGroup
, existingAppNameText
, browseAppsButton);
}
@@ -752,19 +771,19 @@
class NewApplicationNameValidator extends MultiValidator {
- private final ISWTObservableValue useExistingAppBtnbservable;
- private final ISWTObservableValue applicationNameTextObservable;
+ private final IObservableValue useExistingAppbservable;
+ private final IObservableValue applicationNameObservable;
- public NewApplicationNameValidator(ISWTObservableValue useExistingAppBtnbservable,
- ISWTObservableValue applicationNameTextObservable) {
- this.useExistingAppBtnbservable = useExistingAppBtnbservable;
- this.applicationNameTextObservable = applicationNameTextObservable;
+ public NewApplicationNameValidator(IObservableValue useExistingAppObservable,
+ IObservableValue applicationNameObservable) {
+ this.useExistingAppbservable = useExistingAppObservable;
+ this.applicationNameObservable = applicationNameObservable;
}
@Override
protected IStatus validate() {
- final String applicationName = (String) applicationNameTextObservable.getValue();
- final boolean useExistingApp = (Boolean) useExistingAppBtnbservable.getValue();
+ final String applicationName = (String) applicationNameObservable.getValue();
+ final boolean useExistingApp = (Boolean) useExistingAppbservable.getValue();
if (useExistingApp) {
return ValidationStatus.ok();
}
@@ -774,9 +793,9 @@
}
if (!StringUtils.isAlphaNumeric(applicationName)) {
return OpenShiftUIActivator.createErrorStatus(
- "The application name must not contain spaces.");
+ "The name may only contain letters and numbers.");
}
- if (isExistingApplication(applicationName)) {
+ if (pageModel.isExistingApplication(applicationName)) {
return OpenShiftUIActivator.createErrorStatus(
"An application with the same name already exists on OpenShift.");
}
@@ -787,15 +806,6 @@
return ValidationStatus.ok();
}
- private boolean isExistingApplication(final String applicationName) {
- for (IApplication application : pageModel.getExistingApplications()) {
- if (application.getName().equalsIgnoreCase(applicationName)) {
- return true;
- }
- }
- return false;
- }
-
private boolean isExistingProject(String name) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
return project.exists();
@@ -804,30 +814,30 @@
@Override
public IObservableList getTargets() {
WritableList targets = new WritableList();
- targets.add(applicationNameTextObservable);
+ targets.add(applicationNameObservable);
return targets;
}
}
class NewApplicationTypeValidator extends MultiValidator {
- private final ISWTObservableValue useExistingAppBtnbservable;
- private final ISWTObservableValue cartridgesComboObservable;
+ private final IObservableValue useExistingAppBtnbservable;
+ private final IObservableValue selectedCartridgeObservable;
- public NewApplicationTypeValidator(ISWTObservableValue useExistingAppBtnbservable,
- ISWTObservableValue cartridgesComboObservable) {
+ public NewApplicationTypeValidator(IObservableValue useExistingAppBtnbservable,
+ IObservableValue selectedCartridgeObservable) {
this.useExistingAppBtnbservable = useExistingAppBtnbservable;
- this.cartridgesComboObservable = cartridgesComboObservable;
+ this.selectedCartridgeObservable = selectedCartridgeObservable;
}
@Override
protected IStatus validate() {
final boolean useExistingApp = (Boolean) useExistingAppBtnbservable.getValue();
- final String cartridge = (String) cartridgesComboObservable.getValue();
+ final String cartridge = (String) selectedCartridgeObservable.getValue();
if (useExistingApp) {
return ValidationStatus.ok();
}
- if (cartridge == null || cartridge.isEmpty()) {
+ if (StringUtils.isEmpty(cartridge)) {
return OpenShiftUIActivator.createCancelStatus(
"Select an alphanumerical name and a type for the application to
create.");
}
@@ -837,7 +847,7 @@
@Override
public IObservableList getTargets() {
WritableList targets = new WritableList();
- targets.add(cartridgesComboObservable);
+ targets.add(selectedCartridgeObservable);
return targets;
}
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-15
15:57:46 UTC (rev 38761)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-02-15
16:01:31 UTC (rev 38762)
@@ -50,18 +50,12 @@
private List<IApplication> existingApplications = null;
private List<ICartridge> cartridges = new ArrayList<ICartridge>();
private List<IEmbeddableCartridge> embeddableCartridges = new
ArrayList<IEmbeddableCartridge>();
- // private String applicationName;
- private ICartridge selectedCartridge;
private String existingApplicationName;
- // private boolean useExistingApplication;
-
- public ApplicationConfigurationWizardPageModel(OpenShiftExpressApplicationWizardModel
wizardModel) throws OpenShiftException {
+ public ApplicationConfigurationWizardPageModel(OpenShiftExpressApplicationWizardModel
wizardModel)
+ throws OpenShiftException {
this.wizardModel = wizardModel;
setExistingApplication(wizardModel.getApplication());
- // setUseExistingApplication(wizardModel.isExistingApplication());
- // setExistingApplicationName(wizardModel.getApplication() != null ?
- // wizardModel.getApplication().getName() : null);
}
/**
@@ -107,6 +101,10 @@
, wizardModel.setUseExistingApplication(useExistingApplication));
}
+ protected void setUseExistingApplication(IApplication application) {
+ setUseExistingApplication(application != null);
+ }
+
public String getExistingApplicationName() {
return existingApplicationName;
}
@@ -117,6 +115,14 @@
, this.existingApplicationName = applicationName);
}
+ protected void setExistingApplicationName(IApplication application) {
+ String applicationName = null;
+ if (application != null) {
+ applicationName = application.getName();
+ }
+ setExistingApplicationName(applicationName);
+ }
+
public void loadExistingApplications() throws OpenShiftException {
IUser user = getUser();
if (user != null) {
@@ -131,6 +137,15 @@
return existingApplications;
}
+ public boolean isExistingApplication(String applicationName) {
+ for (IApplication application : getExistingApplications()) {
+ if (application.getName().equalsIgnoreCase(applicationName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* @param existingApplications
* the existingApplications to set
@@ -154,14 +169,23 @@
}
public ICartridge getSelectedCartridge() {
- return selectedCartridge;
+ return wizardModel.getApplicationCartridge();
}
public void setSelectedCartridge(ICartridge cartridge) {
- wizardModel.setApplicationCartridge(cartridge);
- firePropertyChange(PROPERTY_SELECTED_CARTRIDGE, selectedCartridge,
this.selectedCartridge = cartridge);
+ firePropertyChange(PROPERTY_SELECTED_CARTRIDGE
+ , wizardModel.getApplicationCartridge()
+ , wizardModel.setApplicationCartridge(cartridge));
}
+ protected void setSelectedCartridge(IApplication application) {
+ ICartridge applicationCartridge = null;
+ if (application != null) {
+ applicationCartridge = application.getCartridge();
+ }
+ setSelectedCartridge(applicationCartridge);
+ }
+
public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException {
// List<IEmbeddableCartridge> cartridges =
// OpenShiftUIActivator.getDefault().getUser().getEmbeddableCartridges();
@@ -171,33 +195,32 @@
}
public void setExistingApplication(IApplication application) throws OpenShiftException
{
- if (application == null) {
- return;
- }
+ // setUseExistingApplication(application);
+ setExistingApplicationName(application);
+ setApplicationName(application);
+ setSelectedCartridge(application);
+ setSelectedEmbeddableCartridges(application);
wizardModel.setApplication(application);
- setExistingApplicationName(application.getName());
- setApplicationName(application.getName());
- setSelectedCartridge(application.getCartridge());
- Set<IEmbeddableCartridge> embeddedCartridges = new
HashSet<IEmbeddableCartridge>();
- embeddedCartridges.addAll(application.getEmbeddedCartridges());
- setSelectedEmbeddableCartridges(embeddedCartridges);
}
- public void resetExistingApplication() {
- wizardModel.setApplication(null);
- setExistingApplicationName(null);
- setApplicationName(null);
- setSelectedCartridge(null);
- setSelectedEmbeddableCartridges(new HashSet<IEmbeddableCartridge>());
+ public void resetExistingApplication() throws OpenShiftException {
+ setExistingApplication(null);
}
public void setApplicationName(String applicationName) {
- wizardModel.setApplicationName(applicationName);
firePropertyChange(PROPERTY_APPLICATION_NAME
, wizardModel.getApplicationName()
, wizardModel.setApplicationName(applicationName));
}
+ protected void setApplicationName(IApplication application) {
+ String applicationName = null;
+ if (application != null) {
+ applicationName = application.getName();
+ }
+ setApplicationName(applicationName);
+ }
+
public String getApplicationName() {
return wizardModel.getApplicationName();
}
@@ -221,6 +244,14 @@
wizardModel.setSelectedEmbeddableCartridges(selectedEmbeddableCartridges));
}
+ protected void setSelectedEmbeddableCartridges(IApplication application) throws
OpenShiftException {
+ HashSet<IEmbeddableCartridge> selectedEmbeddableCartridges = new
HashSet<IEmbeddableCartridge>();
+ if (application != null) {
+ selectedEmbeddableCartridges.addAll(application.getEmbeddedCartridges());
+ }
+ setSelectedEmbeddableCartridges(selectedEmbeddableCartridges);
+ }
+
public boolean hasApplication(ICartridge cartridge) {
try {
return getUser().hasApplication(cartridge);
@@ -238,5 +269,4 @@
public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException {
return wizardModel.createApplication(name, ICartridge.JENKINS_14, monitor);
}
-
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java 2012-02-15
15:57:46 UTC (rev 38761)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java 2012-02-15
16:01:31 UTC (rev 38762)
@@ -17,11 +17,17 @@
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -37,6 +43,9 @@
import org.jboss.tools.common.ui.databinding.InvertingBooleanConverter;
import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
+import org.jboss.tools.openshift.egit.core.EGitUtils;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
/**
* @author Andre Dietisheim
@@ -88,10 +97,10 @@
final Text repoPathText = new Text(cloneGroup, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).align(SWT.FILL,
SWT.CENTER).grab(true, false)
.applyTo(repoPathText);
- final IObservableValue repoPathTextObservable =
WidgetProperties.text(SWT.Modify).observe(repoPathText);
+ final IObservableValue repoPathObservable =
WidgetProperties.text(SWT.Modify).observe(repoPathText);
final IObservableValue repoPathModelObservable =
BeanProperties.value(GitCloningSettingsWizardPageModel.PROPERTY_REPO_PATH).observe(pageModel);
- ValueBindingBuilder.bind(repoPathTextObservable).to(repoPathModelObservable).in(dbc);
+ ValueBindingBuilder.bind(repoPathObservable).to(repoPathModelObservable).in(dbc);
Button browseRepoPathButton = new Button(cloneGroup, SWT.PUSH);
browseRepoPathButton.setText("Browse");
@@ -99,11 +108,11 @@
.align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(browseRepoPathButton);
browseRepoPathButton.addSelectionListener(onRepoPath());
- final IObservableValue useDefaultRepoButtonSelectionObservable =
+ final IObservableValue isDefaultRepoObservable =
WidgetProperties.selection().observe(useDefaultRepoPathButton);
final IObservableValue useDefaultRepoModelObservable = BeanProperties.value(
GitCloningSettingsWizardPageModel.PROPERTY_USE_DEFAULT_REPO_PATH).observe(pageModel);
- ValueBindingBuilder.bind(useDefaultRepoButtonSelectionObservable).to(useDefaultRepoModelObservable).in(dbc);
+ ValueBindingBuilder.bind(isDefaultRepoObservable).to(useDefaultRepoModelObservable).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(repoPathText))
.notUpdating(useDefaultRepoModelObservable).converting(new
InvertingBooleanConverter()).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(browseRepoPathButton))
@@ -118,11 +127,14 @@
}
});
- IObservableValue repoPathValidityObservable = BeanProperties.value(
- GitCloningSettingsWizardPageModel.PROPERTY_CUSTOM_REPO_PATH_VALIDITY).observe(pageModel);
- dbc.addValidationStatusProvider(new
RepoPathValidationStatusProvider(repoPathValidityObservable,
- repoPathTextObservable));
+// IObservableValue repoPathValidityObservable = BeanProperties.value(
+// GitCloningSettingsWizardPageModel.PROPERTY_CUSTOM_REPO_PATH_VALIDITY).observe(pageModel);
+// dbc.addValidationStatusProvider(
+// new RepoPathValidationStatusProvider(isDefaultRepoObservable,
repoPathObservable));
+ dbc.addValidationStatusProvider(
+ new RepoPathValidationStatusProvider(isDefaultRepoObservable, repoPathObservable));
+
// Remote Name Management
useDefaultRemoteNameButton = new Button(cloneGroup, SWT.CHECK);
useDefaultRemoteNameButton.setText("Use default remote name");
@@ -142,13 +154,12 @@
BeanProperties.value(GitCloningSettingsWizardPageModel.PROPERTY_REMOTE_NAME).observe(pageModel);
ValueBindingBuilder.bind(remoteNameTextObservable).to(remoteNameModelObservable).in(dbc);
- final IObservableValue useDefaultRemoteNameButtonSelectionObservable =
+ final IObservableValue useDefaultRemoteNameObservable =
WidgetProperties.selection().observe(useDefaultRemoteNameButton);
final IObservableValue useDefaultRemoteNameModelObservable =
BeanProperties.value(GitCloningSettingsWizardPageModel.PROPERTY_USE_DEFAULT_REMOTE_NAME).observe(
pageModel);
-
- ValueBindingBuilder.bind(useDefaultRemoteNameButtonSelectionObservable).to(useDefaultRemoteNameModelObservable)
+ ValueBindingBuilder.bind(useDefaultRemoteNameObservable).to(useDefaultRemoteNameModelObservable)
.in(dbc);
ValueBindingBuilder
.bind(WidgetProperties.enabled().observe(remoteNameText))
@@ -156,11 +167,16 @@
// move focus to the project name text control when choosing the 'Use an
// existing project' option.
useDefaultRemoteNameButton.addSelectionListener(onDefaultRemoteNameUnchecked());
- IObservableValue remoteNameValidityObservable = BeanProperties.value(
- GitCloningSettingsWizardPageModel.PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY).observe(pageModel);
- dbc.addValidationStatusProvider(new
RemoteNameValidationStatusProvider(remoteNameValidityObservable,
- remoteNameTextObservable));
+ // IObservableValue remoteNameValidityObservable = BeanProperties.value(
+ //
GitCloningSettingsWizardPageModel.PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY).observe(pageModel);
+ // dbc.addValidationStatusProvider(new
+ // RemoteNameValidationStatusProvider(remoteNameValidityObservable,
+ // remoteNameTextObservable));
+ dbc.addValidationStatusProvider(
+ new RemoteNameValidationStatusProvider(
+ useDefaultRemoteNameObservable, remoteNameTextObservable));
+
Link sshPrefsLink = new Link(parent, SWT.NONE);
sshPrefsLink.setText("Make sure your SSH key used with the domain is listed in
<a>SSH2 Preferences</a>.");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).indent(10,
0)
@@ -218,7 +234,7 @@
// allow to enable a proj only for as7 openshift applications
// setTitle(NLS.bind("Import OpenShift application {0}",
// pageModel.getApplicationName()));
-// pageModel.resetRepositoryPath();
+ // pageModel.resetRepositoryPath();
pageModel.resetRemoteName();
if (pageModel.isNewProject()) {
useDefaultRepoPathButton.setEnabled(true);
@@ -247,66 +263,126 @@
*/
}
+ /**
+ * A multivalidator for the repo path. Validates the repo path on behalf of
+ * the selection to use the default repo path and the repo path value.
+ */
class RepoPathValidationStatusProvider extends MultiValidator {
- private final IObservableValue repoPathValidityObservable;
+ private final IObservableValue isDefaultRepoPathObservable;
+ private final IObservableValue repoPathObservable;
- private final IObservableValue repoPathTextObservable;
-
- public RepoPathValidationStatusProvider(IObservableValue repoPathValidityObservable,
- IObservableValue repoPathTextObservable) {
- this.repoPathValidityObservable = repoPathValidityObservable;
- this.repoPathTextObservable = repoPathTextObservable;
+ public RepoPathValidationStatusProvider(IObservableValue isDefaultRepoPathObservable,
+ IObservableValue repoPathObservable) {
+ this.isDefaultRepoPathObservable = isDefaultRepoPathObservable;
+ this.repoPathObservable = repoPathObservable;
}
@Override
protected IStatus validate() {
- final IStatus repoPathValidityStatus = (IStatus)
repoPathValidityObservable.getValue();
+ Boolean isDefaultRepoPath = (Boolean) isDefaultRepoPathObservable.getValue();
+ String repoPath = (String) repoPathObservable.getValue();
- if (repoPathValidityStatus != null) {
- return repoPathValidityStatus;
+ // skip the validation if the user wants to create a new project.
+ // The
+ // name and state of the existing project do
+ // not matter...
+ String applicationName = pageModel.getApplicationName();
+ if (applicationName == null
+ || applicationName.length() == 0) {
+ return OpenShiftUIActivator
+ .createCancelStatus("You have to choose an application name / existing
application");
}
+
+ if (isDefaultRepoPath == null
+ || !isDefaultRepoPath) {
+ final IPath repoResourcePath = new Path(repoPath);
+ if (repoResourcePath.isEmpty()
+ || !repoResourcePath.isAbsolute()
+ || !repoResourcePath.toFile().canWrite()) {
+ return OpenShiftUIActivator.createErrorStatus("The path does not exist or is
not writeable.");
+ }
+ final IPath applicationPath = repoResourcePath.append(new Path(applicationName));
+ if (applicationPath.toFile().exists()) {
+ return OpenShiftUIActivator.createErrorStatus(
+ NLS.bind("The location \"{0}\" already contains a folder named
\"{1}\"",
+ repoResourcePath.toOSString(), applicationName));
+ }
+ }
+
return ValidationStatus.ok();
}
@Override
public IObservableList getTargets() {
WritableList targets = new WritableList();
- targets.add(repoPathTextObservable);
+ targets.add(repoPathObservable);
return targets;
}
}
+ /**
+ * A multi validator that validates the remote name on behalf of the
+ * selection to use the default remote name and the remote name value.
+ */
class RemoteNameValidationStatusProvider extends MultiValidator {
- private final IObservableValue remoteNameValidityObservable;
+ private final IObservableValue isDefaultRemoteNameObservable;
+ private final IObservableValue remoteNameObservable;
- private final IObservableValue remoteNameTextObservable;
-
- public RemoteNameValidationStatusProvider(IObservableValue
remoteNameValidityObservable,
+ public RemoteNameValidationStatusProvider(IObservableValue isDefaultRemoteName,
IObservableValue remoteNameTextObservable) {
- this.remoteNameValidityObservable = remoteNameValidityObservable;
- this.remoteNameTextObservable = remoteNameTextObservable;
+ this.isDefaultRemoteNameObservable = isDefaultRemoteName;
+ this.remoteNameObservable = remoteNameTextObservable;
}
@Override
protected IStatus validate() {
- final IStatus remoteNameValidityStatus = (IStatus)
remoteNameValidityObservable.getValue();
+ IStatus status = Status.OK_STATUS;
+ Boolean isDefaultRemoteName = (Boolean) isDefaultRemoteNameObservable.getValue();
+ String remoteName = (String) remoteNameObservable.getValue();
- if (remoteNameValidityStatus != null) {
- return remoteNameValidityStatus;
+ // skip the validation if the user wants to create a new project.
+ // The name and state of the existing project do
+ // not matter...
+ if (isDefaultRemoteName == null
+ || !isDefaultRemoteName) {
+ if (StringUtils.isEmpty(remoteName)) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "The custom remote name must not be empty.");
+ } else if (!remoteName.matches("\\S+")) {
+ return OpenShiftUIActivator.createErrorStatus(
+ "The custom remote name must not contain spaces.");
+ } else if (hasRemoteName(remoteName, pageModel.getProject())) {
+ return OpenShiftUIActivator.createErrorStatus(NLS.bind(
+ "The existing project already has a remote named {0}.", remoteName));
+ }
}
- return ValidationStatus.ok();
+ return status;
}
+ private boolean hasRemoteName(String remoteName, IProject project) {
+ try {
+ if (project == null
+ || !project.isAccessible()) {
+ return false;
+ }
+
+ Repository repository = EGitUtils.getRepository(project);
+ return EGitUtils.hasRemote(remoteName, repository);
+ } catch (Exception e) {
+ OpenShiftUIActivator.log(OpenShiftUIActivator.createErrorStatus(e.getMessage(), e));
+ return false;
+ }
+ }
+
@Override
public IObservableList getTargets() {
WritableList targets = new WritableList();
- targets.add(remoteNameTextObservable);
+ targets.add(remoteNameObservable);
return targets;
}
-
}
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java 2012-02-15
15:57:46 UTC (rev 38761)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java 2012-02-15
16:01:31 UTC (rev 38762)
@@ -15,16 +15,8 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
-import org.jboss.tools.openshift.egit.core.EGitUtils;
import org.jboss.tools.openshift.egit.ui.util.EGitUIUtils;
-import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import com.openshift.express.client.IApplication;
import com.openshift.express.client.ICartridge;
@@ -43,30 +35,12 @@
public static final String PROPERTY_REPO_PATH = "repositoryPath";
public static final String PROPERTY_REMOTE_NAME = "remoteName";
public static final String PROPERTY_LOADING = "loading";
-
- public static final String CREATE_SERVER = "createServer";
- public static final String MODE = "serverMode";
- public static final String MODE_SOURCE = "serverModeSource";
- public static final String MODE_BINARY = "serverModeBinary";
- public static final String SERVER_TYPE = "serverType";
-
public static final String PROPERTY_USE_DEFAULT_REPO_PATH =
"useDefaultRepoPath";
-
- public static final String PROPERTY_CUSTOM_REPO_PATH_VALIDITY =
"customRepoPathValidity";
-
public static final String PROPERTY_USE_DEFAULT_REMOTE_NAME =
"useDefaultRemoteName";
- public static final String PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY =
"customRemoteNameValidity";
-
private IOpenShiftExpressWizardModel wizardModel;
private boolean loading;
-
private boolean useDefaultRepoPath = true;
-
- private IStatus customRepoPathValidity = null;
-
- private IStatus customRemoteNameValidity = null;
-
private boolean useDefaultRemoteName = true;
public GitCloningSettingsWizardPageModel(IOpenShiftExpressWizardModel wizardModel) {
@@ -135,8 +109,6 @@
public void setRepositoryPath(String repositoryPath) {
firePropertyChange(PROPERTY_REPO_PATH, wizardModel.getRepositoryPath(),
wizardModel.setRepositoryPath(repositoryPath));
- validateRepoPathProject();
-
}
// public void resetRepositoryPath() {
@@ -147,17 +119,21 @@
// }
public void resetRemoteName() {
- // if existing project and remote name is still 'origin' -> switch to
- // 'openshift'
- // (so, if existing project and remote name is not 'origin', leave as-is
- if (!wizardModel.isNewProject() &&
NEW_PROJECT_REMOTE_NAME_DEFAULT.equals(getRemoteName())) {
- setRemoteName(EXISTING_PROJECT_REMOTE_NAME_DEFAULT);
+ if (!wizardModel.isNewProject()) {
+ // if existing project and remote name is still 'origin'
+ // -> switch to 'openshift' (leave as is if existing project and
+ // remote name != 'origin')
+ if (NEW_PROJECT_REMOTE_NAME_DEFAULT.equals(getRemoteName())) {
+ setRemoteName(EXISTING_PROJECT_REMOTE_NAME_DEFAULT);
+ }
+ } else {
+ // if new project and remote name is not 'origin'
+ // -> restore 'origin'
+ if (!NEW_PROJECT_REMOTE_NAME_DEFAULT.equals(getRemoteName())) {
+ setUseDefaultRemoteName(true);
+ setRemoteName(NEW_PROJECT_REMOTE_NAME_DEFAULT);
+ }
}
- // if new project and remote name is not 'origin' -> restore
'origin'
- else if (wizardModel.isNewProject() &&
!NEW_PROJECT_REMOTE_NAME_DEFAULT.equals(getRemoteName())) {
- setUseDefaultRemoteName(true);
- setRemoteName(NEW_PROJECT_REMOTE_NAME_DEFAULT);
- }
}
private String getDefaultRepositoryPath() {
@@ -170,7 +146,6 @@
public void setRemoteName(String remoteName) {
firePropertyChange(PROPERTY_REMOTE_NAME, wizardModel.getRemoteName(),
wizardModel.setRemoteName(remoteName));
- validateRemoteName();
}
public boolean isLoading() {
@@ -187,147 +162,34 @@
&& application.getCartridge().equals(cartridge);
}
- public static class GitUri {
-
- private String label;
- private String gitUri;
- private ICartridge cartridge;
-
- private GitUri(String label, String gitUri, ICartridge cartridge) {
- this.label = label;
- this.gitUri = gitUri;
- this.cartridge = cartridge;
- }
-
- public String getLabel() {
- return label;
- }
-
- public String getGitUri() {
- return gitUri;
- }
-
- public String toString() {
- return getLabel();
- }
-
- public ICartridge getCartridge() {
- return cartridge;
- }
-
- public boolean isCompatible(ICartridge cartridge) {
- return this.cartridge.equals(cartridge);
- }
- }
-
public void setUseDefaultRepoPath(boolean useDefaultRepoPath) {
- firePropertyChange(PROPERTY_USE_DEFAULT_REPO_PATH, useDefaultRepoPath,
- this.useDefaultRepoPath = useDefaultRepoPath);
- if (this.useDefaultRepoPath) {
+ firePropertyChange(PROPERTY_USE_DEFAULT_REPO_PATH
+ , this.useDefaultRepoPath
+ , this.useDefaultRepoPath = useDefaultRepoPath);
+ if (useDefaultRepoPath) {
setRepositoryPath(getDefaultRepositoryPath());
- } else {
-
}
- validateRepoPathProject();
}
public boolean isUseDefaultRepoPath() {
return useDefaultRepoPath;
}
- private IStatus validateRepoPathProject() {
- IStatus status = Status.OK_STATUS;
- // skip the validation if the user wants to create a new project. The
- // name and state of the existing project do
- // not matter...
- String applicationName = getApplicationName();
- if (applicationName == null
- || applicationName.length() == 0) {
- status = OpenShiftUIActivator
- .createCancelStatus("You have to choose an application name / existing
application");
- } else {
- if (!isUseDefaultRepoPath()) {
- final IPath repoPath = new Path(getRepositoryPath());
- if (repoPath.isEmpty()
- || !repoPath.isAbsolute()
- || !repoPath.toFile().canWrite()) {
- status = OpenShiftUIActivator.createErrorStatus("The path does not exist or is
not writeable.");
- } else {
- final IPath applicationPath = repoPath.append(new Path(getApplicationName()));
- if (applicationPath.toFile().exists()) {
- status = OpenShiftUIActivator.createErrorStatus(
- "The location '" + repoPath.toOSString() + "' already
contains a folder named '"
- + getApplicationName() + "'.");
- }
- }
- }
- }
-
- setCustomRepoPathValidity(status);
- return status;
- }
-
- public void setCustomRepoPathValidity(IStatus status) {
- firePropertyChange(PROPERTY_CUSTOM_REPO_PATH_VALIDITY, this.customRepoPathValidity,
- this.customRepoPathValidity = status);
- }
-
- public IStatus getCustomRepoPathValidity() {
- return this.customRepoPathValidity;
- }
-
public void setUseDefaultRemoteName(boolean useDefaultRemoteName) {
firePropertyChange(PROPERTY_USE_DEFAULT_REMOTE_NAME, useDefaultRemoteName,
this.useDefaultRemoteName = useDefaultRemoteName);
if (useDefaultRemoteName) {
- setRemoteName(isNewProject() ? NEW_PROJECT_REMOTE_NAME_DEFAULT :
EXISTING_PROJECT_REMOTE_NAME_DEFAULT);
+ // setRemoteName(isNewProject() ? NEW_PROJECT_REMOTE_NAME_DEFAULT :
+ // EXISTING_PROJECT_REMOTE_NAME_DEFAULT);
+ resetRemoteName();
}
- validateRemoteName();
}
public boolean isUseDefaultRemoteName() {
return useDefaultRemoteName;
}
- private IStatus validateRemoteName() {
- IStatus status = Status.OK_STATUS;
- // skip the validation if the user wants to create a new project. The
- // name and state of the existing project do
- // not matter...
- if (!isUseDefaultRemoteName()) {
- final String remoteName = getRemoteName();
- if (remoteName == null || remoteName.isEmpty()) {
- status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "The custom remote name must not be empty.");
- } else if (!remoteName.matches("\\S+")) {
- status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "The custom remote name must not contain spaces.");
- } else if (hasRemoteName(remoteName, getProject())) {
- status = new Status(IStatus.ERROR,
- OpenShiftUIActivator.PLUGIN_ID, NLS.bind(
- "The existing project already has a remote named {0}.", remoteName));
- }
- }
- setCustomRemoteNameValidity(status);
- return status;
- }
-
- private boolean hasRemoteName(String remoteName, IProject project) {
- try {
- if (project == null
- || !project.isAccessible()) {
- return false;
- }
-
- Repository repository = EGitUtils.getRepository(project);
- return EGitUtils.hasRemote(remoteName, repository);
- } catch (Exception e) {
- OpenShiftUIActivator.log(OpenShiftUIActivator.createErrorStatus(e.getMessage(), e));
- return false;
- }
- }
-
- private IProject getProject() {
+ public IProject getProject() {
String projectName = wizardModel.getProjectName();
if (projectName == null) {
return null;
@@ -336,13 +198,4 @@
return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
- public void setCustomRemoteNameValidity(IStatus status) {
- firePropertyChange(PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY,
this.customRemoteNameValidity,
- this.customRemoteNameValidity = status);
- }
-
- public IStatus getCustomRemoteNameValidity() {
- return this.customRemoteNameValidity;
- }
-
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IOpenShiftExpressWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IOpenShiftExpressWizardModel.java 2012-02-15
15:57:46 UTC (rev 38761)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IOpenShiftExpressWizardModel.java 2012-02-15
16:01:31 UTC (rev 38762)
@@ -139,7 +139,7 @@
public String getApplicationName();
- public void setApplicationCartridge(ICartridge cartridge);
+ public ICartridge setApplicationCartridge(ICartridge cartridge);
public ICartridge getApplicationCartridge();
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java 2012-02-15
15:57:46 UTC (rev 38761)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java 2012-02-15
16:01:31 UTC (rev 38762)
@@ -379,15 +379,15 @@
}
@Override
- public void setApplicationCartridge(ICartridge cartridge) {
- dataModel.put(APPLICATION_CARTRIDGE, cartridge);
+ public ICartridge setApplicationCartridge(ICartridge cartridge) {
+ return (ICartridge) dataModel.put(APPLICATION_CARTRIDGE, cartridge);
}
protected void setApplicationCartridge(IApplication application) {
if (application == null) {
return;
}
- dataModel.put(APPLICATION_CARTRIDGE, application.getCartridge());
+ setApplicationCartridge(application.getCartridge());
}
@Override
@@ -404,7 +404,7 @@
if (application == null) {
return;
}
- dataModel.put(APPLICATION_NAME, application.getName());
+ setApplicationName(application.getName());
}
@Override