| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TableSelectionToLabelHandler | 
 | 
 | 2.0;2 | 
| 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 | 0 |      public TableSelectionToLabelHandler(FixedWidthGrid dataTable, KSLabel selection) { | 
| 40 | 0 |          this.dataTable = dataTable; | 
| 41 | 0 |          this.selection = selection; | 
| 42 | 0 |          this.labelPrefix = selection.getText(); | 
| 43 | 0 |      } | 
| 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 | 0 |          Set<Integer>selectedRows = dataTable.getSelectedRows(); | 
| 52 |          //Set<Row>selectedRows = event.getSelectedRows(); | |
| 53 | 0 |          int colCount = dataTable.getColumnCount(); | 
| 54 | 0 |          StringBuilder sb = new StringBuilder(labelPrefix); | 
| 55 | 0 |          sb.append('\n'); | 
| 56 | 0 |          for(Integer row:selectedRows){             | 
| 57 | 0 |              selection.setText(labelPrefix); | 
| 58 | 0 |              for(int column = 0; column < colCount; column++) { | 
| 59 | 0 |                 sb.append(dataTable.getText(row, column)).append(' ');  | 
| 60 | } | |
| 61 | 0 |              sb.append('\n'); | 
| 62 | } | |
| 63 | 0 |          selection.setText(sb.toString()); | 
| 64 | 0 |      } | 
| 65 | } |