Author: adietish
Date: 2012-02-07 17:52:17 -0500 (Tue, 07 Feb 2012)
New Revision: 38488
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/GitCloningSettingsWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java
Log:
[JBIDE-10479] added validator to the remote name so that it errors if the existing project
already has a remote with the very same name
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-07
21:47:05 UTC (rev 38487)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java 2012-02-07
22:52:17 UTC (rev 38488)
@@ -59,7 +59,7 @@
this.pageModel = new GitCloningSettingsWizardPageModel(model);
setPageComplete(false);
}
-
+
public GitCloningSettingsWizardPage(ImportExistingApplicationWizard wizard,
IOpenShiftWizardModel model) {
super(
"Import an existing OpenShift application",
@@ -82,8 +82,9 @@
Group cloneGroup = new Group(parent, SWT.BORDER);
cloneGroup.setText("Cloning settings");
cloneGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
- GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).margins(10, 10)//
.extendedMargins(0, 0, 0, 10)
- .applyTo(cloneGroup);
+ GridLayoutFactory.fillDefaults()
+ .numColumns(3).equalWidth(false).margins(10, 10).applyTo(cloneGroup);
+
// Repo Path Management
useDefaultRepoPathButton = new Button(cloneGroup, SWT.CHECK);
useDefaultRepoPathButton.setText("Use default location");
@@ -97,17 +98,18 @@
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 repoPathModelObservable = BeanProperties.value(
- GitCloningSettingsWizardPageModel.PROPERTY_REPO_PATH).observe(pageModel);
+ final IObservableValue repoPathModelObservable =
+ BeanProperties.value(GitCloningSettingsWizardPageModel.PROPERTY_REPO_PATH).observe(pageModel);
ValueBindingBuilder.bind(repoPathTextObservable).to(repoPathModelObservable).in(dbc);
Button browseRepoPathButton = new Button(cloneGroup, SWT.PUSH);
browseRepoPathButton.setText("Browse");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100,
SWT.DEFAULT).applyTo(browseRepoPathButton);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(browseRepoPathButton);
browseRepoPathButton.addSelectionListener(onRepoPath());
- final IObservableValue useDefaultRepoButtonSelectionObservable =
WidgetProperties.selection().observe(
- useDefaultRepoPathButton);
+ final IObservableValue useDefaultRepoButtonSelectionObservable =
+ WidgetProperties.selection().observe(useDefaultRepoPathButton);
final IObservableValue useDefaultRepoModelObservable = BeanProperties.value(
GitCloningSettingsWizardPageModel.PROPERTY_USE_DEFAULT_REPO_PATH).observe(pageModel);
ValueBindingBuilder.bind(useDefaultRepoButtonSelectionObservable).to(useDefaultRepoModelObservable).in(dbc);
@@ -115,25 +117,21 @@
.notUpdating(useDefaultRepoModelObservable).converting(new
InvertingBooleanConverter()).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(browseRepoPathButton))
.notUpdating(useDefaultRepoModelObservable).converting(new
InvertingBooleanConverter()).in(dbc);
- // move focus to the project location text control when not choosing the 'Use
default location' option.
- useDefaultRepoPathButton.addSelectionListener(new SelectionListener() {
+ // move focus to the project location text control when not choosing the
+ // 'Use default location' option.
+ useDefaultRepoPathButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
repoPathText.setFocus();
repoPathText.selectAll();
}
+ });
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- });
-
IObservableValue repoPathValidityObservable = BeanProperties.value(
GitCloningSettingsWizardPageModel.PROPERTY_CUSTOM_REPO_PATH_VALIDITY).observe(pageModel);
dbc.addValidationStatusProvider(new
RepoPathValidationStatusProvider(repoPathValidityObservable,
repoPathTextObservable));
-
// Remote Name Management
useDefaultRemoteNameButton = new Button(cloneGroup, SWT.CHECK);
useDefaultRemoteNameButton.setText("Use default remote name");
@@ -149,20 +147,23 @@
.grab(true, false).applyTo(remoteNameText);
final IObservableValue remoteNameTextObservable =
WidgetProperties.text(SWT.Modify).observe(remoteNameText);
- final IObservableValue remoteNameModelObservable = BeanProperties.value(
- GitCloningSettingsWizardPageModel.PROPERTY_REMOTE_NAME).observe(pageModel);
+ final IObservableValue remoteNameModelObservable =
+ BeanProperties.value(GitCloningSettingsWizardPageModel.PROPERTY_REMOTE_NAME).observe(pageModel);
ValueBindingBuilder.bind(remoteNameTextObservable).to(remoteNameModelObservable).in(dbc);
- final IObservableValue useDefaultRemoteNameButtonSelectionObservable =
WidgetProperties.selection().observe(
- useDefaultRemoteNameButton);
- final IObservableValue useDefaultRemoteNameModelObservable = BeanProperties.value(
- GitCloningSettingsWizardPageModel.PROPERTY_USE_DEFAULT_REMOTE_NAME).observe(pageModel);
+ final IObservableValue useDefaultRemoteNameButtonSelectionObservable =
+ WidgetProperties.selection().observe(useDefaultRemoteNameButton);
+ final IObservableValue useDefaultRemoteNameModelObservable =
+ BeanProperties.value(GitCloningSettingsWizardPageModel.PROPERTY_USE_DEFAULT_REMOTE_NAME).observe(
+ pageModel);
ValueBindingBuilder.bind(useDefaultRemoteNameButtonSelectionObservable).to(useDefaultRemoteNameModelObservable)
.in(dbc);
- ValueBindingBuilder.bind(WidgetProperties.enabled().observe(remoteNameText))
+ ValueBindingBuilder
+ .bind(WidgetProperties.enabled().observe(remoteNameText))
.notUpdating(useDefaultRemoteNameModelObservable).converting(new
InvertingBooleanConverter()).in(dbc);
- // move focus to the project name text control when choosing the 'Use an existing
project' option.
+ // 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);
@@ -224,7 +225,8 @@
protected void onPageActivated(DataBindingContext dbc) {
// allow to enable a proj only for as7 openshift applications
- // setTitle(NLS.bind("Import OpenShift application {0}",
pageModel.getApplicationName()));
+ // setTitle(NLS.bind("Import OpenShift application {0}",
+ // pageModel.getApplicationName()));
pageModel.resetRepositoryPath();
pageModel.resetRemoteName();
if (pageModel.isNewProject()) {
@@ -237,16 +239,20 @@
useDefaultRemoteNameButton.setEnabled(true);
remoteNameText.setEnabled(!useDefaultRemoteNameButton.getSelection());
}
- // pageModel.getWizardModel().setProperty(AdapterWizardPageModel.MODE,
AdapterWizardPageModel.MODE_SOURCE);
+ // pageModel.getWizardModel().setProperty(AdapterWizardPageModel.MODE,
+ // AdapterWizardPageModel.MODE_SOURCE);
onPageActivatedBackground(dbc);
}
protected void onPageActivatedBackground(final DataBindingContext dbc) {
/*
- * new Job("Loading remote OpenShift application") { public IStatus
run(IProgressMonitor monitor) { try {
- * pageModel.loadGitUri(); pageModel.loadApplicationUrl(); } catch (OpenShiftException
e) { IStatus status =
- * OpenShiftUIActivator.createErrorStatus(e.getMessage(), e);
OpenShiftUIActivator.log(status); return status; }
- * return Status.OK_STATUS; } }.schedule();
+ * new Job("Loading remote OpenShift application") { public IStatus
+ * run(IProgressMonitor monitor) { try { pageModel.loadGitUri();
+ * pageModel.loadApplicationUrl(); } catch (OpenShiftException e) {
+ * IStatus status =
+ * OpenShiftUIActivator.createErrorStatus(e.getMessage(), e);
+ * OpenShiftUIActivator.log(status); return status; } return
+ * Status.OK_STATUS; } }.schedule();
*/
}
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-07
21:47:05 UTC (rev 38487)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPageModel.java 2012-02-07
22:52:17 UTC (rev 38488)
@@ -10,12 +10,19 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import static
org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftApplicationWizardModel.*;
+import static
org.jboss.tools.openshift.express.internal.ui.wizard.IOpenShiftWizardModel.EXISTING_PROJECT_REMOTE_NAME_DEFAULT;
+import static
org.jboss.tools.openshift.express.internal.ui.wizard.IOpenShiftWizardModel.NEW_PROJECT_REMOTE_NAME_DEFAULT;
+
+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;
@@ -24,7 +31,7 @@
import com.openshift.express.client.OpenShiftException;
/**
- * @author Andr� Dietisheim
+ * @author Andre Dietisheim
* @author Rob Stryker
* @author Xavier Coulon
*/
@@ -33,7 +40,6 @@
public static final String PROPERTY_NEW_PROJECT = "newProject";
public static final String PROPERTY_CLONE_URI = "cloneUri";
// public static final String PROPERTY_MERGE_URI = "mergeUri";
- public static final String PROPERTY_PROJECT_NAME = "projectName";
public static final String PROPERTY_APPLICATION_URL = "applicationUrl";
public static final String PROPERTY_REPO_PATH = "repositoryPath";
public static final String PROPERTY_REMOTE_NAME = "remoteName";
@@ -347,12 +353,39 @@
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() {
+ String projectName = wizardModel.getProjectName();
+ if (projectName == null) {
+ return null;
+ }
+
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ }
+
public void setCustomRemoteNameValidity(IStatus status) {
firePropertyChange(PROPERTY_CUSTOM_REMOTE_NAME_VALIDITY,
this.customRemoteNameValidity,
this.customRemoteNameValidity = status);
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java 2012-02-07
21:47:05 UTC (rev 38487)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ConfigureGitSharedProject.java 2012-02-07
22:52:17 UTC (rev 38488)
@@ -33,6 +33,7 @@
import org.jboss.tools.openshift.egit.core.EGitUtils;
import org.jboss.tools.openshift.egit.core.GitIgnore;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIException;
import org.jboss.tools.openshift.express.internal.ui.UnCommittedChangesException;
import org.jboss.tools.openshift.express.internal.ui.utils.FileUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.ResourceUtils;
@@ -49,7 +50,7 @@
*/
public class ConfigureGitSharedProject extends AbstractImportApplicationOperation {
- private ArrayList<IResource> modifiedResources;
+ private List<IResource> modifiedResources;
public ConfigureGitSharedProject(String projectName, IApplication application, String
remoteName,
IUser user) {
@@ -114,18 +115,20 @@
return Collections.singletonList(project);
}
- private void addRemote(String remoteName, String uuid, IProject project) throws
MalformedURLException, URISyntaxException, IOException, OpenShiftException, CoreException
{
+ private void addRemote(String remoteName, String uuid, IProject project)
+ throws MalformedURLException, URISyntaxException, IOException, OpenShiftException,
CoreException {
Repository repository = EGitUtils.getRepository(project);
Assert.isTrue(repository != null);
-
-// if (EGitUtils.hasRemoteUrl("rhcloud.com", repository)) {
-// return;
-// }
-
- EGitUtils.addRemoteTo(
- getRemoteName(),
- getApplication().getGitUri(),
- repository);
+
+ if (EGitUtils.hasRemote(remoteName, repository)) {
+ // we shouldn't get here, the UI should validate the remote name and
+ // inform about an error in this case
+ throw new OpenShiftUIException(
+ "Could not enable OpenShift on project {0}. There's already a a remote
called {1}.",
+ project.getName(), remoteName);
+ }
+
+ EGitUtils.addRemoteTo(getRemoteName(), getApplication().getGitUri(), repository);
}
private void addAndCommitModifiedResource(IProject project, IProgressMonitor monitor)
throws CoreException {