/* $Id: RemoveAction.java 268 2011-07-19 10:00:29Z shayashi $ */
package smart_gs.image_search.normal.swingui;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import smart_gs.image_search.logical.SearchResult;

/*
 * 20071111 田村
 * "Remove" にチェックが入ったときのアクション
 */
public class RemoveAction implements ItemListener {
    private SearchResult result;
    private SearchResultViewer parent;

    public RemoveAction(SearchResultViewer parent, SearchResult searchResult) {
	// TODO Auto-generated constructor stub
	this.result = searchResult;
	this.parent = parent;
    }

    public void itemStateChanged(ItemEvent arg0) {
	// TODO Auto-generated method stub
	// 外したい候補が既に bucket に入っているときはまずそれを bucket から消す
	// if (!parent.getSelectedResults().contains(result)) {
	    if (arg0.getStateChange() == ItemEvent.SELECTED) {
		/*if (parent.getSelectedResults().contains(result)) {
		    parent.getBucket().remove(parent.getSelectedResults().indexOf(result) + 1);
		    parent.getSelectedResults().remove(result);
		    parent.updateBucket(false);
		}*/
		// parent.getBucket().add(result.toQuery());
		parent.getRemovedResults().add(result);
		parent.updateRemoved();
	    } else if (parent.getRemovedResults().contains(result)) {
		// parent.getBucket().remove(parent.getSelectedResults().indexOf(result) + 1);
		parent.getRemovedResults().remove(result);
		parent.updateRemoved();
	    }
	//}

    }
}
