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.widget.table.cells;
 
 import java.util.List;
 
A Popup drop-down Editor for bound Fact Patterns. This cell listens for PatternsChangedEvents so that it's content can be maintained as and when Patterns are added, deleted or edited.
 
         implements
         BoundFactsChangedEvent.Handler {
 
     private final ListBox listBox;
 
     public PopupBoundPatternDropDownEditCellEventBus eventBus,
                                               boolean isReadOnly ) {
         superisReadOnly );
         this. = new ListBox();
 
         // Tabbing out of the ListBox commits changes
         .addKeyDownHandlernew KeyDownHandler() {
 
             public void onKeyDownKeyDownEvent event ) {
                 boolean keyTab = event.getNativeKeyCode() == .;
                 boolean keyEnter = event.getNativeKeyCode() == .;
                 if ( keyEnter || keyTab ) {
                     commit();
                 }
             }
 
         } );
 
         .add );
 
         //Wire-up the events
         eventBus.addHandler.,
                              this );
     }
 
     @Override
     public void renderCell.Context context,
                         String value,
                         SafeHtmlBuilder sb ) {
         if ( value != null ) {
             sb.append.rendervalue ) );
         }
     }
 
     public void onBoundFactsChangedBoundFactsChangedEvent event ) {
         setFactBindingsevent.getFactBindings() );
     }

    
Set content of drop-down.

Parameters:
factBindings
 
     public void setFactBindingsList<StringfactBindings ) {
         .clear();
         for ( String binding : factBindings ) {
             .addItembinding );
         }
         .setEnabled.getItemCount() > 0 );
         if ( .getItemCount() == 0 ) {
         }
     }
 
     // Commit the change
    @Override
    protected void commit() {
        //If there are no pattern bindings don't update the model
        if ( !.isEnabled() ) {
            return;
        }
        // Update value
        String value = null;
        int selectedIndex = .getSelectedIndex();
        if ( selectedIndex >= 0 ) {
            value = .getValueselectedIndex );
        }
        setValue,
                  ,
                  value );
        if (  != null ) {
            .updatevalue );
        }
        .hide();
    }
    // Start editing the cell
    @Override
    protected void startEditingfinal Cell.Context context,
                                 final Element parent,
                                 final String value ) {
        // Select the appropriate item
        boolean emptyValue = ( value == null );
        if ( emptyValue ) {
            .setSelectedIndex( 0 );
        } else {
            for ( int i = 0; i < .getItemCount(); i++ ) {
                if ( .getValuei ).equalsvalue ) ) {
                    .setSelectedIndexi );
                    break;
                }
            }
        }
            public void setPositionint offsetWidth,
                                     int offsetHeight ) {
                .setPopupPositionparent.getAbsoluteLeft()
                                                + ,
                                        parent.getAbsoluteTop()
                                                +  );
                // Focus the first enabled control
                Scheduler.get().scheduleDeferrednew ScheduledCommand() {
                    public void execute() {
                        .setFocustrue );
                    }
                } );
            }
        } );
    }
New to GrepCode? Check out our FAQ X