Author: adietish
Date: 2011-10-12 18:11:13 -0400 (Wed, 12 Oct 2011)
New Revision: 35585
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java
Log:
[JBIDE-9793] implementing user settable clone destination (folder) and branch to clone
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java 2011-10-12
22:05:58 UTC (rev 35584)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java 2011-10-12
22:11:13 UTC (rev 35585)
@@ -12,12 +12,19 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Pattern;
+import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.window.Window;
@@ -37,7 +44,6 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.ListDialog;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IRuntimeType;
import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
@@ -52,6 +58,7 @@
import org.eclipse.wst.server.ui.wizard.WizardFragment;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.ui.UIUtil;
+import org.jboss.tools.common.ui.databinding.DataBindingUtils;
import org.jboss.tools.openshift.express.client.ICartridge;
import org.jboss.tools.openshift.express.client.OpenshiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenshiftUIActivator;
@@ -102,9 +109,8 @@
Text cloneDirText = new Text(projectGroup, SWT.BORDER);
GridDataFactory.fillDefaults()
.align(SWT.LEFT, SWT.CENTER).align(SWT.FILL, SWT.CENTER).grab(true,
false).applyTo(cloneDirText);
- // DataBindingUtils.bindMandatoryTextField(
- // cloneDirText, "Repository Destination",
- // AdapterWizardPageModel.PROPERTY_CLONEDIR, model, dbc);
+ DataBindingUtils.bindMandatoryTextField(
+ cloneDirText, "Repository Destination",
AdapterWizardPageModel.PROPERTY_CLONEDIR, model, dbc);
Button browseDestinationButton = new Button(projectGroup, SWT.PUSH);
browseDestinationButton.setText("Browse");
GridDataFactory.fillDefaults()
@@ -114,18 +120,22 @@
Label branchLabel = new Label(projectGroup, SWT.NONE);
branchLabel.setText("Branch to clone");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(branchLabel);
- Text branchText = new Text(projectGroup, SWT.NONE);
- branchText.setEditable(false);
- branchText.setBackground(projectGroup.getBackground());
+ Text branchText = new Text(projectGroup, SWT.BORDER);
GridDataFactory.fillDefaults()
.align(SWT.LEFT, SWT.CENTER).align(SWT.FILL, SWT.CENTER).grab(true, false)
.applyTo(branchText);
-
- Button selectBranchButton = new Button(projectGroup, SWT.PUSH);
- selectBranchButton.setText("Select Branch");
+ Binding branchNameBinding = dbc.bindValue(
+ WidgetProperties.text(SWT.Modify).observe(branchText)
+ , BeanProperties.value(AdapterWizardPageModel.PROPERTY_BRANCHNAME).observe(model)
+ , new UpdateValueStrategy().setAfterGetValidator(new BranchNameValidator())
+ , null);
+ ControlDecorationSupport.create(branchNameBinding, SWT.TOP | SWT.LEFT);
+
+ Button defaultBranchnameButton = new Button(projectGroup, SWT.PUSH);
+ defaultBranchnameButton.setText("Default");
GridDataFactory.fillDefaults()
- .align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(selectBranchButton);
- selectBranchButton.addSelectionListener(onSelectBranch());
+ .align(SWT.LEFT, SWT.CENTER).hint(100,
SWT.DEFAULT).applyTo(defaultBranchnameButton);
+ defaultBranchnameButton.addSelectionListener(onBranchnameDefault());
return projectGroup;
}
@@ -138,28 +148,18 @@
DirectoryDialog dialog = new DirectoryDialog(getShell());
String cloneDir = dialog.open();
if (cloneDir != null) {
- model.setCloneDir(cloneDir);
+ model.setCloneDirectory(cloneDir);
}
}
};
}
- private SelectionListener onSelectBranch() {
+ private SelectionListener onBranchnameDefault() {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ListDialog branchesDialog = new ListDialog(getShell());
- branchesDialog.setContentProvider(new BranchNameContentProvider());
- branchesDialog.setTitle("Branches");
- if (Dialog.OK == branchesDialog.open()) {
- Object[] selectedBranches = branchesDialog.getResult();
- if (selectedBranches != null
- && selectedBranches.length >= 1
- && selectedBranches[1] instanceof String) {
- model.setBranch((String) selectedBranches[1]);
- }
- }
+ model.resetBranchname();
}
};
}
@@ -181,7 +181,7 @@
}
private void fillServerAdapterGroup(Group serverAdapterGroup) {
- Composite c = new Composite(serverAdapterGroup, SWT.BORDER);
+ Composite c = new Composite(serverAdapterGroup, SWT.NONE);
c.setLayout(new FormLayout());
Button serverAdapterCheckbox = new Button(c, SWT.CHECK);
serverAdapterCheckbox.setText("Create a JBoss server adapter");
@@ -337,4 +337,26 @@
return returnValue;
}
+ private static class BranchNameValidator implements IValidator {
+
+ private static final Pattern BRANCH_PATTERN = Pattern.compile(".+\\/.+");
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value == null
+ || ((String) value).length() == 0) {
+ return ValidationStatus.error("you have to provide a branch to clone");
+ }
+
+ if (!isValidBranch((String) value)) {
+ return ValidationStatus.error("you have to provide a valid branch name (ex.
origin/master)");
+ }
+ return ValidationStatus.ok();
+ }
+
+ private boolean isValidBranch(String branchname) {
+ return BRANCH_PATTERN.matcher(branchname).matches();
+ }
+ }
+
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java 2011-10-12
22:05:58 UTC (rev 35584)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java 2011-10-12
22:11:13 UTC (rev 35585)
@@ -17,8 +17,11 @@
* @author Rob Stryker
*/
public class AdapterWizardPageModel extends ObservableUIPojo {
- public static final String PROPERTY_CLONEDIR = "cloneDir";
- public static final String PROPERTY_BRANCH = "branch";
+
+ private static final String BRANCHNAME_DEFAULT = "origin/master";
+
+ public static final String PROPERTY_CLONEDIR = "cloneDirectory";
+ public static final String PROPERTY_BRANCHNAME = "branchname";
public static final String CREATE_SERVER = "createServer";
public static final String MODE = "serverMode";
@@ -28,33 +31,39 @@
public static final String SERVER_TYPE = "serverType";
private String cloneDir;
- private String branch;
+ private String branchname;
private ImportProjectWizardModel wizardModel;
public AdapterWizardPageModel(ImportProjectWizardModel wizardModel) {
this.wizardModel = wizardModel;
+ this.branchname = BRANCHNAME_DEFAULT;
}
- public String getCloneDir() {
+ public String getCloneDirectory() {
return cloneDir;
}
- public void setCloneDir(String cloneDir) {
- firePropertyChange(PROPERTY_CLONEDIR, cloneDir, this.cloneDir = cloneDir);
+ public void setCloneDirectory(String cloneDir) {
+ firePropertyChange(PROPERTY_CLONEDIR, this.cloneDir, this.cloneDir = cloneDir);
+ wizardModel.setCloneDirectory(cloneDir);
}
- public String getBranch() {
- return branch;
+ public String getBranchname() {
+ return branchname;
}
- public void setBranch(String branch) {
- firePropertyChange(PROPERTY_BRANCH, branch, this.branch = branch);
+ public void setBranchname(String branchname) {
+ firePropertyChange(PROPERTY_BRANCHNAME, this.branchname, this.branchname =
branchname);
+ wizardModel.setBranchname(branchname);
}
+ public void resetBranchname() {
+ setBranchname(BRANCHNAME_DEFAULT);
+ }
+
// TODO is this the best way? Or should we expose ONLY getters to the parent model?
public ImportProjectWizardModel getParentModel() {
return wizardModel;
}
-
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java 2011-10-12
22:05:58 UTC (rev 35584)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java 2011-10-12
22:11:13 UTC (rev 35585)
@@ -49,6 +49,8 @@
private static final String USER = "user";
private static final String APPLICATION = "application";
+ private static final String BRANCHNAME = "branchname";
+ private static final String CLONE_DIR = "cloneDir";
public void setProperty(String key, Object value) {
dataModel.put(key, value);
@@ -70,10 +72,26 @@
return (IApplication) dataModel.get(APPLICATION);
}
+ public void setBranchname(String branchname) {
+ dataModel.put(BRANCHNAME, branchname);
+ }
+
+ public String getBranchname() {
+ return (String) dataModel.get(BRANCHNAME);
+ }
+
+ public void setCloneDirectory(String cloneDir) {
+ dataModel.put(CLONE_DIR, cloneDir);
+ }
+
+ public String getCloneDirectory() {
+ return (String) dataModel.get(CLONE_DIR);
+ }
+
public void setApplication(IApplication application) {
dataModel.put(APPLICATION, application);
}
-
+
public void importProject(final File projectFolder, IProgressMonitor monitor) throws
OpenshiftException,
CoreException,
InterruptedException {
@@ -119,8 +137,9 @@
public File cloneRepository(IProgressMonitor monitor) throws URISyntaxException,
OpenshiftException,
InvocationTargetException,
InterruptedException {
- File destination = getDestinationDirectory(getApplication());
- cloneRepository(getApplication().getGitUri(), destination, monitor);
+ IApplication application = getApplication();
+ File destination = new File(getCloneDirectory(), application.getName());
+ cloneRepository(application.getGitUri(), destination, monitor);
return destination;
}
@@ -134,11 +153,12 @@
ensureEgitUIIsStarted();
URIish gitUri = new URIish(uri);
RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
+
CloneOperation cloneOperation =
+// new CloneOperation(gitUri, true, null, destination, Constants.HEAD,
"origin", 10 * 1024);
new CloneOperation(gitUri, true, null, destination, Constants.HEAD,
"origin", 10 * 1024);
- cloneOperation.run(null);
- File gitDirectory = new File(destination, Constants.DOT_GIT);
- repositoryUtil.addConfiguredRepository(gitDirectory);
+ cloneOperation.run(monitor);
+ repositoryUtil.addConfiguredRepository(new File(destination, Constants.DOT_GIT));
}
/**
@@ -162,15 +182,6 @@
Activator.getDefault();
}
- private File getDestinationDirectory(IApplication application) {
- String applicationDirectory = application.getName();
- // File workspace =
- // ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
- String userHome = System.getProperty("java.io.tmpdir");
- // File workDir = new File(workspace, applicationWorkingdir);
- return new File(userHome, applicationDirectory);
- }
-
private void createServerAdapterIfRequired() {
// TODO
}