001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.student.common.ui.client.widgets.pagetable;
017    
018    import java.util.Set;
019    
020    import org.kuali.student.common.ui.client.widgets.KSLabel;
021    
022    import com.google.gwt.gen2.table.client.FixedWidthGrid;
023    import com.google.gwt.gen2.table.event.client.RowSelectionEvent;
024    import com.google.gwt.gen2.table.event.client.RowSelectionHandler;
025    
026    /**
027     * When this event handler is added to a table that extends 
028     * @see class com.google.gwt.gen2.table.client.AbstractScrollTable
029     * Where all columns contain text, the text of every selected row is copied
030     * to a Label
031     * @author Kuali Student Team (gstruthers@berkeley.edu)
032     *
033     */
034    @Deprecated
035    public class TableSelectionToLabelHandler implements RowSelectionHandler {
036        private FixedWidthGrid dataTable;
037        private KSLabel selection;
038        private String labelPrefix;
039        
040        public TableSelectionToLabelHandler(FixedWidthGrid dataTable, KSLabel selection) {
041            this.dataTable = dataTable;
042            this.selection = selection;
043            this.labelPrefix = selection.getText();
044        }
045        /**
046         * Copy the text from every column in every selected row to a Label
047         * 
048         * @see com.google.gwt.gen2.table.event.client.RowSelectionHandler#onRowSelection(com.google.gwt.gen2.table.event.client.RowSelectionEvent)
049         */
050        @Override
051        public void onRowSelection(RowSelectionEvent event) {
052            Set<Integer>selectedRows = dataTable.getSelectedRows();
053            //Set<Row>selectedRows = event.getSelectedRows();
054            int colCount = dataTable.getColumnCount();
055            StringBuilder sb = new StringBuilder(labelPrefix);
056            sb.append('\n');
057            for(Integer row:selectedRows){            
058                selection.setText(labelPrefix);
059                for(int column = 0; column < colCount; column++) {
060                   sb.append(dataTable.getText(row, column)).append(' '); 
061                }
062                sb.append('\n');
063            }
064            selection.setText(sb.toString());
065        }
066    }