package rhogenwizard.preferences;

import java.util.List;

import org.eclipse.ui.IWorkbench;
import rhogenwizard.Activator;

public class RhogenPreferencePage extends BasePreferencePage 
{
	PreferenceInitializer		   m_pInit = null;
	private RhogenComboFieldEditor m_selectCombo = null;
	
	public RhogenPreferencePage() 
	{
		super(GRID);
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
		setDescription("Rhodes rhobuild.yml preferences");
	}
	
	@Override
	public boolean performOk()
	{
		boolean ret = super.performOk();
		m_pInit.savePreferences();
		return ret;
	}

	private String[][] prepareComboItems()
	{
		checkRhodesSdk();
		
		List<String> projNames = PreferenceInitializer.getInstance().getRhodesProjects();

//		if (projNames == null || projNames.size() == 0)
//		{
//			MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.OK); 
//			messageBox.setText("Error");
//			messageBox.setMessage(MsgConstants.errNotFoundRhodesSdk);
//			messageBox.open();				
//			
//			return null;
//		}
		
		String[][] comboItems = new String[projNames.size()][];
		
		for (int i=0; i<projNames.size(); ++i)
		{
			String ver = projNames.get(i);
			String[] newItem = {ver, ver};
			comboItems[i] = newItem;
		}
		
		return comboItems;
	}
	
	/**
	 * Creates the field editors. Field editors are abstractions of
	 * the common GUI blocks needed to manipulate various types
	 * of preferences. Each field editor knows how to save and
	 * restore itself.
	 */
	public void createFieldEditors() 
	{
		String[][] comboItems = prepareComboItems();
		
//		if (comboItems == null)
//		{
//			String[][] emptyComboItems = {{"",""}};
//			comboItems = emptyComboItems;
//		}
//		
//		m_selectCombo = new RhogenComboFieldEditor(PreferenceConstants.BB_VERSION, 
//							"Project:", comboItems, getFieldEditorParent());
//		m_selectCombo.setSelectionListener(new SelectionAdapter() 
//		{
//			@Override
//			public void widgetSelected(SelectionEvent e)
//			{
//				try 
//				{
//					String projectName = m_selectCombo.getCombo().getText();
//					m_pInit.initFromProject(projectName);
//				} 
//				catch (Exception e1) 
//				{
//					e1.printStackTrace();
//				}
//			}
//		});
//		addField(m_selectCombo);
		
		addField(new RhogenDirectoryFieldEditor(PreferenceConstants.JAVA_PATH, 
				"&Java path:", getFieldEditorParent()));
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
	 */
	public void init(IWorkbench workbench) 
	{
		m_pInit = PreferenceInitializer.getInstance();
	}	
}
@@ -733,307 +733,8 @@
 s();
-%0A%0A//%09%09if (projNames == null %7C%7C projNames.size() == 0)%0A//%09%09%7B%0A//%09%09%09MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING %7C SWT.OK); %0A//%09%09%09messageBox.setText(%22Error%22);%0A//%09%09%09messageBox.setMessage(MsgConstants.errNotFoundRhodesSdk);%0A//%09%09%09messageBox.open();%09%09%09%09%0A//%09%09%09%0A//%09%09%09return null;%0A//%09%09%7D
 %0A%09%09%0A

remove unused code