|
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 the License "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 |
|
18 package com.nokia.carbide.cpp.internal.pi.button.ui; |
|
19 |
|
20 import java.io.File; |
|
21 |
|
22 import org.eclipse.jface.wizard.WizardPage; |
|
23 import org.eclipse.swt.SWT; |
|
24 import org.eclipse.swt.events.ModifyEvent; |
|
25 import org.eclipse.swt.events.ModifyListener; |
|
26 import org.eclipse.swt.events.SelectionAdapter; |
|
27 import org.eclipse.swt.events.SelectionEvent; |
|
28 import org.eclipse.swt.layout.GridData; |
|
29 import org.eclipse.swt.layout.GridLayout; |
|
30 import org.eclipse.swt.widgets.Button; |
|
31 import org.eclipse.swt.widgets.Composite; |
|
32 import org.eclipse.swt.widgets.FileDialog; |
|
33 import org.eclipse.swt.widgets.Label; |
|
34 import org.eclipse.swt.widgets.Text; |
|
35 import org.eclipse.ui.PlatformUI; |
|
36 |
|
37 import com.nokia.carbide.cpp.pi.button.ComNokiaCarbidePiButtonHelpIDs; |
|
38 |
|
39 |
|
40 public class ExportBupMapGetXmlTask extends WizardPage { |
|
41 String exportXmlPathString = null; |
|
42 |
|
43 protected ExportBupMapGetXmlTask() { |
|
44 super(Messages.getString("ExportBupMapGetXmlTask.selectProfile")); //$NON-NLS-1$ |
|
45 setTitle(Messages.getString("ExportBupMapGetXmlTask.selectProfile")); //$NON-NLS-1$ |
|
46 setDescription(Messages.getString("ExportBupMapGetXmlTask.exportProfileExplained")); //$NON-NLS-1$ |
|
47 } |
|
48 |
|
49 // controls |
|
50 Composite container; |
|
51 private Text exportXmlFileText; |
|
52 |
|
53 /* (non-Javadoc) |
|
54 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
|
55 */ |
|
56 public void createControl(Composite parent) { |
|
57 container = new Composite(parent, SWT.NULL); |
|
58 GridLayout layout = new GridLayout(); |
|
59 container.setLayout(layout); |
|
60 layout.numColumns = 1; |
|
61 layout.verticalSpacing = 9; |
|
62 |
|
63 Label labelSampleFile = new Label(container, SWT.NONE); |
|
64 labelSampleFile.setText(Messages.getString("ExportBupMapGetXmlTask.exportThisProfile")); //$NON-NLS-1$ |
|
65 |
|
66 // subcomposite with textbox/button |
|
67 Composite subContainer = new Composite(container, SWT.NULL); |
|
68 GridLayout subLayout = new GridLayout(); |
|
69 subContainer.setLayout(subLayout); |
|
70 subContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
71 subLayout.numColumns = 2; |
|
72 subLayout.verticalSpacing = 9; |
|
73 |
|
74 exportXmlFileText = new Text(subContainer, SWT.BORDER | SWT.SINGLE); |
|
75 exportXmlFileText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
76 exportXmlFileText.addModifyListener(new ModifyListener(){ |
|
77 public void modifyText(ModifyEvent arg0) { |
|
78 validatePage(); |
|
79 } |
|
80 }); |
|
81 |
|
82 Button button = new Button(subContainer, SWT.PUSH); |
|
83 button.setText(Messages.getString("ExportBupMapGetXmlTask.keyPressProfile")); //$NON-NLS-1$ |
|
84 button.addSelectionListener(new SelectionAdapter() { |
|
85 public void widgetSelected(SelectionEvent e) { |
|
86 handleBrowse(); |
|
87 } |
|
88 }); |
|
89 |
|
90 // top tap get focus |
|
91 exportXmlFileText.setFocus(); |
|
92 |
|
93 setControl(container); |
|
94 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ComNokiaCarbidePiButtonHelpIDs.PI_KEY_MAP_EXPORT_WIZARD_XML); |
|
95 } |
|
96 |
|
97 public void validatePage() { |
|
98 if (exportXmlFileText.getText() == null || exportXmlFileText.getText().length() < 1) { |
|
99 updateStatus(null); |
|
100 setPageComplete(false); |
|
101 return; // blank should be OK, consistent with Eclipse guideline |
|
102 } |
|
103 |
|
104 setMessage(null, WARNING); |
|
105 String xmlFileString = exportXmlFileText.getText(); |
|
106 File xmlFile = new File (xmlFileString); |
|
107 if (xmlFile != null && !xmlFile.isDirectory()) { |
|
108 String parentString = xmlFile.getParent(); |
|
109 if (parentString != null) { |
|
110 File parentFile = new File(parentString); |
|
111 if (parentFile.isDirectory() && parentFile.exists()) { |
|
112 if (!xmlFileString.endsWith(".xml")) { //$NON-NLS-1$ |
|
113 updateStatus (Messages.getString("ExportBupMapGetXmlTask.extensionMustBeXML")); //$NON-NLS-1$ |
|
114 return; |
|
115 } |
|
116 } else { |
|
117 updateStatus(Messages.getString("ExportBupMapGetXmlTask.directory") + parentString + Messages.getString("ExportBupMapGetXmlTask.doesNotExist")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
118 return; |
|
119 } |
|
120 } else { |
|
121 updateStatus(Messages.getString("ExportBupMapGetXmlTask.directory") + xmlFileString + Messages.getString("ExportBupMapGetXmlTask.doesNotExist")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
122 return; |
|
123 } |
|
124 } else { |
|
125 updateStatus(Messages.getString("ExportBupMapGetXmlTask.enterFileName")); //$NON-NLS-1$ |
|
126 return; |
|
127 } |
|
128 |
|
129 exportXmlPathString = xmlFileString; |
|
130 if (new File(exportXmlPathString).exists()) { |
|
131 setMessage(exportXmlPathString + Messages.getString("ExportBupMapGetXmlTask.willBeOverwritten"), WARNING); //$NON-NLS-1$ |
|
132 } |
|
133 |
|
134 setPageComplete(true); |
|
135 updateStatus(null); |
|
136 } |
|
137 |
|
138 private void updateStatus(String message) { |
|
139 // need to enable finish, setPageComplete eventually check global states |
|
140 setErrorMessage(message); |
|
141 setPageComplete(message == null); |
|
142 } |
|
143 |
|
144 private void handleBrowse() { |
|
145 FileDialog dialog = new FileDialog(getShell()); |
|
146 String[] datExtensions = {"*.xml", //$NON-NLS-1$ |
|
147 "*.*"}; //$NON-NLS-1$ |
|
148 String[] datNames = {Messages.getString("ExportBupMapGetXmlTask.profilerFiles"), //$NON-NLS-1$ |
|
149 Messages.getString("ExportBupMapGetXmlTask.allFiles")}; //$NON-NLS-1$ |
|
150 dialog.setFilterExtensions(datExtensions); |
|
151 dialog.setFilterNames(datNames); |
|
152 // Try guiding user to path user is trying to fill |
|
153 File clueFile = new File(exportXmlFileText.getText()); |
|
154 String cluePath = null; |
|
155 if (clueFile.isDirectory()) { |
|
156 cluePath = clueFile.getAbsolutePath(); |
|
157 } else { |
|
158 cluePath = clueFile.getParent(); |
|
159 } |
|
160 if (cluePath != null) { |
|
161 dialog.setFilterPath(cluePath); |
|
162 } |
|
163 String filePath = dialog.open(); |
|
164 |
|
165 if (filePath != null) { |
|
166 if (filePath.length() > 0) { |
|
167 if (!filePath.endsWith(".xml")) { //$NON-NLS-1$ |
|
168 filePath += ".xml"; //$NON-NLS-1$ |
|
169 } |
|
170 exportXmlFileText.setText(filePath); |
|
171 } |
|
172 } |
|
173 } |
|
174 |
|
175 public String getExportXml() { |
|
176 return exportXmlPathString; |
|
177 } |
|
178 } |