Extend NpTextBox to support hinting and use it.
Create a new class: HintTextBox. This class extends NpTextBox and can display a hint text when the text field would be blank. This class will keep track of whether the hint is currently being displayed or not and set the style to hintStyleName if the hint is currently displayed. This class will also modify the getText() method to never return the hintText unless a user enters this text manually. Use this new class everywhere where hinting was previously implemented manually. Change-Id: Ie4c0d891a2045e292b68139c956713127d92d0be
This commit is contained in:
@@ -15,14 +15,11 @@
|
||||
package com.google.gerrit.client;
|
||||
|
||||
import com.google.gerrit.client.changes.QueryScreen;
|
||||
import com.google.gerrit.client.ui.HintTextBox;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gwt.event.dom.client.BlurEvent;
|
||||
import com.google.gwt.event.dom.client.BlurHandler;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.FocusEvent;
|
||||
import com.google.gwt.event.dom.client.FocusHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||
@@ -35,7 +32,7 @@ import com.google.gwtexpui.globalkey.client.KeyCommand;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
|
||||
class SearchPanel extends Composite {
|
||||
private final NpTextBox searchBox;
|
||||
private final HintTextBox searchBox;
|
||||
private HandlerRegistration regFocus;
|
||||
|
||||
SearchPanel() {
|
||||
@@ -43,28 +40,9 @@ class SearchPanel extends Composite {
|
||||
initWidget(body);
|
||||
setStyleName(Gerrit.RESOURCES.css().searchPanel());
|
||||
|
||||
searchBox = new NpTextBox();
|
||||
searchBox = new HintTextBox();
|
||||
searchBox.setVisibleLength(70);
|
||||
searchBox.setText(Gerrit.C.searchHint());
|
||||
searchBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
searchBox.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
if (Gerrit.C.searchHint().equals(searchBox.getText())) {
|
||||
searchBox.setText("");
|
||||
searchBox.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
searchBox.addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(BlurEvent event) {
|
||||
if ("".equals(searchBox.getText())) {
|
||||
searchBox.setText(Gerrit.C.searchHint());
|
||||
searchBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
searchBox.setHintText(Gerrit.C.searchHint());
|
||||
searchBox.addKeyPressHandler(new KeyPressHandler() {
|
||||
@Override
|
||||
public void onKeyPress(final KeyPressEvent event) {
|
||||
@@ -93,13 +71,7 @@ class SearchPanel extends Composite {
|
||||
}
|
||||
|
||||
void setText(final String query) {
|
||||
if (query == null || query.equals("")) {
|
||||
searchBox.setText(Gerrit.C.searchHint());
|
||||
searchBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
} else {
|
||||
searchBox.setText(query);
|
||||
searchBox.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +101,7 @@ class SearchPanel extends Composite {
|
||||
|
||||
private void doSearch() {
|
||||
final String query = searchBox.getText().trim();
|
||||
if (query.length() == 0 || Gerrit.C.searchHint().equals(query)) {
|
||||
if ("".equals(query)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,17 +18,14 @@ import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.FancyFlexTable;
|
||||
import com.google.gerrit.client.ui.HintTextBox;
|
||||
import com.google.gerrit.client.ui.ProjectLink;
|
||||
import com.google.gerrit.client.ui.ProjectNameSuggestOracle;
|
||||
import com.google.gerrit.common.data.AccountProjectWatchInfo;
|
||||
import com.google.gerrit.reviewdb.AccountProjectWatch;
|
||||
import com.google.gerrit.reviewdb.Change.Status;
|
||||
import com.google.gwt.event.dom.client.BlurEvent;
|
||||
import com.google.gwt.event.dom.client.BlurHandler;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.FocusEvent;
|
||||
import com.google.gwt.event.dom.client.FocusHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||
@@ -44,7 +41,6 @@ import com.google.gwt.user.client.ui.SuggestBox;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -54,9 +50,9 @@ public class MyWatchedProjectsScreen extends SettingsScreen {
|
||||
private WatchTable watches;
|
||||
|
||||
private Button addNew;
|
||||
private NpTextBox nameBox;
|
||||
private HintTextBox nameBox;
|
||||
private SuggestBox nameTxt;
|
||||
private NpTextBox filterTxt;
|
||||
private HintTextBox filterTxt;
|
||||
private Button delSel;
|
||||
private boolean submitOnSelection;
|
||||
|
||||
@@ -65,29 +61,10 @@ public class MyWatchedProjectsScreen extends SettingsScreen {
|
||||
super.onInitUI();
|
||||
|
||||
{
|
||||
nameBox = new NpTextBox();
|
||||
nameBox = new HintTextBox();
|
||||
nameTxt = new SuggestBox(new ProjectNameSuggestOracle(), nameBox);
|
||||
nameBox.setVisibleLength(50);
|
||||
nameBox.setText(Util.C.defaultProjectName());
|
||||
nameBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
nameBox.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
if (Util.C.defaultProjectName().equals(nameBox.getText())) {
|
||||
nameBox.setText("");
|
||||
nameBox.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameBox.addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(BlurEvent event) {
|
||||
if ("".equals(nameBox.getText())) {
|
||||
nameBox.setText(Util.C.defaultProjectName());
|
||||
nameBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameBox.setHintText(Util.C.defaultProjectName());
|
||||
nameBox.addKeyPressHandler(new KeyPressHandler() {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
@@ -112,28 +89,9 @@ public class MyWatchedProjectsScreen extends SettingsScreen {
|
||||
}
|
||||
});
|
||||
|
||||
filterTxt = new NpTextBox();
|
||||
filterTxt = new HintTextBox();
|
||||
filterTxt.setVisibleLength(50);
|
||||
filterTxt.setText(Util.C.defaultFilter());
|
||||
filterTxt.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
filterTxt.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
if (Util.C.defaultFilter().equals(filterTxt.getText())) {
|
||||
filterTxt.setText("");
|
||||
filterTxt.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
filterTxt.addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(BlurEvent event) {
|
||||
if ("".equals(filterTxt.getText())) {
|
||||
filterTxt.setText(Util.C.defaultFilter());
|
||||
filterTxt.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
filterTxt.setHintText(Util.C.defaultFilter());
|
||||
filterTxt.addKeyPressHandler(new KeyPressHandler() {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
@@ -188,8 +146,7 @@ public class MyWatchedProjectsScreen extends SettingsScreen {
|
||||
|
||||
void doAddNew() {
|
||||
final String projectName = nameTxt.getText();
|
||||
if (projectName == null || projectName.length() == 0
|
||||
|| Util.C.defaultProjectName().equals(projectName)) {
|
||||
if ("".equals(projectName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.client.admin;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.AccountGroupSuggestOracle;
|
||||
import com.google.gerrit.client.ui.HintTextBox;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ProjectDetail;
|
||||
import com.google.gerrit.reviewdb.ApprovalCategory;
|
||||
@@ -45,15 +46,14 @@ import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.ListBox;
|
||||
import com.google.gwt.user.client.ui.SuggestBox;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
|
||||
public class AccessRightEditor extends Composite
|
||||
implements HasValueChangeHandlers<ProjectDetail> {
|
||||
private Project.NameKey projectKey;
|
||||
private ListBox catBox;
|
||||
private NpTextBox nameTxt;
|
||||
private HintTextBox nameTxt;
|
||||
private SuggestBox nameSug;
|
||||
private NpTextBox referenceTxt;
|
||||
private HintTextBox referenceTxt;
|
||||
private ListBox topBox;
|
||||
private ListBox botBox;
|
||||
private Button addBut;
|
||||
@@ -99,32 +99,12 @@ public class AccessRightEditor extends Composite
|
||||
}
|
||||
});
|
||||
|
||||
nameTxt = new NpTextBox();
|
||||
nameTxt = new HintTextBox();
|
||||
nameSug = new SuggestBox(new AccountGroupSuggestOracle(), nameTxt);
|
||||
nameTxt.setVisibleLength(50);
|
||||
nameTxt.setText(Util.C.defaultAccountGroupName());
|
||||
nameTxt.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
nameTxt.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
if (Util.C.defaultAccountGroupName().equals(nameTxt.getText())) {
|
||||
nameTxt.setText("");
|
||||
nameTxt.removeStyleName(Gerrit.RESOURCES.css()
|
||||
.inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameTxt.addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(BlurEvent event) {
|
||||
if ("".equals(nameTxt.getText())) {
|
||||
nameTxt.setText(Util.C.defaultAccountGroupName());
|
||||
nameTxt.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameTxt.setHintText(Util.C.defaultAccountGroupName());
|
||||
|
||||
referenceTxt = new NpTextBox();
|
||||
referenceTxt = new HintTextBox();
|
||||
referenceTxt.setVisibleLength(50);
|
||||
referenceTxt.setText("");
|
||||
referenceTxt.addKeyPressHandler(new KeyPressHandler() {
|
||||
@@ -196,7 +176,7 @@ public class AccessRightEditor extends Composite
|
||||
|
||||
public void clear() {
|
||||
setCat(null);
|
||||
setName(Util.C.defaultAccountGroupName());
|
||||
setName("");
|
||||
setReference("");
|
||||
}
|
||||
|
||||
@@ -319,11 +299,6 @@ public class AccessRightEditor extends Composite
|
||||
}
|
||||
|
||||
protected void setName(final String name) {
|
||||
if (Util.C.defaultAccountGroupName().equals(name)) {
|
||||
nameTxt.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
} else {
|
||||
nameTxt.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
nameTxt.setText(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,18 +20,15 @@ import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.FancyFlexTable;
|
||||
import com.google.gerrit.client.ui.HintTextBox;
|
||||
import com.google.gerrit.common.data.GitwebLink;
|
||||
import com.google.gerrit.common.data.ListBranchesResult;
|
||||
import com.google.gerrit.common.errors.InvalidNameException;
|
||||
import com.google.gerrit.common.errors.InvalidRevisionException;
|
||||
import com.google.gerrit.reviewdb.Branch;
|
||||
import com.google.gerrit.reviewdb.Project;
|
||||
import com.google.gwt.event.dom.client.BlurEvent;
|
||||
import com.google.gwt.event.dom.client.BlurHandler;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.FocusEvent;
|
||||
import com.google.gwt.event.dom.client.FocusHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||
@@ -44,7 +41,6 @@ import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
import com.google.gwtjsonrpc.client.RemoteJsonException;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -55,8 +51,8 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
||||
private BranchesTable branches;
|
||||
private Button delBranch;
|
||||
private Button addBranch;
|
||||
private NpTextBox nameTxtBox;
|
||||
private NpTextBox irevTxtBox;
|
||||
private HintTextBox nameTxtBox;
|
||||
private HintTextBox irevTxtBox;
|
||||
private FlowPanel addPanel;
|
||||
|
||||
public ProjectBranchesScreen(final Project.NameKey toShow) {
|
||||
@@ -97,28 +93,9 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
||||
|
||||
final Grid addGrid = new Grid(2, 2);
|
||||
|
||||
nameTxtBox = new NpTextBox();
|
||||
nameTxtBox = new HintTextBox();
|
||||
nameTxtBox.setVisibleLength(50);
|
||||
nameTxtBox.setText(Util.C.defaultBranchName());
|
||||
nameTxtBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
nameTxtBox.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
if (Util.C.defaultBranchName().equals(nameTxtBox.getText())) {
|
||||
nameTxtBox.setText("");
|
||||
nameTxtBox.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameTxtBox.addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(BlurEvent event) {
|
||||
if ("".equals(nameTxtBox.getText())) {
|
||||
nameTxtBox.setText(Util.C.defaultBranchName());
|
||||
nameTxtBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameTxtBox.setHintText(Util.C.defaultBranchName());
|
||||
nameTxtBox.addKeyPressHandler(new KeyPressHandler() {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
@@ -130,28 +107,9 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
||||
addGrid.setText(0, 0, Util.C.columnBranchName() + ":");
|
||||
addGrid.setWidget(0, 1, nameTxtBox);
|
||||
|
||||
irevTxtBox = new NpTextBox();
|
||||
irevTxtBox = new HintTextBox();
|
||||
irevTxtBox.setVisibleLength(50);
|
||||
irevTxtBox.setText(Util.C.defaultRevisionSpec());
|
||||
irevTxtBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
irevTxtBox.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
if (Util.C.defaultRevisionSpec().equals(irevTxtBox.getText())) {
|
||||
irevTxtBox.setText("");
|
||||
irevTxtBox.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
irevTxtBox.addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(BlurEvent event) {
|
||||
if ("".equals(irevTxtBox.getText())) {
|
||||
irevTxtBox.setText(Util.C.defaultRevisionSpec());
|
||||
irevTxtBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
irevTxtBox.setHintText(Util.C.defaultRevisionSpec());
|
||||
irevTxtBox.addKeyPressHandler(new KeyPressHandler() {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
@@ -190,13 +148,13 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
||||
|
||||
private void doAddNewBranch() {
|
||||
String branchName = nameTxtBox.getText();
|
||||
if ("".equals(branchName) || Util.C.defaultBranchName().equals(branchName)) {
|
||||
if ("".equals(branchName)) {
|
||||
nameTxtBox.setFocus(true);
|
||||
return;
|
||||
}
|
||||
|
||||
String rev = irevTxtBox.getText();
|
||||
if ("".equals(rev) || Util.C.defaultRevisionSpec().equals(rev)) {
|
||||
if ("".equals(rev)) {
|
||||
irevTxtBox.setText("HEAD");
|
||||
DeferredCommand.addCommand(new Command() {
|
||||
@Override
|
||||
|
||||
@@ -16,12 +16,9 @@ package com.google.gerrit.client.ui;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.admin.Util;
|
||||
import com.google.gwt.event.dom.client.BlurEvent;
|
||||
import com.google.gwt.event.dom.client.BlurHandler;
|
||||
import com.google.gerrit.client.ui.HintTextBox;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.FocusEvent;
|
||||
import com.google.gwt.event.dom.client.FocusHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||
@@ -32,42 +29,22 @@ import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.SuggestBox;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
|
||||
public class AddMemberBox extends Composite {
|
||||
private final FlowPanel addPanel;
|
||||
private final Button addMember;
|
||||
private final NpTextBox nameTxtBox;
|
||||
private final HintTextBox nameTxtBox;
|
||||
private final SuggestBox nameTxt;
|
||||
private boolean submitOnSelection;
|
||||
|
||||
public AddMemberBox() {
|
||||
addPanel = new FlowPanel();
|
||||
addMember = new Button(Util.C.buttonAddGroupMember());
|
||||
nameTxtBox = new NpTextBox();
|
||||
nameTxtBox = new HintTextBox();
|
||||
nameTxt = new SuggestBox(new AccountSuggestOracle(), nameTxtBox);
|
||||
|
||||
nameTxtBox.setVisibleLength(50);
|
||||
nameTxtBox.setText(Util.C.defaultAccountName());
|
||||
nameTxtBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
nameTxtBox.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(final FocusEvent event) {
|
||||
if (Util.C.defaultAccountName().equals(nameTxtBox.getText())) {
|
||||
nameTxtBox.setText("");
|
||||
nameTxtBox.removeStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameTxtBox.addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(final BlurEvent event) {
|
||||
if ("".equals(nameTxtBox.getText())) {
|
||||
nameTxtBox.setText(Util.C.defaultAccountName());
|
||||
nameTxtBox.addStyleName(Gerrit.RESOURCES.css().inputFieldTypeHint());
|
||||
}
|
||||
}
|
||||
});
|
||||
nameTxtBox.setHintText(Util.C.defaultAccountName());
|
||||
nameTxtBox.addKeyPressHandler(new KeyPressHandler() {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
@@ -108,10 +85,7 @@ public class AddMemberBox extends Composite {
|
||||
|
||||
public String getText() {
|
||||
String s = nameTxtBox.getText();
|
||||
if (s == null || s.equals(Util.C.defaultAccountName())) {
|
||||
s = "";
|
||||
}
|
||||
return s;
|
||||
return s == null ? "" : s;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.ui;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gwt.event.dom.client.BlurEvent;
|
||||
import com.google.gwt.event.dom.client.BlurHandler;
|
||||
import com.google.gwt.event.dom.client.FocusEvent;
|
||||
import com.google.gwt.event.dom.client.FocusHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
|
||||
public class HintTextBox extends NpTextBox {
|
||||
private String hintText;
|
||||
private String hintStyleName = Gerrit.RESOURCES.css().inputFieldTypeHint();
|
||||
private boolean hintOn;
|
||||
private HandlerRegistration hintFocusHandler;
|
||||
private HandlerRegistration hintBlurHandler;
|
||||
|
||||
public String getText() {
|
||||
if (hintOn) {
|
||||
return "";
|
||||
}
|
||||
return super.getText();
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
focusHint();
|
||||
super.setText(text);
|
||||
blurHint();
|
||||
}
|
||||
|
||||
public String getHintText() {
|
||||
return hintText;
|
||||
}
|
||||
|
||||
public void setHintText(String text) {
|
||||
if (text == null) {
|
||||
|
||||
// Clearing Hints
|
||||
|
||||
if (hintText != null) { // was set
|
||||
hintFocusHandler.removeHandler();
|
||||
hintFocusHandler = null;
|
||||
hintBlurHandler.removeHandler();
|
||||
hintBlurHandler = null;
|
||||
hintText = null;
|
||||
focusHint();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Setting Hints
|
||||
|
||||
if (hintText == null) { // first time (was not already set)
|
||||
hintText = text;
|
||||
|
||||
hintFocusHandler = addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
focusHint();
|
||||
}
|
||||
});
|
||||
|
||||
hintBlurHandler = addBlurHandler(new BlurHandler() {
|
||||
@Override
|
||||
public void onBlur(BlurEvent event) {
|
||||
blurHint();
|
||||
}
|
||||
});
|
||||
|
||||
blurHint();
|
||||
return;
|
||||
}
|
||||
|
||||
// Changing Hint
|
||||
|
||||
hintText = text;
|
||||
if (hintOn) {
|
||||
super.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHintStyleName(String styleName) {
|
||||
if (hintStyleName != null && hintOn) {
|
||||
removeStyleName(hintStyleName);
|
||||
}
|
||||
|
||||
hintStyleName = styleName;
|
||||
|
||||
if (styleName != null && hintOn) {
|
||||
addStyleName(styleName);
|
||||
}
|
||||
}
|
||||
|
||||
public String getHintStyleName() {
|
||||
return hintStyleName;
|
||||
}
|
||||
|
||||
protected void blurHint() {
|
||||
if (! hintOn && getHintText() != null && "".equals(super.getText())) {
|
||||
super.setText(getHintText());
|
||||
hintOn = true;
|
||||
if (getHintStyleName() != null) {
|
||||
addStyleName(getHintStyleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void focusHint() {
|
||||
if (hintOn) {
|
||||
super.setText("");
|
||||
hintOn = false;
|
||||
if (getHintStyleName() != null) {
|
||||
removeStyleName(getHintStyleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user