View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.ui.client.widgets.pagetable;
17  
18  import java.util.Set;
19  
20  import org.kuali.student.common.ui.client.widgets.KSLabel;
21  
22  import com.google.gwt.gen2.table.client.FixedWidthGrid;
23  import com.google.gwt.gen2.table.event.client.RowSelectionEvent;
24  import com.google.gwt.gen2.table.event.client.RowSelectionHandler;
25  
26  /**
27   * When this event handler is added to a table that extends 
28   * @see class com.google.gwt.gen2.table.client.AbstractScrollTable
29   * Where all columns contain text, the text of every selected row is copied
30   * to a Label
31   * @author Kuali Student Team (gstruthers@berkeley.edu)
32   *
33   */
34  public class TableSelectionToLabelHandler implements RowSelectionHandler {
35      private FixedWidthGrid dataTable;
36      private KSLabel selection;
37      private String labelPrefix;
38      
39      public TableSelectionToLabelHandler(FixedWidthGrid dataTable, KSLabel selection) {
40          this.dataTable = dataTable;
41          this.selection = selection;
42          this.labelPrefix = selection.getText();
43      }
44      /**
45       * Copy the text from every column in every selected row to a Label
46       * 
47       * @see com.google.gwt.gen2.table.event.client.RowSelectionHandler#onRowSelection(com.google.gwt.gen2.table.event.client.RowSelectionEvent)
48       */
49      @Override
50      public void onRowSelection(RowSelectionEvent event) {
51          Set<Integer>selectedRows = dataTable.getSelectedRows();
52          //Set<Row>selectedRows = event.getSelectedRows();
53          int colCount = dataTable.getColumnCount();
54          StringBuilder sb = new StringBuilder(labelPrefix);
55          sb.append('\n');
56          for(Integer row:selectedRows){            
57              selection.setText(labelPrefix);
58              for(int column = 0; column < colCount; column++) {
59                 sb.append(dataTable.getText(row, column)).append(' '); 
60              }
61              sb.append('\n');
62          }
63          selection.setText(sb.toString());
64      }
65  }