List of usage examples for org.apache.wicket.extensions.ajax.markup.html.autocomplete AutoCompleteTextField AutoCompleteTextField
@SuppressWarnings("unchecked") public AutoCompleteTextField(final String id, final IModel<T> model, final Class<T> type, final AutoCompleteSettings settings)
From source file:com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteItemDefinitionPanel.java
License:Apache License
private void initLayout(final IModel<ItemDefinition<?>> model) { final Model<String> itemDefinitionAsStringModel = new Model<>(null); AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, itemDefinitionAsStringModel, String.class, createAutoCompleteSettings()) { private static final long serialVersionUID = 1L; @Override//from w w w . jav a 2 s. co m protected Iterator<String> getChoices(String input) { List<String> defsAsString = new ArrayList<>(); for (ItemDefinition<?> def : listChoices(input).values()) { defsAsString.add(def.getName().getLocalPart()); } return defsAsString.iterator(); } @Override protected void onConfigure() { super.onConfigure(); itemDefinitionAsStringModel.setObject(null); } }; input.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { String newValue = itemDefinitionAsStringModel.getObject(); if (StringUtils.isNotBlank(newValue)) { ItemDefinition<?> def = listChoices("").get(newValue); if (def != null) { model.setObject(def); } } } }); add(input); }
From source file:com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel.java
License:Apache License
private void initLayout(final IModel<QName> model) { setOutputMarkupId(true);/*from w ww. j a v a 2 s .c om*/ AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings(); final IModel<String> stringModel = new Model<String>() { @Override public void setObject(String object) { super.setObject(object); model.setObject(convertToQname(object)); } }; // The inner autocomplete field is always String. Non-string auto-complete fields are problematic final AutoCompleteTextField<String> input = new AutoCompleteTextField<String>(ID_INPUT, stringModel, String.class, autoCompleteSettings) { private static final long serialVersionUID = 1L; @Override protected Iterator<String> getChoices(String input) { return getIterator(input); } }; input.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { String inputString = stringModel.getObject(); if (StringUtils.isBlank(inputString)) { QName modelObject = model.getObject(); if (modelObject != null) { model.setObject(null); AutoCompleteQNamePanel.this.onChange(target); } } else { QName inputQName = convertToQname(stringModel.getObject()); if (inputQName == null) { // We have some input, but it does not match any QName. Just do nothing. } else { QName modelObject = model.getObject(); if (inputQName.equals(modelObject)) { model.setObject(inputQName); AutoCompleteQNamePanel.this.onChange(target); } } } } }); add(input); }
From source file:com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel.java
License:Apache License
public AutoCompleteTextPanel(String id, final IModel<T> model, Class<T> type) { super(id);/* w w w . ja va 2 s . co m*/ AutoCompleteSettings autoCompleteSettings = createAutoCompleteSettings(); // this has to be copied because the AutoCompleteTextField dies if renderer=null final AutoCompleteTextField<T> input = new AutoCompleteTextField<T>(ID_INPUT, model, type, autoCompleteSettings) { private static final long serialVersionUID = 1L; @Override protected Iterator<T> getChoices(String input) { return getIterator(input); } }; input.setType(type); if (model instanceof LookupPropertyModel) { input.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { checkInputValue(input, target, (LookupPropertyModel<T>) model); } }); } add(input); }
From source file:org.dcm4chee.web.war.tc.keywords.TCKeywordListInput.java
License:LGPL
public TCKeywordListInput(final String id, TCQueryFilterKey filterKey, boolean usedForSearch, final boolean exclusive, List<TCKeyword> selectedKeywords, final List<TCKeyword> keywords) { super(id, filterKey, usedForSearch, exclusive); if (keywords != null && !keywords.isEmpty()) { keywordMap = new HashMap<String, TCKeyword>(keywords.size()); for (TCKeyword keyword : keywords) { keywordMap.put(keyword.toString(), keyword); }/*from w w w .ja v a 2 s .c om*/ } setDefaultModel( new ListModel<TCKeyword>(selectedKeywords != null ? new ArrayList<TCKeyword>(selectedKeywords) : new ArrayList<TCKeyword>()) { private static final long serialVersionUID = 1L; @Override public void setObject(List<TCKeyword> keywords) { List<TCKeyword> cur = getObject(); if (!TCUtilities.equals(cur, keywords)) { super.setObject(keywords); fireValueChanged(); } } }); final MultipleKeywordsTextModel textModel = new MultipleKeywordsTextModel(selectedKeywords); text = new AutoCompleteTextField<String>("text", textModel, String.class, new AutoCompleteSettings()) { private static final long serialVersionUID = 1L; @Override protected Iterator<String> getChoices(String s) { List<String> match = new ArrayList<String>(); if (s.length() >= 3) { String ks = null; for (TCKeyword keyword : keywords) { ks = keyword.toString(); if (ks.toUpperCase().contains(s.toUpperCase())) { match.add(ks); } } } return match.iterator(); } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); if (exclusive) { tag.put("readonly", "readonly"); } else { tag.put("onmouseover", "$(this).addClass('ui-input-hover')"); tag.put("onmouseout", "$(this).removeClass('ui-input-hover')"); tag.put("onfocus", "$(this).addClass('ui-input-focus')"); tag.put("onblur", "$(this).removeClass('ui-input-focus')"); } } }; text.setOutputMarkupId(true); text.add(new AttributeAppender("class", true, new Model<String>(exclusive ? "ui-input-readonly" : "ui-input"), " ")); text.add(new AutoSelectInputTextBehaviour()); text.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; @Override public void onUpdate(AjaxRequestTarget target) { text.updateModel(); getModel().setObject(textModel.getKeywordItems()); } }); trigger = new WebMarkupContainer("chooser-button", new Model<String>("...")) { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("onmouseover", "$(this).addClass('ui-state-hover')"); tag.put("onmouseout", "$(this).removeClass('ui-state-hover')"); } }; popup = new KeywordListPopup(keywords); add(text); add(popup); add(trigger); }
From source file:org.dcm4chee.web.war.tc.keywords.TCKeywordTreeInput.java
License:LGPL
public TCKeywordTreeInput(final String id, TCQueryFilterKey filterKey, boolean usedForSearch, final boolean exclusive, List<TCKeyword> selectedKeywords, final TCKeywordNode root) { super(id, filterKey, usedForSearch, exclusive); setDefaultModel(new ListModel<TCKeyword>(selectedKeywords) { private static final long serialVersionUID = 1L; @Override/*from w w w . ja va 2 s . c om*/ public void setObject(List<TCKeyword> keywords) { List<TCKeyword> cur = getObject(); if (!TCUtilities.equals(cur, keywords)) { super.setObject(keywords); fireValueChanged(); } } }); this.root = root; final MultipleKeywordsTextModel textModel = new MultipleKeywordsTextModel(selectedKeywords); this.text = new AutoCompleteTextField<String>("text", textModel, String.class, new AutoCompleteSettings()) { private static final long serialVersionUID = 1L; @Override protected Iterator<String> getChoices(String s) { LinkedHashMap<String, TCKeyword> keywords = new LinkedHashMap<String, TCKeyword>(); findMatchingKeywords(root, s, keywords); return keywords.keySet().iterator(); } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); if (exclusive) { tag.put("readonly", "readonly"); } else { tag.put("onmouseover", "$(this).addClass('ui-input-hover')"); tag.put("onmouseout", "$(this).removeClass('ui-input-hover')"); tag.put("onfocus", "$(this).addClass('ui-input-focus')"); tag.put("onblur", "$(this).removeClass('ui-input-focus')"); } } }; text.setOutputMarkupId(true); text.add(new AttributeAppender("class", true, new Model<String>(exclusive ? "ui-input-readonly" : "ui-input"), " ")); text.add(new AutoSelectInputTextBehaviour()); text.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; @Override public void onUpdate(AjaxRequestTarget target) { text.updateModel(); getModel().setObject(textModel.getKeywordItems()); } }); popup = new KeywordTreePopup(); trigger = new WebMarkupContainer("chooser-button", new Model<String>("...")) { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("onmouseover", "$(this).addClass('ui-state-hover')"); tag.put("onmouseout", "$(this).removeClass('ui-state-hover')"); } }; // chooserBtn.add(new Image("chooser-button-img", ImageManager.IMAGE_TC_ARROW_DOWN) // .setOutputMarkupId(true)); final Tree tree = new Tree("keyword-tree", new DefaultTreeModel(root)) { private static final long serialVersionUID = 1L; @Override protected void populateTreeItem(WebMarkupContainer item, int level) { super.populateTreeItem(item, level); //(WEB-429) workaround: disable browser-native drag and drop item.add(new AttributeModifier("onmousedown", true, new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return "return false;"; } })); } @Override public void onNodeLinkClicked(AjaxRequestTarget target, TreeNode node) { if (isMultipleKeywordSearchEnabled()) { boolean selected = getTreeState().isNodeSelected(node); if (selected) { popup.addSelectedNode((TCKeywordNode) node); } else { popup.removeSelectedNode((TCKeywordNode) node); } } else { popup.setSelectedNodes((TCKeywordNode) node); popup.hide(target); } } }; tree.setOutputMarkupId(true); tree.setRootLess(true); tree.setLinkType(LinkType.AJAX); tree.getTreeState().setAllowSelectMultiple(isMultipleKeywordSearchEnabled()); popup.setTree(root, tree); popup.add(tree); add(text); add(trigger); add(popup); }