/*
 * DesmarcadoSHSTAction.java
 *
 * Created on January 31, 2007, 6:21 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package siprp.medicina.presencas.actions;

import com.evolute.utils.ui.DialogException;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import siprp.medicina.presencas.Presenca;
import siprp.medicina.presencas.PresencasDataProvider;

/**
 *
 * @author fpalma
 */
public class DesmarcadoSHSTAction extends AbstractAction
{
	public static final int SINGLE = 0;
	public static final int MULTIPLE = 1;
	
	protected int cardinality;
	protected Presenca presencas[];
	
	/** Creates a new instance of DesmarcadoSHSTAction */
	public DesmarcadoSHSTAction( int cardinality, Presenca presencas[] )
	{
		super( cardinality == SINGLE ? "SIPRP Desmarcou" : "Marcar restantes como \"SIPRP desmarcou\"" );
		this.cardinality = cardinality;
		this.presencas = presencas;
	}

	public void actionPerformed(ActionEvent e)
	{
		try
		{
			PresencasDataProvider provider = PresencasDataProvider.getProvider();
			for( int n = 0; n < presencas.length; n++ )
			{
				provider.marcarDesmarcadoSHST( presencas[ n ].getID() );
			}
			if( cardinality == SINGLE )
			{
				setEnabled( false );
			}
		}
		catch( Exception ex )
		{
			DialogException.showExceptionMessage( ex, "Erro a marcar", true );
		}
	}
	
}
