Unverified Commit ce9cb23a authored by Ramanathi's avatar Ramanathi Committed by GitHub

Propose valid project names in creating new project (#2143)

parent bb7c8241
......@@ -179,8 +179,14 @@ public class LabeledTextBox extends Composite {
*/
private void setErrorStyles(boolean validationResult) {
if (validationResult) {
textbox.getElement().getStyle().setBorderColor(defaultTextBoxColor);
errorLabel.setText("");
if (errorMessage.length() > 0) { // handling warnings
String warningColor = "yellow";
textbox.getElement().getStyle().setBorderColor(warningColor);
errorLabel.setText(errorMessage);
} else {
textbox.getElement().getStyle().setBorderColor(defaultTextBoxColor);
errorLabel.setText("");
}
} else {
String errorColor = "red";
textbox.getElement().getStyle().setBorderColor(errorColor);
......
......@@ -60,6 +60,7 @@ public final class NewYoungAndroidProjectWizard extends NewProjectWizard {
disableOkButton();
return false;
}
errorMessage = TextValidators.getWarningMessages(value);
enableOkButton();
return true;
}
......@@ -113,8 +114,8 @@ public final class NewYoungAndroidProjectWizard extends NewProjectWizard {
initFinishCommand(new Command() {
@Override
public void execute() {
String projectName = projectNameTextBox.getText();
String projectName = projectNameTextBox.getText().trim();
projectName = projectName.replaceAll("( )+", " ").replace(" ","_");
if (TextValidators.checkNewProjectName(projectName)) {
String packageName = StringUtils.getProjectPackage(
Ode.getInstance().getUser().getUserEmail(), projectName);
......
......@@ -68,7 +68,7 @@ public final class RemixedYoungAndroidProjectWizard extends NewProjectWizard { /
initFinishCommand(new Command() {
@Override
public void execute() {
String projectName = projectNameTextBox.getText();
String projectName = projectNameTextBox.getText().trim();
final PopupPanel popup = new PopupPanel(true);
final FlowPanel content = new FlowPanel();
popup.setWidget(content);
......@@ -77,7 +77,7 @@ public final class RemixedYoungAndroidProjectWizard extends NewProjectWizard { /
// loading indicator will be hided or forced to be hided in gallery.loadSourceFile
content.add(loading);
popup.center();
boolean success = gallery.loadSourceFile(app, projectNameTextBox.getText(), popup);
boolean success = gallery.loadSourceFile(app, projectNameTextBox.getText().trim(), popup);
if(success){
gallery.appWasDownloaded(app.getGalleryAppId(), app.getDeveloperId());
}
......
......@@ -187,15 +187,35 @@ public final class TextValidators {
String errorMessage = "";
String noWhitespace = "[\\S]+";
String firstCharacterLetter = "[A-Za-z].*";
if(!filename.matches("[A-Za-z][A-Za-z0-9_]*") && filename.length() > 0) {
if(!filename.matches(noWhitespace)) { //Check to make sure that this project does not contain any whitespace
errorMessage = MESSAGES.whitespaceProjectNameError();
} else if (!filename.matches(firstCharacterLetter)) { //Check to make sure that the first character is a letter
errorMessage = MESSAGES.firstCharProjectNameError();
} else { //The text contains a character that is not a letter, number, or underscore
errorMessage = MESSAGES.invalidCharProjectNameError();
String temp = filename.trim().replaceAll("( )+", " ").replace(" ","_");
if (temp.length() > 0) {
if (!temp.matches("[A-Za-z][A-Za-z0-9_]*")) {
if (!temp.matches(firstCharacterLetter)) {
//Check to make sure that the first character is a letter
errorMessage = MESSAGES.firstCharProjectNameError();
} else { //The text contains a character that is not a letter, number, or underscore
errorMessage = MESSAGES.invalidCharProjectNameError();
}
}
}
return errorMessage;
}
/**
* Determines human-readable message for specific warning if there are no errors.
* @param filename The filename (not path) of uploaded file
* @return String representing warning message, empty string if no warning and no error
*/
public static String getWarningMessages(String filename) {
String warningMessage = "";
if (getErrorMessage(filename).length() == 0 && filename.trim().length() > 0) {
if (!filename.matches("[A-Za-z][A-Za-z0-9_]*")) {
// check to make sure if filename has no spaces
String errorMessage = MESSAGES.whitespaceProjectNameError();
filename = filename.trim().replaceAll("( )+", " ").replace(" ","_");
warningMessage = errorMessage + ". \n '" + filename + "' will be used if continued.";
}
}
return warningMessage;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment