private boolean isThereABoundVariableToSet() { boolean retour = false; List<String> vars = this.scenario.getFactNamesInScope(executionTrace, true); if (vars.size() > 0) { for (int i = 0; i < vars.size(); i++) { String var = (String) vars.get(i); FactData f = (FactData) scenario.getFactTypes().get(var); String fieldType = sce.getFieldType(this.factType, field.getFieldName()); if (f.getType().equals(fieldType)) { retour = true; break; } } } return retour; }
private Widget variableEditor() { List<String> vars = this.scenario.getFactNamesInScope(this.executionTrace, true); final ListBox box = new ListBox(); if (this.field.getExpected() == null) { box.addItem(constants.Choose()); } int j = 0; for (int i = 0; i < vars.size(); i++) { String var = vars.get(i); FactData f = (FactData) scenario.getFactTypes().get(var); String fieldType = sce.getFieldType(this.factType, field.getFieldName()); if (f.getType().equals(fieldType)) { if (box.getItemCount() == 0) { box.addItem("..."); j++; } box.addItem("=" + var); if (this.field.getExpected() != null && this.field.getExpected().equals("=" + var)) { box.setSelectedIndex(j); } j++; } } box.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { field.setExpected(box.getItemText(box.getSelectedIndex())); } }); return box; }
private void refreshEditor() { String key = factType + "." + field.getFieldName(); String flType = sce.getFieldType(key); panel.clear(); if (flType != null && flType.equals(SuggestionCompletionEngine.TYPE_NUMERIC)) { final TextBox box = editableTextBox(callback, field.getFieldName(), field.getExpected()); box.addKeyPressHandler(new NumbericFilterKeyPressHandler(box)); panel.add(box); } else if (flType != null && flType.equals(SuggestionCompletionEngine.TYPE_BOOLEAN)) { String[] c = new String[] {"true", "false"}; panel.add( new EnumDropDown( field.getExpected(), new DropDownValueChanged() { public void valueChanged(String newText, String newValue) { callback.valueChanged(newValue); } }, DropDownData.create(c))); } else if (flType != null && flType.equals(SuggestionCompletionEngine.TYPE_DATE)) { final DatePickerTextBox datePicker = new DatePickerTextBox(field.getExpected()); String m = ((Constants) GWT.create(Constants.class)).ValueFor0(field.getFieldName()); datePicker.setTitle(m); datePicker.addValueChanged( new ValueChanged() { public void valueChanged(String newValue) { field.setExpected(newValue); } }); panel.add(datePicker); } else { String[] enums = sce.getDataEnumList(key); if (enums != null) { // GUVNOR-1324: Java enums are of type TYPE_COMPARABLE whereas Guvnor enums are not. // The distinction here controls whether the EXPECTED value is handled as a true // Java enum or a literal with a selection list (i.e. Guvnor enum) String dataType = sce.getFieldType(key); if (dataType.equals(SuggestionCompletionEngine.TYPE_COMPARABLE)) { field.setNature(FieldData.TYPE_ENUM); } else { field.setNature(FieldData.TYPE_LITERAL); } panel.add( new EnumDropDown( field.getExpected(), new DropDownValueChanged() { public void valueChanged(String newText, String newValue) { callback.valueChanged(newValue); } }, DropDownData.create(enums))); } else { if (field.getExpected() != null && field.getExpected().length() > 0 && field.getNature() == FieldData.TYPE_UNDEFINED) { if (field.getExpected().charAt(0) == '=') { field.setNature(FieldData.TYPE_VARIABLE); } else { field.setNature(FieldData.TYPE_LITERAL); } } if (field.getNature() == FieldData.TYPE_UNDEFINED && isThereABoundVariableToSet() == true) { Image clickme = new Image(images.edit()); clickme.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { showTypeChoice((Widget) event.getSource(), field); } }); panel.add(clickme); } else if (field.getNature() == FieldData.TYPE_VARIABLE) { panel.add(variableEditor()); } else { panel.add(editableTextBox(callback, field.getFieldName(), field.getExpected())); } } } }