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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user