Package DisplayProject.actions

Source Code of DisplayProject.actions.TableRow

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject.actions;

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.SwingUtilities;

import DisplayProject.UIutils;
import DisplayProject.controls.ArrayField;

/**
* Gets and sets the current row on a ArrayField (JTable)
*
*/
public class TableRow extends PendingAction {

    private int value;
    private TableRow(Component pComponent, int row) {
        super(pComponent);
        this.value = row;
    }
    public int getRow() {
        return this.value;
    }

    public void performAction() {
        JTable table = (JTable)this._component;
        if (table!=null && table.getRowCount() >= this.value && this.value > 0)
          // CraigM:20/08/2008 - Actually change the selection so the focus will move
            // table.addRowSelectionInterval(this.value-1, this.value-1);
          table.changeSelection(this.value-1, 0, false, false);
    }
    /**
     * Set the current row for the passed table. The passed index is one-based and should
     * be in the range 1 <= value <= comp.getRowCount otherwise this method will have no
     * effect.
     * @param comp  the JTable having it's current row set
     * @param value the row to select as the current row
     */
    public static void set(JTable comp, int value){
        ActionMgr.addAction(new TableRow(comp, value));
    }

    /**
     * Get the row of the passed JTable that is the current row. Note that this is meant
     * largely to operate on ArrayFields which only define a single row as being the current
     * row, and it will be this value that is returned. If a normal JTable is passed, the
     * returned value will be the selected row.<p>
     * <p>
     * This method returns the current row as a 1-based offset, not a 0-based offset.
     * @param comp
     * @return
     */
    public static int get(JTable comp){
        int value;
        TableRow action = ActionMgr.getAction(comp, TableRow.class);
        if (action != null) {
            value = ((TableRow)action).getRow();
        } else if (comp instanceof ArrayField
            && !SwingUtilities.isEventDispatchThread()) { // DK:31/12/2008:use getRowForEvents() only if we currently not in EDT thread

            ArrayField table = (ArrayField)comp;
            //value = table.getSelectedRow() + 1;
            // TF: 30/9/07: We need to wait for the EDT to become idle... See the comments associated with this method and ArrayField if you don't know why...
            UIutils.waitForEDTToBeIdle();

            // TF:11/10/07:Created a new method to return the real current row at the point in time this code is executing.
            //value = table.getCurrentRow() + 1; // CraigM 24/08/2007
            value = table.getRowForEvents() + 1;

        } else {
            value = comp.getSelectedRow() + 1;
        }
        return value;
    }

}
TOP

Related Classes of DisplayProject.actions.TableRow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.