Last active
April 12, 2016 01:00
-
-
Save kevzlou7979/dfb18c003513311345e53af7253b1e39 to your computer and use it in GitHub Desktop.
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 gwt.material.design.demo.client.application.addins.autocomplete.base; | |
import java.io.Serializable; | |
public class User implements Serializable { | |
public enum Position { | |
CEO("CEO"), | |
CTO("CTO"), | |
DEVELOPER("Developer"), | |
MARKETING("Marketing"); | |
private final String value; | |
Position(String value) { | |
this.value = value; | |
} | |
public String getValue() { | |
return value; | |
} | |
} | |
private String picture; | |
private String name; | |
private String email; | |
private String password; | |
private String address; | |
private String contactNo; | |
private String company; | |
private boolean starred; | |
private Position position; | |
public User() {} | |
public User(String picture, Position position, boolean starred, String name, String email, String password, String contactNo, String address, String company) { | |
this.picture = picture; | |
this.position = position; | |
this.starred = starred; | |
this.name = name; | |
this.email = email; | |
this.password = password; | |
this.contactNo = contactNo; | |
this.address = address; | |
this.company = company; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getEmail() { | |
return email; | |
} | |
public void setEmail(String email) { | |
this.email = email; | |
} | |
public String getPassword() { | |
return password; | |
} | |
public void setPassword(String password) { | |
this.password = password; | |
} | |
public String getAddress() { | |
return address; | |
} | |
public void setAddress(String address) { | |
this.address = address; | |
} | |
public String getCompany() { | |
return company; | |
} | |
public void setCompany(String company) { | |
this.company = company; | |
} | |
public String getContactNo() { | |
return contactNo; | |
} | |
public void setContactNo(String contactNo) { | |
this.contactNo = contactNo; | |
} | |
public boolean isStarred() { | |
return starred; | |
} | |
public void setStarred(boolean starred) { | |
this.starred = starred; | |
} | |
public String getPicture() { | |
return picture; | |
} | |
public void setPicture(String picture) { | |
this.picture = picture; | |
} | |
public Position getPosition() { | |
return position; | |
} | |
public void setPosition(Position position) { | |
this.position = position; | |
} | |
} |
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 gwt.material.design.demo.client.application.addins.autocomplete.base; | |
import gwt.material.design.addins.client.autocomplete.base.MaterialSuggestionOracle; | |
import java.util.ArrayList; | |
import java.util.LinkedList; | |
import java.util.List; | |
public class UserOracle extends MaterialSuggestionOracle{ | |
private List<User> contacts = new LinkedList<>(); | |
public void addContacts(List<User> users) { | |
contacts.addAll(users); | |
} | |
@Override | |
public void requestSuggestions(Request request, Callback callback) { | |
Response resp = new Response(); | |
if(contacts.isEmpty()){ | |
callback.onSuggestionsReady(request, resp); | |
return; | |
} | |
String text = request.getQuery(); | |
text = text.toLowerCase(); | |
List<UserSuggestion> list = new ArrayList<>(); | |
for(User contact : contacts){ | |
if(contact.getName().toLowerCase().contains(text)){ | |
list.add(new UserSuggestion(contact)); | |
} | |
} | |
resp.setSuggestions(list); | |
callback.onSuggestionsReady(request, resp); | |
} | |
} |
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 gwt.material.design.demo.client.application.addins.autocomplete.base; | |
import com.google.gwt.user.client.ui.SuggestOracle; | |
public class UserSuggestion implements SuggestOracle.Suggestion { | |
private User user; | |
public UserSuggestion(User user) { | |
this.user = user; | |
} | |
@Override | |
public String getDisplayString() { | |
return getReplacementString(); | |
} | |
@Override | |
public String getReplacementString() { | |
return user.getName(); | |
} | |
public User getUser() { | |
return user; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment