2016-06-30 18 views
0

CellListコンポーネントで複数のセルを選択したいと思います。 私はGWTを初めて使いました。誰かが助けてください。 複数選択を行うには、以下のコードをどのように変更すればよいですか?GWT CellListで複数選択が必要

public class HelloWorld implements EntryPoint { 
private static final List<String> DAYS = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
     "Friday", "Saturday"); 

public void onModuleLoad() { 
    // Create a cell to render each value. 
    TextCell textCell = new TextCell(); 

    // Create a CellList that uses the cell. 
    CellList<String> cellList = new CellList<String>(textCell); 
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); 

    // Add a selection model to handle user selection. 
    final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>(); 
    cellList.setSelectionModel(selectionModel); 
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { 
     public void onSelectionChange(SelectionChangeEvent event) { 
      String selected = selectionModel.getSelectedObject(); 
      if (selected != null) { 
       // Window.alert("You selected: " + selected); 
      } 
     } 
    }); 

    cellList.setRowCount(DAYS.size(), true); 

    // Push the data into the widget. 
    cellList.setRowData(0, DAYS); 

    // Add it to the root panel. 
    RootPanel.get("gwtCellListBox").add(cellList); 
} 
} 
+0

こんにちは、複数の選択のために以下のコードを試してみましたが、それは_ ** Ctrl ** _キーの長押しでうまくいきました。 ** ** Ctrl ** _ ** Ctrl ** _ –

+0

final MultiSelectionModel selectModel = new MultiSelectionModel ();を押さずに_ **を使用してこの複数選択を行いたいと思います。 \t \t cellList.setSelectionModel(selectModel); \t \t selectModel.addSelectionChangeHandler(新SelectionChangeEvent.Handler(){ \t \t \tます。public void onSelectionChange(SelectionChangeEventイベント){ \t \t \t \tセット= selectModel.getSelectedSet(選択); \t \t \t \t選択(もし! )「+選択され; := NULL){ \t \t \t \t \t //Window.alert("You選択0 \t \t \t} \t \t \t} \t \t})。 –

+0

複数の選択肢のチェックボックス列を追加することをお勧めします。 –

答えて

0

まずこの

public class HelloWorld implements EntryPoint { 
private static final List<String> DAYS = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
     "Friday", "Saturday"); 

public void onModuleLoad() { 
    // Create a cell to render each value. 
    TextCell textCell = new TextCell(); 

    // Create a CellList that uses the cell. 
    CellList<String> cellList = new CellList<String>(textCell); 
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); 

    // Add a selection model to handle user selection. 
    final MultiSelectionModel<String> selectionModel = new MultiSelectionModel<String>(); 
    cellList.setSelectionModel(selectionModel); 
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { 
    public void onSelectionChange(SelectionChangeEvent event) { 

     Set<String> selectedItems = selectionModel.getSelectedSet(); 

     for (String s : selectedItems) { 
      System.out.println(s); 
      Window.alert("You selected: " + s); 
     } 
    } 
}); 

    cellList.setRowCount(DAYS.size(), true); 

    // Push the data into the widget. 
    cellList.setRowData(0, DAYS); 

    // Add it to the root panel. 
    RootPanel.get("gwtCellListBox").add(cellList); 
} 
} 
1

を試してみてください、あなたはMultiSelectionModelを必要としています。 Ctrlキーを押したままにしたい場合は、にEventTranslatorのようにDefaultSelectionEventManagerを使用し、常にTOGGLEfalseを返します。

関連する問題