SmartGwt中ListGrid的扩展

SmartGwt中ListGrid可以通过扩展各种方法来扩展ListGrid表格的特性,通过扩展creatRecordComponents()方法可以在某个单元格上扩展为ImgButton或者Img等,通过扩展为Label可以实现SmartGwt中的提示Hint的效果(SmartGwt默认单元格上是无法使用hint信息的,虽然有setPromt("")方法,但是不起作用。)如下代码所示,就是在单元格上放了ImgButton

 

  1.   public void onModuleLoad() {  
  2.   
  3.         final ListGrid countryGrid = new ListGrid() {  
  4.             @Override  
  5.             protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {  
  6.   
  7.                 String fieldName = this.getFieldName(colNum);  
  8.   
  9.                 if (fieldName.equals("iconField")) {  
  10.                     HLayout recordCanvas = new HLayout(3);  
  11.                     recordCanvas.setHeight(22);  
  12.                     recordCanvas.setAlign(Alignment.CENTER);  
  13.                     ImgButton editImg = new ImgButton();  
  14.                     editImg.setShowDown(false);  
  15.                     editImg.setShowRollOver(false);  
  16.                     editImg.setLayoutAlign(Alignment.CENTER);  
  17.                     editImg.setSrc("silk/comment_edit.png");  
  18.                     editImg.setPrompt("Edit Comments");  
  19.                     editImg.setHeight(16);  
  20.                     editImg.setWidth(16);  
  21.                     editImg.addClickHandler(new ClickHandler() {  
  22.                         public void onClick(ClickEvent event) {  
  23.                             SC.say("Edit Comment Icon Clicked for country : " + record.getAttribute("countryName"));  
  24.                         }  
  25.                     });  
  26.   
  27.                     ImgButton chartImg = new ImgButton();  
  28.                     chartImg.setShowDown(false);  
  29.                     chartImg.setShowRollOver(false);  
  30.                     chartImg.setAlign(Alignment.CENTER);  
  31.                     chartImg.setSrc("silk/chart_bar.png");  
  32.                     chartImg.setPrompt("View Chart");  
  33.                     chartImg.setHeight(16);  
  34.                     chartImg.setWidth(16);  
  35.                     chartImg.addClickHandler(new ClickHandler() {  
  36.                         public void onClick(ClickEvent event) {  
  37.                             SC.say("Chart Icon Clicked for country : " + record.getAttribute("countryName"));  
  38.                         }  
  39.                     });  
  40.   
  41.                     recordCanvas.addMember(editImg);  
  42.                     recordCanvas.addMember(chartImg);  
  43.                     return recordCanvas;  
  44.                 } else if (fieldName.equals("buttonField")) {  
  45.                     IButton button = new IButton();  
  46.                     button.setHeight(18);  
  47.                     button.setWidth(65);                      
  48.                     button.setIcon("flags/16/" + record.getAttribute("countryCode") + ".png");  
  49.                     button.setTitle("Info");  
  50.                     button.addClickHandler(new ClickHandler() {  
  51.                         public void onClick(ClickEvent event) {  
  52.                             SC.say(record.getAttribute("countryName") + " info button clicked.");  
  53.                         }  
  54.                     });  
  55.                     return button;  
  56.                 } else {  
  57.                     return null;  
  58.                 }  
  59.   
  60.             }  
  61.         };  

你可能感兴趣的:(smartgwt)