List of usage examples for com.google.gwt.user.client.ui SuggestBox setTabIndex
public void setTabIndex(int index)
From source file:org.openxdata.sharedlib.client.widget.RuntimeWidgetWrapper.java
/** * Loads values for the widget.//from ww w . java2 s. c om */ public void loadQuestion() { if (questionDef == null) return; //questionDef.clearChangeListeners(); Removed from here because we want to allow more that one widget listen on the same question. questionDef.addChangeListener(this); questionDef.setAnswer(questionDef.getDefaultValueSubmit()); String defaultValue = questionDef.getDefaultValue(); QuestionType type = questionDef.getDataType(); if ((type == QuestionType.LIST_EXCLUSIVE || type == QuestionType.LIST_EXCLUSIVE_DYNAMIC || type == QuestionType.LIST_MULTIPLE) && widget instanceof ListBox) { List<OptionDef> options = questionDef.getOptions(); int defaultValueIndex = 0; ListBox listBox = (ListBox) widget; listBox.clear(); //Could be called more than once. listBox.addItem("", ""); if (options != null) { for (int index = 0; index < options.size(); index++) { OptionDef optionDef = (OptionDef) options.get(index); listBox.addItem(optionDef.getText(), optionDef.getVariableName()); if (optionDef.getVariableName().equalsIgnoreCase(defaultValue)) defaultValueIndex = index + 1; } } listBox.setSelectedIndex(defaultValueIndex); } else if ((type == QuestionType.LIST_EXCLUSIVE || type == QuestionType.LIST_EXCLUSIVE_DYNAMIC) && widget instanceof TextBox) { MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); FormUtil.loadOptions(questionDef.getOptions(), oracle); if (widget.getParent() != null) { RuntimeWidgetWrapper copyWidget = new RuntimeWidgetWrapper(this); panel.remove(widget.getParent()); panel.remove(widget); copyWidgetProperties(copyWidget); setWidth(getWidth()); setHeight(getHeight()); } SuggestBox sgstBox = new SuggestBox(oracle, (TextBox) widget); panel.add(sgstBox); sgstBox.setTabIndex(((TextBox) widget).getTabIndex()); setupTextBoxEventListeners(); } else if (type == QuestionType.BOOLEAN && widget instanceof ListBox) { ListBox listBox = (ListBox) widget; listBox.addItem("", ""); listBox.addItem(constants.displayValueTrue(), QuestionDef.TRUE_VALUE); listBox.addItem(constants.displayValueFalse(), QuestionDef.FALSE_VALUE); listBox.setSelectedIndex(0); if (defaultValue != null) { if (defaultValue.equalsIgnoreCase(QuestionDef.TRUE_VALUE)) listBox.setSelectedIndex(1); else if (defaultValue.equalsIgnoreCase(QuestionDef.FALSE_VALUE)) listBox.setSelectedIndex(2); } } else if (type == QuestionType.LIST_MULTIPLE && defaultValue != null && defaultValue.trim().length() > 0 && binding != null && binding.trim().length() > 0 && widget instanceof CheckBox) { if (defaultValue.contains(binding)) ((CheckBox) widget).setValue(true); } else if (type == QuestionType.DATE_TIME && widget instanceof DateTimeWidget) { if (defaultValue != null && defaultValue.trim().length() > 0 && questionDef.isDate()) { if (QuestionDef.isDateFunction(defaultValue)) defaultValue = questionDef.getDefaultValueDisplay(); else defaultValue = fromSubmit2DisplayDate(defaultValue); ((DateTimeWidget) widget).setText(defaultValue); } } if (widget instanceof TextBoxBase) { ((TextBoxBase) widget).setText(""); //first init just incase we have default value if (defaultValue != null && defaultValue.trim().length() > 0) { if (type == QuestionType.LIST_EXCLUSIVE) { OptionDef optionDef = questionDef.getOptionWithValue(defaultValue); if (optionDef != null) ((TextBox) widget).setText(optionDef.getText()); } else { if (defaultValue.trim().length() > 0 && questionDef.isDate() && QuestionDef.isDateFunction(defaultValue)) defaultValue = questionDef.getDefaultValueDisplay(); else if (defaultValue.trim().length() > 0 && questionDef.isDate()) defaultValue = fromSubmit2DisplayDate(defaultValue); ((TextBoxBase) widget).setText(defaultValue); setExternalSourceDisplayValue(); } } } if (questionDef.getDataType() == QuestionType.REPEAT) questionDef.setAnswer("0"); if (!questionDef.isEnabled()) setEnabled(false); if (!questionDef.isVisible()) setVisible(false); if (questionDef.isLocked()) setLocked(true); }