/*
 * Copyright (C) 2005 NTT DATA Corporation
 * 
 */
package org.postgresforest.tool.dialog.partition;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Item;
import org.postgresforest.tool.bean.ServerPartition2Info;

/**
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Partition2ColumnCellModifier implements ICellModifier {
	private TableViewer viewer;
	
	
	public Partition2ColumnCellModifier(TableViewer viewer) {
		this.viewer = viewer;
	}
	
	public boolean canModify(Object element, String property) {
		return true;
	}
	
	public Object getValue(Object element, String property) {
		
		if( property != null ){
			ServerPartition2Info info = (ServerPartition2Info)element;
			return info.getMakeInstance(Integer.parseInt(property));
		}
		return Boolean.TRUE;
	}
	
	public void modify(Object element, String property, Object value) {
		if (element instanceof Item) {
			element = ((Item) element).getData();
		}

		ServerPartition2Info info = (ServerPartition2Info)element;
		info.setMakeInstance(Integer.parseInt(property),(Boolean)value);

		
		// テーブル・ビューワを更新
		viewer.update(element, null);
		viewer.setSelection(new isele());
	}

	class isele implements ISelection{
		
	
			/* (非 Javadoc)
		 * @see org.eclipse.jface.viewers.ISelection#isEmpty()
		 */
		public boolean isEmpty() {
			// TODO 自動生成されたメソッド・スタブ
			return false;
		}
}
	
}