001package gwt.material.design.addins.client.autocomplete.base; 002 003/* 004 * #%L 005 * GwtMaterial 006 * %% 007 * Copyright (C) 2015 GwtMaterialDesign 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import com.google.gwt.user.client.ui.Image; 024import com.google.gwt.user.client.ui.MultiWordSuggestOracle; 025 026public class MaterialSuggestionOracle extends MultiWordSuggestOracle { 027 028 public MaterialSuggestionOracle() { 029 } 030 031 private String imageElem = ""; 032 033 @Override 034 public boolean isDisplayStringHTML() { 035 return super.isDisplayStringHTML(); 036 } 037 038 /** 039 * Autocomplete with Image item selection. 040 */ 041 public void add(String text, Image image){ 042 this.imageElem = image.getElement().toString(); 043 add(text + image); 044 } 045 046 /* (non-Javadoc) 047 * @see com.google.gwt.user.client.ui.MultiWordSuggestOracle#add(java.lang.String) 048 */ 049 @Override 050 public void add(String suggestion) { 051 super.add(suggestion); 052 } 053 054 @Override 055 protected MultiWordSuggestion createSuggestion(String display, String suggestion) { 056 suggestion = display.replace(imageElem, ""); 057 return new gwt.material.design.client.base.Suggestion(display, suggestion); 058 } 059 060 /** 061 * @return the imageElem 062 */ 063 public String getImageElem() { 064 return imageElem; 065 } 066 067 /** 068 * @param imageElem the imageElem to set 069 */ 070 public void setImageElem(String imageElem) { 071 this.imageElem = imageElem; 072 } 073}