|
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.headerwizards; |
|
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.graphics.FontMetrics; |
|
31 import org.eclipse.swt.graphics.GC; |
|
32 import org.eclipse.swt.layout.GridData; |
|
33 import org.eclipse.swt.layout.GridLayout; |
|
34 import org.eclipse.swt.widgets.Button; |
|
35 import org.eclipse.swt.widgets.Combo; |
|
36 import org.eclipse.swt.widgets.Composite; |
|
37 import org.eclipse.swt.widgets.Label; |
|
38 import org.eclipse.swt.widgets.Text; |
|
39 import org.eclipse.ui.PlatformUI; |
|
40 |
|
41 import com.nokia.s60tools.symbianfoundationtemplates.SymbianFoundationTemplates; |
|
42 import com.nokia.s60tools.symbianfoundationtemplates.engine.OriginalTemplate; |
|
43 import com.nokia.s60tools.symbianfoundationtemplates.engine.s60.S60TransformKeys; |
|
44 import com.nokia.s60tools.symbianfoundationtemplates.resources.HelpContextIDs; |
|
45 import com.nokia.s60tools.symbianfoundationtemplates.resources.LastUsedData; |
|
46 import com.nokia.s60tools.symbianfoundationtemplates.resources.Messages; |
|
47 import com.nokia.s60tools.symbianfoundationtemplates.resources.PreferenceConstants; |
|
48 import com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.FileSelectionControl; |
|
49 import com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.FolderSelectionControl; |
|
50 import com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.S60TemplatePageType; |
|
51 import com.nokia.s60tools.symbianfoundationtemplates.ui.wizards.s60.S60TemplateWizardPage; |
|
52 import com.nokia.s60tools.symbianfoundationtemplates.util.Util; |
|
53 |
|
54 /** |
|
55 * Header page. |
|
56 * |
|
57 */ |
|
58 public class HeaderPage extends S60TemplateWizardPage { |
|
59 private FolderSelectionControl folderSelectionControl; |
|
60 |
|
61 private FileSelectionControl fileSelectionControl; |
|
62 private Text subSystemText; |
|
63 private Text moduleText; |
|
64 private Text descriptionText; |
|
65 private Text copyrightText; |
|
66 private Composite topLevel; |
|
67 private Combo licenseText; |
|
68 private Combo companyNameText; |
|
69 private Combo copyrightString; |
|
70 private Button cleanBtn; |
|
71 |
|
72 /** |
|
73 * Default constructor. |
|
74 * |
|
75 * @param pageType the page type |
|
76 */ |
|
77 public HeaderPage(S60TemplatePageType pageType) { |
|
78 super(pageType); |
|
79 setTitle(pageType.getTitle()); |
|
80 } |
|
81 |
|
82 public void createControl(Composite parent) { |
|
83 topLevel = new Composite(parent, SWT.NONE); |
|
84 // Layout manager |
|
85 topLevel.setLayout(new GridLayout(1, false)); |
|
86 topLevel.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
87 |
|
88 Composite selection = new Composite(topLevel, SWT.NONE); |
|
89 selection.setLayout(new GridLayout(3, false)); |
|
90 selection.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
91 |
|
92 // Folder selection control |
|
93 folderSelectionControl = new FolderSelectionControl(selection, this, Messages.getString("WizardPageHeaderFolderLabel")); //$NON-NLS-1$ |
|
94 |
|
95 // File selection control |
|
96 fileSelectionControl = new FileSelectionControl(selection, this, Messages.getString("WizardPageHeaderFileLabel")); //$NON-NLS-1$ |
|
97 |
|
98 // Separator |
|
99 Label separator = new Label(topLevel, SWT.SEPARATOR | SWT.HORIZONTAL); |
|
100 separator.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
101 |
|
102 // Info control |
|
103 Composite info = new Composite(topLevel, SWT.NONE); |
|
104 info.setLayout(new GridLayout(2, false)); |
|
105 info.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
106 |
|
107 new Label(info, SWT.NONE).setText(Messages.getString("WizardPageSubSystemLabel")); //$NON-NLS-1$ |
|
108 subSystemText = new Text(info, SWT.BORDER); |
|
109 subSystemText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
110 |
|
111 new Label(info, SWT.NONE).setText(Messages.getString("WizardPageModuleLabel")); //$NON-NLS-1$ |
|
112 moduleText = new Text(info, SWT.BORDER); |
|
113 moduleText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
114 |
|
115 new Label(info, SWT.NONE).setText(Messages.getString("WizardPageDescriptionLabel")); //$NON-NLS-1$ |
|
116 descriptionText = new Text(info, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.WRAP); |
|
117 |
|
118 GC gc = new GC(descriptionText); |
|
119 FontMetrics fm = gc.getFontMetrics(); |
|
120 int cols = 20; |
|
121 int rows = 6; |
|
122 int width = cols * fm.getAverageCharWidth(); |
|
123 int height = rows * fm.getHeight(); |
|
124 |
|
125 GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); |
|
126 gridData.widthHint = width; |
|
127 gridData.heightHint = height; |
|
128 |
|
129 descriptionText.setLayoutData(gridData); |
|
130 |
|
131 new Label(info, SWT.NONE).setText(Messages.getString("WizardPageCopyrightLabel")); //$NON-NLS-1$ |
|
132 copyrightText = new Text(info, SWT.BORDER); |
|
133 copyrightText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
134 |
|
135 new Label(info, SWT.NONE).setText(Messages.getString("WizardPageLicenseLabel")); //$NON-NLS-1$ |
|
136 licenseText = new Combo(info, SWT.BORDER|SWT.READ_ONLY); |
|
137 licenseText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
138 |
|
139 new Label(info, SWT.NONE).setText(Messages.getString("WizardPageCompanyLabel")); //$NON-NLS-1$ |
|
140 companyNameText = new Combo(info, SWT.BORDER); |
|
141 companyNameText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
142 |
|
143 new Label(info, SWT.NONE).setText(Messages.getString("WizardPageCopyrightStringLabel")); |
|
144 copyrightString = new Combo(info, SWT.BORDER);// | SWT.V_SCROLL | SWT.MULTI | SWT.WRAP); |
|
145 copyrightString.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); |
|
146 |
|
147 GridData data=new GridData(GridData.FILL_HORIZONTAL); |
|
148 data.heightHint=30; |
|
149 cleanBtn=new Button(topLevel,SWT.CHECK); |
|
150 cleanBtn.setText(Messages.getString("WizardPageIncludeInstructionsLabel")); |
|
151 cleanBtn.setSelection(true); |
|
152 cleanBtn.setLayoutData(data); |
|
153 |
|
154 setControl(topLevel); |
|
155 setPageComplete(true); |
|
156 |
|
157 copyrightText.setText(new Integer(Util.getCopyrightYear()).toString()); |
|
158 licenseText.setItems(Util.getDefaultLicence()); |
|
159 licenseText.select(0); |
|
160 |
|
161 LastUsedData previousData = new LastUsedData(); |
|
162 String[] values = previousData.getPreviousValues(LastUsedData.ValueTypes.NAME); |
|
163 if(values!=null) |
|
164 { |
|
165 companyNameText.setItems(values); |
|
166 companyNameText.select(0); |
|
167 } |
|
168 else |
|
169 { |
|
170 companyNameText.setText(Util.getDefaultCompanyName()); |
|
171 previousData.saveValues(LastUsedData.ValueTypes.NAME, companyNameText.getText()); |
|
172 } |
|
173 |
|
174 values = previousData.getPreviousValues(LastUsedData.ValueTypes.COPYRIGHT); |
|
175 if(values !=null) |
|
176 { |
|
177 copyrightString.setItems(values); |
|
178 copyrightString.select(0); |
|
179 } |
|
180 else |
|
181 { |
|
182 copyrightString.setText(Util.getDefaultCompanyCopyright()); |
|
183 previousData.saveValues(LastUsedData.ValueTypes.COPYRIGHT, copyrightString.getText()); |
|
184 } |
|
185 |
|
186 if(!preferenceStore.getBoolean(PreferenceConstants.OPENED_FROM_VIEW)) |
|
187 setPreferencesFromStore(); |
|
188 |
|
189 performHelp(); |
|
190 //updateStatus(); |
|
191 topLevel.setFocus(); |
|
192 } |
|
193 |
|
194 public void performHelp() { |
|
195 PlatformUI.getWorkbench().getHelpSystem().setHelp(topLevel, |
|
196 HelpContextIDs.SF_TEMPLATES_OVERVIEW); |
|
197 } |
|
198 |
|
199 @Override |
|
200 public AbstractList<OriginalTemplate> getTemplates() { |
|
201 AbstractList<OriginalTemplate> templates = new ArrayList<OriginalTemplate>(); |
|
202 |
|
203 String[] templateFiles = pageType.getTemplateFiles().split(";"); |
|
204 String fileName = templateFiles[0]; |
|
205 //To return the empty template file name |
|
206 if(!cleanBtn.getSelection()) |
|
207 fileName = templateFiles[1]; |
|
208 templates.add(new OriginalTemplate(SymbianFoundationTemplates.getDefault().getTemplatesPath() + File.separator + fileName, getSelectedFile(), getTransformRules())); |
|
209 |
|
210 return templates; |
|
211 } |
|
212 |
|
213 public AbstractList<IStatus> getStatuses() { |
|
214 AbstractList<IStatus> statuses = new ArrayList<IStatus>(); |
|
215 |
|
216 statuses.add(Util.getFolderNameStatus(folderSelectionControl.getSelectedFolder(), Messages.getString("WizardPageHeaderFolderMsg"))); //$NON-NLS-1$ |
|
217 statuses.add(Util.getFileNameStatus(fileSelectionControl.getSelectedFile(), |
|
218 pageType.getTemplateFiles(), folderSelectionControl.getSelectedFolder())); |
|
219 |
|
220 return statuses; |
|
221 } |
|
222 |
|
223 protected void updateFields() { |
|
224 moduleText.setText(Util.getModuleName(folderSelectionControl.getSelectedFolder())); |
|
225 subSystemText.setText(Util.getSubSystemName(folderSelectionControl.getSelectedFolder())); |
|
226 } |
|
227 |
|
228 protected void savePreferencesToStore() { |
|
229 if(preferenceStore.getBoolean(PreferenceConstants.OPENED_FROM_VIEW)==false) |
|
230 { |
|
231 preferenceStore.setValue(PreferenceConstants.SF_HEADER_PAGE_DIRECTORY, folderSelectionControl.getSelectedFolder()); |
|
232 preferenceStore.setValue(PreferenceConstants.SF_HEADER_PAGE_MODULE, moduleText.getText()); |
|
233 preferenceStore.setValue(PreferenceConstants.SF_HEADER_PAGE_SUBSYSTEM, subSystemText.getText()); |
|
234 } |
|
235 preferenceStore.setValue(PreferenceConstants.SF_LICENSE_INDEX, licenseText.getSelectionIndex()); |
|
236 LastUsedData saveData = new LastUsedData(); |
|
237 saveData.saveValues(LastUsedData.ValueTypes.NAME, companyNameText.getText()); |
|
238 saveData.saveValues(LastUsedData.ValueTypes.COPYRIGHT, copyrightString.getText()); |
|
239 } |
|
240 |
|
241 private Map<String, String> getTransformRules() { |
|
242 Map<String, String> transformRules = new HashMap<String, String>(); |
|
243 |
|
244 transformRules.put(S60TransformKeys.getString("key_filename"), fileSelectionControl.getSelectedFileWithoutExtension()); //$NON-NLS-1$ |
|
245 transformRules.put(S60TransformKeys.getString("key_module"), moduleText.getText()); //$NON-NLS-1$ |
|
246 transformRules.put(S60TransformKeys.getString("key_subsystem"), subSystemText.getText()); //$NON-NLS-1$ |
|
247 transformRules.put(S60TransformKeys.getString("key_description"), descriptionText.getText()); //$NON-NLS-1$ |
|
248 transformRules.put(S60TransformKeys.getString("key_copyright"), copyrightText.getText()); //$NON-NLS-1$ |
|
249 transformRules.put(S60TransformKeys.getString("key_classname"), fileSelectionControl.getSelectedFileWithoutExtension()); //$NON-NLS-1$ |
|
250 transformRules.put(S60TransformKeys.getString("key_license"), licenseText.getText()); //$NON-NLS-1$ |
|
251 transformRules.put(S60TransformKeys.getString("key_companyname"), companyNameText.getText()); //$NON-NLS-1$ |
|
252 transformRules.put(S60TransformKeys.getString("key_companycopyright"), copyrightString.getText()); |
|
253 |
|
254 if(licenseText.getText().equalsIgnoreCase("Symbian Foundation License v1.0")) |
|
255 transformRules.put(S60TransformKeys.getString("key_licenseurl"), "http://www.symbianfoundation.org/legal/sfl-v10.html"); |
|
256 else if(licenseText.getText().equalsIgnoreCase("Eclipse Public License v1.0")) |
|
257 transformRules.put(S60TransformKeys.getString("key_licenseurl"), "http://www.eclipse.org/legal/epl-v10.html"); |
|
258 |
|
259 String upperCaseClassName = fileSelectionControl.getSelectedFileWithoutExtension().toUpperCase(); |
|
260 |
|
261 switch(pageType) { |
|
262 case C_HEADER_PAGE: |
|
263 transformRules.put(S60TransformKeys.getString("key_cclassname"), "C_" + upperCaseClassName + "_H"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
264 break; |
|
265 case M_HEADER_PAGE: |
|
266 transformRules.put(S60TransformKeys.getString("key_mclassname"), "M_" + upperCaseClassName + "_H"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
267 break; |
|
268 case R_HEADER_PAGE: |
|
269 transformRules.put(S60TransformKeys.getString("key_rclassname"), "R_" + upperCaseClassName + "_H"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
270 break; |
|
271 case T_HEADER_PAGE: |
|
272 transformRules.put(S60TransformKeys.getString("key_tclassname"), "T_" + upperCaseClassName + "_H"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
273 break; |
|
274 } |
|
275 |
|
276 return transformRules; |
|
277 } |
|
278 |
|
279 private IFile getSelectedFile() { |
|
280 return ResourcesPlugin.getWorkspace().getRoot().getFile( |
|
281 new Path(folderSelectionControl.getSelectedFolder() |
|
282 + File.separator |
|
283 + fileSelectionControl.getSelectedFile())); |
|
284 } |
|
285 |
|
286 private void setPreferencesFromStore() { |
|
287 if(preferenceStore.getBoolean(PreferenceConstants.OPENED_FROM_VIEW)==false && preferenceStore.getString(PreferenceConstants.SF_HEADER_PAGE_DIRECTORY)!="") |
|
288 { |
|
289 folderSelectionControl.setSelectedFolder(preferenceStore.getString(PreferenceConstants.SF_HEADER_PAGE_DIRECTORY)); |
|
290 moduleText.setText(preferenceStore.getString(PreferenceConstants.SF_HEADER_PAGE_MODULE)); |
|
291 subSystemText.setText(preferenceStore.getString(PreferenceConstants.SF_HEADER_PAGE_SUBSYSTEM)); |
|
292 } |
|
293 licenseText.select(preferenceStore.getInt(PreferenceConstants.SF_LICENSE_INDEX)); |
|
294 } |
|
295 } |