/*
______________________________________________________________________
*
* Copyright (c) 1996-2004, QUEST SOFTWARE INC. All Rights Reserved.
* http://java.quest.com
*
* This file is provided for demonstration and educational uses only.
* Permission to use, copy, modify and distribute this file for
* any purpose and without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all
* copies, and that the name of Quest Software not be used in advertising
* or publicity pertaining to this material without the specific,
* prior written permission of an authorized representative of
* Quest Software.
*
* QUEST SOFTWARE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. QUEST SOFTWARE SHALL NOT BE LIABLE FOR ANY
* DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
* ______________________________________________________________________
*/

//   RCSID -- $RCSfile: SingleSelectionExample.java,v $ $Revision: 1.1.1.1 $
//            $Date: 2006-03-09 22:09:15 $  $Locker:  $  Quest Software Inc.

package examples.higrid.visual;

import java.util.*;
import java.awt.event.*;

import javax.swing.*;

import com.klg.jclass.higrid.*;
import com.klg.jclass.util.swing.JCExitFrame;

import examples.higrid.*;

/**
 * Allow a maximum of one row to be selected in HiGrid.
 */
public class SingleSelectionExample extends BaseExample {

public SingleSelectionExample() {
    super();
    grid.addHiGridRowSelectionListener(new SingleSelectionHiGridRowSelectionListener());
    setTitle("Single Selection");
    setPrompt(usage);
}

static String usage = "This example shows how to allow at most one\n" +
                      "row to be selected by the user.";

class SingleSelectionHiGridRowSelectionListener extends HiGridRowSelectionAdapter {
    public void beforeSelectRow(HiGridRowSelectionEvent event) {
        // this is a selection, not a de-selection
        if (event.getSelectState()) {
            // reject multi-row selections
            if (event.getNewRows().size() > 1) {
                event.cancelProposedAction();
            }
            // clear all currently selected rows
            grid.resetRowSelection();
        }
    }
}

public static void main(String args[]) throws InterruptedException {
    JCExitFrame f = new JCExitFrame("Single Selection Example");
    SingleSelectionExample app = new SingleSelectionExample();
    f.getContentPane().add(app);
    f.pack();
    f.show();
    javax.swing.FocusManager.getCurrentManager().focusNextComponent(app.getGrid());    
}

}
