Created
September 28, 2018 20:23
-
-
Save branflake2267/9416f58928a7331155cff0e3eb7d1525 to your computer and use it in GitHub Desktop.
GXT combo example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sencha.gxt.test.client.combo; | |
import com.google.gwt.core.client.EntryPoint; | |
import com.google.gwt.core.shared.GWT; | |
import com.google.gwt.event.logical.shared.ValueChangeEvent; | |
import com.google.gwt.event.logical.shared.ValueChangeHandler; | |
import com.google.gwt.safehtml.shared.SafeHtmlUtils; | |
import com.google.gwt.user.client.ui.RootPanel; | |
import com.google.gwt.user.client.ui.Widget; | |
import com.sencha.gxt.cell.core.client.form.ComboBoxCell; | |
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; | |
import com.sencha.gxt.core.client.Style.Side; | |
import com.sencha.gxt.data.shared.LabelProvider; | |
import com.sencha.gxt.data.shared.ListStore; | |
import com.sencha.gxt.data.shared.ModelKeyProvider; | |
import com.sencha.gxt.widget.core.client.WidgetComponent; | |
import com.sencha.gxt.widget.core.client.container.MarginData; | |
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; | |
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; | |
import com.sencha.gxt.widget.core.client.container.Viewport; | |
import com.sencha.gxt.widget.core.client.event.InvalidEvent; | |
import com.sencha.gxt.widget.core.client.event.InvalidEvent.InvalidHandler; | |
import com.sencha.gxt.widget.core.client.form.ComboBox; | |
import com.sencha.gxt.widget.core.client.form.error.SideErrorHandler; | |
import com.sencha.gxt.widget.core.client.tips.ToolTip; | |
import com.sencha.gxt.widget.core.client.tips.ToolTipConfig; | |
public class ComboboxExample implements EntryPoint { | |
public class SideErrorHandlerExt extends SideErrorHandler { | |
public SideErrorHandlerExt(Widget target) { | |
super(target); | |
} | |
public ToolTip getTip() { | |
return tip; | |
} | |
public WidgetComponent getIcon() { | |
return errorIcon; | |
} | |
} | |
@Override | |
public void onModuleLoad() { | |
VerticalLayoutContainer vlc = new VerticalLayoutContainer(); | |
vlc.add(createCombo(), new VerticalLayoutData(-1, -1)); | |
Viewport vp = new Viewport(); | |
vp.add(vlc, new MarginData(50)); | |
RootPanel.get().add(vp); | |
} | |
private ComboBox<Company> createCombo() { | |
ListStore<Company> store = new ListStore<Company>(new ModelKeyProvider<Company>() { | |
@Override | |
public String getKey(Company item) { | |
return item.getId().toString(); | |
} | |
}); | |
store.add(new Company("0", "Company 11")); | |
store.add(new Company("1", "Company 22")); | |
store.add(new Company("2", "Company 33")); | |
store.add(new Company("3", "Company 44")); | |
store.add(new Company("4", "Company 55")); | |
LabelProvider<Company> labelProvider = new LabelProvider<Company>() { | |
@Override | |
public String getLabel(Company item) { | |
if (item.getName() == null) { | |
return ""; | |
} | |
return item.getName(); | |
} | |
}; | |
ComboBoxCell<Company> cell = new ComboBoxCell<Company>(store, labelProvider); | |
final ComboBox<Company> combo = new ComboBox<Company>(cell); | |
//combo.setErrorSupport(null); | |
combo.setTriggerAction(TriggerAction.ALL); | |
combo.setValidateOnBlur(false); | |
combo.setClearValueOnParseError(false); | |
combo.addValueChangeHandler(new ValueChangeHandler<Company>(){ | |
@Override | |
public void onValueChange(ValueChangeEvent<Company> event) { | |
// TODO Auto-generated method stub | |
if (event.getValue() != null){ | |
GWT.log("validate " + event.getValue().getName()); | |
} else { | |
GWT.log("validate value null"); | |
} | |
if (event.getValue() != null && event.getValue().getName().contains("11")) { | |
combo.markInvalid("Invalid Option"); | |
} else { | |
combo.setAllowBlank(true); | |
combo.clearInvalid(); | |
combo.isValid(); | |
combo.removeToolTip(); | |
} | |
} | |
}); | |
combo.addInvalidHandler(new InvalidHandler() { | |
@Override | |
public void onInvalid(InvalidEvent event) { | |
ToolTipConfig config = new ToolTipConfig(); | |
config.setTitle(""); | |
config.setBody(SafeHtmlUtils.fromTrustedString("<span style=\"color:red;\">" + "Invalid Option 111111111 22222222 3333333333 44444444" +"</span>")); | |
config.setMouseOffsetX(0); | |
config.setMouseOffsetY(0); | |
config.setAnchor(Side.BOTTOM); | |
config.setMaxWidth(100); | |
config.setMinWidth(20); | |
config.setShowDelay(0); | |
combo.setToolTipConfig(config); | |
} | |
}); | |
return combo; | |
} | |
public class Company { | |
private String id; | |
private String name; | |
public Company(String id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
public String getId() { | |
return id; | |
} | |
public String getName() { | |
return name; | |
} | |
@Override | |
public String toString() { | |
return name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment