diff options
author | Remy Suen | 2010-05-14 22:34:54 +0000 |
---|---|---|
committer | Remy Suen | 2010-05-14 22:34:54 +0000 |
commit | 7c48242225178bbd879149e61423a036574f9206 (patch) | |
tree | 211fba31ca980839dac7f0f1c0c02315794da6bb /org.eclipse.egit.ui/src | |
parent | df6aff2361256f113da4dbead00d286afec560a0 (diff) | |
download | egit-7c48242225178bbd879149e61423a036574f9206.tar.gz egit-7c48242225178bbd879149e61423a036574f9206.tar.xz egit-7c48242225178bbd879149e61423a036574f9206.zip |
Improve error validation in the patch wizard
Currently, no error messages are presented to the user for invalid
input into the wizard. This is very unhelpful as the user may not
know what is wrong with their input. Switching to the clipboard
mode may also not clear the error message due to an error in the
validation logic. To also help prevent the user from entering data
that may not end up being processed, controls are now enabled and
disabled based on which radio button has been selected.
Change-Id: I50998266c213deabec4a01a44024d95015a56b55
Diffstat (limited to 'org.eclipse.egit.ui/src')
3 files changed, 44 insertions, 11 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index 575d8fcb9e..967a672f74 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -1849,6 +1849,18 @@ public class UIText extends NLS { public static String GitCreatePatchWizard_SelectOptionsTitle; /** */ + public static String GitCreatePatchWizard_FilesystemError; + + /** */ + public static String GitCreatePatchWizard_FilesystemInvalidError; + + /** */ + public static String GitCreatePatchWizard_FilesystemDirectoryError; + + /** */ + public static String GitCreatePatchWizard_FilesystemDirectoryNotExistsError; + + /** */ public static String GitCreateProjectViaWizardWizard_AbortedMessage; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java index 45c5d86e14..b71a4af26e 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java @@ -265,8 +265,6 @@ public class GitCreatePatchWizard extends Wizard { private Button fsBrowseButton; - private boolean canValidate = true; - private boolean pageValid; /** @@ -285,6 +283,7 @@ public class GitCreatePatchWizard extends Wizard { gridLayout.numColumns = 3; composite.setLayout(gridLayout); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + initializeDialogUnits(composite); setControl(composite); // clipboard @@ -293,15 +292,18 @@ public class GitCreatePatchWizard extends Wizard { cpRadio = new Button(composite, SWT.RADIO); cpRadio.setText(UIText.GitCreatePatchWizard_Clipboard); cpRadio.setLayoutData(gd); + cpRadio.setSelection(true); // filesystem fsRadio = new Button(composite, SWT.RADIO); fsRadio.setText(UIText.GitCreatePatchWizard_File); + fsRadio.setSelection(false); fsPathText = new Text(composite, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); fsPathText.setLayoutData(gd); fsPathText.setText(createFileName()); + fsPathText.setEnabled(false); fsBrowseButton = new Button(composite, SWT.PUSH); fsBrowseButton.setText(UIText.GitCreatePatchWizard_Browse); @@ -311,10 +313,25 @@ public class GitCreatePatchWizard extends Wizard { SWT.DEFAULT, true); data.widthHint = Math.max(widthHint, minSize.x); fsBrowseButton.setLayoutData(data); + fsBrowseButton.setEnabled(false); + + cpRadio.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + // disable other input controls + fsPathText.setEnabled(false); + fsBrowseButton.setEnabled(false); + validatePage(); + } + }); fsRadio.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { + // enable filesystem input controls + fsPathText.setEnabled(true); + fsBrowseButton.setEnabled(true); + // set focus to filesystem input text control + fsPathText.setFocus(); validatePage(); } }); @@ -372,11 +389,11 @@ public class GitCreatePatchWizard extends Wizard { * @return page is valid */ protected boolean validatePage() { - if (!canValidate) - return false; - - if (fsRadio.getSelection()) + if (fsRadio.getSelection()) { pageValid = validateFilesystemLocation(); + } else if (cpRadio.getSelection()) { + pageValid = true; + } /** * Avoid draw flicker by clearing error message if all is valid. @@ -401,29 +418,29 @@ public class GitCreatePatchWizard extends Wizard { final String pathString = fsPathText.getText().trim(); if (pathString.length() == 0 || !new Path("").isValidPath(pathString)) { //$NON-NLS-1$ - setErrorMessage(""); //$NON-NLS-1$ + setErrorMessage(UIText.GitCreatePatchWizard_FilesystemError); return false; } final File file = new File(pathString); if (!file.isAbsolute()) { - setErrorMessage(""); //$NON-NLS-1$ + setErrorMessage(UIText.GitCreatePatchWizard_FilesystemInvalidError); return false; } if (file.isDirectory()) { - setErrorMessage(""); //$NON-NLS-1$ + setErrorMessage(UIText.GitCreatePatchWizard_FilesystemDirectoryError); return false; } if (pathString.endsWith("/") || pathString.endsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$ - setErrorMessage(""); //$NON-NLS-1$ + setErrorMessage(UIText.GitCreatePatchWizard_FilesystemDirectoryNotExistsError); return false; } final File parent = file.getParentFile(); if (!(parent.exists() && parent.isDirectory())) { - setErrorMessage(""); //$NON-NLS-1$ + setErrorMessage(UIText.GitCreatePatchWizard_FilesystemDirectoryNotExistsError); return false; } return true; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 904cb84fcd..05a73c539d 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -661,6 +661,10 @@ GitCreatePatchWizard_SelectLocationDescription=Select the location for the patch GitCreatePatchWizard_SelectLocationTitle=Create a Patch GitCreatePatchWizard_SelectOptionsDescription=Select options for patch creation GitCreatePatchWizard_SelectOptionsTitle=Select options +GitCreatePatchWizard_FilesystemError=Please select a location in the filesystem by browsing. +GitCreatePatchWizard_FilesystemInvalidError=Please enter a valid location. +GitCreatePatchWizard_FilesystemDirectoryError=Please enter a file name. +GitCreatePatchWizard_FilesystemDirectoryNotExistsError=The specified directory does not exist. GitCreateProjectViaWizardWizard_AbortedMessage=Action was aborted GitCreateProjectViaWizardWizard_WizardTitle=Import projects from Git Repository {0} GitImportProjectsWizard_ImportExistingProjects0=Import existing projects |