package aji;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
//import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;


/*
 * InsertWindow.java レシピ登録画面
 * 作成日: 2005/11/04
 *
 * TODO この生成されたファイルのテンプレートを変更するには次へジャンプ:
 * ウィンドウ - 設定 - Java - コード・スタイル - コード・テンプレート
 */

/**z
 * @author yui
 *
 * TODO この生成された型コメントのテンプレートを変更するには次へジャンプ:
 * ウィンドウ - 設定 - Java - コード・スタイル - コード・テンプレート
 */

//材料検索
public class SearchMate{
		Singleton instance = Singleton.getInstance();
		private Composite c1;
		private Text[] HiraText = new Text[21];
		private Text[] SuuText = new Text[24];
		private Combo cm1,cm2,cm3;
		private List list1;
		private int getComboBig,getComboMiddle;
		private String Bigitem[] = {"野菜","肉類","魚類","その他"};
		
		private String Miditem[][] = {	{"きゅうり","とまと"},
										{"豚","牛","鳥"},
										{"さんま","あじ"},
										{"卵","ちーず"},
										{""}
									};
		//0-野菜1-肉2-魚3-その他
		private String Smlitem[][] = {	{"ちち","しり","ふともも"},
										{"ロース","カルビ","ればー"},
										{""}
									};


		public SearchMate(){


//####ここのレイアウト
		    c1 = new Composite(instance.getShell(), SWT.NULL); // shellが親
		    GridData gridDataText = new GridData(GridData.FILL);
		    gridDataText.widthHint = 3000; // 横幅を最低300確保
		    c1.setLayoutData(gridDataText);
		    c1.setSize(800,536);
		     
//####コンボ		    
		    
		    makeComboBig();
		    makeComboMiddle();
		    makeComboSmall();
		    
//####リスト		    
		    
		    list1 = new List(c1,SWT.MULTI|SWT.BORDER|SWT.V_SCROLL);
		    list1.setBounds(300,0,100,100);
		    
//####適応
		    
		    Button accept = new Button(c1,SWT.PUSH);
		    accept.setBounds(100,0,100,30);
		    accept.setText("追加");
		    accept.addSelectionListener(new SelectionAdapter(){
		    	  public void widgetSelected(SelectionEvent e){
		    	  	
		    	  	if(cm1.getText() != ""){
		    	  		if(cm2.getText() != ""){
		    	  			if(cm3.getText() != "") list1.add(cm2.getText() + cm3.getText());
		    	  			else list1.add(cm2.getText());
		    	  			
		    	  		}
		    	  	}
		    	  	for(int i=0;i<list1.getItemCount();i++)
	    	  		System.out.println("###"+list1.getItems()[i]);
		    	  	
		    	  }
		    });
		    
		    
		    Button accept2 = new Button(c1,SWT.PUSH);
		    accept2.setBounds(100,36,100,30);
		    accept2.setText("削除");
		    accept2.addSelectionListener(new SelectionAdapter(){
		    	  public void widgetSelected(SelectionEvent e){
		    	    list1.remove(list1.getSelectionIndices());
		    	  }
		    }); 
		    
		    Button accept3 = new Button(c1,SWT.PUSH);
		    accept3.setBounds(300,300,30,30);
		    accept3.setText("送信");
		    accept3.addSelectionListener(new SelectionAdapter(){
		    	  public void widgetSelected(SelectionEvent e){
		    	  	if(list1.getItemCount() != 0){
		    	  	//System.out.println(list1.getItems());
		    	  		String [] ssss = list1.getItems();
		    	  		for(int xxx=0;xxx<ssss.length;xxx++)
		    	  			System.out.println(ssss[xxx]);
		    	  		visiWin();
		    	  	new SearchMateList().make_SearchMateList();
		    	  	}
		    	  }
		    });
		    c1.setVisible(true);
	}

		int a = 4,b = 2;

		public void makeComboBig(){
	
			cm1 = new Combo(c1,SWT.DROP_DOWN | SWT.READ_ONLY);
			cm1.setBounds(0,0,100,30);
			cm1.setItems(Bigitem);
		    cm1.addSelectionListener(new SelectionAdapter(){
		    	  public void widgetSelected(SelectionEvent e){
		    	  
		    	  	System.out.println("1 - " + cm1.getText());
		    	  	a = cm1.getSelectionIndex();
		    	  	cm2.setItems(Miditem[a]);
		    	  	cm3.setItems(Smlitem[2]);
		    	  }
				  
		    });
			
		    
		}
		
		public void makeComboMiddle(){
			
			cm2 = new Combo(c1,SWT.DROP_DOWN | SWT.READ_ONLY);
			cm2.setBounds(0,20,100,30);
			cm2.setItems(Miditem[a]);
			cm2.addSelectionListener(new SelectionAdapter(){
				    public void widgetSelected(SelectionEvent e){
				    	  
				    	System.out.println("2 - " + cm2.getText());
				    	b = cm2.getSelectionIndex();
				    	//0:豚　1:牛
				    	if(b == 1 && a == 1){
				    		cm3.setItems(Smlitem[1]);
				    	}else if(b == 0 && a == 1){
				    		cm3.setItems(Smlitem[0]);
				    	}else{
				    		cm3.setItems(Smlitem[2]);
				    	}
				    	  	
				    }
			});
			
		}
		
		public void makeComboSmall(){
			
			cm3 = new Combo(c1,SWT.DROP_DOWN | SWT.READ_ONLY);
			cm3.setBounds(0,40,100,30);
			cm3.setItems(Smlitem[b]);
			cm3.addSelectionListener(new SelectionAdapter(){
				    public void widgetSelected(SelectionEvent e){
				    	if(a == 1 && b == 1){
				    		System.out.println("3 - " + cm3.getText());
				    	}else if(a == 1 && b == 0){
				    		System.out.println("3 - " + cm3.getText());
				    	}else{
				    		e.doit = false;
				    		if(e.doit) System.out.println("3 - " + cm3.getText());
				    	}
				    	  	
				    }
			});
					
			
		}
		
		public void visiWin(){
			c1.setVisible(false);
		}
}
