/* PasteSpecialHandler.java

{{IS_NOTE
	Purpose:
		
	Description:
		
	History:
		2013/8/5 , Created by dennis
}}IS_NOTE

Copyright (C) 2013 Potix Corporation. All Rights Reserved.

{{IS_RIGHT
}}IS_RIGHT
*/
package org.zkoss.zssex.ui.impl.ua;

import org.zkoss.util.resource.Labels;
import org.zkoss.zss.api.IllegalOpArgumentException;
import org.zkoss.zss.api.Range;
import org.zkoss.zss.api.AreaRef;
import org.zkoss.zss.api.Range.PasteOperation;
import org.zkoss.zss.api.Range.PasteType;
import org.zkoss.zss.api.Ranges;
import org.zkoss.zss.api.model.Sheet;
import org.zkoss.zss.ui.UserActionContext;
import org.zkoss.zss.ui.UserActionContext.Clipboard;

/**
 * @author dennis
 *
 */
public class PasteSpecialHandler extends AbstractPasteSpecialHandler {
	private static final long serialVersionUID = 6005845018927840123L;
	private final PasteType _type;
	private final PasteOperation _operation;
	private final boolean _skipBlank;
	private final boolean _transpose;
	
	
	
	public PasteSpecialHandler(PasteType type, PasteOperation operation,
			boolean skipBlank, boolean transpose) {
		this._type = type;
		this._operation = operation;
		this._skipBlank = skipBlank;
		this._transpose = transpose;
	}



	@Override
	protected boolean processAction(final UserActionContext ctx) {
		final Sheet sheet = ctx.getSheet();
		final AreaRef selection = ctx.getSelection();
		final Range range = Ranges.range(sheet,selection);
		if(range.isProtected())
			return true;
		Clipboard cb = ctx.getClipboard();
		if(cb==null){
			showInfoMessage(Labels.getLabel("zss.actionhandler.msg.cant_find_thing_to_paste"));
			return true;
		}
		if(cb.isCutMode()){
			throw new IllegalOpArgumentException("Cannot support paste special for cut");
		}
		
		doPaste(ctx,_type, _operation, _skipBlank, _transpose);
		
		return true;
	}
}
