/**
 * @(#)RUnitChooseCEC.java
 * Copyright 2001 Nomura Research Institute, LTD. All rights reserved.
 * RID-3 : Rid Unit Choose Cell Editor Component
 * @author  Intelligent Technology Inc.
 * @version 1.00 2001/10/01-2002/03/26
 * @see iUnitReloadable
 */
package	jp.co.nri.rid.table.editor;

//import	java.awt.*;
//import	java.awt.event.*;
//import	javax.swing.*;
import	java.util.*;

import jp.co.nri.rid.xml.*;
import java.awt.event.*;

/**
 * ユニットを選ぶセルエディタ/レンダラコンポーネント(コンボボックス)
 */
public class RUnitChooseCEC extends ChooseCEC implements iUnitReloadable{
	protected static final String KEY = "Key";
	protected String[] myUnits;
	
	/**
	 * @param	items		リスト配列。
	 * @param	editable	編集可否。
	 * @param	listener	アクションリスナー。
	 * @since	1.00
	 */
	public RUnitChooseCEC(String[] items ,boolean editable ,ActionListener listener){
		super(editable ,listener);
		Vector vec = new Vector(Arrays.asList(items));
		vec.remove(0);
		myUnits = (String[])vec.toArray(new String[0]);
	}
	
	/**
	 * リストを読み直す。
	 * @since	1.00
	 */
    public void	reload(elementBooster element){
		pauseCECAdapter();
		
		removeAllItems();
		addItem("");
		
		String text = text();
		
		int mx = myUnits.length;
		for(int i=0;i<mx;i++){
			elementBooster[] units = element.offspring(myUnits[i]);
			if(null==units)	continue;
			int mx2 = units.length;
			for(int j=0;j<mx2;j++) addItem(units[j].attribute(KEY));
		}
		
		text(text);
		
		playCECAdapter();
	}
}
