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.util;
 
 import java.util.List;
 
The GWT StackPanel is not working as we want. So doing a custom one.
 
 public class LazyStackPanel extends Composite
         implements
 
     private FlexTable flexTable = new FlexTable();
     private int       rowIndex  = 0;
 
     public LazyStackPanel() {
 
         initWidget );
 
         .setStyleName"guvnor-lazyStackPanel" );
 
 
             public void onSelection(SelectionEvent<LazyStackPanelRowevent) {
                 LazyStackPanelRow row = event.getSelectedItem();
                 if ( row.isExpanded() ) {
                     row.compress();
                 } else {
                     row.expand();
                 }
             }
         } );
     }

    
Add a new (collapsed) element to the stack.

Parameters:
headerText
contentLoad
 
     public void add(String headerText,
                     LoadContentCommand contentLoad) {
         this.addheaderText,
                   contentLoad,
                   false );
     }
 
     public void add(String headerText,
                     LoadContentCommand contentLoad,
                     boolean expanded) {
         LazyStackPanelHeader header = new LazyStackPanelHeaderheaderText );
         addheader,
              contentLoad,
              expanded );
     }
 
     public void add(String headerText,
                     Image icon,
                     LoadContentCommand contentLoad) {
         LazyStackPanelHeader header = new LazyStackPanelHeaderheaderText,
                                                                 icon );
         addheader,
              contentLoad,
              false );
     }

    
Add a new (collapsed) element to the stack.

Parameters:
header
contentLoad
    public void add(AbstractLazyStackPanelHeader header,
                    LoadContentCommand contentLoad) {
        this.addheader,
                  contentLoad,
                  false );
    }
    public void add(AbstractLazyStackPanelHeader header,
                    LoadContentCommand contentLoad,
                    boolean expanded) {
        final LazyStackPanelRow row = new LazyStackPanelRowheader,
                                                             contentLoad );
        header.addOpenHandlernew OpenHandler<AbstractLazyStackPanelHeader>() {
            public void onOpen(OpenEvent<AbstractLazyStackPanelHeaderevent) {
                selectRowrow );
            }
        } );
            public void onClose(com.google.gwt.event.logical.shared.CloseEvent<AbstractLazyStackPanelHeaderevent) {
                selectRowrow );
            }
        } );
        addHeaderRowrow );
        addContentRowrow.getContentPanel() );
        if ( expanded ) {
            header.expand();
        }
    }
    private void addHeaderRow(final LazyStackPanelRow row) {
        .setWidget,
                             0,
                             row );
                                                       0,
                                                       "guvnor-LazyStackPanel-row-header" );
        ++;
    }
    private void addContentRow(final SimplePanel panel) {
        .setWidget++,
                             0,
                             panel );
    }
    private void selectRow(LazyStackPanelRow row) {
        SelectionEvent.firethis,
                             row );
    }
    @Override
        return addHandlerhandler,
                           SelectionEvent.getType() );
    }
    public void swap(int firstIndex,
                     int secondIndex) {
        // Every list item is made of the header and content row.
        // So we have twice as many rows.
        firstIndex = firstIndex * 2;
        secondIndex = secondIndex * 2;
        Widget firstHeader = .getWidgetfirstIndex,
                                                  0 );
        Widget firstContent = .getWidgetfirstIndex + 1,
                                                   0 );
        Widget secondHeader = .getWidgetsecondIndex,
                                                   0 );
        Widget secondContent = .getWidgetsecondIndex + 1,
                                                    0 );
        .setWidgetfirstIndex,
                             0,
                             secondHeader );
        .setWidgetfirstIndex + 1,
                             0,
                             secondContent );
        .setWidgetsecondIndex,
                             0,
                             firstHeader );
        .setWidgetsecondIndex + 1,
                             0,
                             firstContent );
    }
        Iterator<Widgetiterator = .iterator();
        while ( iterator.hasNext() ) {
            Widget widget = (Widgetiterator.next();
            if ( widget instanceof LazyStackPanelRow ) {
                result.add( ((LazyStackPanelRowwidget).getHeader() );
            }
        }
        return result.iterator();
    }
    public void remove(int index) {
        index = index * 2;
        .removeRowindex + 1 );
        .removeRowindex );
    }
New to GrepCode? Check out our FAQ X