Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.workbench.screens.guided.dtable.client.wizard.pages;
 
 import java.util.List;
 import java.util.Set;
 
An implementation of the Fact Patterns page
 
 public class FactPatternsPageViewImpl extends Composite
         implements
         FactPatternsPageView {
 
     private Presenter presenter;
 
     private Validator validator;
 
     private Set<StringavailableTypesSelections;
 
     private List<Pattern52chosenPatterns;
     private Pattern52 chosenPatternSelection;
 
     @UiField
 
     @UiField
 
     @UiField
     PushButton btnAdd;
 
     @UiField
 
     @UiField
 
     @UiField
 
     @UiField
 
    @UiField
    @UiField
    @UiField
    @UiField
    @UiField(provided = true)
    @UiField(provided = true)
    @New
    @Inject
    private PatternCell patternCell;
            extends
            UiBinder<WidgetFactPatternsPageViewImpl> {
    }
    private static FactPatternsPageWidgetBinder uiBinder = GWT.createFactPatternsPageWidgetBinder.class );
    public FactPatternsPageViewImpl() {
        initWidget.createAndBindUithis ) );
    }
    public void setup() {
        this. = new MinimumWidthCellList<String>( new TextCell(),
                                                                      . );
                                                                        . );
        initialiseAvailableTypes();
        initialiseChosenPatterns();
        initialiseBinding();
        initialiseEntryPoint();
        initialiseCEPWindow();
        initialiseShufflers();
    }
    @Override
    public void setValidatorfinal Validator validator ) {
        this. = validator;
        this..setValidatorvalidator );
    }
    private void initialiseAvailableTypes() {
        .setMinimumWidth( 275 );
        .setEmptyListWidgetlstEmpty );
        final MultiSelectionModel<StringselectionModel = new MultiSelectionModel<String>();
        .setSelectionModelselectionModel );
        selectionModel.addSelectionChangeHandlernew SelectionChangeEvent.Handler() {
            @Override
            public void onSelectionChangefinal SelectionChangeEvent event ) {
                 = selectionModel.getSelectedSet();
                .setEnabled.size() > 0 );
            }
        } );
    }
    private void initialiseChosenPatterns() {
        .setMinimumWidth( 275 );
        .setEmptyListWidgetlstEmpty );
        final MultiSelectionModel<Pattern52selectionModel = new MultiSelectionModel<Pattern52>();
        .setSelectionModelselectionModel );
        selectionModel.addSelectionChangeHandlernew SelectionChangeEvent.Handler() {
            @Override
            public void onSelectionChangefinal SelectionChangeEvent event ) {
                 = selectionModel.getSelectedSet();
                chosenTypesSelected );
            }
            private void chosenTypesSelectedfinal Set<Pattern52ps ) {
                .setEnabledtrue );
                if ( ps.size() == 1 ) {
                     = ps.iterator().next();
                    .setVisibletrue );
                    validateBinding();
                    .setEnabledtrue );
                    .setText.getBoundName() );
                    .setEnabledtrue );
                    .setText.getEntryPointName() );
                    enableMoveUpButton();
                    enableMoveDownButton();
                    if ( .isPatternEvent ) ) {
                        .setCEPWindow );
                        .setVisibletrue );
                    } else {
                        .setVisiblefalse );
                    }
                } else {
                     = null;
                    .setVisiblefalse );
                    .setEnabledfalse );
                    .setText"" );
                    .setEnabledfalse );
                    .setText"" );
                    .setEnabledfalse );
                    .setEnabledfalse );
                    .setVisiblefalse );
                }
            }
        } );
    }
    private void validateBinding() {
        } else {
        }
    }
    private void enableMoveUpButton() {
        if (  == null ||  == null ) {
            .setEnabledfalse );
            return;
        }
        int index = .indexOf );
        .setEnabledindex > 0 );
    }
    private void enableMoveDownButton() {
        if (  == null ||  == null ) {
            .setEnabledfalse );
            return;
        }
        int index = .indexOf );
        .setEnabledindex < .size() - 1 );
    }
    private void initialiseBinding() {
            @Override
            public void onValueChangefinal ValueChangeEvent<Stringevent ) {
                String binding = .getText();
                .setBoundNamebinding );
                .stateChanged();
                validateBinding();
            }
        } );
    }
    private void initialiseEntryPoint() {
            @Override
            public void onValueChangefinal ValueChangeEvent<Stringevent ) {
                if (  == null ) {
                    return;
                }
                .setEntryPointNameevent.getValue() );
            }
        } );
    }
    private void initialiseCEPWindow() {
            @Override
            public void onValueChangefinal ValueChangeEvent<OperatorSelectionevent ) {
                if (  == null ) {
                    return;
                }
                OperatorSelection selection = event.getValue();
                String selected = selection.getValue();
                .getWindow().setOperatorselected );
            }
        } );
    }
    private void initialiseShufflers() {
        .addClickHandlernew ClickHandler() {
            @Override
            public void onClickfinal ClickEvent event ) {
                int index = .indexOf );
                final Pattern52 p = .removeindex );
                .addindex - 1,
                                    p );
                setChosenPatterns );
                .setConditionPatterns );
            }
        } );
        .addClickHandlernew ClickHandler() {
            @Override
            public void onClickfinal ClickEvent event ) {
                int index = .indexOf );
                final Pattern52 p = .removeindex );
                .addindex + 1,
                                    p );
                setChosenPatterns );
                .setConditionPatterns );
            }
        } );
    }
    @Override
    public void setAvailableFactTypesfinal List<Stringtypes ) {
        .setRowCounttypes.size(),
                                          true );
        .setRowDatatypes );
    }
    @Override
    public void setChosenPatternsfinal List<Pattern52types ) {
         = types;
        .setRowCounttypes.size(),
                                         true );
        .setRowDatatypes );
        enableMoveUpButton();
        enableMoveDownButton();
        .stateChanged();
    }
    @Override
    public void initfinal FactPatternsPageView.Presenter presenter ) {
        this. = presenter;
    }
    @Override
    public void setArePatternBindingsUniquefinal boolean arePatternBindingsUnique ) {
        .setVisible( !arePatternBindingsUnique );
        .redraw();
    }
    @UiHandler(value = "btnAdd")
    public void btnAddClickfinal ClickEvent event ) {
        for ( String type :  ) {
            final Pattern52 pattern = new Pattern52();
            pattern.setFactTypetype );
            .addpattern );
        }
        setChosenPatterns );
        .stateChanged();
    }
    @UiHandler(value = "btnRemove")
    public void btnRemoveClickfinal ClickEvent event ) {
        for ( Pattern52 pattern :  ) {
            .removepattern );
            //Raise an Event so ActionSetFieldPage can synchronise Patterns
            .signalRemovalOfPatternpattern );
        }
        setChosenPatterns );
        .stateChanged();
        .setText"" );
        .setEnabledfalse );
        .setText"" );
        .setEnabledfalse );
        .setEnabledfalse );
        .setVisiblefalse );
    }
New to GrepCode? Check out our FAQ X