/* DeleteCommentHandler.java

	Purpose:
		
	Description:
		
	History:
		Wed, Dec 17, 2014 10:27:56 AM, Created by JerryChen

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

*/
package org.zkoss.zssex.ui.impl.ua;

import org.zkoss.util.resource.Labels;
import org.zkoss.zss.api.AreaRef;
import org.zkoss.zss.api.Ranges;
import org.zkoss.zss.api.model.Book;
import org.zkoss.zss.api.model.Sheet;
import org.zkoss.zss.ui.UserActionContext;
import org.zkoss.zss.ui.impl.ua.AbstractCellHandler;
import org.zkoss.zss.ui.sys.UndoableActionManager;
import org.zkoss.zssex.ui.impl.undo.CellCommentAction;

/**
 * 
 * @author JerryChen
 * @since 3.7.0
 */
public class DeleteCommentHandler extends AbstractCellHandler {
	private static final long serialVersionUID = 5338583594307137935L;

	/* (non-Javadoc)
	 * @see org.zkoss.zss.ui.sys.ua.impl.AbstractHandler#processAction(org.zkoss.zss.ui.UserActionContext)
	 */
	@Override
	protected boolean processAction(final UserActionContext ctx) {
		final Sheet sheet = ctx.getSheet();
		final AreaRef selection = ctx.getSelection();
		final int row = selection.getRow();
		final int column = selection.getColumn();

		UndoableActionManager uam = ctx.getSpreadsheet().getUndoableActionManager();
		uam.doAction(new CellCommentAction(Labels.getLabel("zss.undo.insertComment"),sheet,row,column,row,column,null));
		return true;
	}

	@Override
	public boolean isEnabled(Book book, Sheet sheet) {
		return book != null && sheet != null && 
			!(sheet.isProtected() && !Ranges.range(sheet).getSheetProtection().isObjectsEditable());
	}
	
	
}