Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.uberfire.ext.widgets.common.client.tables;
  
  import  com.google.gwt.cell.client.Cell;
  import  com.google.gwt.cell.client.ClickableTextCell;
  import  com.google.gwt.cell.client.ValueUpdater;
  import  com.google.gwt.resources.client.ImageResource;
  import  com.google.gwt.safehtml.shared.SafeHtmlBuilder;
  import  com.google.gwt.user.cellview.client.Column;
  import  com.google.gwt.user.cellview.client.Header;
 import  com.google.gwt.user.client.ui.AbstractImagePrototype;
Based on GWT bikeshed example.
 
 public class SortableHeader<T, C extends Comparableextends Header<String> {
 
     private static final String DOWN_ARROW       = makeImage..images().downArrow() );
     private static final String SMALL_DOWN_ARROW = makeImage..images().smallDownArrow() );
     private static final String UP_ARROW         = makeImage..images().upArrow() );
     private static final String SMALL_UP_ARROW   = makeImage..images().smallUpArrow() );
 
     private static String makeImage( ImageResource resource ) {
         AbstractImagePrototype prototype = AbstractImagePrototype.create( resource );
         return prototype.getHTML();
     }
 
     private final SortableHeaderGroup sortableHeaderGroup;
     private       String              text;
     private final Column<T, C>        column;
     private int           sortIndex     = -1;
 
     public SortableHeaderSortableHeaderGroup sortableHeaderGroup,
                            String text,
                            Column<T, C> column ) {
         supernew ClickableTextCell() );
         this. = sortableHeaderGroup;
         this. = text;
         this. = column;
         setUpdaternew ValueUpdater<String>() {
             public void updateString s ) {
                 SortableHeader.this..headerClickedSortableHeader.this );
             }
         } );
     }

    

Returns:
the header label
 
     public String getValue() {
         return ;
     }

    
Set the Column header

Parameters:
text
 
     public void setValueString text ) {
         this. = text;
     }
 
     public Column<T, C> getColumn() {
         return ;
     }
 
     public SortDirection getSortDirection() {
         return ;
     }
 
     public void setSortDirectionSortDirection sortDirection ) {
         this. = sortDirection;
     }
 
     public int getSortIndex() {
         return ;
     }
 
     public void setSortIndexint sortIndex ) {
         this. = sortIndex;
     }
 
     @Override
     public void render( Cell.Context context,
                         SafeHtmlBuilder sb ) {
         sb.appendHtmlConstant( "<div style='position: relative; cursor: pointer; padding: 0px;'>" );
         sb.appendHtmlConstant( "<span style='padding-right: 10px'>" );
         sb.appendEscaped(  );
         sb.appendHtmlConstant( "</span>" );
         // sb.appendHtmlConstant("<div style='position:absolute;right:0px;top:0px;'></div>");
         switch (  ) {
             case :
                 // nothing
                 break;
             case :
                 sb.appendHtmlConstant(  == 0 ?  :  );
                 break;
             case :
                 sb.appendHtmlConstant(  == 0 ?  :  );
                break;
            default:
                throw new IllegalArgumentException"Unknown sortDirection ("
                                                            + 
                                                            + ")." );
        }
        sb.appendHtmlConstant( "</div>" );
        // sb.appendHtmlConstant("<div>");
        // sb.appendHtmlConstant("</div></div>");
    }
New to GrepCode? Check out our FAQ X