private DSLVariableValue visitDSLVariableValue( DSLVariableValue value ) { DSLVariableValue clone = new DSLVariableValue(); clone.setValue( value.getValue() ); return clone; }
public void setValue( DSLVariableValue value ) { this.oldVariableValue = value; box.setText( value.getValue() ); }
public DSLVariableValue getSelectedValue() { int selectedIndex = resultWidget.getSelectedIndex(); if ( selectedIndex != -1 ) { return new DSLVariableValue( resultWidget.getValue( selectedIndex ) ); } else { return new DSLVariableValue( "" ); } }
private DSLSentence toDSLSentence( List<String> dslPatterns, String dslLine ) { DSLSentence dslSentence = new DSLSentence(); for ( String dslPattern : dslPatterns ) { String regex = dslPattern.replaceAll( "\\{\\s*[\\:\\.\\w]+\\s*\\}", "(.*)" ); Matcher m = Pattern.compile( regex ).matcher( dslLine ); if ( m.matches() ) { dslSentence.setDefinition( dslPattern ); for ( int i = 0; i < m.groupCount(); i++ ) { dslSentence.getValues().get( i ).setValue( m.group( i + 1 ) ); } return dslSentence; } } dslSentence.setDefinition( dslLine ); return dslSentence; }
/** * This will strip off any "{" stuff, substituting values accordingly */ public String interpolate() { getValues(); if ( definition == null ) { return ""; } int variableStart = definition.indexOf( "{" ); if ( variableStart < 0 ) { return definition; } int index = 0; int variableEnd = 0; StringBuilder sb = new StringBuilder(); while ( variableStart >= 0 ) { sb.append( definition.substring( variableEnd, variableStart ) ); variableEnd = getIndexForEndOfVariable( definition, variableStart ) + 1; variableStart = definition.indexOf( "{", variableEnd ); sb.append( values.get( index++ ).getValue() ); } if ( variableEnd < definition.length() ) { sb.append( definition.substring( variableEnd ) ); } return sb.toString(); }
public void valueChanged( String newText, String newValue ) { makeDirty(); selectedValue = new DSLVariableValue( newValue ); //When the value changes we need to reset the content of *ALL* DSLSentenceWidget drop-downs. //An improvement would be to determine the chain of dependent drop-downs and only update //children of the one whose value changes. However in reality DSLSentences only contain //a couple of drop-downs so it's quicker to simply update them all. updateEnumDropDowns(); } };
@Test public void testDSLExpansionLHS() { final String dslDefinition = "The credit rating is {rating:ENUM:Applicant.creditRating}"; final String drlExpected = "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "The credit rating is AA\n" + "then\n" + "end"; final DSLSentence dsl = new DSLSentence(); dsl.setDefinition( dslDefinition ); //The following line is normally performed by the UI when the user sets values dsl.getValues().get( 0 ).setValue( "AA" ); //Append DSL to RuleModel to check marshalling final RuleModel m = new RuleModel(); m.name = "r1"; m.addLhsItem( dsl ); final String drlActual = brlPersistence.marshal( m ); assertEqualsIgnoreWhitespace( drlExpected, drlActual ); }
public void refreshDropDownData() { resultWidget.setDropDownData( selectedValue.getValue(), getDropDownData() ); }
public DSLVariableValue getSelectedValue() { String value = this.resultWidget.getSelectedIndex() == 0 ? "true" : "false"; return new DSLVariableValue( value ); } }
factAndField.length() ); fieldValueMap.put( field, values.get( iVariable ).getValue() );
public DSLVariableValue getSelectedValue() { return new DSLVariableValue( resultWidget.getDateString() ); } }
public Widget getBox( DSLVariableValue variableDef, String regex, boolean readonly ) { FieldEditor currentBox = new FieldEditor(); currentBox.setVisibleLength( variableDef.getValue().length() + 1 ); currentBox.setValue( variableDef ); currentBox.setRestriction( regex ); currentBox.box.setEnabled( !readonly ); return currentBox; }
private DSLVariableValue parseValue( String variable ) { //if the variable doesn't have a ':', then it is considered as a //simple value if ( !variable.contains( ":" ) ) { return new DSLVariableValue( variable ); } //if it does containt a ':', then the part before it is considered //as the real value (used to create the final drl) and the part //after it is considered as an id String value = variable.substring( 0, variable.indexOf( ":" ) ); String id = variable.substring( variable.indexOf( ":" ) + 1 ); return new DSLComplexVariableValue( id, value ); }
resultWidget = new EnumDropDown( value.getValue(), handler, dropDownData );
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) protected void addCurrentElementToCollection( HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection, Collection target ) { Object item = readItem( reader, context, collection ); if ( item instanceof DSLVariableValue) { target.add( item ); } else if ( item instanceof String ) { //The only other possible legacy type is a String, so using toString() should be OK DSLVariableValue value = new DSLVariableValue( item.toString() ); target.add( value ); } }
public DSLDateSelector( DSLVariableValue selectedDate, String dateFormat ) { resultWidget = new DatePickerLabel( selectedDate.getValue(), dateFormat ); resultWidget.addValueChanged( new ValueChanged() { public void valueChanged( String newValue ) { updateSentence(); makeDirty(); } } ); //Wrap widget within a HorizontalPanel to add a space before and after the Widget HorizontalPanel hp = new HorizontalPanel(); hp.add( new HTML( " " ) ); hp.add( resultWidget ); hp.add( new HTML( " " ) ); initWidget( hp ); }
public DSLVariableValue getSelectedValue() { //if oldVariableValue was of type DSLComplexVariableValue, then return a //copy of it with only the 'value' part modified if ( oldVariableValue instanceof DSLComplexVariableValue) { return new DSLComplexVariableValue( ( (DSLComplexVariableValue) oldVariableValue ).getId(), box.getText() ); } return new DSLVariableValue( box.getText() ); }
public void onClick( ClickEvent event ) { final CustomFormPopUp customFormPopUp = new CustomFormPopUp( GuidedRuleEditorImages508.INSTANCE.Wizard(), Constants.INSTANCE.FieldValue(), DSLCustomFormButton.this.customFormConfiguration ); customFormPopUp.addOkButtonHandler( new ClickHandler() { public void onClick( ClickEvent event ) { String id = customFormPopUp.getFormId(); String value = customFormPopUp.getFormValue(); btnCustomForm.setText( value ); selectedValue = new DSLComplexVariableValue( id, value ); updateSentence(); makeDirty(); customFormPopUp.hide(); } } ); //if selectedValue is an instance of DSLComplexVariableValue, //then both id and value are passed to the custom form //if not, only the value is passed and "" is passed as id if ( selectedValue instanceof DSLComplexVariableValue ) { DSLComplexVariableValue complexSelectedValue = (DSLComplexVariableValue) selectedValue; customFormPopUp.show( complexSelectedValue.getId(), complexSelectedValue.getValue() ); } else { customFormPopUp.show( "", selectedValue.getValue() ); } } } );
public DSLCheckBox( String variableDef, DSLVariableValue value ) { resultWidget = new ListBox(); resultWidget.addItem( "true" ); resultWidget.addItem( "false" ); if ( value.getValue().equalsIgnoreCase( "true" ) ) { resultWidget.setSelectedIndex( 0 ); } else { resultWidget.setSelectedIndex( 1 ); } resultWidget.addChangeHandler( new ChangeHandler() { public void onChange( ChangeEvent event ) { updateSentence(); makeDirty(); } } ); resultWidget.setVisible( true ); //Wrap widget within a HorizontalPanel to add a space before and after the Widget HorizontalPanel hp = new HorizontalPanel(); hp.add( new HTML( " " ) ); hp.add( resultWidget ); hp.add( new HTML( " " ) ); initWidget( hp ); }