All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.alpharogroup.swing.tablemodel.GenericShuffleTableModel Maven / Gradle / Ivy

There is a newer version: 5.5
Show newest version
/**
 * The MIT License
 *
 * Copyright (C) 2007 Asterios Raptis
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package de.alpharogroup.swing.tablemodel;


/**
 * The Class GenericShuffleTableModel is a helper class to shuffle between the two given
 * GenericTableModel.
 *
 * @param 
 *            the generic type of the given model
 */
public class GenericShuffleTableModel
{

	/** The left table model. */
	private final GenericTableModel leftTableModel;

	/** The right table model. */
	private final GenericTableModel rightTableModel;

	/**
	 * Instantiates a new generic shuffle table model.
	 *
	 * @param leftTableModel
	 *            the left table model
	 * @param rightTableModel
	 *            the right table model
	 */
	public GenericShuffleTableModel(final GenericTableModel leftTableModel,
		final GenericTableModel rightTableModel)
	{
		super();
		this.leftTableModel = leftTableModel;
		this.rightTableModel = rightTableModel;
	}

	/**
	 * Adds the all left rows to right table model.
	 */
	public void addAllLeftRowsToRightTableModel()
	{
		rightTableModel.addList(leftTableModel.getData());
		leftTableModel.clear();
	}

	/**
	 * Adds the all right rows to left table model.
	 */
	public void addAllRightRowsToLeftTableModel()
	{
		leftTableModel.addList(rightTableModel.getData());
		rightTableModel.clear();
	}

	/**
	 * Shuffle selected left rows to right table model.
	 *
	 * @param selectedRows
	 *            the selected rows
	 */
	public void shuffleSelectedLeftRowsToRightTableModel(final int[] selectedRows)
	{
		final int lastIndex = selectedRows.length - 1;
		for (int i = lastIndex; -1 < i; i--)
		{
			final int selectedRow = selectedRows[i];
			final T row = leftTableModel.removeAt(selectedRow);
			rightTableModel.add(row);
		}
	}

	/**
	 * Shuffle selected left row to right table model.
	 *
	 * @param selectedRow
	 *            the selected row
	 */
	public void shuffleSelectedLeftRowToRightTableModel(final int selectedRow)
	{
		final T row = leftTableModel.removeAt(selectedRow);
		rightTableModel.add(row);
	}

	/**
	 * Shuffle selected right rows to left table model.
	 *
	 * @param selectedRows
	 *            the selected rows
	 */
	public void shuffleSelectedRightRowsToLeftTableModel(final int[] selectedRows)
	{
		final int lastIndex = selectedRows.length - 1;
		for (int i = lastIndex; -1 < i; i--)
		{
			final int selectedRow = selectedRows[i];
			final T row = rightTableModel.removeAt(selectedRow);
			leftTableModel.add(row);
		}
	}

	/**
	 * Shuffle selected right row to left table model.
	 *
	 * @param selectedRow
	 *            the selected row
	 */
	public void shuffleSelectedRightRowToLeftTableModel(final int selectedRow)
	{
		final T row = rightTableModel.removeAt(selectedRow);
		leftTableModel.add(row);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy