|
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.swmtanalyser.wizards; |
|
18 |
|
19 import java.io.File; |
|
20 |
|
21 import org.eclipse.swt.SWT; |
|
22 import org.eclipse.swt.events.ModifyEvent; |
|
23 import org.eclipse.swt.events.ModifyListener; |
|
24 import org.eclipse.swt.events.SelectionEvent; |
|
25 import org.eclipse.swt.events.SelectionListener; |
|
26 import org.eclipse.swt.layout.GridData; |
|
27 import org.eclipse.swt.layout.GridLayout; |
|
28 import org.eclipse.swt.widgets.Button; |
|
29 import org.eclipse.swt.widgets.Composite; |
|
30 import org.eclipse.swt.widgets.Display; |
|
31 import org.eclipse.swt.widgets.FileDialog; |
|
32 import org.eclipse.swt.widgets.Label; |
|
33 import org.eclipse.swt.widgets.Text; |
|
34 import org.eclipse.swt.widgets.Tree; |
|
35 import org.eclipse.swt.widgets.TreeItem; |
|
36 import org.eclipse.ui.PlatformUI; |
|
37 |
|
38 import com.nokia.s60tools.swmtanalyser.resources.HelpContextIds; |
|
39 import com.nokia.s60tools.ui.wizards.S60ToolsWizardPage; |
|
40 /** |
|
41 * First page in the Report Generation wizard. i.e. Comments page. |
|
42 * |
|
43 */ |
|
44 public class CommentsPage extends S60ToolsWizardPage implements SelectionListener, ModifyListener { |
|
45 |
|
46 //Radio button for creating type1 report |
|
47 private Button type1_radio; |
|
48 //Radio button for creating overview type report |
|
49 private Button type2_radio; |
|
50 //Save as button to select the pdf file path/name |
|
51 private Button browse_btn; |
|
52 //Text box to show the selected path |
|
53 private Text path_txt; |
|
54 //Text box to enetr comments |
|
55 private Text commentsText; |
|
56 //Label to explain about the selected radio option |
|
57 private Label info; |
|
58 |
|
59 //Temporary variables used |
|
60 private Tree all_tree_items; |
|
61 private boolean checked = false; |
|
62 |
|
63 /** |
|
64 * Create a comments page |
|
65 * @param pageName |
|
66 * @param all_tree_items |
|
67 */ |
|
68 protected CommentsPage(String pageName, Tree all_tree_items) { |
|
69 super(pageName); |
|
70 setTitle("Report Options"); |
|
71 setDescription("Select your options"); |
|
72 this.all_tree_items = all_tree_items; |
|
73 } |
|
74 |
|
75 /* (non-Javadoc) |
|
76 * @see com.nokia.s60tools.ui.wizards.S60ToolsWizardPage#recalculateButtonStates() |
|
77 */ |
|
78 public void recalculateButtonStates() { |
|
79 |
|
80 } |
|
81 |
|
82 /* (non-Javadoc) |
|
83 * @see com.nokia.s60tools.ui.wizards.S60ToolsWizardPage#setInitialFocus() |
|
84 */ |
|
85 public void setInitialFocus() { |
|
86 |
|
87 } |
|
88 |
|
89 /* (non-Javadoc) |
|
90 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
|
91 */ |
|
92 public void widgetDefaultSelected(SelectionEvent e) { |
|
93 |
|
94 } |
|
95 |
|
96 /* (non-Javadoc) |
|
97 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
98 */ |
|
99 public void widgetSelected(SelectionEvent e) { |
|
100 if(e.widget == browse_btn) |
|
101 { |
|
102 FileDialog dlg = new FileDialog(this.getShell(), SWT.SAVE); |
|
103 dlg.setFilterExtensions(new String[]{"*.pdf"}); |
|
104 String path = dlg.open(); |
|
105 if(path != null) |
|
106 path_txt.setText(path); |
|
107 } |
|
108 else if(e.widget == type1_radio) |
|
109 { |
|
110 //If option 1 is selected, explain about that option. |
|
111 info.setText("This case the report contains only the information about the selected issues.\nAnd graph will be shown for the selected issues."); |
|
112 } |
|
113 else if(e.widget == type2_radio) |
|
114 { |
|
115 //If option 2 is selected, explain about that option. |
|
116 info.setText("This case the report contains the overview information of all the type of issues."); |
|
117 } |
|
118 |
|
119 checkForCompletion(); |
|
120 this.getContainer().updateButtons(); |
|
121 } |
|
122 |
|
123 /* (non-Javadoc) |
|
124 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) |
|
125 */ |
|
126 public void modifyText(ModifyEvent arg0) { |
|
127 checkForCompletion(); |
|
128 this.getContainer().updateButtons(); |
|
129 } |
|
130 |
|
131 /* (non-Javadoc) |
|
132 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
|
133 */ |
|
134 public void createControl(Composite parent) { |
|
135 Composite parentComposite = new Composite(parent, SWT.NONE); |
|
136 parentComposite.setLayout(new GridLayout(2, false)); |
|
137 |
|
138 GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
|
139 gd.horizontalSpan = 2; |
|
140 |
|
141 Label title = new Label(parentComposite, SWT.WRAP); |
|
142 title.setText("Select type of report to be created:"); |
|
143 title.setLayoutData(gd); |
|
144 |
|
145 type1_radio = new Button(parentComposite, SWT.RADIO); |
|
146 type1_radio.setText("Create report for the selected issues"); |
|
147 type1_radio.setLayoutData(gd); |
|
148 type1_radio.setToolTipText("This case the report contains only the information about the selected issues.\nAnd graph will be shown for the selected issues."); |
|
149 type1_radio.addSelectionListener(this); |
|
150 |
|
151 type2_radio = new Button(parentComposite, SWT.RADIO); |
|
152 type2_radio.setText("Create overview report"); |
|
153 type2_radio.setLayoutData(gd); |
|
154 type2_radio.setToolTipText("This case the report contains the overview information of all the type of issues"); |
|
155 type2_radio.addSelectionListener(this); |
|
156 |
|
157 info=new Label(parentComposite,SWT.WRAP); |
|
158 info.setText("This case the report contains only the information about the selected issues.\nAnd graph will be shown for the selected issues."); |
|
159 GridData lblGD=new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1); |
|
160 lblGD.horizontalSpan = 2; |
|
161 lblGD.verticalIndent=8; |
|
162 info.setLayoutData(lblGD); |
|
163 |
|
164 Label comments_label = new Label(parentComposite, SWT.WRAP); |
|
165 comments_label.setText("Enter your comments here:"); |
|
166 GridData lbl_gd = new GridData(GridData.FILL_HORIZONTAL); |
|
167 lbl_gd.horizontalSpan = 2; |
|
168 comments_label.setLayoutData(lbl_gd); |
|
169 |
|
170 commentsText = new Text(parentComposite, SWT.BORDER|SWT.MULTI|SWT.V_SCROLL|SWT.H_SCROLL); |
|
171 GridData txt_gd = new GridData(GridData.FILL_HORIZONTAL); |
|
172 txt_gd.heightHint = 100; |
|
173 txt_gd.horizontalSpan = 2; |
|
174 commentsText.setLayoutData(txt_gd); |
|
175 commentsText.addModifyListener(this); |
|
176 |
|
177 Label browse_label = new Label(parentComposite, SWT.WRAP); |
|
178 browse_label.setText("Provide report file path here:"); |
|
179 browse_label.setLayoutData(lbl_gd); |
|
180 |
|
181 path_txt = new Text(parentComposite, SWT.BORDER); |
|
182 path_txt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
183 path_txt.addModifyListener(this); |
|
184 |
|
185 browse_btn = new Button(parentComposite, SWT.PUSH); |
|
186 browse_btn.setText("Save as..."); |
|
187 browse_btn.addSelectionListener(this); |
|
188 |
|
189 setHelp(parentComposite); |
|
190 setControl(parentComposite); |
|
191 } |
|
192 |
|
193 /** |
|
194 * Check if overview report was selected or not. |
|
195 * @return <code>true</code> if overview report was selected, <code>false</code> otherwise. |
|
196 */ |
|
197 public boolean isOverviewReportSelected() |
|
198 { |
|
199 return type2_radio.getSelection(); |
|
200 } |
|
201 |
|
202 /** |
|
203 * Returns filename with path provided in the text box |
|
204 * @return file name |
|
205 */ |
|
206 public String getFileName() |
|
207 { |
|
208 return path_txt.getText(); |
|
209 } |
|
210 |
|
211 /** |
|
212 * Returns comments provided. |
|
213 * @return comment text |
|
214 */ |
|
215 public String getComments() |
|
216 { |
|
217 return commentsText.getText(); |
|
218 } |
|
219 |
|
220 /* (non-Javadoc) |
|
221 * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage() |
|
222 */ |
|
223 public boolean canFlipToNextPage() { |
|
224 checkForCompletion(); |
|
225 return super.canFlipToNextPage(); |
|
226 } |
|
227 |
|
228 /** |
|
229 * Checks wizard completion. |
|
230 * @return true if completed. |
|
231 */ |
|
232 public boolean checkForCompletion(){ |
|
233 setErrorMessage(null); |
|
234 if(type1_radio.getSelection() && !areItemsChecked()) |
|
235 { |
|
236 setErrorMessage("No issues are selected. Please select some issues in the analysis view."); |
|
237 return false; |
|
238 } |
|
239 else if(commentsText.getText()==null || commentsText.getText() == "") |
|
240 { |
|
241 setErrorMessage("Enter your comments"); |
|
242 return false; |
|
243 } |
|
244 else if(!(new File(path_txt.getText()).isAbsolute())|| !(new File(path_txt.getText())).getParentFile().exists()) |
|
245 { |
|
246 setErrorMessage("Invalid file name"); |
|
247 return false; |
|
248 } |
|
249 return true; |
|
250 } |
|
251 |
|
252 /** |
|
253 * Checks whether any issues are selected or not. |
|
254 * @return true if any issue(child) is selected. |
|
255 */ |
|
256 private boolean areItemsChecked() { |
|
257 checked = false; |
|
258 //To avoid invalid thread access, running in new thread. |
|
259 Display.getDefault().syncExec(new Runnable() { |
|
260 public void run() { |
|
261 for(TreeItem i:all_tree_items.getItems()) |
|
262 { |
|
263 if(i.getItemCount() > 0) |
|
264 { |
|
265 for(TreeItem child : i.getItems()) |
|
266 { |
|
267 if(child.getChecked()) |
|
268 { |
|
269 checked = true; |
|
270 return; |
|
271 } |
|
272 } |
|
273 } |
|
274 } |
|
275 }}); |
|
276 return checked; |
|
277 } |
|
278 |
|
279 /** |
|
280 * Set context sensitive helps |
|
281 * @param parentComposite |
|
282 */ |
|
283 private void setHelp(Composite parentComposite) |
|
284 { |
|
285 PlatformUI.getWorkbench().getHelpSystem().setHelp(parentComposite, |
|
286 HelpContextIds.SWMT_REPORT_WIZARD_HELP); |
|
287 |
|
288 } |
|
289 } |