Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 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.guvnor.client.ruleeditor;
 
 /*
  * Copyright 2005 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.
  */
 
 import java.util.List;
 
 import  org.drools.guvnor.client.messages.Constants;
 
 import  com.google.gwt.user.client.ui.Button;
 import  com.google.gwt.user.client.ui.ClickListener;
 import  com.google.gwt.user.client.ui.FocusListener;
 import  com.google.gwt.user.client.ui.HorizontalPanel;
 import  com.google.gwt.user.client.ui.KeyboardListener;
 import  com.google.gwt.user.client.ui.ListBox;
 import  com.google.gwt.user.client.ui.PopupPanel;
 import  com.google.gwt.user.client.ui.TextBox;
 import  com.google.gwt.user.client.ui.VerticalPanel;
 import  com.google.gwt.user.client.ui.Widget;
 import  com.google.gwt.core.client.GWT;

This is a popup list for "content assistance" - although on the web, its not assistance - its mandatory ;)
 
 public class ChoiceList extends PopupPanel {
 
     private ListBox             list;
     private final DSLSentence[] sentences;
     private HorizontalPanel     buttons;
     private TextBox             filter;
     private Constants constants = ((Constants) GWT.create(Constants.class));

    
Pass in a list of suggestions for the popup lists. Set a click listener to get notified when the OK button is clicked.
 
     public ChoiceList(final DSLSentence[] sen,
                       final DSLRuleEditor self) {
         supertrue );
 
         this. = sen;
          = new TextBox();
         .setWidth( "100%" );
         final String defaultMessage = .enterTextToFilterList();
         .setText( defaultMessage );
         .addFocusListener( new FocusListener() {
             public void onFocus(Widget w) {
                 .setText( "" );
             }
 
             public void onLostFocus(Widget w) {
                 .setText( defaultMessage );
             }
         } );
         .addKeyboardListener( new KeyboardListener() {
 
             public void onKeyDown(Widget arg0,
                                   char arg1,
                                   int arg2) {
 
             }
 
             public void onKeyPress(Widget arg0,
                                    char arg1,
                                    int arg2) {
             }
 
             public void onKeyUp(Widget arg0,
                                char arg1,
                                int arg2) {
                if ( arg1 == KEY_ENTER ) {
                    applyChoiceself );
                } else {
                    populateList( ListUtil.filter,
                                                   .getText() ) );
                }
            }
        } );
        .setFocus( true );
        VerticalPanel panel = new VerticalPanel();
        panel.add(  );
         = new ListBox();
        .setVisibleItemCount( 5 );
        populateList( ListUtil.filterthis.,
                                       "" ) );
        panel.add(  );
        Button ok = new Button( .OK() );
        ok.addClickListener( new ClickListener() {
            public void onClick(Widget btn) {
                applyChoiceself );
            }
        } );
        Button cancel = new Button(.Cancel());
        cancel.addClickListener( new ClickListener() {
            public void onClick(Widget btn) {
                hide();
            }
        } );
         = new HorizontalPanel();
        .add( ok );
        .add( cancel );
        panel.add(  );
        add( panel );
        setStyleName"ks-popups-Popup" );  //NON-NLS
    }
    private void applyChoice(final DSLRuleEditor self) {
        self.insertTextgetSelectedItem() );
        hide();
    }
    private void populateList(List filtered) {
        .clear();
        for ( int i = 0; i < filtered.size(); i++ ) {
            .addItem( ((DSLSentencefiltered.geti )). );
        }
    }
    public String getSelectedItem() {
        return .getItemText( .getSelectedIndex() );
    }
New to GrepCode? Check out our FAQ X