package nc.ui.wa.ruleex.action;

import java.awt.event.ActionEvent;

import javax.swing.Action;

import nc.bs.logging.Logger;
import nc.hr.utils.ResHelper;
import nc.itf.hr.wa.IHRWAActionCode;
import nc.ui.hr.uif2.action.BodyTabAction;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.UITable;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillModel;
import nc.ui.uif2.editor.IEditor;
import nc.ui.wa.ruleex.view.WaRuleForm;
import nc.uitheme.ui.ThemeResourceCenter;
import nc.vo.hrwa.waruleex.WageformdetExVO;

/**
 * 上移行Action<BR>
 * <BR>
 *
 * @author: xuhw
 * @date: 2009-11-10
 * @since: eHR V6.0
 * @走查人:
 * @走查日期:
 * @修改人:
 * @修改日期:
 */
public class WaRuleUpLineAction extends BodyTabAction
{
	/**
	 * @author xuhw on 2009-12-16
	 */
	private static final long serialVersionUID = 200912120912L;

	private IEditor editor;

	/**
	 * 初始化按钮
	 */
	public WaRuleUpLineAction()
	{
		super();
		setBtnName(ResHelper.getString("60130payrule","060130payrule0008")/*@res "上移行"*/);
		setCode(IHRWAActionCode.Up);
		// putValue(Action.ACCELERATOR_KEY,
		// KeyStroke.getKeyStroke(KeyEvent.VK_U, Event.CTRL_MASK));
		putValue(Action.SHORT_DESCRIPTION, ResHelper.getString("60130payrule","060130payrule0008")/*@res "上移行"*/);
		putValue(Action.SMALL_ICON, 
				ThemeResourceCenter.getInstance().getImage("themeres/ui/toolbaricons/move_up.png"));
	}

	@Override
	public void doAction(ActionEvent e) throws Exception
	{
		BillCardPanel billCardPanel = ((WaRuleForm) this.getEditor()).getBillCardPanel();
		BillModel billModel = billCardPanel.getBillModel();
		UITable table = billCardPanel.getBillTable();
		// 当前选中的子表的行数
		int intSelectedIndex = table.getSelectedRow();
		// 取得选中的子表的vo
		WageformdetExVO wageFormDetVO = (WageformdetExVO) billModel.getBodyValueRowVO(intSelectedIndex, WageformdetExVO.class.getName());
		// 取得子表所有的VO
		WageformdetExVO[] wageFormDetVOs = (WageformdetExVO[]) billModel.getBodyValueVOs(WageformdetExVO.class.getName());

		// //用户未选中行
		if (intSelectedIndex == -1)
		{
			Logger.debug("请先选中要移动的行数。");
			MessageDialog.showHintDlg(getModel().getContext().getEntranceUI(), null, ResHelper.getString("60130payrule","060130payrule0003")/*@res "请先选中要移动的行。"*/);
			return;
		}
		// //如果已是第一行
		else if (intSelectedIndex == 0)
		{
			Logger.debug("第一行不能向上移动。");
			MessageDialog.showHintDlg(getModel().getContext().getEntranceUI(), null, ResHelper.getString("60130payrule","060130payrule0009")/*@res "第一行不能向上移动。"*/);
			return;
		}

		// 取得选中的子表的vo
		wageFormDetVOs[intSelectedIndex] = wageFormDetVOs[intSelectedIndex - 1];
		wageFormDetVOs[intSelectedIndex - 1] = wageFormDetVO;
		wageFormDetVOs[intSelectedIndex].setIlevel(Integer.valueOf(intSelectedIndex + 1));
		wageFormDetVOs[intSelectedIndex - 1].setIlevel(Integer.valueOf(intSelectedIndex));
		billModel.setBodyDataVO(wageFormDetVOs);
		table.setRowSelectionInterval(intSelectedIndex - 1, intSelectedIndex - 1);

	}

	public IEditor getEditor()
	{
		return editor;
	}

	public void setEditor(IEditor editor)
	{
		this.editor = editor;
	}
}