Skip to content

Commit 8a90fe2

Browse files
author
Vitaliy Guliy
committed
CHE-124 Create/Import wizards are displaying errors while nothing is entered
Signed-off-by: Vitaliy Guliy <vguliy@codenvy.com>
1 parent 5dad4fe commit 8a90fe2

15 files changed

Lines changed: 286 additions & 110 deletions

File tree

core/commons/che-core-commons-gwt/src/main/java/org/eclipse/che/ide/util/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public static String nullToEmpty(String s) {
297297
}
298298

299299
public static boolean isNullOrEmpty(String s) {
300-
return s == null || "".equals(s);
300+
return s == null || s.isEmpty();
301301
}
302302

303303
public static boolean isNullOrWhitespace(String s) {

core/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/Core.css

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ body, td {
177177
.gwt-TextBox {
178178
min-height: 22px;
179179
padding: 0 5px 0 5px;
180+
transition: border-bottom 0.2s linear;
180181
}
181182

182183
.gwt-TextArea {
@@ -185,9 +186,14 @@ body, td {
185186
resize: none;
186187
}
187188

189+
.gwt-TextBox[success] {
190+
border-bottom: 1px solid successColor;
191+
}
192+
188193
.gwt-TextBox:invalid,
189194
.gwt-TextBox:required,
190-
.gwt-TextBox.inputError {
195+
.gwt-TextBox.inputError,
196+
.gwt-TextBox[error] {
191197
border-bottom: 1px solid errorColor !important;
192198
}
193199

@@ -201,11 +207,6 @@ body, td {
201207
-webkit-animation: textFieldFocus 0.2s infinite;
202208
}
203209

204-
.gwt-TextBox:focus {
205-
border-bottom: 1px solid successColor;
206-
transition: border-bottom 0.2s linear;
207-
}
208-
209210
.gwt-TextBox-readonly:focus {
210211
border-bottom: 1px solid textFieldBorderColor;
211212
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012-2016 Codenvy, S.A.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Codenvy, S.A. - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.che.ide.ui;
12+
13+
/**
14+
* An Extension of GWT TextBox.
15+
* Contains methods for marking the text box containing valid or invalid values.
16+
*
17+
* @author Vitaliy Guliy
18+
*/
19+
public class TextBox extends com.google.gwt.user.client.ui.TextBox {
20+
21+
/**
22+
* Marks text box containing valid value.
23+
*/
24+
public void markValid() {
25+
getElement().setAttribute("success", "");
26+
getElement().removeAttribute("error");
27+
}
28+
29+
/**
30+
* Marks text box containing invalid value.
31+
*/
32+
public void markInvalid() {
33+
getElement().removeAttribute("success");
34+
getElement().setAttribute("error", "");
35+
}
36+
37+
/**
38+
* Removes mark from text box.
39+
*/
40+
public void unmark() {
41+
getElement().removeAttribute("success");
42+
getElement().removeAttribute("error");
43+
}
44+
45+
}

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/importer/page/GitImporterPagePresenter.java

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.ide.ext.git.client.importer.page;
1212

13+
import com.google.common.base.Strings;
1314
import com.google.gwt.regexp.shared.RegExp;
1415
import com.google.gwt.user.client.ui.AcceptsOneWidget;
1516
import com.google.inject.Inject;
@@ -44,6 +45,8 @@ public class GitImporterPagePresenter extends AbstractWizardPage<ProjectConfigDt
4445
private GitLocalizationConstant locale;
4546
private GitImporterPageView view;
4647

48+
private boolean ignoreChanges;
49+
4750
@Inject
4851
public GitImporterPagePresenter(GitImporterPageView view,
4952
GitLocalizationConstant locale) {
@@ -59,6 +62,10 @@ public boolean isCompleted() {
5962

6063
@Override
6164
public void projectNameChanged(@NotNull String name) {
65+
if (ignoreChanges) {
66+
return;
67+
}
68+
6269
dataObject.setName(name);
6370
updateDelegate.updateControls();
6471

@@ -67,14 +74,18 @@ public void projectNameChanged(@NotNull String name) {
6774

6875
private void validateProjectName() {
6976
if (NameUtils.checkProjectName(view.getProjectName())) {
70-
view.hideNameError();
77+
view.markNameValid();
7178
} else {
72-
view.showNameError();
79+
view.markNameInvalid();
7380
}
7481
}
7582

7683
@Override
7784
public void projectUrlChanged(@NotNull String url) {
85+
if (ignoreChanges) {
86+
return;
87+
}
88+
7889
dataObject.getSource().setLocation(url);
7990
isGitUrlCorrect(url);
8091

@@ -166,6 +177,14 @@ public void branchNameChanged(@NotNull String branch) {
166177
public void go(@NotNull AcceptsOneWidget container) {
167178
container.setWidget(view);
168179

180+
if (Strings.isNullOrEmpty(dataObject.getName()) && Strings.isNullOrEmpty(dataObject.getSource().getLocation())) {
181+
ignoreChanges = true;
182+
183+
view.unmarkURL();
184+
view.unmarkName();
185+
view.setURLErrorMessage(null);
186+
}
187+
169188
view.setProjectName(dataObject.getName());
170189
view.setProjectDescription(dataObject.getDescription());
171190
view.setProjectUrl(dataObject.getSource().getLocation());
@@ -180,6 +199,8 @@ public void go(@NotNull AcceptsOneWidget container) {
180199

181200
view.setInputsEnableState(true);
182201
view.focusInUrlInput();
202+
203+
ignoreChanges = false;
183204
}
184205

185206
/** Gets project name from uri. */
@@ -193,6 +214,7 @@ private String extractProjectNameFromUri(@NotNull String uri) {
193214
if (indexStartProjectName != 0) {
194215
return uri.substring(indexStartProjectName);
195216
}
217+
196218
return "";
197219
}
198220

@@ -205,26 +227,38 @@ private String extractProjectNameFromUri(@NotNull String uri) {
205227
*/
206228
private boolean isGitUrlCorrect(@NotNull String url) {
207229
if (WHITE_SPACE.test(url)) {
208-
view.showUrlError(locale.importProjectMessageStartWithWhiteSpace());
230+
view.markURLInvalid();
231+
view.setURLErrorMessage(locale.importProjectMessageStartWithWhiteSpace());
209232
return false;
210233
}
234+
211235
if (SCP_LIKE_SYNTAX.test(url)) {
212-
view.hideUrlError();
236+
view.markURLValid();
237+
view.setURLErrorMessage(null);
213238
return true;
214239
}
240+
215241
if (!PROTOCOL.test(url)) {
216-
view.showUrlError(locale.importProjectMessageProtocolIncorrect());
242+
view.markURLInvalid();
243+
view.setURLErrorMessage(locale.importProjectMessageProtocolIncorrect());
217244
return false;
218245
}
246+
219247
if (!(HOST1.test(url) || HOST2.test(url))) {
220-
view.showUrlError(locale.importProjectMessageHostIncorrect());
248+
view.markURLInvalid();
249+
view.setURLErrorMessage(locale.importProjectMessageHostIncorrect());
221250
return false;
222251
}
252+
223253
if (!(REPO_NAME.test(url))) {
224-
view.showUrlError(locale.importProjectMessageNameRepoIncorrect());
254+
view.markURLInvalid();
255+
view.setURLErrorMessage(locale.importProjectMessageNameRepoIncorrect());
225256
return false;
226257
}
227-
view.hideUrlError();
258+
259+
view.markURLValid();
260+
view.setURLErrorMessage(null);
228261
return true;
229262
}
263+
230264
}

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/importer/page/GitImporterPageView.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,42 @@ interface ActionDelegate {
4545
}
4646

4747
/**
48-
* Show the name error.
48+
* Marks URL field containing valid value.
4949
*/
50-
void showNameError();
50+
void markURLValid();
5151

5252
/**
53-
* Hide the name error.
53+
* Marks URL field containing invalid value.
5454
*/
55-
void hideNameError();
55+
void markURLInvalid();
5656

5757
/**
58-
* Show URL error.
58+
* Removes mark from URL field.
5959
*/
60-
void showUrlError(@NotNull String message);
60+
void unmarkURL();
6161

6262
/**
63-
* Hide URL error.
63+
* Displays error message under URL field.
64+
*
65+
* @param message
66+
* message
67+
*/
68+
void setURLErrorMessage(@NotNull String message);
69+
70+
/**
71+
* Marks name field containing valid value.
72+
*/
73+
void markNameValid();
74+
75+
/**
76+
* Marks name field containing invalid value.
77+
*/
78+
void markNameInvalid();
79+
80+
/**
81+
* Removes mark from Name field.
6482
*/
65-
void hideUrlError();
83+
void unmarkName();
6684

6785
/**
6886
* Set the project's URL.

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/importer/page/GitImporterPageViewImpl.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
import com.google.gwt.user.client.ui.DockLayoutPanel;
2424
import com.google.gwt.user.client.ui.FlowPanel;
2525
import com.google.gwt.user.client.ui.Label;
26-
import com.google.gwt.user.client.ui.RadioButton;
2726
import com.google.gwt.user.client.ui.TextArea;
28-
import com.google.gwt.user.client.ui.TextBox;
2927
import com.google.inject.Inject;
3028

3129
import org.eclipse.che.ide.ext.git.client.GitResources;
30+
import org.eclipse.che.ide.ui.TextBox;
3231

3332
import javax.validation.constraints.NotNull;
3433

@@ -144,25 +143,38 @@ public void setProjectUrl(@NotNull String url) {
144143
}
145144

146145
@Override
147-
public void showNameError() {
148-
projectName.addStyleName(style.inputError());
146+
public void markURLValid() {
147+
projectUrl.markValid();
149148
}
150149

151150
@Override
152-
public void hideNameError() {
153-
projectName.removeStyleName(style.inputError());
151+
public void markURLInvalid() {
152+
projectUrl.markInvalid();
154153
}
155154

156155
@Override
157-
public void showUrlError(@NotNull String message) {
158-
projectUrl.addStyleName(style.inputError());
159-
labelUrlError.setText(message);
156+
public void unmarkURL() {
157+
projectUrl.unmark();
160158
}
161159

162160
@Override
163-
public void hideUrlError() {
164-
projectUrl.removeStyleName(style.inputError());
165-
labelUrlError.setText("");
161+
public void setURLErrorMessage(@NotNull String message) {
162+
labelUrlError.setText(message != null ? message : "");
163+
}
164+
165+
@Override
166+
public void markNameValid() {
167+
projectName.markValid();
168+
}
169+
170+
@Override
171+
public void markNameInvalid() {
172+
projectName.markInvalid();
173+
}
174+
175+
@Override
176+
public void unmarkName() {
177+
projectName.unmark();
166178
}
167179

168180
@NotNull

plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/importer/page/GitImporterPageViewImpl.ui.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
1212
-->
1313
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
14-
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
14+
xmlns:g='urn:import:com.google.gwt.user.client.ui'
15+
xmlns:ide='urn:import:org.eclipse.che.ide.ui'>
1516
<ui:with field='locale' type='org.eclipse.che.ide.ext.git.client.GitLocalizationConstant'/>
1617
<ui:with field="style" type="org.eclipse.che.ide.ext.git.client.importer.page.GitImporterPageViewImpl.Style"/>
1718
<g:DockLayoutPanel unit="PX" addStyleNames="{style.mainPanel}">
@@ -20,7 +21,7 @@
2021
<g:FlowPanel height="65px" addStyleNames="{style.namePanel}">
2122
<g:Label text="{locale.gitImporterPageProjectUrl}"
2223
addStyleNames="{style.labelPosition}"/>
23-
<g:TextBox ui:field="projectUrl" addStyleNames="{style.inputField} {style.alignRight}" tabIndex="3"
24+
<ide:TextBox ui:field="projectUrl" addStyleNames="{style.inputField} {style.alignRight}" tabIndex="3"
2425
debugId="file-importProject-projectUrl"/>
2526
<g:Label ui:field="labelUrlError" width="100%" wordWrap="true" addStyleNames="{style.labelErrorPosition}"/>
2627
</g:FlowPanel>
@@ -31,7 +32,7 @@
3132
<g:FlowPanel height="50px" addStyleNames="{style.namePanel}">
3233
<g:Label text="{locale.gitImporterPageProjectName}"
3334
addStyleNames="{style.labelPosition}"/>
34-
<g:TextBox ui:field="projectName" addStyleNames="{style.inputField} {style.alignRight}"
35+
<ide:TextBox ui:field="projectName" addStyleNames="{style.inputField} {style.alignRight}"
3536
tabIndex="4"
3637
debugId="file-importProject-projectName" title="{locale.gitImporterPageProjectNamePrompt}"/>
3738
</g:FlowPanel>
@@ -51,7 +52,7 @@
5152

5253
<g:FlowPanel height="55px" addStyleNames="{style.namePanel}">
5354
<g:Label text="{locale.gitImporterPageKeepDirectoryField}" addStyleNames="{style.labelPosition}"/>
54-
<g:TextBox ui:field="directoryName" addStyleNames="{style.inputField} {style.alignRight}"
55+
<ide:TextBox ui:field="directoryName" addStyleNames="{style.inputField} {style.alignRight}"
5556
tabIndex="9" debugId="file-importProject-keepDirectoryName" title="{locale.gitImporterPageBranchField}"/>
5657
</g:FlowPanel>
5758

@@ -62,7 +63,7 @@
6263

6364
<g:FlowPanel height="20px" addStyleNames="{style.namePanel}">
6465
<g:Label text="{locale.gitImporterPageBranchField}" addStyleNames="{style.labelPosition}"/>
65-
<g:TextBox ui:field="branch" addStyleNames="{style.inputField} {style.alignRight}"
66+
<ide:TextBox ui:field="branch" addStyleNames="{style.inputField} {style.alignRight}"
6667
tabIndex="10" debugId="file-importProject-branchName" title="{locale.gitImporterPageBranchField}"/>
6768
</g:FlowPanel>
6869

0 commit comments

Comments
 (0)