|
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.testfw.codegen.ui.wizard; |
|
18 |
|
19 import java.util.HashSet; |
|
20 import java.util.Map; |
|
21 import java.util.Set; |
|
22 |
|
23 import org.eclipse.cdt.core.CConventions; |
|
24 import org.eclipse.core.resources.IProject; |
|
25 import org.eclipse.core.runtime.CoreException; |
|
26 import org.eclipse.swt.SWT; |
|
27 import org.eclipse.swt.events.ModifyEvent; |
|
28 import org.eclipse.swt.events.ModifyListener; |
|
29 import org.eclipse.swt.events.SelectionAdapter; |
|
30 import org.eclipse.swt.events.SelectionEvent; |
|
31 import org.eclipse.swt.layout.GridData; |
|
32 import org.eclipse.swt.widgets.Button; |
|
33 import org.eclipse.swt.widgets.Composite; |
|
34 import org.eclipse.swt.widgets.Label; |
|
35 import org.eclipse.swt.widgets.Text; |
|
36 |
|
37 import com.nokia.testfw.codegen.ui.CodegenUIPlugin; |
|
38 import com.nokia.testfw.codegen.ui.Messages; |
|
39 import com.nokia.testfw.codegen.ui.parser.ProjectInfoHelper; |
|
40 |
|
41 public class ModuleAndPropertyPage extends PropertyPage { |
|
42 |
|
43 private Text iModuleNameText; |
|
44 private String iModuleName; |
|
45 private Set<String> iModuleSet = new HashSet<String>(); |
|
46 private Button iModuleSeparateFolderBtn; |
|
47 private boolean iSeparateFolder = false; |
|
48 private IProject iProject; |
|
49 |
|
50 public ModuleAndPropertyPage() { |
|
51 super(Messages.getString("ModuleAndPropertyPage.Title")); |
|
52 setTitle(Messages.getString("ModuleAndPropertyPage.Title")); |
|
53 setDescription(Messages.getString("ModuleAndPropertyPage.Description")); |
|
54 } |
|
55 |
|
56 protected void customExtention(Composite parent) { |
|
57 // Module |
|
58 Label lTestFolderLocationLabel = new Label(parent, SWT.NONE); |
|
59 GridData gd_TestFolderLocationLabel = new GridData(); |
|
60 lTestFolderLocationLabel.setLayoutData(gd_TestFolderLocationLabel); |
|
61 lTestFolderLocationLabel.setText("Test Class Name:"); |
|
62 |
|
63 iModuleNameText = new Text(parent, SWT.BORDER); |
|
64 GridData gd_ModuleNameText = new GridData(4, 16777216, true, false); |
|
65 gd_ModuleNameText.horizontalSpan = 2; |
|
66 iModuleNameText.setLayoutData(gd_ModuleNameText); |
|
67 iModuleNameText.addModifyListener(new ModifyListener() { |
|
68 public void modifyText(ModifyEvent event) { |
|
69 setPageComplete(validatePage()); |
|
70 } |
|
71 }); |
|
72 |
|
73 iModuleSeparateFolderBtn = new Button(parent, SWT.CHECK); |
|
74 GridData gd_TModuleSeparateFolderBtn = new GridData(); |
|
75 gd_TModuleSeparateFolderBtn.horizontalSpan = 3; |
|
76 iModuleSeparateFolderBtn.setLayoutData(gd_TModuleSeparateFolderBtn); |
|
77 iModuleSeparateFolderBtn |
|
78 .setText("Create individual folder for this Test Class"); |
|
79 iModuleSeparateFolderBtn.addSelectionListener(new SelectionAdapter() { |
|
80 public void widgetSelected(SelectionEvent event) { |
|
81 iSeparateFolder = iModuleSeparateFolderBtn.getSelection(); |
|
82 } |
|
83 }); |
|
84 iModuleSeparateFolderBtn.setSelection(iSeparateFolder); |
|
85 } |
|
86 |
|
87 @Override |
|
88 public void initPage(Map<String, Object> dataMap) { |
|
89 super.initPage(dataMap); |
|
90 iProject = ((AbstractTemplateWizard) getWizard()).getTargetProject(); |
|
91 try { |
|
92 if (((AbstractTemplateWizard) getWizard()).isShowNewProjectPage()) { |
|
93 String lProjectName = (String) iDataMap |
|
94 .get(AbstractTemplateWizard.PROJECT_NAME); |
|
95 iModuleNameText.setText(lProjectName); |
|
96 } else { |
|
97 String modules = ProjectInfoHelper.getProjectStorage(iProject, |
|
98 STFNewTestWizard.STF_SCRIPT, STFNewTestWizard.MODULES); |
|
99 if (modules != null) { |
|
100 String[] module = modules.split(","); |
|
101 for (String m : module) { |
|
102 iModuleSet.add(m.toLowerCase()); |
|
103 } |
|
104 } |
|
105 |
|
106 String separate_folder = ProjectInfoHelper.getProjectStorage( |
|
107 iProject, STFNewTestWizard.STF_SCRIPT, |
|
108 STFNewTestWizard.SEPARATE_FOLDER); |
|
109 iSeparateFolder = Boolean.parseBoolean(separate_folder); |
|
110 iModuleSeparateFolderBtn.setSelection(iSeparateFolder); |
|
111 } |
|
112 } catch (CoreException e) { |
|
113 CodegenUIPlugin.getDefault().getLog().log(e.getStatus()); |
|
114 } |
|
115 } |
|
116 |
|
117 protected boolean validatePage() { |
|
118 boolean isValid = true; |
|
119 setMessage(null); |
|
120 |
|
121 if(!(CConventions.validateFieldName(iModuleNameText.getText()).isOK())){ |
|
122 isValid = false; |
|
123 setErrorMessage(Messages |
|
124 .getString("ModuleAndPropertyPage.Invalid_ModuleName")); |
|
125 } |
|
126 if (iModuleSet.contains(iModuleNameText.getText().toLowerCase())) { |
|
127 isValid = false; |
|
128 setErrorMessage(Messages |
|
129 .getString("ModuleAndPropertyPage.Duplicate_ModuleName")); |
|
130 } |
|
131 |
|
132 if (isValid) { |
|
133 iModuleName = iModuleNameText.getText().trim(); |
|
134 iSeparateFolder = iModuleSeparateFolderBtn.getSelection(); |
|
135 setErrorMessage(null); |
|
136 return super.validatePage(); |
|
137 } |
|
138 return isValid; |
|
139 } |
|
140 |
|
141 public String getModuleName() { |
|
142 return iModuleNameText.getText().trim(); |
|
143 } |
|
144 |
|
145 public void setModuleName(String module) { |
|
146 iModuleName = module; |
|
147 } |
|
148 |
|
149 public void collectData() { |
|
150 super.collectData(); |
|
151 iDataMap.put("class_name", iModuleName); |
|
152 ((STFNewTestWizard) getWizard()).setModuleName(iModuleName); |
|
153 if (iSeparateFolder) { |
|
154 ((AbstractTemplateWizard) getWizard()) |
|
155 .setTestFolderLocation(iModuleName); |
|
156 } else { |
|
157 ((AbstractTemplateWizard) getWizard()).setTestFolderLocation(null); |
|
158 } |
|
159 } |
|
160 } |