final String factType = getFactType( fp,
con );
String title = ( con == null ) ? GuidedRuleEditorResources.CONSTANTS.ModifyConstraintsFor0( fp.getFactType() ) : GuidedRuleEditorResources.CONSTANTS.AddSubFieldConstraint();
final FormStylePopup popup = new FormStylePopup( GuidedRuleEditorImages508.INSTANCE.Wizard(),
title );
final ListBox box = new ListBox();
box.addItem( "..." );
this.oracle.getFieldCompletions( factType,
FieldAccessorsAndMutators.ACCESSOR,
new Callback<ModelField[]>() {
@Override
public void callback( final ModelField[] fields ) {
for ( int i = 0; i < fields.length; i++ ) {
//You can't use "this" in a nested accessor
final String fieldName = fields[ i ].getName();
if ( !isNested || !fieldName.equals( DataType.TYPE_THIS ) ) {
box.addItem( fieldName );
}
}
}
} );
box.setSelectedIndex( 0 );
box.addChangeHandler( new ChangeHandler() {
public void onChange( ChangeEvent event ) {
String fieldName = box.getItemText( box.getSelectedIndex() );
if ( "...".equals( fieldName ) ) {
return;
}
String fieldType = oracle.getFieldType( factType,
fieldName );
fp.addConstraint( new SingleFieldConstraint( factType,
fieldName,
fieldType,
con ) );
modeller.refreshWidget();
popup.hide();
}
} );
popup.addAttribute( GuidedRuleEditorResources.CONSTANTS.AddARestrictionOnAField(),
box );
final ListBox composites = new ListBox();
composites.addItem( "..." );
composites.addItem( GuidedRuleEditorResources.CONSTANTS.AllOfAnd(),
CompositeFieldConstraint.COMPOSITE_TYPE_AND );
composites.addItem( GuidedRuleEditorResources.CONSTANTS.AnyOfOr(),
CompositeFieldConstraint.COMPOSITE_TYPE_OR );
composites.setSelectedIndex( 0 );
composites.addChangeHandler( new ChangeHandler() {
public void onChange( ChangeEvent event ) {
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType( composites.getValue( composites.getSelectedIndex() ) );
fp.addConstraint( comp );
modeller.refreshWidget();
popup.hide();
}
} );
InfoPopup infoComp = new InfoPopup( GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraints(),
GuidedRuleEditorResources.CONSTANTS.MultipleConstraintsTip1() );
HorizontalPanel horiz = new HorizontalPanel();
horiz.add( composites );
horiz.add( infoComp );
if ( con == null ) {
popup.addAttribute( GuidedRuleEditorResources.CONSTANTS.MultipleFieldConstraint(),
horiz );
}
if ( con == null ) {
popup.addRow( new SmallLabel( "<i>" + GuidedRuleEditorResources.CONSTANTS.AdvancedOptionsColon() + "</i>" ) ); //NON-NLS
Button predicate = new Button( GuidedRuleEditorResources.CONSTANTS.NewFormula() );
predicate.addClickHandler( new ClickHandler() {
public void onClick( ClickEvent event ) {
SingleFieldConstraint con = new SingleFieldConstraint();
con.setConstraintValueType( SingleFieldConstraint.TYPE_PREDICATE );
fp.addConstraint( con );
modeller.refreshWidget();
popup.hide();
}
} );
popup.addAttribute( GuidedRuleEditorResources.CONSTANTS.AddANewFormulaStyleExpression(),
predicate );
Button ebBtn = new Button( GuidedRuleEditorResources.CONSTANTS.ExpressionEditor() );
ebBtn.addClickHandler( new ClickHandler() {
public void onClick( ClickEvent event ) {
SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
con.setConstraintValueType( SingleFieldConstraint.TYPE_UNDEFINED );
fp.addConstraint( con );
con.setExpressionLeftSide( new ExpressionFormLine( new ExpressionUnboundFact( pattern ) ) );
modeller.refreshWidget();
popup.hide();
}
} );
popup.addAttribute( GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(),
ebBtn );
doBindingEditor( popup );
}
popup.show();
}