|
Lines 46-52
Link Here
|
| 46 |
* |
46 |
* |
| 47 |
* @author Bianca Xue Jiang |
47 |
* @author Bianca Xue Jiang |
| 48 |
* @author Paul E. Slauenwhite |
48 |
* @author Paul E. Slauenwhite |
| 49 |
* @version October 31, 2008 |
49 |
* @version November 4, 2008 |
| 50 |
* @since March 18, 2005 |
50 |
* @since March 18, 2005 |
| 51 |
*/ |
51 |
*/ |
| 52 |
public class DatapoolImportWizard extends Wizard implements IImportWizard { |
52 |
public class DatapoolImportWizard extends Wizard implements IImportWizard { |
|
Lines 110-237
Link Here
|
| 110 |
*/ |
110 |
*/ |
| 111 |
public boolean performFinish() { |
111 |
public boolean performFinish() { |
| 112 |
|
112 |
|
| 113 |
IRunnableWithProgress operation = new WorkspaceModifyOperation() { |
113 |
IRunnableWithProgress operation = new WorkspaceModifyOperation() { |
| 114 |
|
114 |
|
| 115 |
public void execute(IProgressMonitor monitor) throws InvocationTargetException { |
115 |
public void execute(IProgressMonitor monitor) throws InvocationTargetException { |
| 116 |
|
116 |
|
| 117 |
monitor.beginTask(UiPluginResourceBundle.DatapoolImportWizard_progressMonitor, 4); |
117 |
monitor.beginTask(UiPluginResourceBundle.DatapoolImportWizard_progressMonitor, 4); |
| 118 |
|
118 |
|
| 119 |
try { |
119 |
//Resolve the selected datapool: |
| 120 |
|
120 |
IDatapool datapool = datapoolImportPageTwo.getSelectedDatapool(); |
| 121 |
IDatapool datapool = datapoolImportPageTwo.getSelectedDatapool(); |
121 |
boolean isEncrypted = datapoolImportPageTwo.isSelectedDatapoolEncrypted(); |
| 122 |
|
122 |
String password = datapoolImportPageTwo.getEncryptedDatapoolPassword(); |
| 123 |
monitor.worked(1); |
123 |
|
| 124 |
|
124 |
try { |
| 125 |
if(datapool == null){ |
125 |
|
| 126 |
|
126 |
monitor.worked(1); |
| 127 |
//Assumption: The file name will include the file extension (see org.eclipse.tptp.platform.common.ui.wizard.LocationPage.getFileName()). |
127 |
|
| 128 |
String datapoolFileName = locationPage.getFileName(); |
128 |
if(datapool != null){ |
| 129 |
|
129 |
|
| 130 |
datapool = ((DPLDatapool)(DatapoolUtil.createNewDatapool(datapoolFileName.substring(0, datapoolFileName.indexOf('.')), null))); |
130 |
if(isEncrypted){ |
| 131 |
|
131 |
DatapoolEncryptManager.decryptDatapool(datapool, password); |
| 132 |
Resource datapoolResource = EMFUtil.getResourceFactory(locationPage.getFileExtension()).createResource(URI.createPlatformResourceURI(locationPage.getContainerFullPath().append(datapoolFileName).toOSString(), false)); |
132 |
} |
| 133 |
datapoolResource.getContents().add(datapool); |
133 |
|
| 134 |
} |
134 |
//Empty the datapool if it contains only an empty default cell: |
| 135 |
|
135 |
if(CSVImportExportUtil.getInstance().isDefaultEmptyDatapool(datapool)){ |
| 136 |
//If the existing datapool only contains only an empty default cell, empty the datapool: |
136 |
|
| 137 |
else if(CSVImportExportUtil.getInstance().isDefaultEmptyDatapool(datapool)){ |
137 |
datapool.removeVariable(0); |
| 138 |
|
138 |
datapool.removeEquivalenceClass(0); |
| 139 |
datapool.removeVariable(0); |
139 |
} |
| 140 |
datapool.removeEquivalenceClass(0); |
140 |
} |
| 141 |
} |
141 |
else { |
| 142 |
|
142 |
|
| 143 |
String key = datapoolImportPageTwo.getEncryptedDatapoolPasswordText().getText(); |
143 |
//Assumption: The file name will include the file extension (see org.eclipse.tptp.platform.common.ui.wizard.LocationPage.getFileName()). |
| 144 |
|
144 |
String datapoolFileName = locationPage.getFileName(); |
| 145 |
if(datapoolImportPageTwo.isEncrypted()){ |
145 |
|
| 146 |
if(!DatapoolEncryptManager.isKeyCorrect(datapool, key)){ |
146 |
//Create a new datapool: |
| 147 |
datapoolImportPageTwo.setMessage(UiPluginResourceBundle.DatapoolExportWizard_wrongpass,3); |
147 |
datapool = ((DPLDatapool)(DatapoolUtil.createNewDatapool(datapoolFileName.substring(0, datapoolFileName.indexOf('.')), null))); |
| 148 |
datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setText(""); |
148 |
|
| 149 |
datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setFocus(); |
149 |
//Create the resource and add the datapool: |
| 150 |
throw new Exception("Password is not correct!"); |
150 |
EMFUtil.getResourceFactory(locationPage.getFileExtension()).createResource(URI.createPlatformResourceURI(locationPage.getContainerFullPath().append(datapoolFileName).toOSString(), false)).getContents().add(datapool); |
| 151 |
} |
151 |
} |
| 152 |
} |
152 |
|
| 153 |
|
153 |
monitor.worked(1); |
| 154 |
if( DatapoolEncryptManager.isDatapoolEncrypted(datapool)) |
154 |
|
| 155 |
{ |
155 |
if(datapool.getVariableCount() == 0){ |
| 156 |
DatapoolEncryptManager.decryptDatapool(datapool, key); |
156 |
|
| 157 |
} |
157 |
//Import the CSV file to the datapool: |
| 158 |
|
158 |
CSVImportExportUtil.getInstance().importCSV(datapool, |
| 159 |
monitor.worked(1); |
159 |
datapoolImportPage.getCSVFileName(), |
| 160 |
|
160 |
datapoolImportPage.firstRowContainsVariableNameType(), |
| 161 |
if(datapool.getVariableCount() == 0){ |
161 |
datapoolImportPage.firstColumnContainsEquivalenceClassName(), |
| 162 |
|
162 |
datapoolImportPage.getImportEncoding()); |
| 163 |
CSVImportExportUtil.getInstance().importCSV(datapool, |
163 |
} |
| 164 |
datapoolImportPage.getCSVFileName(), |
164 |
else{ |
| 165 |
datapoolImportPage.firstRowContainsVariableNameType(), |
165 |
|
| 166 |
datapoolImportPage.firstColumnContainsEquivalenceClassName(), |
166 |
//Append the CSV file to the datapool: |
| 167 |
datapoolImportPage.getImportEncoding()); |
167 |
CSVImportExportUtil.getInstance().appendFromCSV(datapool, |
| 168 |
} |
168 |
datapoolImportPage.getCSVFileName(), |
| 169 |
else{ |
169 |
datapoolImportPage.firstRowContainsVariableNameType(), |
| 170 |
|
170 |
datapoolImportPage.firstColumnContainsEquivalenceClassName(), |
| 171 |
CSVImportExportUtil.getInstance().appendFromCSV(datapool, |
171 |
datapoolImportPage.getImportEncoding()); |
| 172 |
datapoolImportPage.getCSVFileName(), |
172 |
} |
| 173 |
datapoolImportPage.firstRowContainsVariableNameType(), |
173 |
|
| 174 |
datapoolImportPage.firstColumnContainsEquivalenceClassName(), |
174 |
monitor.worked(1); |
| 175 |
datapoolImportPage.getImportEncoding()); |
175 |
|
| 176 |
} |
176 |
Resource datapoolResource = ((EObject)(datapool)).eResource(); |
| 177 |
|
177 |
|
| 178 |
monitor.worked(1); |
178 |
//Save (or serialize) the datapool resource to the workspace: |
| 179 |
|
179 |
EMFUtil.save(datapoolResource); |
| 180 |
if( DatapoolEncryptManager.isDatapoolEncrypted(datapool)) |
180 |
|
| 181 |
{ |
181 |
//Attempt to open the editor: |
| 182 |
DatapoolEncryptManager.encryptDatapool(datapool, key); |
182 |
TestUIUtilities.openEditor(datapoolResource, TestUIExtension.DATAPOOL_EDITOR_PART_ID); |
| 183 |
} |
183 |
|
| 184 |
|
184 |
monitor.worked(1); |
| 185 |
Resource datapoolResource = ((EObject)(datapool)).eResource(); |
185 |
} |
| 186 |
|
186 |
catch(Exception e){ |
| 187 |
//Save (or serialize) the datapool resource to the workspace: |
187 |
|
| 188 |
EMFUtil.save(datapoolResource); |
188 |
UiPlugin.logError(e); |
| 189 |
|
189 |
|
| 190 |
//Attempt to open the editor: |
190 |
new ErrorDialog(getShell(), |
| 191 |
TestUIUtilities.openEditor(datapoolResource, TestUIExtension.DATAPOOL_EDITOR_PART_ID); |
191 |
UiPluginResourceBundle.WIZ_DATAPOOL_CSV_ERRDLG_TITLE, |
| 192 |
|
192 |
UiPluginResourceBundle._ERROR_WIZ_DATAPOOL_CSV_ERRDLG_IMPFILE, |
| 193 |
monitor.worked(1); |
193 |
new Status(IStatus.ERROR, |
| 194 |
} |
194 |
UiPlugin.PLUGIN_ID, |
| 195 |
catch(Exception e){ |
195 |
IStatus.OK, |
| 196 |
|
196 |
e.toString(), |
| 197 |
UiPlugin.logError(e); |
197 |
e), |
| 198 |
|
198 |
IStatus.ERROR).open(); |
| 199 |
new ErrorDialog(getShell(), |
199 |
} |
| 200 |
UiPluginResourceBundle.WIZ_DATAPOOL_CSV_ERRDLG_TITLE, |
200 |
finally{ |
| 201 |
UiPluginResourceBundle._ERROR_WIZ_DATAPOOL_CSV_ERRDLG_IMPFILE, |
201 |
|
| 202 |
new Status(IStatus.ERROR, |
202 |
//Encrypted the datapool if decrypted: |
| 203 |
UiPlugin.PLUGIN_ID, |
203 |
if(isEncrypted){ |
| 204 |
IStatus.OK, |
204 |
DatapoolEncryptManager.encryptDatapool(datapool, password); |
| 205 |
e.toString(), |
205 |
} |
| 206 |
e), |
206 |
|
| 207 |
IStatus.ERROR).open(); |
207 |
monitor.done(); |
| 208 |
} |
|
|
| 209 |
finally{ |
| 210 |
monitor.done(); |
| 211 |
} |
| 212 |
} |
| 213 |
}; |
| 214 |
|
| 215 |
try { |
| 216 |
String key = datapoolImportPageTwo.getEncryptedDatapoolPasswordText().getText(); |
| 217 |
IDatapool datapool = datapoolImportPageTwo.getSelectedDatapool(); |
| 218 |
if(datapoolImportPageTwo.isEncrypted()){ |
| 219 |
if(!DatapoolEncryptManager.isKeyCorrect(datapool, key)){ |
| 220 |
datapoolImportPageTwo.setMessage(UiPluginResourceBundle.DatapoolExportWizard_wrongpass,3); |
| 221 |
datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setText(""); |
| 222 |
datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setFocus(); |
| 223 |
return false; |
| 224 |
} |
208 |
} |
| 225 |
} |
209 |
} |
| 226 |
getContainer().run(false, false, operation); |
210 |
}; |
| 227 |
} |
211 |
|
| 228 |
catch (InvocationTargetException e) { |
212 |
try { |
| 229 |
UiPlugin.logError(e); |
213 |
getContainer().run(false, false, operation); |
| 230 |
} |
214 |
} |
| 231 |
catch (InterruptedException e) { |
215 |
catch (InvocationTargetException e) { |
| 232 |
//Ignore since the operation cannot be cancelled. |
216 |
UiPlugin.logError(e); |
| 233 |
} |
217 |
} |
| 234 |
|
218 |
catch (InterruptedException e) { |
|
|
219 |
//Ignore since the operation cannot be canceled. |
| 220 |
} |
| 221 |
|
| 235 |
return true; |
222 |
return true; |
| 236 |
} |
223 |
} |
| 237 |
} |
224 |
} |