2017-08-08 6 views
0

私はツリーグリッドのデフォルトアイコンを自分のアイコンに変更する必要があるGWTアプリケーションに取り組んでいます。他のケースでは、簡単にアイコンを設定できますが、ツリーグリッドがある場合はそうではありません。私はデフォルトのグリッドセットのアイコンのための私のコードは次のようである持っている:ツリーグリッドGXT(GWT)の列にアイコンを設定する方法は?

Protected List<ColumnConfig> getColumns() { 
     List<ColumnConfig> columnConfigs = new ArrayList<ColumnConfig>(); 

     ColumnConfig columnConfig = new ColumnConfig("status", MSGS.gridUserColumnHeaderStatus(), 50); 
     GridCellRenderer<GwtUser> setStatusIcon = new GridCellRenderer<GwtUser>() { 

      public String render(GwtUser gwtUser, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtUser> deviceList, Grid<GwtUser> grid) { 

       KapuaIcon icon; 
       if (gwtUser.getStatusEnum() != null) { 
        switch (gwtUser.getStatusEnum()) { 
        case DISABLED: 
         icon = new KapuaIcon(IconSet.USER); 
         icon.setColor(Color.RED); 
         break; 
        case ENABLED: 
         icon = new KapuaIcon(IconSet.USER); 
         icon.setColor(Color.GREEN); 
         break; 
        default: 
         icon = new KapuaIcon(IconSet.USER); 
         icon.setColor(Color.GREY); 
         break; 
        } 
       } else { 
        icon = new KapuaIcon(IconSet.USER); 
        icon.setColor(Color.GREY); 
       } 

       return icon.getInlineHTML(); 
      } 
     }; 
     columnConfig.setRenderer(setStatusIcon); 
     columnConfig.setAlignment(HorizontalAlignment.CENTER); 
     columnConfig.setSortable(false); 
     columnConfigs.add(columnConfig); 

をしかし、私は私のツリーグリッド上でそれを適用するときにだけ、最初の項目のアイコンを持っている、と私は、グリッドを展開することはできません。これは、そのツリーグリッドの現在のコードです

List<ColumnConfig> configs = new ArrayList<ColumnConfig>(); 

     ColumnConfig column = new ColumnConfig("topicName", MSGS.topicInfoTableTopicHeader(), 150); 
     column.setRenderer(new TreeGridCellRenderer<GwtTopic>()); 
     configs.add(column); 

     column = new ColumnConfig("timestamp", MSGS.topicInfoTableLastPostedHeader(), 150); 
     configs.add(column); 

     store = new TreeStore<GwtTopic>(); 
     AsyncCallback<List<GwtTopic>> topicsCallback = new AsyncCallback<List<GwtTopic>>() { 

      @Override 
      public void onSuccess(List<GwtTopic> topics) { 
       store.add(topics, true); 
       topicInfoGrid.unmask(); 
      } 

      @Override 
      public void onFailure(Throwable t) { 
       FailureHandler.handle(t); 
       topicInfoGrid.unmask(); 
      } 
     }; 
     dataService.findTopicsTree(currentSession.getSelectedAccount().getId(), topicsCallback); 
     topicInfoGrid = new TreeGrid<GwtTopic>(store, new ColumnModel(configs)); 
     topicInfoGrid.setBorders(false); 
     topicInfoGrid.setStateful(false); 
     topicInfoGrid.setLoadMask(true); 
     topicInfoGrid.mask("Loading"); 
     topicInfoGrid.setStripeRows(true); 
     topicInfoGrid.getView().setAutoFill(true); 
     topicInfoGrid.getView().setEmptyText(MSGS.topicInfoGridEmptyText()); 
     topicInfoGrid.disableTextSelection(false); 

このコードを変更して自分のアイコンを設定する方法はありますか?

答えて

0

あなたは葉のアイコンを変更するsetIconProviderメソッドを使用することができます。

topicInfoGrid.setIconProvider(new IconProvider<GwtTopic>() { 
      @Override 
      public ImageResource getIcon(GwtTopic gwtTopic) { 
       GwtTopicType type = gwtTopic.getType(); 
       if (type == GwtTopicType.Folder) { 
        if (topicInfoGrid.isExpanded(gwtTopic)) return new TopicInfoResources.Instance.iconFolderOpen(); 
        else return TopicInfoResources.Instance.iconFolder(); 
       } 
       return TopicInfoResources.Instance.user(); 
      } 
     }); 

そして、これはClientBundleを拡張し、あなたのインターフェイスである:

public interface TopicInfoResources extends ClientBundle 
{ 
    public static final TopicInfoResources Instance = GWT.create(TopicInfoResources.class); 

    @Source("folder.png")    ImageResource iconFolder(); 
    @Source("folder-open.png")   ImageResource iconFolderOpen(); 
    @Source("user.png")     ImageResource user(); 
} 

は、この情報がお役に立てば幸い!

+0

エラー:KapuaIconからAbstractImagePrototypeへの変換から変換できません... – Atenica

+0

私はそれがImageResourceの実装であると仮定して、KapuaIcon()の背後にあるものがわかりません。私は自分の答えを編集しています。 – Euclides

関連する問題