core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/sdk/ui/SDKPreferencePage.java
branchC3_BUILDER_WORK
changeset 1421 587da7cb64b7
parent 1352 2953a4d4c5d9
child 1431 536cdcdc768b
equal deleted inserted replaced
1419:ab555eecf681 1421:587da7cb64b7
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 package com.nokia.carbide.cpp.internal.sdk.ui;
    17 package com.nokia.carbide.cpp.internal.sdk.ui;
    18 
    18 
    19 import java.io.*;
    19 import java.io.File;
    20 import java.util.*;
    20 import java.text.MessageFormat;
       
    21 import java.util.Iterator;
    21 import java.util.List;
    22 import java.util.List;
    22 
    23 
       
    24 import org.eclipse.core.runtime.IPath;
       
    25 import org.eclipse.core.runtime.Path;
       
    26 import org.eclipse.core.runtime.jobs.IJobChangeEvent;
       
    27 import org.eclipse.core.runtime.jobs.IJobChangeListener;
    23 import org.eclipse.jface.dialogs.MessageDialog;
    28 import org.eclipse.jface.dialogs.MessageDialog;
    24 import org.eclipse.jface.preference.IPreferenceStore;
    29 import org.eclipse.jface.preference.IPreferenceStore;
    25 import org.eclipse.jface.preference.PreferencePage;
    30 import org.eclipse.jface.preference.PreferencePage;
    26 import org.eclipse.jface.viewers.*;
    31 import org.eclipse.jface.viewers.ArrayContentProvider;
       
    32 import org.eclipse.jface.viewers.CellEditor;
       
    33 import org.eclipse.jface.viewers.CheckboxTableViewer;
       
    34 import org.eclipse.jface.viewers.ColumnViewer;
       
    35 import org.eclipse.jface.viewers.EditingSupport;
       
    36 import org.eclipse.jface.viewers.ISelectionChangedListener;
       
    37 import org.eclipse.jface.viewers.IStructuredSelection;
       
    38 import org.eclipse.jface.viewers.ITableLabelProvider;
       
    39 import org.eclipse.jface.viewers.LabelProvider;
       
    40 import org.eclipse.jface.viewers.SelectionChangedEvent;
       
    41 import org.eclipse.jface.viewers.StructuredSelection;
       
    42 import org.eclipse.jface.viewers.TableViewerColumn;
       
    43 import org.eclipse.jface.viewers.TextCellEditor;
    27 import org.eclipse.swt.SWT;
    44 import org.eclipse.swt.SWT;
    28 import org.eclipse.swt.events.*;
    45 import org.eclipse.swt.events.SelectionAdapter;
       
    46 import org.eclipse.swt.events.SelectionEvent;
       
    47 import org.eclipse.swt.events.SelectionListener;
    29 import org.eclipse.swt.graphics.Color;
    48 import org.eclipse.swt.graphics.Color;
    30 import org.eclipse.swt.graphics.Image;
    49 import org.eclipse.swt.graphics.Image;
    31 import org.eclipse.swt.layout.GridData;
    50 import org.eclipse.swt.layout.GridData;
    32 import org.eclipse.swt.layout.GridLayout;
    51 import org.eclipse.swt.layout.GridLayout;
    33 import org.eclipse.swt.widgets.*;
    52 import org.eclipse.swt.widgets.Button;
    34 import org.eclipse.ui.*;
    53 import org.eclipse.swt.widgets.Composite;
       
    54 import org.eclipse.swt.widgets.Control;
       
    55 import org.eclipse.swt.widgets.DirectoryDialog;
       
    56 import org.eclipse.swt.widgets.Display;
       
    57 import org.eclipse.swt.widgets.Label;
       
    58 import org.eclipse.swt.widgets.Shell;
       
    59 import org.eclipse.swt.widgets.Table;
       
    60 import org.eclipse.swt.widgets.Text;
       
    61 import org.eclipse.ui.ISharedImages;
       
    62 import org.eclipse.ui.IWorkbench;
       
    63 import org.eclipse.ui.IWorkbenchPreferencePage;
       
    64 import org.eclipse.ui.PlatformUI;
    35 
    65 
    36 import com.nokia.carbide.cpp.internal.api.sdk.SymbianBuildContextDataCache;
    66 import com.nokia.carbide.cpp.internal.api.sdk.SymbianBuildContextDataCache;
    37 import com.nokia.carbide.cpp.internal.sdk.core.model.SDKManager;
    67 import com.nokia.carbide.cpp.internal.sdk.core.model.SDKManager;
    38 import com.nokia.carbide.cpp.sdk.core.*;
    68 import com.nokia.carbide.cpp.sdk.core.ISDKManager;
       
    69 import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
       
    70 import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
    39 import com.nokia.carbide.cpp.sdk.ui.SDKUIPlugin;
    71 import com.nokia.carbide.cpp.sdk.ui.SDKUIPlugin;
    40 import com.nokia.carbide.cpp.sdk.ui.shared.AddSDKDialog;
    72 import com.nokia.carbide.cpp.sdk.ui.shared.AddSDKDialog;
       
    73 import com.nokia.carbide.cpp.ui.TextAndDialogCellEditor;
       
    74 import com.nokia.cpp.internal.api.utils.ui.BrowseDialogUtils;
    41 
    75 
    42 public class SDKPreferencePage
    76 public class SDKPreferencePage
    43 	extends PreferencePage
    77 	extends PreferencePage
    44 	implements IWorkbenchPreferencePage {
    78 	implements IWorkbenchPreferencePage {
    45 	
    79 	
    46 	ISDKManager sdkMgr;
    80 	private class SDKLabelProvider extends LabelProvider implements ITableLabelProvider {
       
    81 		public Image getColumnImage(Object element, int columnIndex) {
       
    82 			return null;
       
    83 		}
       
    84 
       
    85 		public String getColumnText(Object element, int columnIndex) {
       
    86 			ISymbianSDK sdk = (ISymbianSDK) element;
       
    87 			switch (columnIndex) {
       
    88 			case 1:
       
    89 				return sdk.getUniqueId();
       
    90 			case 2:
       
    91 				return sdk.getEPOCROOT();
       
    92 			default:
       
    93 				return "";
       
    94 			}
       
    95 		}
       
    96 	}
       
    97 
       
    98 	private class IdEditingSupport extends EditingSupport {
       
    99 		private TextCellEditor editor;
       
   100 
       
   101 		public IdEditingSupport(ColumnViewer viewer) {
       
   102 			super(viewer);
       
   103 			editor = new TextCellEditor((Composite) viewer.getControl());
       
   104 		}
       
   105 
       
   106 		@Override
       
   107 		protected boolean canEdit(Object element) {
       
   108 			if (element instanceof ISymbianSDK) {
       
   109 				return true;
       
   110 			}
       
   111 			return false;
       
   112 		}
       
   113 
       
   114 		@Override
       
   115 		protected CellEditor getCellEditor(Object element) {
       
   116 			return editor;
       
   117 		}
       
   118 
       
   119 		@Override
       
   120 		protected Object getValue(Object element) {
       
   121 			ISymbianSDK sdk = (ISymbianSDK) element;
       
   122 			return sdk.getUniqueId();
       
   123 		}
       
   124 
       
   125 		@Override
       
   126 		protected void setValue(Object element, Object value) {
       
   127 			ISymbianSDK sdk = (ISymbianSDK) element;
       
   128 			sdk.setUniqueID(value.toString());
       
   129 			SDKCorePlugin.getSDKManager().updateSDK(sdk);
       
   130 			getViewer().refresh();
       
   131 		}
       
   132 	}
       
   133 
       
   134 	private class LocationEditingSupport extends EditingSupport {
       
   135 		private LocationCellEditor editor;
       
   136 
       
   137 		public LocationEditingSupport(ColumnViewer viewer) {
       
   138 			super(viewer);
       
   139 			editor = new LocationCellEditor((Composite) viewer.getControl());
       
   140 		}
       
   141 
       
   142 		@Override
       
   143 		protected boolean canEdit(Object element) {
       
   144 			if (element instanceof ISymbianSDK) {
       
   145 				return true;
       
   146 			}
       
   147 			return false;
       
   148 		}
       
   149 
       
   150 		@Override
       
   151 		protected CellEditor getCellEditor(Object element) {
       
   152 			return editor;
       
   153 		}
       
   154 
       
   155 		@Override
       
   156 		protected Object getValue(Object element) {
       
   157 			ISymbianSDK sdk = (ISymbianSDK) element;
       
   158 			return sdk.getEPOCROOT();
       
   159 		}
       
   160 
       
   161 		@Override
       
   162 		protected void setValue(Object element, Object value) {
       
   163 			ISymbianSDK sdk = (ISymbianSDK) element;
       
   164 			sdk.setEPOCROOT(value.toString());
       
   165 			SDKCorePlugin.getSDKManager().updateSDK(sdk);
       
   166 			getViewer().refresh();
       
   167 		}
       
   168 	}
       
   169 
       
   170 	private class LocationCellEditor extends TextAndDialogCellEditor {
       
   171 		private Button button;
       
   172 		private Text text;
       
   173 
       
   174 		public LocationCellEditor(Composite parent) {
       
   175 			super(parent);
       
   176 		}
       
   177 
       
   178 		@Override
       
   179 		protected Control createContents(Composite parent) {
       
   180 			text = (Text) super.createContents(parent);
       
   181 			return text;
       
   182 		}
       
   183 
       
   184 		@Override
       
   185 		protected Control createControl(Composite parent) {
       
   186 			Control control = super.createControl(parent);
       
   187 			button = getButton();
       
   188 			button.setText(Messages.getString("SDKPreferencePage.Browse_Location_Label")); //$NON-NLS-1$
       
   189 			return control;
       
   190 		}
       
   191 
       
   192 		@Override
       
   193 		protected Object openDialogBox(Control cellEditorWindow) {
       
   194 			DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN);
       
   195 			BrowseDialogUtils.initializeFrom(dialog, text);
       
   196 			return dialog.open();
       
   197 		}		
       
   198 	}
       
   199 
       
   200 	private class ScanJobListener implements IJobChangeListener {
       
   201 		public void done(IJobChangeEvent event) {
       
   202 			Display.getDefault().asyncExec(new Runnable() {
       
   203 				public void run() {
       
   204 					rescanSDKs();
       
   205 				}
       
   206 			});
       
   207 		}
       
   208 
       
   209 		public void aboutToRun(IJobChangeEvent event) {}
       
   210 		public void awake(IJobChangeEvent event) {}
       
   211 		public void running(IJobChangeEvent event) {}
       
   212 		public void scheduled(IJobChangeEvent event) {}
       
   213 		public void sleeping(IJobChangeEvent event) {}
       
   214 		
       
   215 	}
       
   216 
       
   217 	private IPreferenceStore prefsStore;
       
   218 	private ISDKManager sdkMgr;
       
   219 	private List<ISymbianSDK> sdkList;
       
   220 	private ScanJobListener scanJobListner;
       
   221 	private boolean scanForNewPlugins;
    47 	private CheckboxTableViewer sdkListTableViewer;
   222 	private CheckboxTableViewer sdkListTableViewer;
    48 	private List<ISymbianSDK> sdkList; 
   223 	private Button addButton;
    49 	private Button sdkpropertiesButton;
   224 	private Button deleteButton;
    50 	private Button removeSdkButton;
   225 	private Button propertiesButton;
    51 	private Button addNewSdkButton;
   226 	private Button scanForNewPluginsButton;
    52 	private Button rescanNowButton;
   227 	private Button rescanButton;
    53 	
   228 	private Label iconLabel;
    54 	private Label epocrootLabel;
   229 	private Label statusLabel;
    55 	private Label availablePlatformsLabel;
   230 
    56 	private Label osVersionLabel;
   231 	private Color red;
    57 	private Label diagnosticCheckLabel;
   232 	private Color black;
    58 	
   233 	private Color gray;
    59 	private Button listenForDevicesXMLChangeButton;
   234 
    60 	
   235 	/**
    61 	private static final String EPOCROOT_LABEL = "EPOCROOT: ";	//$NON-NLS-1$
   236 	 * Constructor.
    62 	private static final String PLATFORMS_LABEL = "Available Platforms: "; //$NON-NLS-1$
   237 	 */
    63 	private static final String DIAGNOSTIC_CHECK_LABEL = "Diagnostic Check: "; //$NON-NLS-1$
       
    64 	private static final String OS_VERSION_LABEL = "OS Version: "; //$NON-NLS-1$
       
    65 	
       
    66 	private Color RED;
       
    67 	private Color BLACK;
       
    68 	private Color GRAY;
       
    69 	Shell shell;
       
    70 	
       
    71 	public SDKPreferencePage() {
   238 	public SDKPreferencePage() {
    72 		super();
   239 		super();
    73 		
   240 		scanJobListner = new ScanJobListener();
    74 	}
   241 	}
    75 	
   242 
    76 	@Override
   243 	/*
    77 	protected Control createContents(Composite parent) {
   244 	 * (non-Javadoc)
    78 		return null;
   245 	 * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
    79 	}
       
    80 
       
    81 	/* (non-Javadoc)
       
    82 	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
       
    83 	 */
   246 	 */
    84 	public void init(IWorkbench workbench) {
   247 	public void createControl(Composite parent){
    85 	}
   248 		prefsStore = SDKUIPlugin.getDefault().getPreferenceStore();
    86 	
       
    87 	/* (non-Javadoc)
       
    88 	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
       
    89 	 */
       
    90 	public void createControl(Composite parent) {
       
    91 		
       
    92 		IPreferenceStore prefsStore = SDKUIPlugin.getDefault().getPreferenceStore();
       
    93 		sdkMgr = SDKCorePlugin.getSDKManager();
   249 		sdkMgr = SDKCorePlugin.getSDKManager();
    94 		if (sdkMgr == null){
   250 		if (sdkMgr == null){
    95 			return; 
   251 			return; 
    96 		}
   252 		}
    97 		
       
    98 		shell = parent.getShell();
       
    99 		sdkList = sdkMgr.getSDKList();
   253 		sdkList = sdkMgr.getSDKList();
   100 		RED = shell.getDisplay().getSystemColor(SWT.COLOR_RED);
   254 		if (sdkMgr instanceof SDKManager) {
   101 		BLACK = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK);
   255 			SDKManager mgr = (SDKManager) sdkMgr;
   102 		GRAY = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
   256 			mgr.addScanJobListner(scanJobListner);
   103 		
   257 		}
   104 		// check that devices.xml actually exists
   258 
   105 		if (sdkMgr instanceof SDKManager)
   259 		super.createControl(parent);
   106 			((SDKManager) sdkMgr).checkDevicesXMLExistAndCreate();
   260 
   107 		
   261 		// Hide "Restore Defaults" button
   108 		Composite content = new Composite(parent, SWT.NONE);
   262 		getDefaultsButton().setVisible(false);
   109 		setControl(content);
   263 
   110 		final GridLayout gridLayout = new GridLayout();
       
   111 		gridLayout.numColumns = 2;
       
   112 		content.setLayout(gridLayout);
       
   113 
       
   114 		final Group availableSymbianOsGroup = new Group(content, SWT.NONE);
       
   115 		availableSymbianOsGroup.setToolTipText(Messages.getString("SDKPreferencePage.OS_Group_ToolTip")); //$NON-NLS-1$
       
   116 		final GridData availableSymbianOsGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
       
   117 		availableSymbianOsGridData.widthHint = 350;
       
   118 		availableSymbianOsGroup.setText(Messages.getString("SDKPreferencePage.Available_SDKs_Label")); //$NON-NLS-1$
       
   119 		availableSymbianOsGroup.setLayoutData(availableSymbianOsGridData);
       
   120 		availableSymbianOsGroup.setLayout(new GridLayout());
       
   121 
       
   122 		sdkListTableViewer = CheckboxTableViewer.newCheckList(availableSymbianOsGroup, SWT.BORDER);
       
   123 		sdkListTableViewer.getTable().setLayoutData(availableSymbianOsGridData);
       
   124 		
       
   125 		final Composite composite = new Composite(content, SWT.NONE);
       
   126 		composite.setLayoutData(new GridData());
       
   127 		final GridLayout gridLayout_1 = new GridLayout();
       
   128 		gridLayout_1.makeColumnsEqualWidth = true;
       
   129 		composite.setLayout(gridLayout_1);
       
   130 
       
   131 		removeSdkButton = new Button(composite, SWT.NONE);
       
   132 		removeSdkButton.setToolTipText(Messages.getString("SDKPreferencePage.Delete_SDK_ToolTip")); //$NON-NLS-1$
       
   133 		final GridData gridData = new GridData(SWT.LEFT, SWT.TOP, true, false);
       
   134 		removeSdkButton.setLayoutData(gridData);
       
   135 		removeSdkButton.setText(Messages.getString("SDKPreferencePage.Remove_SDK_Label")); //$NON-NLS-1$
       
   136 		addButtonListener(removeSdkButton);
       
   137 		
       
   138 		addNewSdkButton = new Button(composite, SWT.NONE);
       
   139 		addNewSdkButton.setToolTipText(Messages.getString("SDKPreferencePage.Add_New_SDK_ToolTip")); //$NON-NLS-1$
       
   140 		addNewSdkButton.setLayoutData(gridData);
       
   141 		addNewSdkButton.setText(Messages.getString("SDKPreferencePage.Add_New_SDK_Label")); //$NON-NLS-1$
       
   142 		addButtonListener(addNewSdkButton);
       
   143 		
       
   144 		sdkpropertiesButton = new Button(composite, SWT.NONE);
       
   145 		sdkpropertiesButton.setToolTipText(Messages.getString("SDKPreferencePage.SDK_Props_Button_ToolTip")); //$NON-NLS-1$
       
   146 		sdkpropertiesButton.setLayoutData(gridData);
       
   147 		sdkpropertiesButton.setText(Messages.getString("SDKPreferencePage.SDK_Props_Button_Label")); //$NON-NLS-1$
       
   148 		addButtonListener(sdkpropertiesButton);
       
   149 		
       
   150 		final Group sdkInformationGroup = new Group(content, SWT.NONE);
       
   151 		sdkInformationGroup.setToolTipText(Messages.getString("SDKPreferencePage.SDK_Info_ToolTip")); //$NON-NLS-1$
       
   152 		final GridData sdkInfoGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
       
   153 		sdkInfoGridData.widthHint = 350;
       
   154 		sdkInformationGroup.setText(Messages.getString("SDKPreferencePage.SDK_Info_Label")); //$NON-NLS-1$
       
   155 		sdkInformationGroup.setLayoutData(sdkInfoGridData);
       
   156 		sdkInformationGroup.setLayout(new GridLayout());
       
   157 
       
   158 		epocrootLabel = new Label(sdkInformationGroup, SWT.WRAP);
       
   159 		epocrootLabel.setToolTipText(Messages.getString("SDKPreferencePage.EPOC32_Loc_ToolTip")); //$NON-NLS-1$
       
   160 		epocrootLabel.setLayoutData(new GridData(300, SWT.DEFAULT));
       
   161 		epocrootLabel.setText("EPOCROOT:"); //$NON-NLS-1$
       
   162 
       
   163 		osVersionLabel = new Label(sdkInformationGroup, SWT.WRAP);
       
   164 		osVersionLabel.setToolTipText(Messages.getString("SDKPreferencePage.OSVesions_ToolTip")); //$NON-NLS-1$
       
   165 		osVersionLabel.setLayoutData(new GridData(300, SWT.DEFAULT));
       
   166 		osVersionLabel.setText(Messages.getString("SDKPreferencePage.OSVersion_Label")); //$NON-NLS-1$
       
   167 
       
   168 		availablePlatformsLabel = new Label(sdkInformationGroup, SWT.WRAP);
       
   169 		availablePlatformsLabel.setToolTipText(Messages.getString("SDKPreferencePage.Platforms_ToolTip")); //$NON-NLS-1$
       
   170 		availablePlatformsLabel.setLayoutData(new GridData(300, SWT.DEFAULT));
       
   171 		availablePlatformsLabel.setText(Messages.getString("SDKPreferencePage.Available_Platforms")); //$NON-NLS-1$
       
   172 
       
   173 		diagnosticCheckLabel = new Label(sdkInformationGroup, SWT.WRAP);
       
   174 		diagnosticCheckLabel.setToolTipText(Messages.getString("SDKPreferencePage.Diagnostic_Check_ToolTip")); //$NON-NLS-1$
       
   175 		diagnosticCheckLabel.setLayoutData(sdkInfoGridData);
       
   176 		diagnosticCheckLabel.setText(Messages.getString("SDKPreferencePage.Diagnostic_Check_Label")); //$NON-NLS-1$
       
   177 		new Label(content, SWT.NONE);
       
   178 
       
   179 		listenForDevicesXMLChangeButton = new Button(content, SWT.CHECK);
       
   180 		listenForDevicesXMLChangeButton.setText(Messages.getString("SDKPreferencePage.listerForDevicesXML"));
       
   181 		listenForDevicesXMLChangeButton.setToolTipText(Messages.getString("SDKPreferencePage.listerForDevicesXML_Tooltip"));	//$NON-NLS-1$
       
   182 		listenForDevicesXMLChangeButton.setSelection(prefsStore.getBoolean(SDKUIPreferenceConstants.LISTEN_FOR_DEVICES_XML_CHANGE));
       
   183 		
       
   184 		new Label(content, SWT.WRAP); // filler
       
   185 		
       
   186 		rescanNowButton = new Button(content, SWT.NONE);
       
   187 		rescanNowButton.setToolTipText(Messages.getString("SDKPreferencePage.Rescan_Button_ToolTip")); //$NON-NLS-1$
       
   188 		rescanNowButton.setLayoutData(new GridData());
       
   189 		rescanNowButton.setText(Messages.getString("SDKPreferencePage.Rescan_Button_Label")); //$NON-NLS-1$
       
   190 		addButtonListener(rescanNowButton);
       
   191 		new Label(content, SWT.NONE);
       
   192 		
       
   193 		// Build the checked table of SDKs
       
   194 		addSDKComponentTableItems();
       
   195 		
       
   196 		ISymbianSDK sdk = (ISymbianSDK)sdkListTableViewer.getElementAt(0);
       
   197 		if (sdk != null){
       
   198 			sdkListTableViewer.setSelection(new StructuredSelection(sdk), true);
       
   199 			setSelectedSDKInfoText(sdk);
       
   200 		}
       
   201 		
       
   202 		
       
   203 		PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(), SDKUIHelpIds.SDK_PREFERENCES_PAGE);
   264 		PlatformUI.getWorkbench().getHelpSystem().setHelp(super.getControl(), SDKUIHelpIds.SDK_PREFERENCES_PAGE);
   204 	}
   265 	}
   205 	
   266 
       
   267 	/*
       
   268 	 * (non-Javadoc)
       
   269 	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
       
   270 	 */
       
   271 	public void dispose() {
       
   272 		if (sdkMgr != null && sdkMgr instanceof SDKManager){
       
   273 			SDKManager mgr = (SDKManager) sdkMgr;
       
   274 			mgr.removeScanJobLisner(scanJobListner);
       
   275 		}
       
   276 	}
       
   277 
       
   278 	/*
       
   279 	 * (non-Javadoc)
       
   280 	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
       
   281 	 */
       
   282 	public void init(IWorkbench arg0) {
       
   283 	}
       
   284 
       
   285 	/*
       
   286 	 * (non-Javadoc)
       
   287 	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
       
   288 	 */
   206 	public boolean performOk() {
   289 	public boolean performOk() {
   207 		
   290 		// Save preference page specific values;
   208 		IPreferenceStore prefsStore = SDKUIPlugin.getDefault().getPreferenceStore();
   291 		prefsStore.setValue(SDKUIPreferenceConstants.SCAN_FOR_NEW_PLUGINS, scanForNewPluginsButton.getSelection());
   209 		prefsStore.setValue(SDKUIPreferenceConstants.LISTEN_FOR_DEVICES_XML_CHANGE, listenForDevicesXMLChangeButton.getSelection());
   292 
   210 		
   293 		// Remember which SDK is enabled
   211 		for (ISymbianSDK sdk : sdkMgr.getSDKList()){
   294 		for (ISymbianSDK sdk : sdkMgr.getSDKList()){
   212 			sdk.setEnabled(false);
   295 			sdk.setEnabled(false);
   213 		}
   296 		}
   214 		Object[] sdkObjects = sdkListTableViewer.getCheckedElements();
   297 		Object[] sdkObjects = sdkListTableViewer.getCheckedElements();
   215 		for (Object currObj : sdkObjects){
   298 		for (Object currObj : sdkObjects){
   216 			if (currObj instanceof ISymbianSDK){
   299 			if (currObj instanceof ISymbianSDK){
   217 				ISymbianSDK sdk = (ISymbianSDK)currObj;
   300 				ISymbianSDK sdk = (ISymbianSDK)currObj;
   218 				sdk.setEnabled(true);
   301 				sdk.setEnabled(true);
   219 			}
   302 			}
   220 		}
   303 		}
       
   304 
       
   305 		// Update cached SDK info
       
   306 		sdkMgr.updateCarbideSDKCache();
       
   307 		return super.performOk();
       
   308 	}
       
   309 
       
   310 	/*
       
   311 	 * (non-Javadoc)
       
   312 	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
       
   313 	 */
       
   314 	@Override
       
   315 	protected Control createContents(Composite parent) {
       
   316 		// Set up colors used in this preference page
       
   317 		Shell shell = parent.getShell();
       
   318 		red = shell.getDisplay().getSystemColor(SWT.COLOR_RED);
       
   319 		black = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK);
       
   320 		gray = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
       
   321 
       
   322 		Composite content = new Composite(parent, SWT.NONE);
       
   323 		GridLayout gridLayout = new GridLayout();
       
   324 		gridLayout.numColumns = 2;
       
   325 		content.setLayout(gridLayout);
       
   326 
       
   327 		// SDK table
       
   328 		sdkListTableViewer = CheckboxTableViewer.newCheckList(content, 
       
   329 				SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
       
   330 		createSDKTable();
       
   331 
       
   332 		// Buttons composite
       
   333 		Composite composite1 = new Composite(content, SWT.NONE);
       
   334 		composite1.setLayoutData(new GridData());
       
   335 		gridLayout = new GridLayout();
       
   336 		gridLayout.makeColumnsEqualWidth = true;
       
   337 		composite1.setLayout(gridLayout);
       
   338 		GridData gridData = new GridData(SWT.LEFT, SWT.TOP, true, false);
       
   339 
       
   340 		// Add button
       
   341 		addButton = new Button(composite1, SWT.NONE);
       
   342 		addButton.setLayoutData(gridData);
       
   343 		addButton.setText(Messages.getString("SDKPreferencePage.Add_Button_Label")); //$NON-NLS-1$
       
   344 		addButton.setToolTipText(Messages.getString("SDKPreferencePage.Add_Button_ToolTip")); //$NON-NLS-1$
       
   345 		addButtonListener(addButton);
       
   346 
       
   347 		// Delete button
       
   348 		deleteButton = new Button(composite1, SWT.NONE);
       
   349 		deleteButton.setLayoutData(gridData);
       
   350 		deleteButton.setText(Messages.getString("SDKPreferencePage.Delete_Button_Label")); //$NON-NLS-1$
       
   351 		deleteButton.setToolTipText(Messages.getString("SDKPreferencePage.Delete_Button_ToolTip")); //$NON-NLS-1$
       
   352 		addButtonListener(deleteButton);
       
   353 
       
   354 		// Properties button
       
   355 		propertiesButton = new Button(composite1, SWT.NONE);
       
   356 		propertiesButton.setLayoutData(gridData);
       
   357 		propertiesButton.setText(Messages.getString("SDKPreferencePage.Properties_Button_Label")); //$NON-NLS-1$
       
   358 		propertiesButton.setToolTipText(Messages.getString("SDKPreferencePage.Properties_Button_ToolTip")); //$NON-NLS-1$
       
   359 		addButtonListener(propertiesButton);
       
   360 
       
   361 		// Status and Rescan composite
       
   362 		Composite composite2 = new Composite(content, SWT.NONE);
       
   363 		gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
       
   364 		gridData.widthHint = 350;
       
   365 		gridData.heightHint = 50;
       
   366 		composite2.setLayoutData(gridData);
       
   367 		gridLayout = new GridLayout();
       
   368 		gridLayout.numColumns = 2;
       
   369 		composite2.setLayout(gridLayout);
       
   370 
       
   371 		// IStatus icon label
       
   372 		iconLabel = new Label(composite2, SWT.NONE);
       
   373 		// IStatus text label
       
   374 		statusLabel = new Label(composite2, SWT.WRAP);
       
   375 		gridData = new GridData(SWT.LEFT, SWT.TOP, true, false);
       
   376 		gridData.verticalSpan = 2;
       
   377 		statusLabel.setLayoutData(gridData);
       
   378 
       
   379 		new Label(content, SWT.WRAP); // filler
   221 		
   380 		
   222 		ISDKManager sdkMgr =SDKCorePlugin.getSDKManager();
   381 		// Scan SDK checkbox
   223 		sdkMgr.updateCarbideSDKCache();
   382 		scanForNewPluginsButton = new Button(content, SWT.CHECK);
       
   383 		scanForNewPluginsButton.setText(Messages.getString("SDKPreferencePage.ScanForNewPlugins_Button_Label")); //$NON-NLS-1$
       
   384 		scanForNewPluginsButton.setSelection(prefsStore.getBoolean(SDKUIPreferenceConstants.SCAN_FOR_NEW_PLUGINS));
       
   385 		addButtonListener(scanForNewPluginsButton);
       
   386 
       
   387 
       
   388 		new Label(content, SWT.WRAP); // filler
   224 		
   389 		
   225 		return super.performOk();
   390 		// Rescan button
   226 	}
   391 		rescanButton = new Button(content, SWT.NONE);
   227 	
   392 		rescanButton.setToolTipText(Messages.getString("SDKPreferencePage.Rescan_Button_ToolTip")); //$NON-NLS-1$
   228 	private void addSDKComponentTableItems() {
   393 		rescanButton.setText(Messages.getString("SDKPreferencePage.Rescan_Button_Label")); //$NON-NLS-1$
   229 		sdkListTableViewer.setContentProvider(new SDKTableComponentsContentProvider());
   394 		addButtonListener(rescanButton);
   230 		sdkListTableViewer.setLabelProvider(new SDKTableComponentsLabelProvider());
   395 
   231 		Table lTable = sdkListTableViewer.getTable();
   396 		// Populate SDK table
   232 		
   397 		addSDKComponentTableItems();
   233 		sdkList = SDKCorePlugin.getSDKManager().getSDKList();
   398 		selectSDKEntry(0);
   234 		sdkListTableViewer.setInput(sdkList);
   399 
   235 		lTable.setToolTipText(Messages.getString("SDKPreferencePage.List_of_Available_SDKs_ToolTip")); //$NON-NLS-1$
   400 		return content;
   236 		lTable.setVisible(true);
   401 	}
   237 		addSDKTableViewerSelectionListener();
   402 
   238 		//lTable.setLayoutData(grid);
   403 	private void addButtonListener(final Button aButton) {
   239 		if (sdkList == null || sdkList.size() == 0){
   404 		SelectionListener listener = new SelectionAdapter() {
   240 			diagnosticCheckLabel.setText(DIAGNOSTIC_CHECK_LABEL + Messages.getString("SDKPreferencePage.No_SDKs_Available")); //$NON-NLS-1$
   405 			public void widgetSelected(SelectionEvent e)  {
   241 			diagnosticCheckLabel.setForeground(RED);
   406 				if (e.getSource().equals(addButton)) {
   242 			diagnosticCheckLabel.setBackground(GRAY);
   407 					handleAddButton();
   243 		} else {
   408 				} else if (e.getSource().equals(deleteButton)) {
   244 			setCheckBoxes(sdkList);
   409 					handleDeleteButton();
   245 		}
   410 				} else if (e.getSource().equals(propertiesButton)) {
   246 	}
   411 					handlePropertiesButton();
   247 	
   412 				} else if (e.getSource().equals(scanForNewPluginsButton)) {
   248 	/**
   413 					handleScanForNewPluginsButton();
   249 	 * Sets the checkbox state for enabled SDKs.
   414 				} else if (e.getSource().equals(rescanButton)) {
   250 	 */
   415 					handleRescanButton();
   251 	private void setCheckBoxes(List<ISymbianSDK> sdkList) {
       
   252 		List<ISymbianSDK> sdkListCopy = new ArrayList<ISymbianSDK>();
       
   253 		for (ISymbianSDK sdkCheck : sdkList){
       
   254 			if (sdkCheck.isEnabled()){
       
   255 				sdkListCopy.add(sdkCheck);
       
   256 			}
       
   257 		}
       
   258 		sdkListTableViewer.setCheckedElements(sdkListCopy.toArray(new ISymbianSDK[sdkListCopy.size()]));			
       
   259 	}
       
   260 	
       
   261 	 /**
       
   262 	  *  Extends <code>LabelProvider</code> with the default implementation 
       
   263 	  *  and implements<code>ITableLabelProvider</code> with the methods
       
   264 	  *	 to provide the text and/or image for each column of a given element.  
       
   265 	  *	 Used by table viewers.
       
   266 	  */
       
   267 	
       
   268 	static class SDKTableComponentsLabelProvider extends LabelProvider implements ITableLabelProvider, ITableColorProvider  {
       
   269 
       
   270 		/**
       
   271 		 * Returns the label image for the given column of the given element.
       
   272 		 * The default implementation returns null.
       
   273 		 * 
       
   274 		 * @return image object
       
   275 		 */
       
   276 		public Image getColumnImage(Object element, int columnIndex) {
       
   277 			return null;
       
   278 		}
       
   279 
       
   280 		/**
       
   281 		 * Returns the label text for the given column of the given element.
       
   282 		 * 
       
   283 		 * @return string is the label text for the given column.
       
   284 		 */
       
   285 		public String getColumnText(Object arg0, int column) {
       
   286 			if (arg0 instanceof ISymbianSDK){
       
   287 				ISymbianSDK sdk = (ISymbianSDK)arg0;
       
   288 				return sdk.getUniqueId();
       
   289 			}
       
   290 			
       
   291 			return ""; //$NON-NLS-1$
       
   292 		}
       
   293 
       
   294 		private Color lBlack = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
       
   295 		private Color lRed =  Display.getDefault().getSystemColor(SWT.COLOR_RED);
       
   296 		
       
   297 		public Color getForeground(Object obj, int index) {
       
   298 			if (obj instanceof ISymbianSDK) {
       
   299 				ISymbianSDK sdk = (ISymbianSDK)obj;
       
   300 				File epocRootTest = new File(sdk.getEPOCROOT());
       
   301 				if ((sdk.getAvailablePlatforms().size() <= 0) || !epocRootTest.exists()) {
       
   302 					// There are no build configs and/or no epocroot exists
       
   303 					return lRed;
       
   304 				} else {
       
   305 					return lBlack;
       
   306 				}
   416 				}
   307 			}
       
   308 			return null;
       
   309 		}
       
   310 		
       
   311 		public Color getBackground(Object element, int columnIndex) {
       
   312 			return null;
       
   313 		}
       
   314 	}
       
   315 	
       
   316 	/** 
       
   317 	 * This implementation of <code>IStructuredContentProvider</code> handles
       
   318 	 * 	the case where the viewer input is an unchanging array or collection of elements.
       
   319 	 * 
       
   320 	 */
       
   321 	static class SDKTableComponentsContentProvider implements IStructuredContentProvider {
       
   322 		
       
   323 
       
   324 		/**
       
   325 		 * Returns the elements in the input
       
   326 		 * 
       
   327 		 * @return array of objects.
       
   328 		 */
       
   329 		public Object[] getElements(Object arg0) {
       
   330 			if (arg0 instanceof ArrayList) {
       
   331 				return ((ArrayList<?>)arg0).toArray();
       
   332 			}
       
   333 			return new Object[0];
       
   334 		}
       
   335 
       
   336 		public void dispose() {
       
   337 		}
       
   338 
       
   339 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
       
   340 			//do nothing
       
   341 		}
       
   342 	}
       
   343 	
       
   344 	/**
       
   345 	 * Sets the listener event to a button.
       
   346 	 * 
       
   347 	 * @param aButton
       
   348 	 */
       
   349 	private void addButtonListener( final Button aButton ) {
       
   350 		SelectionListener listener = new SelectionAdapter() {
       
   351 			public void widgetSelected( SelectionEvent e )  {
       
   352 				if (e.getSource().equals(sdkpropertiesButton)) {
       
   353 					sdkpropertiesButtonAction();
       
   354 				} else if (e.getSource().equals(addNewSdkButton)) {
       
   355 					addNewSdkButtonAction();
       
   356 				} else if (e.getSource().equals(removeSdkButton)) {
       
   357 					removeSdkButtonAction();
       
   358 				} else if (e.getSource().equals(rescanNowButton)) {
       
   359 					rescanNowButtonAction();
       
   360 				}
       
   361 				
       
   362 			}
   417 			}
   363 		};
   418 		};
   364 		aButton.addSelectionListener(listener);
   419 		aButton.addSelectionListener(listener);
   365 	}
   420 	}
   366 	
   421 
   367 	private void sdkpropertiesButtonAction(){
   422 	private void addSDKComponentTableItems() {
       
   423 		sdkListTableViewer.setLabelProvider(new SDKLabelProvider());
       
   424 		sdkListTableViewer.setContentProvider(new ArrayContentProvider());
       
   425 		sdkList = sdkMgr.getSDKList();
       
   426 		sdkListTableViewer.setInput(sdkList.toArray());
       
   427 		sdkListTableViewer.getTable().setToolTipText(Messages.getString("SDKPreferencePage.List_of_Available_SDKs_ToolTip")); //$NON-NLS-1$
       
   428 		setCheckedElements();
       
   429 		addSDKTableViewerListeners();
       
   430 		if (sdkList == null || sdkList.size() == 0){
       
   431 			statusError(Messages.getString("SDKPreferencePage.No_SDKs_Available_Message")); //$NON-NLS-1$
       
   432 		}
       
   433 	}
       
   434 
       
   435 	private void addSDKTableViewerListeners(){
       
   436 		sdkListTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
       
   437 			public void selectionChanged(SelectionChangedEvent event) {
       
   438 				if(event.getSelection() instanceof IStructuredSelection) {
       
   439 					IStructuredSelection selection = (IStructuredSelection)event.getSelection();
       
   440 					if (selection.size() == 1){
       
   441 						ISymbianSDK sdk = (ISymbianSDK)selection.getFirstElement();
       
   442 						deleteButton.setEnabled(true);
       
   443 						propertiesButton.setEnabled(true);		
       
   444 						updateSDKStatus(sdk);
       
   445 					}
       
   446 					else {
       
   447 						deleteButton.setEnabled(false);
       
   448 						propertiesButton.setEnabled(false);			        	   
       
   449 					}	
       
   450 				}
       
   451 			}
       
   452 		});
       
   453 	}
       
   454 
       
   455 	private void createSDKTable() {
       
   456 		final Table table = sdkListTableViewer.getTable();
       
   457 		GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
       
   458 		gridData.widthHint = 350;
       
   459 		gridData.heightHint = table.getItemHeight() * 6;
       
   460 		table.setLayoutData(gridData);
       
   461 		table.setHeaderVisible(true);
       
   462 		table.setLinesVisible(false);
       
   463 
       
   464 		TableViewerColumn enabledCol = new TableViewerColumn(sdkListTableViewer, SWT.LEFT);
       
   465 		enabledCol.getColumn().setText(Messages.getString("SDKPreferencePage.SDK_Table_Enabled_Column_Label")); //$NON-NLS-1$
       
   466 		enabledCol.getColumn().setWidth(50);
       
   467 
       
   468 		TableViewerColumn idCol = new TableViewerColumn(sdkListTableViewer, SWT.LEFT);
       
   469 		idCol.setEditingSupport(new IdEditingSupport(sdkListTableViewer)); //$NON-NLS-1$
       
   470 		idCol.getColumn().setText(Messages.getString("SDKPreferencePage.SDK_Table_ID_Column_Label"));
       
   471 		idCol.getColumn().setWidth(160);
       
   472 
       
   473 		TableViewerColumn locationCol = new TableViewerColumn(sdkListTableViewer, SWT.LEFT);
       
   474 		locationCol.setEditingSupport(new LocationEditingSupport(sdkListTableViewer));
       
   475 		locationCol.getColumn().setText(Messages.getString("SDKPreferencePage.SDK_Table_Location_Column_Label")); //$NON-NLS-1$
       
   476 		locationCol.getColumn().setWidth(170);
       
   477 	}
       
   478 
       
   479 	private void handleAddButton() {
       
   480 		AddSDKDialog dialog = new AddSDKDialog(getShell());
       
   481 		if (dialog.open() == AddSDKDialog.OK){
       
   482 			sdkList = sdkMgr.getSDKList();
       
   483 			sdkListTableViewer.setInput(sdkList.toArray());
       
   484 			setCheckedElements();
       
   485 			sdkListTableViewer.refresh();
       
   486 			selectSDKEntry(sdkList.size() - 1);
       
   487 		}
       
   488 	}
       
   489 
       
   490 	private void handleDeleteButton() {
       
   491 		ISymbianSDK sdk = (ISymbianSDK)((IStructuredSelection)sdkListTableViewer.getSelection()).getFirstElement();
       
   492 		int index = sdkListTableViewer.getTable().getSelectionIndex();
       
   493 		if (sdk != null){
       
   494 			if (sdkMgr.removeSDK(sdk.getUniqueId())){
       
   495 				sdkList = sdkMgr.getSDKList();
       
   496 				sdkListTableViewer.setInput(sdkList.toArray());
       
   497 				if (index > 0) {
       
   498 					selectSDKEntry(index - 1);
       
   499 				} else {
       
   500 					selectSDKEntry(index);
       
   501 				}
       
   502 				sdkListTableViewer.refresh();
       
   503 			}
       
   504 		}
       
   505 	}
       
   506 
       
   507 	private void handlePropertiesButton() {
   368 		ISymbianSDK sdk = (ISymbianSDK)((IStructuredSelection)sdkListTableViewer.getSelection()).getFirstElement();
   508 		ISymbianSDK sdk = (ISymbianSDK)((IStructuredSelection)sdkListTableViewer.getSelection()).getFirstElement();
   369 		if (sdk != null){
   509 		if (sdk != null){
   370 			SDKPropertiesDialog sdkPropDlg = new SDKPropertiesDialog(getShell(), this, sdk);
   510 			SDKPropertiesDialog sdkPropDlg = new SDKPropertiesDialog(getShell(), sdk);
   371 			if (sdkPropDlg.open() == SDKPropertiesDialog.OK){
   511 			if (sdkPropDlg.open() == SDKPropertiesDialog.OK){
   372 				sdkListTableViewer.refresh();
   512 				sdkListTableViewer.refresh();
   373 				setSelectedSDKInfoText(sdk);
   513 				updateSDKStatus(sdk);
   374 				// forcible rescan; dump cache
   514 				// forcible rescan; dump cache
   375 				SymbianBuildContextDataCache.refreshForSDKs(new ISymbianSDK[] { sdk });
   515 				SymbianBuildContextDataCache.refreshForSDKs(new ISymbianSDK[] { sdk });
   376 				rescanSDKs(false);
   516 				sdkMgr.scanSDKs();
   377 			}
   517 			}
   378 		} else {
   518 		} else {
   379 			MessageDialog.openError(getShell(), Messages.getString("SDKPreferencePage.No_SDK_Selected"), Messages.getString("SDKPreferencePage.No_selected_SDK_detected")); //$NON-NLS-1$ //$NON-NLS-2$
   519 			MessageDialog.openError(getShell(), Messages.getString("SDKPreferencePage.No_SDK_Selected"), Messages.getString("SDKPreferencePage.No_selected_SDK_detected")); //$NON-NLS-1$ //$NON-NLS-2$
   380 		}
   520 		}
   381 
   521 	}
   382 	}
   522 
   383 	
   523 	private void handleScanForNewPluginsButton() {
   384 	private void removeSdkButtonAction(){
   524 		scanForNewPlugins = scanForNewPluginsButton.getSelection();
   385 		ISymbianSDK sdk = (ISymbianSDK)((IStructuredSelection)sdkListTableViewer.getSelection()).getFirstElement();
   525 	}
   386 		if (sdk != null){
   526 
   387 			if (MessageDialog.openConfirm(getShell(), Messages.getString("SDKPreferencePage.Confirm_Delete") + sdk.getUniqueId() , Messages.getString("SDKPreferencePage.Confirm_Delete_Msg"))){ //$NON-NLS-1$ //$NON-NLS-2$
   527 	private void handleRescanButton() {
   388 				if (sdkMgr.removeSDK(sdk.getUniqueId())){
       
   389 					sdkList.remove(sdk);
       
   390 					sdkListTableViewer.refresh();
       
   391 					sdk = (ISymbianSDK)sdkListTableViewer.getElementAt(0);
       
   392 					if (sdk != null){
       
   393 						sdkListTableViewer.setSelection(new StructuredSelection(sdk), true);
       
   394 						setSelectedSDKInfoText(sdk);
       
   395 					}
       
   396 				}
       
   397 			}
       
   398 		}
       
   399 	}
       
   400 	
       
   401 	private void addNewSdkButtonAction(){
       
   402 		
       
   403 		AddSDKDialog dialog = new AddSDKDialog(getShell());
       
   404 		if (dialog.open() == AddSDKDialog.OK){
       
   405 			addSDKComponentTableItems();
       
   406 			sdkListTableViewer.refresh();
       
   407 		}
       
   408 	}
       
   409 	
       
   410 	private void rescanNowButtonAction(){
       
   411 		// forcible rescan; dump cache
   528 		// forcible rescan; dump cache
   412 		SymbianBuildContextDataCache.refreshForSDKs(null);
   529 		SymbianBuildContextDataCache.refreshForSDKs(null);
   413 		rescanSDKs(true);
   530 		sdkMgr.scanSDKs();
   414 	}
   531 	}
   415 	
   532 
   416 	private void rescanSDKs(boolean scanForNewPlugins){
   533 	private void rescanSDKs(){
   417 		sdkListTableViewer.getTable().clearAll();
   534 		sdkListTableViewer.getTable().clearAll();
   418 		sdkListTableViewer.refresh();
   535 		sdkListTableViewer.refresh();
   419 		sdkList.clear();
   536 		sdkList.clear();
   420 		ISDKManager sdkMgr = SDKCorePlugin.getSDKManager();
       
   421 		sdkMgr.scanSDKs();
       
   422 		sdkList = sdkMgr.getSDKList();
   537 		sdkList = sdkMgr.getSDKList();
   423 		addSDKComponentTableItems();
   538 		addSDKComponentTableItems();
   424 		sdkListTableViewer.refresh();
   539 		sdkListTableViewer.refresh();
   425 		
   540 		selectSDKEntry(0);
   426 		ISymbianSDK sdk = (ISymbianSDK)sdkListTableViewer.getElementAt(0);
   541 
       
   542 		if (scanForNewPlugins){
       
   543 			NewPluginChecker.checkForNewlyInstalledPlugins(SDKUIPlugin.getDefault().getWorkbench());
       
   544 		}
       
   545 	}
       
   546 
       
   547 	private void selectSDKEntry(int index) {
       
   548 		ISymbianSDK sdk = (ISymbianSDK)sdkListTableViewer.getElementAt(index);
   427 		if (sdk != null){
   549 		if (sdk != null){
   428 			sdkListTableViewer.setSelection(new StructuredSelection(sdk), true);
   550 			sdkListTableViewer.setSelection(new StructuredSelection(sdk), true);
   429 			setSelectedSDKInfoText(sdk);
   551 			sdkListTableViewer.getTable().setFocus();
   430 		}
   552 		}
   431 		
   553 		updateSDKStatus(sdk);
   432 		if (scanForNewPlugins){
   554 	}
   433 			NewPluginChecker.checkForNewlyInstalledPlugins(SDKUIPlugin.getDefault().getWorkbench());
   555 
   434 		}
   556 	private void setCheckedElements() {
   435 	}
   557 		Iterator<ISymbianSDK> iterator = sdkList.iterator();
   436 	
   558 		while (iterator.hasNext()) {
   437 	/**
   559 			ISymbianSDK sdk = iterator.next();
   438 	 * Sets the selection listener action event to the CheckboxTableViewer.
   560 			sdkListTableViewer.setChecked(sdk, sdk.isEnabled());
   439 	 * 
   561 		}
   440 	 * @param sdkTable 
   562 	}
   441 	 */
   563 
   442 	private void addSDKTableViewerSelectionListener(){
   564 	private void statusClear() {
   443 		sdkListTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
   565 		iconLabel.setImage(null);
   444 			   public void selectionChanged(SelectionChangedEvent event) {
   566 		statusLabel.setText("");
   445 
   567 	}
   446 			       if(event.getSelection() instanceof IStructuredSelection) {
   568 
   447 			           IStructuredSelection selection = (IStructuredSelection)event.getSelection();
   569 	private void statusError(String msg) {
   448 			           if (selection.size() == 1){
   570 		String errorMsg = "Error : " + msg;
   449 			        	   ISymbianSDK sdk = (ISymbianSDK)selection.getFirstElement();
   571 		iconLabel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
   450 			        	   sdkpropertiesButton.setEnabled(true);
   572 		statusLabel.setText(errorMsg);
   451 			          	   removeSdkButton.setEnabled(true);		
   573 		statusLabel.setForeground(red);
   452 			        	   setSelectedSDKInfoText(sdk);
   574 		statusLabel.setBackground(gray);
   453 			        
   575 		statusLabel.update();
   454 			           }else {
   576 		statusLabel.getParent().layout(true);
   455 			        	   sdkpropertiesButton.setEnabled(false);
   577 	}
   456 			        	   removeSdkButton.setEnabled(false);			        	   
   578 
   457 			           }	
   579 	private void statusWarning(String msg) {
   458 			       }
   580 		String warningMsg = "Warning : " + msg; //$NON-NLS-1$
   459 			   }
   581 		iconLabel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
   460 			} );
   582 		statusLabel.setText(warningMsg);
   461 	}
   583 		statusLabel.setForeground(black);
   462 	
   584 		statusLabel.setBackground(gray);
   463 	private void setSelectedSDKInfoText(ISymbianSDK sdk){
   585 		statusLabel.update();
   464 		boolean sdkHasError = false;
   586 		statusLabel.getParent().layout(true);
   465 		String epocRootStr = sdk.getEPOCROOT();
   587 	}
   466 		File epocRootTest = new File(epocRootStr);
   588 
   467 		if (!epocRootTest.exists()) {
   589 	private void statusInfo(String msg) {
   468 			sdkHasError = true;
   590 		String infoMsg = "Info : " + msg; //$NON-NLS-1$
   469 			epocrootLabel.setText(EPOCROOT_LABEL + epocRootStr + Messages.getString("SDKPreferencePage.Path_Does_Not_Exist")); //$NON-NLS-1$
   591 		iconLabel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK));
   470 			epocrootLabel.setForeground(RED);
   592 		statusLabel.setText(infoMsg);
   471 			epocrootLabel.setBackground(GRAY);
   593 		statusLabel.setForeground(black);
   472 		}
   594 		statusLabel.setBackground(gray);
   473 		else {
   595 		statusLabel.update();
   474 			epocrootLabel.setText(EPOCROOT_LABEL + epocRootStr);
   596 		statusLabel.getParent().layout(true);
   475 			epocrootLabel.setForeground(BLACK);
   597 	}
   476 			epocrootLabel.setBackground(GRAY);
   598 
   477 		}
   599 	private void updateSDKStatus(ISymbianSDK sdk){
   478 		
   600 		// No SDK selected
   479 		// Set platforms 
   601 		if (sdk == null) {
   480 		if (sdk.getAvailablePlatforms().size() == 0) {
   602 			statusWarning(Messages.getString("SDKPreferencePage.No_SDKs_Available_Message")); //$NON-NLS-1$
   481 			sdkHasError = true;
   603 			return;
   482 			availablePlatformsLabel.setText(PLATFORMS_LABEL + Messages.getString("SDKPreferencePage.Platforms_cannot_be_determined")); //$NON-NLS-1$
       
   483 			availablePlatformsLabel.setForeground(RED);
       
   484 			availablePlatformsLabel.setBackground(GRAY);
       
   485 		}
       
   486 		else {
       
   487 			availablePlatformsLabel.setText(PLATFORMS_LABEL + sdk.getAvailablePlatforms().toString());
       
   488 			availablePlatformsLabel.setForeground(BLACK);
       
   489 			availablePlatformsLabel.setBackground(GRAY);
       
   490 		}
       
   491 		
       
   492 		// Set OS Version 
       
   493 		if (sdk.getOSVersion().getMajor() == 0) {
       
   494 			sdkHasError = true;
       
   495 			osVersionLabel.setText(OS_VERSION_LABEL + Messages.getString("SDKPreferencePage.OS_Version_Cannot_Be_Determined")); //$NON-NLS-1$
       
   496 			osVersionLabel.setForeground(RED);
       
   497 			osVersionLabel.setBackground(GRAY);
       
   498 		}
       
   499 		else if (!SDKCorePlugin.SUPPORTS_SBSV1_BUILDER && 
       
   500 				 (sdk.getOSVersion().getMajor() < 9 ||
       
   501 				 (sdk.getOSVersion().getMajor() == 9 && sdk.getOSVersion().getMinor() <= 4))){
       
   502 			sdkHasError = true;
       
   503 			osVersionLabel.setText(OS_VERSION_LABEL + "This OS version is not supported: " + sdk.getOSVersion()); 
       
   504 			osVersionLabel.setForeground(RED);
       
   505 			osVersionLabel.setBackground(GRAY);
       
   506 			
       
   507 		} else {
   604 		} else {
   508 			if (sdk.getSDKOSBranch().length() > 0) {
   605 			// Check SDK EPOCROOT
   509 				osVersionLabel.setText(OS_VERSION_LABEL + sdk.getOSVersion().toString() + " (Branch = \"" + sdk.getSDKOSBranch() + "\")"); //$NON-NLS-1$ //$NON-NLS-2$
   606 			String epocRootStr = sdk.getEPOCROOT();
   510 			} else {
   607 			IPath epocRoot = new Path(epocRootStr);
   511 				osVersionLabel.setText(OS_VERSION_LABEL + sdk.getOSVersion().toString());
   608 			epocRoot = epocRoot.append("epoc32");
   512 			}
   609 			File epocRootFile = epocRoot.toFile();
   513 			osVersionLabel.setForeground(BLACK);
   610 			if (!epocRootFile.exists()) {
   514 			osVersionLabel.setBackground(GRAY);
   611 				statusError(Messages.getString("SDKPreferencePage.Invalid_Location_Message")); //$NON-NLS-1$
   515 		}
   612 				return;
   516 		
   613 			}
   517 		//  Get diagnostic check 
   614 
   518 		//if (lsdk.getSomeError().size() <= 0) {
   615 			// Check SDK OS Version
   519 		if (sdkHasError){
   616 			if ((sdk.getOSVersion().getMajor() < 9 ||
   520 			diagnosticCheckLabel.setText(DIAGNOSTIC_CHECK_LABEL + Messages.getString("SDKPreferencePage.SDK_Cannot_Be_Used")); //$NON-NLS-1$
   617 				(sdk.getOSVersion().getMajor() == 9 && sdk.getOSVersion().getMinor() < 5))) {
   521 			diagnosticCheckLabel.setForeground(RED);
   618 				statusError(MessageFormat.format(
   522 			diagnosticCheckLabel.setBackground(GRAY);
   619 						Messages.getString("SDKPreferencePage.Invalid_SDK_Message"),  //$NON-NLS-1$
   523 		}
   620 						sdk.getOSVersion().toString())); //$NON-NLS-1$
   524 		else {
   621 				return;
   525 			// check for other types of errors:
   622 			}			
   526 			if (!sdk.getToolsPath().toFile().exists()){
   623 
   527 				diagnosticCheckLabel.setText(DIAGNOSTIC_CHECK_LABEL + Messages.getString("SDKPreferencePage.No_Tools_Path") +  " " + sdk.getToolsPath().toOSString()); //$NON-NLS-1$
   624 			// No error
   528 				diagnosticCheckLabel.setForeground(RED);
   625 			statusClear();
   529 				diagnosticCheckLabel.setBackground(GRAY);
   626 		}
   530 			} else if (!sdk.getIncludePath().toFile().exists()){
   627 	}
   531 				diagnosticCheckLabel.setText(DIAGNOSTIC_CHECK_LABEL + Messages.getString("SDKPreferencePage.No_Include_Path") +  " " + sdk.getIncludePath().toOSString()); //$NON-NLS-1$
   628 
   532 				diagnosticCheckLabel.setForeground(RED);
       
   533 				diagnosticCheckLabel.setBackground(GRAY);
       
   534 			} else if ( ((sdk.getPrefixFile() == null) || (!sdk.getPrefixFile().exists())) && (sdk.getOSVersion().getMajor() >= 9)){
       
   535 					diagnosticCheckLabel.setText(DIAGNOSTIC_CHECK_LABEL + Messages.getString("SDKPreferencePage.No_HRH_File")); //$NON-NLS-1$
       
   536 					diagnosticCheckLabel.setForeground(RED);
       
   537 					diagnosticCheckLabel.setBackground(GRAY);
       
   538 			} else if ( ((sdk.isS60()) && sdk.getSDKVersion().getMajor() == 0)){
       
   539 				diagnosticCheckLabel.setText(DIAGNOSTIC_CHECK_LABEL + Messages.getString("SDKPreferencePage.No_SDK_Version")); //$NON-NLS-1$
       
   540 				diagnosticCheckLabel.setForeground(RED);
       
   541 				diagnosticCheckLabel.setBackground(GRAY);
       
   542 			} else {
       
   543 				// Everything is OK....
       
   544 				diagnosticCheckLabel.setText(DIAGNOSTIC_CHECK_LABEL + "OK\r\n "); //$NON-NLS-1$
       
   545 				diagnosticCheckLabel.setForeground(BLACK);
       
   546 				diagnosticCheckLabel.setBackground(GRAY);
       
   547 			}
       
   548 		}
       
   549    } 
       
   550 	
       
   551 	protected List<ISymbianSDK> getSDKList(){
       
   552 		return sdkList;
       
   553 	}
       
   554 	
       
   555 	protected ISDKManager getSDKManager(){
       
   556 		return sdkMgr;
       
   557 	}
       
   558 }
   629 }