sftemplateswizard/com.nokia.s60tools.symbianfoundationtemplates/src/com/nokia/s60tools/symbianfoundationtemplates/ui/wizards/s60/projectwizards/BuildInfoPage.java
changeset 0 61163b28edca
equal deleted inserted replaced
-1:000000000000 0:61163b28edca
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 package com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.projectwizards;
       
    18 
       
    19 import java.io.File;
       
    20 import java.util.AbstractList;
       
    21 import java.util.ArrayList;
       
    22 import java.util.HashMap;
       
    23 import java.util.Map;
       
    24 
       
    25 import org.eclipse.core.resources.IFile;
       
    26 import org.eclipse.core.resources.ResourcesPlugin;
       
    27 import org.eclipse.core.runtime.IStatus;
       
    28 import org.eclipse.core.runtime.Path;
       
    29 import org.eclipse.swt.SWT;
       
    30 import org.eclipse.swt.layout.GridData;
       
    31 import org.eclipse.swt.layout.GridLayout;
       
    32 import org.eclipse.swt.widgets.Button;
       
    33 import org.eclipse.swt.widgets.Combo;
       
    34 import org.eclipse.swt.widgets.Composite;
       
    35 import org.eclipse.swt.widgets.Label;
       
    36 import org.eclipse.swt.widgets.Text;
       
    37 import org.eclipse.ui.PlatformUI;
       
    38 
       
    39 import com.nokia.s60tools.symbianfoundationtemplates.SymbianFoundationTemplates;
       
    40 import com.nokia.s60tools.symbianfoundationtemplates.engine.OriginalTemplate;
       
    41 import com.nokia.s60tools.symbianfoundationtemplates.engine.s60.S60TransformKeys;
       
    42 import com.nokia.s60tools.symbianfoundationtemplates.resources.HelpContextIDs;
       
    43 import com.nokia.s60tools.symbianfoundationtemplates.resources.LastUsedData;
       
    44 import com.nokia.s60tools.symbianfoundationtemplates.resources.Messages;
       
    45 import com.nokia.s60tools.symbianfoundationtemplates.resources.PreferenceConstants;
       
    46 import com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.FolderSelectionControl;
       
    47 import com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.S60TemplatePageType;
       
    48 import com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.S60TemplateWizardPage;
       
    49 import com.nokia.s60tools.symbianfoundationtemplates.util.Util;
       
    50 
       
    51 /**
       
    52  * Build info page. 
       
    53  */
       
    54 public class BuildInfoPage extends S60TemplateWizardPage {
       
    55 	private FolderSelectionControl folderSelectionControl;
       
    56 	
       
    57 	private Text subSystemText;
       
    58 	private Text moduleText;
       
    59 	private Text appNameText;
       
    60 	private Text copyrightText;
       
    61 	private Combo licenseText;
       
    62 	private Combo companyNameText;
       
    63 	private Combo copyrightString;
       
    64 	private Button cleanBtn;
       
    65 
       
    66 	private Composite topLevel;
       
    67 	
       
    68 	public BuildInfoPage(S60TemplatePageType pageType) {
       
    69 		super(pageType);
       
    70 		setTitle(pageType.getTitle());
       
    71 	}
       
    72 	
       
    73 	public void createControl(Composite parent) {
       
    74 		topLevel = new Composite(parent, SWT.NONE);
       
    75 		// Layout manager
       
    76 		topLevel.setLayout(new GridLayout(1, false));
       
    77 		topLevel.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
    78 		
       
    79 		Composite selection = new Composite(topLevel, SWT.NONE);
       
    80 		selection.setLayout(new GridLayout(3, false));
       
    81 		selection.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
    82 		
       
    83 		// Folder selection control
       
    84 		folderSelectionControl = new FolderSelectionControl(selection, this, "Group Folder:");
       
    85 		
       
    86 		// Separator
       
    87 		Label separator = new Label(topLevel, SWT.SEPARATOR | SWT.HORIZONTAL);
       
    88 		separator.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
    89 		
       
    90 		// Info control
       
    91 		Composite info = new Composite(topLevel, SWT.NONE);
       
    92 		info.setLayout(new GridLayout(2, false));
       
    93 		info.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
    94 	
       
    95 		new Label(info, SWT.NONE).setText(Messages.getString("WizardPageSubSystemLabel")); //$NON-NLS-1$
       
    96 		subSystemText = new Text(info, SWT.BORDER);
       
    97 		subSystemText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
    98 		
       
    99 		new Label(info, SWT.NONE).setText(Messages.getString("WizardPageModuleLabel")); //$NON-NLS-1$
       
   100 		moduleText = new Text(info, SWT.BORDER);
       
   101 		moduleText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
   102 		
       
   103 		new Label(info, SWT.NONE).setText(Messages.getString("WizardPageApplicationLabel")); //$NON-NLS-1$
       
   104 		appNameText = new Text(info, SWT.BORDER);
       
   105 		appNameText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
   106 				
       
   107 		new Label(info, SWT.NONE).setText(Messages.getString("WizardPageCopyrightLabel")); //$NON-NLS-1$
       
   108 		copyrightText = new Text(info, SWT.BORDER);
       
   109 		copyrightText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
   110 
       
   111 		new Label(info, SWT.NONE).setText(Messages.getString("WizardPageLicenseLabel")); //$NON-NLS-1$
       
   112 		licenseText = new Combo(info, SWT.BORDER|SWT.READ_ONLY);
       
   113 		licenseText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
   114 		
       
   115 		new Label(info, SWT.NONE).setText(Messages.getString("WizardPageCompanyLabel")); //$NON-NLS-1$
       
   116 		companyNameText = new Combo(info, SWT.BORDER);
       
   117 		companyNameText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
   118 		
       
   119 		new Label(info, SWT.NONE).setText(Messages.getString("WizardPageCopyrightStringLabel"));
       
   120 		copyrightString = new Combo(info, SWT.BORDER);// | SWT.V_SCROLL | SWT.MULTI | SWT.WRAP);
       
   121 		copyrightString.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
       
   122 		
       
   123 		GridData data=new GridData(GridData.FILL_HORIZONTAL);
       
   124 		data.heightHint=30;
       
   125 		cleanBtn=new Button(topLevel,SWT.CHECK);
       
   126 		cleanBtn.setText(Messages.getString("WizardPageIncludeInstructionsLabel"));
       
   127 		cleanBtn.setSelection(true);
       
   128 		cleanBtn.setLayoutData(data);
       
   129 		
       
   130 		setControl(topLevel);
       
   131 		//setPageComplete(true);
       
   132 		
       
   133 		copyrightText.setText(new Integer(Util.getCopyrightYear()).toString());
       
   134 		licenseText.setItems(Util.getDefaultLicence());
       
   135 		licenseText.select(0);
       
   136 
       
   137 		LastUsedData previousData = new LastUsedData();
       
   138 		String[] values = previousData.getPreviousValues(LastUsedData.ValueTypes.NAME);
       
   139 		if(values!=null)
       
   140 		{
       
   141 			companyNameText.setItems(values);
       
   142 			companyNameText.select(0);
       
   143 		}
       
   144 		else
       
   145 		{
       
   146 			companyNameText.setText(Util.getDefaultCompanyName());
       
   147 			previousData.saveValues(LastUsedData.ValueTypes.NAME, companyNameText.getText());
       
   148 		}
       
   149 		
       
   150 		values = previousData.getPreviousValues(LastUsedData.ValueTypes.COPYRIGHT);
       
   151 		if(values !=null)
       
   152 		{
       
   153 			copyrightString.setItems(values);
       
   154 			copyrightString.select(0);
       
   155 		}
       
   156 		else
       
   157 		{
       
   158 			copyrightString.setText(Util.getDefaultCompanyCopyright());
       
   159 			previousData.saveValues(LastUsedData.ValueTypes.COPYRIGHT, copyrightString.getText());
       
   160 		}
       
   161 	
       
   162 
       
   163 		setPreferencesFromStore();
       
   164 		performHelp();
       
   165 		//updateStatus();
       
   166 		topLevel.setFocus();
       
   167 	}
       
   168 
       
   169 	public void performHelp() {
       
   170 		PlatformUI.getWorkbench().getHelpSystem().setHelp(topLevel,
       
   171 				HelpContextIDs.SF_TEMPLATES_RESOURCE_WIZARD_PAGE);
       
   172 	}
       
   173 	
       
   174 	@Override
       
   175 	public AbstractList<OriginalTemplate> getTemplates() {
       
   176 		AbstractList<OriginalTemplate> templates = new ArrayList<OriginalTemplate>();
       
   177 		
       
   178 		String[] templateFiles = pageType.getTemplateFiles().split(";");
       
   179 		String fileName = templateFiles[0];
       
   180 		//To return the empty template file name
       
   181 		if(!cleanBtn.getSelection())
       
   182 			fileName = templateFiles[1];
       
   183 		
       
   184 		templates.add(new OriginalTemplate(SymbianFoundationTemplates.getDefault().getTemplatesPath() + File.separator + fileName, getSelectedFile(), getTransformRules()));
       
   185 		
       
   186 		return templates;
       
   187 	}
       
   188 	
       
   189 	@Override
       
   190 	protected AbstractList<IStatus> getStatuses() {
       
   191 		AbstractList<IStatus> statuses = new ArrayList<IStatus>();
       
   192 		
       
   193 		statuses.add(Util.getFolderNameStatus(folderSelectionControl.getSelectedFolder(), "Group folder")); //$NON-NLS-1$
       
   194 				
       
   195 		return statuses;
       
   196 	}
       
   197 
       
   198 	@Override
       
   199 	protected void updateFields() {
       
   200 		moduleText.setText(Util.getModuleName(folderSelectionControl.getSelectedFolder()));
       
   201 		subSystemText.setText(Util.getSubSystemName(folderSelectionControl.getSelectedFolder()));
       
   202 	}
       
   203 
       
   204 	@Override
       
   205 	protected void savePreferencesToStore() {
       
   206 		preferenceStore.setValue(PreferenceConstants.S60_BUILD_INFO_PAGE_DIRECTORY, folderSelectionControl.getSelectedFolder());
       
   207 		preferenceStore.setValue(PreferenceConstants.S60_BUILD_INFO_PAGE_MODULE, moduleText.getText());
       
   208 		preferenceStore.setValue(PreferenceConstants.S60_BUILD_INFO_PAGE_SUBSYSTEM, subSystemText.getText());
       
   209 		preferenceStore.setValue(PreferenceConstants.S60_BUILD_INFO_PAGE_APPNAME, appNameText.getText());
       
   210 		preferenceStore.setValue(PreferenceConstants.SF_LICENSE_INDEX, licenseText.getSelectionIndex());
       
   211 		LastUsedData saveData = new LastUsedData();
       
   212 		saveData.saveValues(LastUsedData.ValueTypes.NAME, companyNameText.getText());
       
   213 		saveData.saveValues(LastUsedData.ValueTypes.COPYRIGHT, copyrightString.getText());
       
   214 	}
       
   215 	
       
   216 	private IFile getSelectedFile() {
       
   217 		return ResourcesPlugin.getWorkspace().getRoot().getFile(
       
   218 				new Path(folderSelectionControl.getSelectedFolder() 
       
   219 						+ File.separator 
       
   220 						+ "bld.inf"));
       
   221 	}
       
   222 	
       
   223 	private Map<String, String> getTransformRules() {
       
   224 		Map<String, String> transformRules = new HashMap<String, String>();
       
   225 		
       
   226 		transformRules.put(S60TransformKeys.getString("key_module"), moduleText.getText()); //$NON-NLS-1$
       
   227 		transformRules.put(S60TransformKeys.getString("key_subsystem"), subSystemText.getText()); //$NON-NLS-1$
       
   228 		transformRules.put(S60TransformKeys.getString("key_copyright"), copyrightText.getText()); //$NON-NLS-1$
       
   229 		transformRules.put(S60TransformKeys.getString("key_appname"), appNameText.getText()); //$NON-NLS-1$
       
   230 		transformRules.put(S60TransformKeys.getString("key_license"), licenseText.getText()); //$NON-NLS-1$		
       
   231 		transformRules.put(S60TransformKeys.getString("key_companyname"), companyNameText.getText()); //$NON-NLS-1$
       
   232 		transformRules.put(S60TransformKeys.getString("key_companycopyright"), copyrightString.getText());
       
   233 		
       
   234 		if(licenseText.getText().equalsIgnoreCase("Symbian Foundation License v1.0"))
       
   235 			transformRules.put(S60TransformKeys.getString("key_licenseurl"), "http://www.symbianfoundation.org/legal/sfl-v10.html");
       
   236 		else if(licenseText.getText().equalsIgnoreCase("Eclipse Public License v1.0"))
       
   237 			transformRules.put(S60TransformKeys.getString("key_licenseurl"), "http://www.eclipse.org/legal/epl-v10.html");
       
   238 		return transformRules;
       
   239 	}
       
   240 	
       
   241 	private void setPreferencesFromStore() {
       
   242 		if(preferenceStore.getString(PreferenceConstants.S60_BUILD_INFO_PAGE_DIRECTORY)!="")
       
   243 			folderSelectionControl.setSelectedFolder(preferenceStore.getString(PreferenceConstants.S60_BUILD_INFO_PAGE_DIRECTORY));
       
   244 		moduleText.setText(preferenceStore.getString(PreferenceConstants.S60_BUILD_INFO_PAGE_MODULE));
       
   245 		subSystemText.setText(preferenceStore.getString(PreferenceConstants.S60_BUILD_INFO_PAGE_SUBSYSTEM));
       
   246 		appNameText.setText(preferenceStore.getString(PreferenceConstants.S60_BUILD_INFO_PAGE_APPNAME));
       
   247 		licenseText.select(preferenceStore.getInt(PreferenceConstants.SF_LICENSE_INDEX));
       
   248 	}
       
   249 	
       
   250 }