Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 117601 Details for
Bug 249588
Datapool (CSV) import/export wizard/operation is slow when importing large CSV files.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch.
Defect_249588_Patch.txt (text/plain), 86.91 KB, created by
Paul Slauenwhite
on 2008-11-11 18:27:23 EST
(
hide
)
Description:
Patch.
Filename:
MIME Type:
Creator:
Paul Slauenwhite
Created:
2008-11-11 18:27:23 EST
Size:
86.91 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.hyades.test.ui >Index: src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolCSVImportPage.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolCSVImportPage.java,v >retrieving revision 1.12 >diff -u -r1.12 DatapoolCSVImportPage.java >--- src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolCSVImportPage.java 4 Mar 2008 19:21:36 -0000 1.12 >+++ src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolCSVImportPage.java 11 Nov 2008 23:27:04 -0000 >@@ -27,6 +27,7 @@ > import org.eclipse.swt.events.ModifyListener; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Cursor; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Button; >@@ -35,6 +36,7 @@ > import org.eclipse.swt.widgets.FileDialog; > import org.eclipse.swt.widgets.Group; > import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.Text; > > /** >@@ -43,7 +45,7 @@ > * > * @author Peter Sun > * @author Paul E. Slauenwhite >- * @version March 4, 2008 >+ * @version November 11, 2008 > * @since February 1, 2005 > */ > public class DatapoolCSVImportPage extends WizardPage implements ModifyListener, SelectionListener { >@@ -286,26 +288,37 @@ > return; > } > >- protected boolean validateSelection() >- { >- setErrorMessage(null); >- boolean isCSVValid = true; >- String path = csvFileText.getText().trim(); >- try >- { >- if (path.length() > 0) { //- Bugzilla 109208 >- isCSVValid = CSVImportExportUtil.getInstance().validateCSVFile(path, firstRowContainsVariableNameType(), firstColumnContainsEquivalenceClassName(), >- getImportEncoding()); >- } >- } >- catch(Exception e) >- { >- isCSVValid = false; >- setErrorMessage(e.getMessage()); >+ protected void validateSelection(){ >+ >+ //Note: The error message is not initially reset to reduce flicker when setting the same error message. >+ boolean isValid = false; >+ String csvFileName = getCSVFileName(); >+ >+ if((csvFileName != null) && (csvFileName.trim().length() > 0)){ >+ >+ Shell shell = getShell(); >+ >+ //Set the wait cursor: >+ shell.setCursor(new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT)); >+ >+ try{ >+ isValid = CSVImportExportUtil.getInstance().validateCSVFile(csvFileName, firstRowContainsVariableNameType(), firstColumnContainsEquivalenceClassName(), getImportEncoding()); >+ } >+ catch(Exception e){ >+ setErrorMessage(e.getMessage()); >+ } >+ finally{ >+ >+ //Set the default cursor: >+ shell.setCursor(null); >+ } >+ >+ if(isValid){ >+ setErrorMessage(null); >+ } > } > >- setPageComplete(isCSVValid); >- getContainer().updateButtons(); >- return isCSVValid; >+ setPageComplete(isValid); >+ getContainer().updateButtons(); > } > } >Index: src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPage.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPage.java,v >retrieving revision 1.8 >diff -u -r1.8 DatapoolImportPage.java >--- src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPage.java 4 Mar 2008 19:22:54 -0000 1.8 >+++ src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPage.java 11 Nov 2008 23:27:04 -0000 >@@ -11,7 +11,6 @@ > *******************************************************************************/ > package org.eclipse.hyades.test.ui.internal.wizard; > >-import org.eclipse.hyades.test.ui.datapool.internal.util.CSVImportExportUtil; > import org.eclipse.swt.widgets.Composite; > > /** >@@ -19,7 +18,7 @@ > * > * @author Bianca Xue Jiang > * @author Paul E. Slauenwhite >- * @version March 4, 2008 >+ * @version November 11, 2008 > * @since March 23, 2005 > */ > public class DatapoolImportPage extends DatapoolCSVImportPage { >@@ -42,28 +41,4 @@ > setControl(parentComposite); > validateSelection(); > } >- >- protected boolean validateSelection() >- { >- boolean valid = false; >- setMessage(null); >- setErrorMessage(null); >- >- String csvFile = getCSVFileName(); >- >- try{ >- if((csvFile != null) && (csvFile.length() > 0)){ >- valid = CSVImportExportUtil.getInstance().validateCSVFile(csvFile, firstRowContainsVariableNameType(), firstColumnContainsEquivalenceClassName(), getImportEncoding()); >- } >- } >- catch(Exception e){ >- valid = false; >- setErrorMessage(e.getMessage()); >- } >- >- setPageComplete(valid); >- getContainer().updateButtons(); >- >- return valid; >- } > } >Index: src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPageTwo.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPageTwo.java,v >retrieving revision 1.3 >diff -u -r1.3 DatapoolImportPageTwo.java >--- src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPageTwo.java 4 Nov 2008 14:20:23 -0000 1.3 >+++ src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportPageTwo.java 11 Nov 2008 23:27:04 -0000 >@@ -19,18 +19,20 @@ > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.graphics.Cursor; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Group; >+import org.eclipse.swt.widgets.Shell; > > /** > * Datapool CSV import page two. > * > * > * @author Paul E. Slauenwhite >- * @version October 31, 2008 >+ * @version November 11, 2008 > * @since October 31, 2008 > */ > public class DatapoolImportPageTwo extends DatapoolSelectionPage { >@@ -116,6 +118,11 @@ > //Validate the selected datapool: > if(selectedDatapool != null){ > >+ Shell shell = getShell(); >+ >+ //Set the wait cursor: >+ shell.setCursor(new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT)); >+ > try { > > DatapoolImportPage datapoolImportPage = ((DatapoolImportWizard)(getWizard())).getDatapoolImportPage(); >@@ -134,6 +141,11 @@ > catch(Exception e) { > setErrorMessage(e.getMessage()); > } >+ finally{ >+ >+ //Set the default cursor: >+ shell.setCursor(null); >+ } > } > } > } >Index: src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportWizard.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportWizard.java,v >retrieving revision 1.17 >diff -u -r1.17 DatapoolImportWizard.java >--- src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportWizard.java 4 Nov 2008 14:20:23 -0000 1.17 >+++ src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolImportWizard.java 11 Nov 2008 23:27:04 -0000 >@@ -46,7 +46,7 @@ > * > * @author Bianca Xue Jiang > * @author Paul E. Slauenwhite >- * @version October 31, 2008 >+ * @version November 11, 2008 > * @since March 18, 2005 > */ > public class DatapoolImportWizard extends Wizard implements IImportWizard { >@@ -110,128 +110,115 @@ > */ > public boolean performFinish() { > >- IRunnableWithProgress operation = new WorkspaceModifyOperation() { >- >- public void execute(IProgressMonitor monitor) throws InvocationTargetException { >- >- monitor.beginTask(UiPluginResourceBundle.DatapoolImportWizard_progressMonitor, 4); >- >- try { >- >- IDatapool datapool = datapoolImportPageTwo.getSelectedDatapool(); >- >- monitor.worked(1); >- >- if(datapool == null){ >- >- //Assumption: The file name will include the file extension (see org.eclipse.tptp.platform.common.ui.wizard.LocationPage.getFileName()). >- String datapoolFileName = locationPage.getFileName(); >- >- datapool = ((DPLDatapool)(DatapoolUtil.createNewDatapool(datapoolFileName.substring(0, datapoolFileName.indexOf('.')), null))); >- >- Resource datapoolResource = EMFUtil.getResourceFactory(locationPage.getFileExtension()).createResource(URI.createPlatformResourceURI(locationPage.getContainerFullPath().append(datapoolFileName).toOSString(), false)); >- datapoolResource.getContents().add(datapool); >- } >- >- //If the existing datapool only contains only an empty default cell, empty the datapool: >- else if(CSVImportExportUtil.getInstance().isDefaultEmptyDatapool(datapool)){ >- >- datapool.removeVariable(0); >- datapool.removeEquivalenceClass(0); >- } >- >- String key = datapoolImportPageTwo.getEncryptedDatapoolPasswordText().getText(); >- >- if(datapoolImportPageTwo.isEncrypted()){ >- if(!DatapoolEncryptManager.isKeyCorrect(datapool, key)){ >- datapoolImportPageTwo.setMessage(UiPluginResourceBundle.DatapoolExportWizard_wrongpass,3); >- datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setText(""); >- datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setFocus(); >- throw new Exception("Password is not correct!"); >- } >- } >- >- if( DatapoolEncryptManager.isDatapoolEncrypted(datapool)) >- { >- DatapoolEncryptManager.decryptDatapool(datapool, key); >- } >- >- monitor.worked(1); >- >- if(datapool.getVariableCount() == 0){ >- >- CSVImportExportUtil.getInstance().importCSV(datapool, >- datapoolImportPage.getCSVFileName(), >- datapoolImportPage.firstRowContainsVariableNameType(), >- datapoolImportPage.firstColumnContainsEquivalenceClassName(), >- datapoolImportPage.getImportEncoding()); >- } >- else{ >- >- CSVImportExportUtil.getInstance().appendFromCSV(datapool, >- datapoolImportPage.getCSVFileName(), >- datapoolImportPage.firstRowContainsVariableNameType(), >- datapoolImportPage.firstColumnContainsEquivalenceClassName(), >- datapoolImportPage.getImportEncoding()); >- } >- >- monitor.worked(1); >- >- if( DatapoolEncryptManager.isDatapoolEncrypted(datapool)) >- { >- DatapoolEncryptManager.encryptDatapool(datapool, key); >- } >- >- Resource datapoolResource = ((EObject)(datapool)).eResource(); >- >- //Save (or serialize) the datapool resource to the workspace: >- EMFUtil.save(datapoolResource); >- >- //Attempt to open the editor: >- TestUIUtilities.openEditor(datapoolResource, TestUIExtension.DATAPOOL_EDITOR_PART_ID); >- >- monitor.worked(1); >- } >- catch(Exception e){ >- >- UiPlugin.logError(e); >- >- new ErrorDialog(getShell(), >- UiPluginResourceBundle.WIZ_DATAPOOL_CSV_ERRDLG_TITLE, >- UiPluginResourceBundle._ERROR_WIZ_DATAPOOL_CSV_ERRDLG_IMPFILE, >- new Status(IStatus.ERROR, >- UiPlugin.PLUGIN_ID, >- IStatus.OK, >- e.toString(), >- e), >- IStatus.ERROR).open(); >- } >- finally{ >- monitor.done(); >- } >- } >- }; >- >- try { >- String key = datapoolImportPageTwo.getEncryptedDatapoolPasswordText().getText(); >- IDatapool datapool = datapoolImportPageTwo.getSelectedDatapool(); >- if(datapoolImportPageTwo.isEncrypted()){ >- if(!DatapoolEncryptManager.isKeyCorrect(datapool, key)){ >- datapoolImportPageTwo.setMessage(UiPluginResourceBundle.DatapoolExportWizard_wrongpass,3); >- datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setText(""); >- datapoolImportPageTwo.getEncryptedDatapoolPasswordText().setFocus(); >- return false; >+ IRunnableWithProgress operation = new WorkspaceModifyOperation() { >+ >+ public void execute(IProgressMonitor monitor) throws InvocationTargetException { >+ >+ monitor.beginTask(UiPluginResourceBundle.DatapoolImportWizard_progressMonitor, 4); >+ >+ //Resolve the selected datapool: >+ IDatapool datapool = datapoolImportPageTwo.getSelectedDatapool(); >+ boolean isEncrypted = datapoolImportPageTwo.isSelectedDatapoolEncrypted(); >+ String password = datapoolImportPageTwo.getEncryptedDatapoolPassword(); >+ >+ try { >+ >+ monitor.worked(1); >+ >+ if(datapool != null){ >+ >+ if(isEncrypted){ >+ DatapoolEncryptManager.decryptDatapool(datapool, password); >+ } >+ >+ //Empty the datapool if it contains only an empty default cell: >+ if(CSVImportExportUtil.getInstance().isDefaultEmptyDatapool(datapool)){ >+ >+ datapool.removeVariable(0); >+ datapool.removeEquivalenceClass(0); >+ } >+ } >+ else { >+ >+ //Assumption: The file name will include the file extension (see org.eclipse.tptp.platform.common.ui.wizard.LocationPage.getFileName()). >+ String datapoolFileName = locationPage.getFileName(); >+ >+ //Create a new datapool: >+ datapool = ((DPLDatapool)(DatapoolUtil.createNewDatapool(datapoolFileName.substring(0, datapoolFileName.indexOf('.')), null))); >+ >+ //Create the resource and add the datapool: >+ EMFUtil.getResourceFactory(locationPage.getFileExtension()).createResource(URI.createPlatformResourceURI(locationPage.getContainerFullPath().append(datapoolFileName).toOSString(), false)).getContents().add(datapool); >+ } >+ >+ monitor.worked(1); >+ >+ if(datapool.getVariableCount() == 0){ >+ >+ //Import the CSV file to the datapool: >+ CSVImportExportUtil.getInstance().importCSV(datapool, >+ datapoolImportPage.getCSVFileName(), >+ datapoolImportPage.firstRowContainsVariableNameType(), >+ datapoolImportPage.firstColumnContainsEquivalenceClassName(), >+ datapoolImportPage.getImportEncoding()); >+ } >+ else{ >+ >+ //Append the CSV file to the datapool: >+ CSVImportExportUtil.getInstance().appendFromCSV(datapool, >+ datapoolImportPage.getCSVFileName(), >+ datapoolImportPage.firstRowContainsVariableNameType(), >+ datapoolImportPage.firstColumnContainsEquivalenceClassName(), >+ datapoolImportPage.getImportEncoding()); >+ } >+ >+ monitor.worked(1); >+ >+ Resource datapoolResource = ((EObject)(datapool)).eResource(); >+ >+ //Save (or serialize) the datapool resource to the workspace: >+ EMFUtil.save(datapoolResource); >+ >+ //Attempt to open the editor: >+ TestUIUtilities.openEditor(datapoolResource, TestUIExtension.DATAPOOL_EDITOR_PART_ID); >+ >+ monitor.worked(1); >+ } >+ catch(Exception e){ >+ >+ UiPlugin.logError(e); >+ >+ new ErrorDialog(getShell(), >+ UiPluginResourceBundle.WIZ_DATAPOOL_CSV_ERRDLG_TITLE, >+ UiPluginResourceBundle._ERROR_WIZ_DATAPOOL_CSV_ERRDLG_IMPFILE, >+ new Status(IStatus.ERROR, >+ UiPlugin.PLUGIN_ID, >+ IStatus.OK, >+ e.toString(), >+ e), >+ IStatus.ERROR).open(); >+ } >+ finally{ >+ >+ //Encrypted the datapool if decrypted: >+ if(isEncrypted){ >+ DatapoolEncryptManager.encryptDatapool(datapool, password); >+ } >+ >+ monitor.done(); > } > } >- getContainer().run(false, false, operation); >- } >- catch (InvocationTargetException e) { >- UiPlugin.logError(e); >- } >- catch (InterruptedException e) { >- //Ignore since the operation cannot be cancelled. >- } >- >+ }; >+ >+ try { >+ getContainer().run(false, false, operation); >+ } >+ catch (InvocationTargetException e) { >+ UiPlugin.logError(e); >+ } >+ catch (InterruptedException e) { >+ //Ignore since the operation cannot be canceled. >+ } >+ > return true; > } > } >Index: src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolExportWizard.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolExportWizard.java,v >retrieving revision 1.14 >diff -u -r1.14 DatapoolExportWizard.java >--- src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolExportWizard.java 4 Nov 2008 14:20:23 -0000 1.14 >+++ src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolExportWizard.java 11 Nov 2008 23:27:04 -0000 >@@ -12,23 +12,31 @@ > package org.eclipse.hyades.test.ui.internal.wizard; > > import java.io.File; >+import java.io.IOException; > > import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResourceStatus; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Status; > import org.eclipse.hyades.edit.datapool.IDatapool; > import org.eclipse.hyades.models.common.datapool.util.DatapoolEncryptManager; >+import org.eclipse.hyades.test.ui.TestUI; > import org.eclipse.hyades.test.ui.TestUIImages; > import org.eclipse.hyades.test.ui.UiPlugin; > import org.eclipse.hyades.test.ui.datapool.internal.util.CSVImportExportUtil; > import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle; >+import org.eclipse.hyades.test.ui.util.TestUIUtil; >+import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.wizard.Wizard; > import org.eclipse.osgi.util.NLS; > import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Display; > import org.eclipse.ui.IExportWizard; > import org.eclipse.ui.IWorkbench; > >@@ -38,7 +46,7 @@ > > * @author Peter Sun > * @author Paul E. Slauenwhite >- * @version October 31, 2008 >+ * @version November 11, 2008 > * @since February 1, 2005 > */ > public class DatapoolExportWizard extends Wizard implements IExportWizard { >@@ -90,66 +98,73 @@ > /* (non-Javadoc) > * @see org.eclipse.jface.wizard.IWizard#performFinish() > */ >- public boolean performFinish() >- { >+ public boolean performFinish() { >+ >+ //Resolve the selected datapool: >+ //Assumption: The datapool is not null. > IDatapool datapool = datapoolSelectionPage.getSelectedDatapool(); >- String key = datapoolSelectionPage.getEncryptedDatapoolPasswordText().getText(); >- >- if(datapoolSelectionPage.isEncrypted()){ >- if(!DatapoolEncryptManager.isKeyCorrect(datapool, key)){ >- datapoolSelectionPage.setMessage(UiPluginResourceBundle.DatapoolExportWizard_wrongpass,3); >- datapoolSelectionPage.getEncryptedDatapoolPasswordText().setText(""); >- datapoolSelectionPage.getEncryptedDatapoolPasswordText().setFocus(); >- return false; >+ boolean isEncrypted = datapoolSelectionPage.isSelectedDatapoolEncrypted(); >+ String password = datapoolSelectionPage.getEncryptedDatapoolPassword(); >+ >+ try { >+ >+ //Decrypt the datapool if encrypted: >+ if(isEncrypted){ >+ DatapoolEncryptManager.decryptDatapool(datapool, password); >+ } >+ >+ //Resolve the CSV file: >+ String csvFileName = TestUIUtil.validateExtension(csvFileLocationPage.getCSVFileName().trim(), TestUI.CSV_FILE_EXTENSION); >+ >+ if (new File(csvFileName).exists()){ >+ >+ MessageDialog overwriteDialog = new MessageDialog(getShell(), >+ UiPluginResourceBundle.WIZ_EXP_DATAPOOL_TTL, >+ null, >+ NLS.bind(UiPluginResourceBundle.WIZ_EXP_DATAPOOL_MSG_EXISTS, csvFileName), >+ MessageDialog.WARNING, >+ new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, >+ 0); >+ >+ //Return if cannot replace existing CSV file: >+ if (overwriteDialog.open() != IDialogConstants.OK_ID){ >+ return false; >+ } >+ } >+ >+ //Export the datapool to the CSV file: >+ CSVImportExportUtil.getInstance().exportCSV(datapool, csvFileName, >+ csvFileLocationPage.getExportVariables(), >+ csvFileLocationPage.getExportEquivalenceClassNames(), >+ csvFileLocationPage.getExportTags(), >+ csvFileLocationPage.getExportEncoding()); >+ >+ //Refresh the CSV file if exported to the workspace: >+ IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(csvFileName)); >+ >+ for (int counter = 0; counter < files.length; counter++) { >+ >+ try { >+ files[counter].refreshLocal(0, null); >+ } >+ catch (CoreException e) { >+ UiPlugin.logError(e); >+ } > } >+ >+ return true; > } >- >- //decrypt datapool before export it into csv file >- if( DatapoolEncryptManager.isDatapoolEncrypted(datapool)) >- { >- DatapoolEncryptManager.decryptDatapool(datapool, key); >+ catch (IOException i) { >+ ErrorDialog.openError(Display.getCurrent().getActiveShell(), UiPluginResourceBundle.W_ERROR, null, new Status(IStatus.ERROR, UiPlugin.getID(), IResourceStatus.ERROR, i.getMessage(), i)); > } >- String csvFileName = csvFileLocationPage.getCSVFileName(); >- if(!csvFileName.endsWith(".csv") && !csvFileName.endsWith(".CSV")) >- csvFileName = csvFileName + ".csv"; >+ finally{ > >- File file = new File(csvFileName); >- >- if (file.exists()) >- { >- String message = NLS.bind(UiPluginResourceBundle.WIZ_EXP_DATAPOOL_MSG_EXISTS, csvFileName); >- MessageDialog overwriteDialog = new MessageDialog(getShell(), >- UiPluginResourceBundle.WIZ_EXP_DATAPOOL_TTL, >- null, >- message, >- MessageDialog.WARNING, >- new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, >- 0); >- >- // user selected - "don't replace", return false >- if (overwriteDialog.open() != 0) >- return false; >+ //Encrypted the datapool if decrypted: >+ if(isEncrypted){ >+ DatapoolEncryptManager.encryptDatapool(datapool, password); >+ } > } > >- boolean exportVariables = csvFileLocationPage.getExportVariables(); >- boolean exportEqClsNames = csvFileLocationPage.getExportEquivalenceClassNames(); >- boolean exportTags = csvFileLocationPage.getExportTags(); >- String exportEncoding = csvFileLocationPage.getExportEncoding(); >- boolean close = CSVImportExportUtil.getInstance().exportCSV(datapool, csvFileName, exportVariables, exportEqClsNames, exportTags, exportEncoding); >- IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(csvFileName)); >- for (int i = 0; i < files.length; i++) { >- try { >- files[i].refreshLocal(0, null); >- } catch (CoreException e) { >- UiPlugin.logError(e); >- } >- } >- >- //encrypted datapool again after finish export it >- if( DatapoolEncryptManager.isDatapoolEncrypted(datapool)) >- { >- DatapoolEncryptManager.encryptDatapool(datapool, key); >- } >- return close; >+ return false; > } > } >Index: src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolSelectionPage.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolSelectionPage.java,v >retrieving revision 1.1 >diff -u -r1.1 DatapoolSelectionPage.java >--- src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolSelectionPage.java 4 Nov 2008 14:20:23 -0000 1.1 >+++ src/org/eclipse/hyades/test/ui/internal/wizard/DatapoolSelectionPage.java 11 Nov 2008 23:27:04 -0000 >@@ -38,7 +38,7 @@ > * > * > * @author Paul E. Slauenwhite >- * @version October 31, 2008 >+ * @version November 11, 2008 > * @since October 31, 2008 > */ > public class DatapoolSelectionPage extends WizardPage { >@@ -48,7 +48,7 @@ > private Text encryptedDatapoolPasswordText = null; > private IStructuredSelection selection = null; > private IDatapool selectedDatapool = null; >- private boolean isEncrypted = false; >+ private boolean isSelectedDatapoolEncrypted = false; > > public DatapoolSelectionPage(String name){ > this(name, null); >@@ -80,7 +80,7 @@ > super.setSelection(); > > selectedDatapool = null; >- isEncrypted = false; >+ isSelectedDatapoolEncrypted = false; > > IProxyNode[] selectedProxyNodes = datapoolSelectionViewer.getSelectedProxyNodes(); > >@@ -93,12 +93,9 @@ > selectedDatapool = ((IDatapool)(eObject)); > > //Determine if the selected datapool is encrypted: >- isEncrypted = DatapoolEncryptManager.isDatapoolEncrypted(selectedDatapool); >+ isSelectedDatapoolEncrypted = DatapoolEncryptManager.isDatapoolEncrypted(selectedDatapool); > >- //Show or hide the encrypted datapool password group: >- encryptedDatapoolPasswordGroup.setVisible(isEncrypted); >- >- if(isEncrypted){ >+ if((isSelectedDatapoolEncrypted) && (!encryptedDatapoolPasswordGroup.isVisible())){ > > //Set the title of the encrypted datapool password group: > encryptedDatapoolPasswordGroup.setText(NLS.bind(UiPluginResourceBundle.DatapoolExportWizard_password, selectedDatapool.getName())); >@@ -107,6 +104,9 @@ > encryptedDatapoolPasswordText.setText(""); > encryptedDatapoolPasswordText.setFocus(); > } >+ >+ //Show or hide the encrypted datapool password group: >+ encryptedDatapoolPasswordGroup.setVisible(isSelectedDatapoolEncrypted); > } > } > >@@ -127,19 +127,7 @@ > encryptedDatapoolPasswordText.addModifyListener(new ModifyListener(){ > > public void modifyText(ModifyEvent e){ >- >- if(encryptedDatapoolPasswordText.getText().trim().length() > 0){ >- >- setErrorMessage(null); >- >- setPageComplete(true); >- } >- else { >- >- setErrorMessage(NLS.bind(UiPluginResourceBundle.DatapoolExportWizard_encrypted, selectedDatapool.getName())); >- >- setPageComplete(false); >- } >+ setPageComplete(validatePage()); > } > }); > >@@ -153,15 +141,15 @@ > public IDatapool getSelectedDatapool(){ > return selectedDatapool; > } >- >- public Text getEncryptedDatapoolPasswordText(){ >- return encryptedDatapoolPasswordText; >- } > >- public boolean isEncrypted(){ >- return isEncrypted; >+ public boolean isSelectedDatapoolEncrypted(){ >+ return isSelectedDatapoolEncrypted; > } > >+ public String getEncryptedDatapoolPassword(){ >+ return (encryptedDatapoolPasswordText.getText().trim()); >+ } >+ > protected boolean validatePage() { > > //Note: The error message is not initially reset to reduce flicker when setting the same error message. >@@ -171,21 +159,37 @@ > if(selectedDatapool != null){ > > //Validate the selected encrypted datapool and its password: >- if((isEncrypted) && (encryptedDatapoolPasswordText.getText().trim().length() == 0)){ >+ if(isSelectedDatapoolEncrypted){ >+ >+ String password = getEncryptedDatapoolPassword(); >+ >+ if(password.length() == 0){ >+ >+ setErrorMessage(NLS.bind(UiPluginResourceBundle.DatapoolExportWizard_encrypted, selectedDatapool.getName())); >+ >+ //Set focus to the encrypted datapool password: >+ encryptedDatapoolPasswordText.setFocus(); >+ } >+ else if(!DatapoolEncryptManager.isKeyCorrect(selectedDatapool, password)){ > >- setErrorMessage(NLS.bind(UiPluginResourceBundle.DatapoolExportWizard_encrypted, selectedDatapool.getName())); >+ setErrorMessage(UiPluginResourceBundle.DatapoolExportWizard_wrongpass); > >- //Set focus to the encrypted datapool password: >- encryptedDatapoolPasswordText.setFocus(); >+ //Set focus to the encrypted datapool password: >+ encryptedDatapoolPasswordText.setFocus(); >+ } >+ else{ >+ isValid = true; >+ } > } > else{ >- > isValid = true; >- >- setErrorMessage(null); > } > } > >+ if(isValid){ >+ setErrorMessage(null); >+ } >+ > return isValid; > } > } >Index: src/org/eclipse/hyades/test/ui/datapool/internal/util/CSVImportExportUtil.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/datapool/internal/util/CSVImportExportUtil.java,v >retrieving revision 1.20 >diff -u -r1.20 CSVImportExportUtil.java >--- src/org/eclipse/hyades/test/ui/datapool/internal/util/CSVImportExportUtil.java 3 Nov 2008 13:35:43 -0000 1.20 >+++ src/org/eclipse/hyades/test/ui/datapool/internal/util/CSVImportExportUtil.java 11 Nov 2008 23:27:03 -0000 >@@ -24,23 +24,15 @@ > import java.util.List; > import java.util.Map; > >-import org.eclipse.core.resources.IResourceStatus; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; > import org.eclipse.hyades.edit.datapool.IDatapool; > import org.eclipse.hyades.edit.datapool.IDatapoolCell; > import org.eclipse.hyades.edit.datapool.IDatapoolEquivalenceClass; > import org.eclipse.hyades.edit.datapool.IDatapoolRecord; > import org.eclipse.hyades.edit.datapool.IDatapoolSuggestedType; > import org.eclipse.hyades.edit.datapool.IDatapoolVariable; >-import org.eclipse.hyades.test.ui.UiPlugin; > import org.eclipse.hyades.test.ui.datapool.util.DatapoolUtilities; > import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle; >-import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.osgi.util.NLS; >-import org.eclipse.swt.widgets.Display; >- >-import com.ibm.icu.text.NumberFormat; > > /** > * CSV import and export utilities. >@@ -49,8 +41,8 @@ > * @author Peter Sun > * @author Bianca Xue Jiang > * @author Paul E. Slauenwhite >- * @author jbozier >- * @version October 7, 2008 >+ * @author Jerome Bozier >+ * @version November 11, 2008 > * @since January 27, 2005 > */ > public class CSVImportExportUtil >@@ -68,276 +60,325 @@ > > private static final CSVImportExportUtil instance = new CSVImportExportUtil(); > >- private static long lineCounter = 1; >- > public static CSVImportExportUtil getInstance() > { > return instance; > } > >- protected CSVImportExportUtil() >- { >- } >- >- public boolean validateCSVFile(String fullyQualifiedCSVName, boolean isFirstRowVariableInfo, boolean isFirstColECInfo, String encoding) throws FileNotFoundException, IOException, CorruptCSVFileException { >+ /** >+ * Private constructor. >+ */ >+ private CSVImportExportUtil(){ >+ //No-operation. >+ } >+ >+ /** >+ * <p>Validates a Comma Separated Values (CSV) file containing datapool records.</p> >+ * >+ * <p>Validation is required when importing a CSV file into a new or existing datapool.</p> >+ * >+ * @param csvFilePath The absolute path of the CSV file. >+ * @param isFirstRowVariableInfo If the first row of the CSV file contains the variable information (name/type), otherwise <code>false</code>. >+ * @param isFirstColumnEquivalenceClassInfo If the first column of the CSV file contains the equivalence class information (name/row index), otherwise <code>false</code>. >+ * @param encoding The encoding of the CSV file, otherwise <code>null</null>. >+ * @return <code>true</code> if the CSV file is valid, otherwise <code>false</code>. >+ * @throws FileNotFoundException The CSV file could not be found. >+ * @throws IOException An error occurs while reading the CSV file. >+ * @throws CorruptCSVFileException The CSV is invalid. >+ * @see #importCSV(IDatapool, String, boolean, boolean, String) >+ * @see #importCSV(IDatapool, String, boolean, boolean, String, int, int) >+ * @see #appendFromCSV(IDatapool, String, boolean, boolean, String) >+ */ >+ public boolean validateCSVFile(String csvFilePath, >+ boolean isFirstRowVariableInfo, >+ boolean isFirstColumnEquivalenceClassInfo, >+ String encoding) throws FileNotFoundException, IOException, CorruptCSVFileException { >+ return (validateCSVFileWithDatapool(csvFilePath, null, isFirstRowVariableInfo, isFirstColumnEquivalenceClassInfo, encoding)); >+ } >+ >+ /** >+ * <p>Validates a Comma Separated Values (CSV) file containing datapool records against a datapool.</p> >+ * >+ * <p>Validation is required when importing a CSV file into a new or existing datapool.</p> >+ * >+ * @param csvFilePath The absolute path of the CSV file. >+ * @param datapool The datapool that the CSV file is validated against, otherwise <code>null</null>. >+ * @param isFirstRowVariableInfo If the first row of the CSV file contains the variable information (name/type), otherwise <code>false</code>. >+ * @param isFirstColumnEquivalenceClassInfo If the first column of the CSV file contains the equivalence class information (name/row index), otherwise <code>false</code>. >+ * @param encoding The encoding of the CSV file, otherwise <code>null</null>. >+ * @return <code>true</code> if the CSV file is valid, otherwise <code>false</code>. >+ * @throws FileNotFoundException The CSV file could not be found. >+ * @throws IOException An error occurs while reading the CSV file. >+ * @throws CorruptCSVFileException The CSV is invalid. >+ * @see #importCSV(IDatapool, String, boolean, boolean, String) >+ * @see #importCSV(IDatapool, String, boolean, boolean, String, int, int) >+ * @see #appendFromCSV(IDatapool, String, boolean, boolean, String) >+ */ >+ public boolean validateCSVFileWithDatapool(String csvFilePath, >+ IDatapool datapool, >+ boolean isFirstRowVariableInfo, >+ boolean isFirstColumnEquivalenceClassInfo, >+ String encoding) throws FileNotFoundException, IOException, CorruptCSVFileException { > >+ //Determine if the datapool should be validated : >+ boolean validateDatapool = ((datapool != null) && (datapool.getVariableCount() > 0) && (!isDefaultEmptyDatapool(datapool))); >+ > //Resolve the input reader: > BufferedReader lineReader = null; > >- if((encoding == null) || (encoding.trim().length() == 0)) { >- lineReader = new BufferedReader(new InputStreamReader(new FileInputStream(fullyQualifiedCSVName))); >- } >- else { >- lineReader = new BufferedReader(new InputStreamReader(new FileInputStream(fullyQualifiedCSVName), encoding)); >- } >- >- //Read the first line: >- String line = lineReader.readLine(); >- int lineCount = 1; >- int variableCount = -1; >- >- //Check if the first line is empty: >- if((line == null) || (line.trim().length() == 0)){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount),UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_CVS_LINE})); >- } >- >- //Validate the variable names and optional suggested types in the first row: >- if(isFirstRowVariableInfo){ >- >- //Parse the first row containing the variable names and optional suggested types: >- CSVTokenizer tokenizer = new CSVTokenizer(line); >+ try { > >- //Check if the first column is the equivalence class cell (e.g. empty value): >- if((isFirstColECInfo) && ((!tokenizer.hasMoreTokens()) || (tokenizer.nextToken().trim().length() > 0))){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount),UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_EQUIVALENCE})); >- } >+ if((encoding == null) || (encoding.trim().length() == 0)) { >+ lineReader = new BufferedReader(new InputStreamReader(new FileInputStream(csvFilePath))); >+ } >+ else { >+ lineReader = new BufferedReader(new InputStreamReader(new FileInputStream(csvFilePath), encoding)); >+ } > >- List variableNames = new ArrayList(); >+ //Read the first line: >+ String line = lineReader.readLine(); >+ int lineCount = 1; >+ int variableCount = -1; > >- //Iterate the columns containing the variable names and optional suggested types: >- while(tokenizer.hasMoreTokens()){ >- >- //Resolve the variable name: >- String suggestedType = null; >- String variableName = tokenizer.nextToken().trim(); >- int twoColonsIndex = variableName.indexOf(CSVTokenizer.TWO_COLONS); >- >- //Resolve the optional suggested type within the variable name: >- if(twoColonsIndex != -1){ >- >- suggestedType = variableName.substring(twoColonsIndex + CSVTokenizer.TWO_COLONS.length()).trim(); >- variableName = variableName.substring(0, twoColonsIndex).trim(); >- } >- >- //Validate the variable name: >- if(variableName.length() == 0){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_VARIABLE})); >- } >- else if(!DatapoolUtilities.getInstance().isVariableNameValid(variableName)){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_NAME_NOT_VALID})); >- } >- else if(variableNames.contains(variableName)){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_NAME_NOT_UNIQUE})); >- } >- else{ >- variableNames.add(variableName); >- } >- >- //Validate the optional suggested type: >- if((suggestedType != null) && (!DatapoolUtilities.getInstance().isVariableTypeValid(suggestedType))){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_TYPE_NOT_VALID})); >- } >+ if(validateDatapool){ >+ variableCount = datapool.getVariableCount(); > } > >- variableCount = variableNames.size(); >- >- //Check if any variables were validated: >- if(variableCount == 0){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount),UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_VARIABLE})); >+ //Check if the first line is empty: >+ if((line == null) || (line.trim().length() == 0)){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount),UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_CVS_LINE})); > } >+ >+ //Validate the variable names and optional suggested types in the first row: >+ if(isFirstRowVariableInfo){ > >- line = lineReader.readLine(); >- lineCount++; >- } >- >- Map equivalenceClassNames = new HashMap(); >- String defaultEquivalenceClassName = null; >- int emptyLineCount = 0; >- >- //Validate the remaining lines: >- while(line != null){ >- >- //Validate the next line that is not empty: >- if(line.trim().length() > 0){ >- >- //Parse the row containing the remaining columns: >+ //Parse the first row containing the variable names and optional suggested types: > CSVTokenizer tokenizer = new CSVTokenizer(line); >- >- //Validate the equivalence class names and optional row numbers in the first column: >- if(isFirstColECInfo){ >- >- //Resolve the equivalence class name: >- String rowNumber = null; >- String equivalenceClassName = tokenizer.nextToken().trim(); >- int twoColonsIndex = equivalenceClassName.indexOf(CSVTokenizer.TWO_COLONS); >- >- //Resolve the optional row number within the equivalence class name: >+ >+ //Check if the first column is the equivalence class cell (e.g. empty value): >+ if((isFirstColumnEquivalenceClassInfo) && ((!tokenizer.hasMoreTokens()) || (tokenizer.nextToken().trim().length() > 0))){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount),UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_EQUIVALENCE})); >+ } >+ >+ List variableNames = new ArrayList(); >+ >+ //Iterate the columns containing the variable names and optional suggested types: >+ while(tokenizer.hasMoreTokens()){ >+ >+ //Resolve the variable name: >+ String suggestedType = null; >+ String variableName = tokenizer.nextToken().trim(); >+ int twoColonsIndex = variableName.indexOf(CSVTokenizer.TWO_COLONS); >+ >+ //Resolve the optional suggested type within the variable name: > if(twoColonsIndex != -1){ >- >- rowNumber = equivalenceClassName.substring(twoColonsIndex + CSVTokenizer.TWO_COLONS.length()).trim(); >- equivalenceClassName = equivalenceClassName.substring(0, twoColonsIndex).trim(); >- } >- >- //Validate the equivalence class name: >- if(equivalenceClassName.length() == 0){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_EQUIVALENCE})); >+ >+ suggestedType = variableName.substring(twoColonsIndex + CSVTokenizer.TWO_COLONS.length()).trim(); >+ variableName = variableName.substring(0, twoColonsIndex).trim(); > } >- else if(!DatapoolUtilities.getInstance().isEquivalenceClassNameValid(equivalenceClassName)){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_ROW_GRP_DLG_ERROR_NAME_NOT_VALID})); >+ >+ //Validate the variable name: >+ if(variableName.length() == 0){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_VARIABLE})); > } >- else if(equivalenceClassNames.containsKey(equivalenceClassName)){ >- equivalenceClassNames.put(equivalenceClassName, new Integer(((Integer)(equivalenceClassNames.get(equivalenceClassName))).intValue() + 1)); >+ else if(!DatapoolUtilities.getInstance().isVariableNameValid(variableName)){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_NAME_NOT_VALID})); >+ } >+ else if(variableNames.contains(variableName)){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_NAME_NOT_UNIQUE})); > } > else{ >- >- equivalenceClassNames.put(equivalenceClassName, new Integer(0)); >- >- if(defaultEquivalenceClassName == null){ >- defaultEquivalenceClassName = equivalenceClassName; >- } >+ variableNames.add(variableName); > } >- >- //Count the empty lines as empty rows for the default equivalence class: >- if(emptyLineCount > 0){ >- >- equivalenceClassNames.put(defaultEquivalenceClassName, new Integer(((Integer)(equivalenceClassNames.get(defaultEquivalenceClassName))).intValue() + emptyLineCount)); >- >- emptyLineCount = 0; >+ >+ //Validate the optional suggested type: >+ if((suggestedType != null) && (!DatapoolUtilities.getInstance().isVariableTypeValid(suggestedType))){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_TYPE_NOT_VALID})); > } >- >- //Validate the optional row number: >- if(rowNumber != null){ >- >+ >+ //Validate the variable name and optional suggested type against the datapool: >+ if(validateDatapool){ >+ > try { >- >- if(Integer.parseInt(rowNumber) != (((Integer)(equivalenceClassNames.get(equivalenceClassName))).intValue())){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), NLS.bind(UiPluginResourceBundle.DATA_COL_DLG_ERROR_INCONSISTENT_ROW_ORDER, rowNumber)})); >- } >+ >+ org.eclipse.hyades.execution.runtime.datapool.IDatapoolVariable variable = datapool.getVariable(variableNames.size() - 1); >+ >+ if((!variableName.equals(variable.getName())) || ((suggestedType != null) && (!TypeChecker.getInstance().isTypeMatch(suggestedType, variable.getSuggestedType())))){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DatapoolImportWizard_diffVariableInfoWarning})); >+ } > } >- catch (NumberFormatException n) { >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), NLS.bind(UiPluginResourceBundle.DATA_COL_DLG_ERROR_INVALID_ROW_COUNT, rowNumber)})); >+ catch (Exception e) { >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DatapoolImportWizard_diffVariableInfoWarning})); > } > } > } >- >- //Validate the number of remaining columns: >- int columnCount = 0; >- >- while(tokenizer.hasMoreTokens()){ >- >- columnCount++; >- >- tokenizer.nextToken(); >+ >+ int columnCount = variableNames.size(); >+ >+ //Check if any variables were validated: >+ if(columnCount == 0){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount),UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_VARIABLE})); > } >- >+ > if(variableCount == -1){ > variableCount = columnCount; > } > else if(columnCount != variableCount){ >- throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), NLS.bind(UiPluginResourceBundle.DATA_COL_DLG_ERROR_INCONSISTENT_COLUMN_COUNT, String.valueOf(columnCount))})); >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), NLS.bind(UiPluginResourceBundle.DATA_COL_DLG_ERROR_INCONSISTENT_COLUMN_COUNT, String.valueOf(columnCount))})); > } >+ >+ line = lineReader.readLine(); >+ lineCount++; > } >- else{ >- emptyLineCount++; >- } >- >- line = lineReader.readLine(); >- lineCount++; >- } >+ >+ Map equivalenceClassNames = new HashMap(); >+ String defaultEquivalenceClassName = null; >+ int emptyLineCount = 0; >+ >+ //Validate the remaining lines: >+ while(line != null){ >+ >+ //Validate the next line that is not empty: >+ if(line.trim().length() > 0){ >+ >+ //Parse the row containing the remaining columns: >+ CSVTokenizer tokenizer = new CSVTokenizer(line); >+ >+ //Validate the equivalence class names and optional row numbers in the first column: >+ if(isFirstColumnEquivalenceClassInfo){ >+ >+ //Resolve the equivalence class name: >+ String rowNumber = null; >+ String equivalenceClassName = tokenizer.nextToken().trim(); >+ int twoColonsIndex = equivalenceClassName.indexOf(CSVTokenizer.TWO_COLONS); >+ >+ //Resolve the optional row number within the equivalence class name: >+ if(twoColonsIndex != -1){ >+ >+ rowNumber = equivalenceClassName.substring(twoColonsIndex + CSVTokenizer.TWO_COLONS.length()).trim(); >+ equivalenceClassName = equivalenceClassName.substring(0, twoColonsIndex).trim(); >+ } >+ >+ //Validate the equivalence class name: >+ if(equivalenceClassName.length() == 0){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_COL_DLG_ERROR_MISSING_EQUIVALENCE})); >+ } >+ else if(!DatapoolUtilities.getInstance().isEquivalenceClassNameValid(equivalenceClassName)){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), UiPluginResourceBundle.DATA_ROW_GRP_DLG_ERROR_NAME_NOT_VALID})); >+ } >+ else if(equivalenceClassNames.containsKey(equivalenceClassName)){ >+ equivalenceClassNames.put(equivalenceClassName, new Integer(((Integer)(equivalenceClassNames.get(equivalenceClassName))).intValue() + 1)); >+ } >+ else{ > >- //Close the input reader: >- try { >- lineReader.close(); >- } >- catch (IOException i) { >- //Ignore since closing input reader. >- } >- >- return true; >- } >+ int recordCount = 0; >+ >+ //Resolve the record count from the equivalence class: >+ if(validateDatapool){ >+ >+ org.eclipse.hyades.execution.runtime.datapool.IDatapoolEquivalenceClass equivalenceClass = datapool.getEquivalenceClass(datapool.getEquivalenceClassIndex(equivalenceClassName)); >+ >+ if(equivalenceClass != null){ >+ recordCount = equivalenceClass.getRecordCount(); >+ } >+ } >+ >+ equivalenceClassNames.put(equivalenceClassName, new Integer(recordCount)); >+ >+ if(defaultEquivalenceClassName == null){ >+ defaultEquivalenceClassName = equivalenceClassName; >+ } >+ } > >- public boolean validateCSVFileWithDatapool(String fullyQualifiedCSVName, IDatapool datapool, boolean isFirstRowVariableInfo, boolean isFirstColECInfo, String encoding) >- throws FileNotFoundException, IOException, CorruptCSVFileException >- { >- if(!validateCSVFile(fullyQualifiedCSVName, isFirstRowVariableInfo, isFirstColECInfo, encoding)) >- return false; >- >- // datapool without columns or empty is always good. >- if(datapool.getVariableCount() < 1) >- return true; >- >- // secondly, if there's only one default cell(created by new datapool wizard for easy data entry) >- // and no value in cell, treat as empty datapool >- // TODO replace when add function to append to existing columns >- if(isDefaultEmptyDatapool(datapool)) >- return true; >- >- InputStreamReader input; >- if(encoding == null || encoding.length() == 0) { >- input = new InputStreamReader(new FileInputStream(fullyQualifiedCSVName)); >- } else { >- input = new InputStreamReader(new FileInputStream(fullyQualifiedCSVName), encoding); >- } >- BufferedReader reader = new BufferedReader(input); >- String firstLine = reader.readLine(); >- reader.close(); >- CSVTokenizer tokenizer = new CSVTokenizer(firstLine); >- List tokens = new ArrayList(); >- if(isFirstColECInfo && tokenizer.hasMoreTokens()) >- tokenizer.nextToken(); //ignore the first token >- while(tokenizer.hasMoreTokens()) { >- String nextToken = tokenizer.nextToken(); >- //- #138616 the first variable is always empty (due to column arrangment), we need to skip it. >- if(nextToken.length() != 0) { >- tokens.add(nextToken); >- } >- } >- >- // compare number of columns >- if(datapool.getVariableCount() != tokens.size()) >- return false; >- >- if(!isFirstRowVariableInfo) >- return true; >- >- // same number of variables and tokens, compare name and type. >- for(int i = 0; i < tokens.size(); i++) >- { >- String nameTypePair = (String)tokens.get(i); >- int separatorIndex = nameTypePair.indexOf(CSVTokenizer.TWO_COLONS); >- String name = new String(); >- String type = new String(); >- if(separatorIndex == -1 ) >- { >- name = nameTypePair; >+ //Count the empty lines as empty rows for the default equivalence class: >+ if(emptyLineCount > 0){ >+ >+ equivalenceClassNames.put(defaultEquivalenceClassName, new Integer(((Integer)(equivalenceClassNames.get(defaultEquivalenceClassName))).intValue() + emptyLineCount)); >+ >+ emptyLineCount = 0; >+ } >+ >+ //Validate the optional row number: >+ if(rowNumber != null){ >+ >+ try { >+ >+ int recordIndex = Integer.parseInt(rowNumber); >+ >+ if(recordIndex > (((Integer)(equivalenceClassNames.get(equivalenceClassName))).intValue())){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), NLS.bind(UiPluginResourceBundle.DATA_COL_DLG_ERROR_INCONSISTENT_ROW_ORDER, rowNumber)})); >+ } >+ else if(validateDatapool){ >+ >+ org.eclipse.hyades.execution.runtime.datapool.IDatapoolEquivalenceClass equivalenceClass = datapool.getEquivalenceClass(datapool.getEquivalenceClassIndex(equivalenceClassName)); >+ >+ if((equivalenceClass != null) && (recordIndex < equivalenceClass.getRecordCount()) && (equivalenceClass.getRecord(recordIndex) != null)){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[] {String.valueOf(lineCount), UiPluginResourceBundle.DATA_CSV_ERROR_RECORD_INDEX_DUP})); >+ } >+ } >+ } >+ catch (NumberFormatException n) { >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), NLS.bind(UiPluginResourceBundle.DATA_COL_DLG_ERROR_INVALID_ROW_COUNT, rowNumber)})); >+ } >+ } >+ } >+ >+ //Validate the number of remaining columns: >+ int columnCount = 0; >+ >+ while(tokenizer.hasMoreTokens()){ >+ >+ columnCount++; >+ >+ tokenizer.nextToken(); >+ } >+ >+ if(variableCount == -1){ >+ variableCount = columnCount; >+ } >+ else if(columnCount != variableCount){ >+ throw new CorruptCSVFileException(NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, new String[]{String.valueOf(lineCount), NLS.bind(UiPluginResourceBundle.DATA_COL_DLG_ERROR_INCONSISTENT_COLUMN_COUNT, String.valueOf(columnCount))})); >+ } >+ } >+ else{ >+ emptyLineCount++; >+ } >+ >+ line = lineReader.readLine(); >+ lineCount++; > } >- else >- { >- name = nameTypePair.substring(0, separatorIndex); >- type = nameTypePair.substring(separatorIndex + 2); >+ >+ return true; >+ } >+ finally{ >+ >+ //Close the input reader: >+ try { >+ lineReader.close(); >+ } >+ catch (IOException i) { >+ //Ignore since closing input reader. > } >- >- org.eclipse.hyades.execution.runtime.datapool.IDatapoolVariable variable = datapool.getVariable(i); >- if(!name.equals(variable.getName())) >- return false; >- >- if(type.length() > 0 && !TypeChecker.getInstance().isTypeMatch(type, variable.getSuggestedType())) >- return false; > } >- >- return true; > } > >+ /** >+ * <p>Determines if a datapool is empty.</p> >+ * >+ * <p>Empty datapools have exactly one of the following:</p> >+ * >+ * <ul> >+ * <li>equivalence class</li> >+ * <li>variable</li> >+ * <li>record</li> >+ * <li>cell</li> >+ * </ul> >+ * >+ * <p>In addition, the cell has no associated value.</p> >+ * >+ * @param datapool The datapool to be evaluated. >+ * @return <code>true</code> if the datapool is empty, otherwise <code>false</code>. >+ */ > public boolean isDefaultEmptyDatapool(IDatapool datapool) > { > if(datapool.getVariableCount() == 1 && datapool.getEquivalenceClassCount() == 1) >@@ -353,164 +394,241 @@ > return false; > } > >+ /** >+ * <p>Imports a Comma Separated Values (CSV) file into a datapool.</p> >+ * >+ * <p><b>Note</b>: The CSV file is assumed to be valid. To validate the CSV file >+ * with the datapool, call the {@link #validateCSVFileWithDatapool(String, IDatapool, boolean, boolean, String)} >+ * method.</p> >+ * >+ * @param datapool The datapool that the CSV file is imported into. >+ * @param csvFilePath The absolute path of the CSV file. >+ * @param isFirstRowVariableInfo If the first row of the CSV file contains the variable information (name/type), otherwise <code>false</code>. >+ * @param isFirstColumnEquivalenceClassInfo If the first column of the CSV file contains the equivalence class information (name/row index), otherwise <code>false</code>. >+ * @param encoding The encoding of the CSV file, otherwise <code>null</null>. >+ * @throws IOException An error occurs while reading the CSV file. >+ * @see #validateCSVFileWithDatapool(String, IDatapool, boolean, boolean, String) >+ */ > public void importCSV(IDatapool datapool, >- String csvFileName, >- boolean isFirstRowVariableNameType, >- boolean isFirstColEqClsName, >- String importEncoding) >- throws IOException, CorruptCSVFileException >- { >+ String csvFileName, >+ boolean isFirstRowVariableInfo, >+ boolean isFirstColumnEquivalenceClassInfo, >+ String encoding)throws IOException { > importCSV(datapool, > csvFileName, >- isFirstRowVariableNameType, >- isFirstColEqClsName, >- importEncoding, >+ isFirstRowVariableInfo, >+ isFirstColumnEquivalenceClassInfo, >+ encoding, > -1, > -1); > } > >+ /** >+ * <p>Imports a Comma Separated Values (CSV) file into a datapool.</p> >+ * >+ * <p><b>Note</b>: The CSV file is assumed to be valid. To validate the CSV file >+ * with the datapool, call the {@link #validateCSVFileWithDatapool(String, IDatapool, boolean, boolean, String)} >+ * method.</p> >+ * >+ * @param datapool The datapool that the CSV file is imported into. >+ * @param csvFilePath The absolute path of the CSV file. >+ * @param isFirstRowVariableInfo If the first row of the CSV file contains the variable information (name/type), otherwise <code>false</code>. >+ * @param isFirstColumnEquivalenceClassInfo If the first column of the CSV file contains the equivalence class information (name/row index), otherwise <code>false</code>. >+ * @param encoding The encoding of the CSV file, otherwise <code>null</null>. >+ * @param numberOfColumns The number of columns of the CSV file to import into the datapool, otherwise <code>-1</code>. >+ * @param numberOfRows The number of rows of the CSV file to import into the datapool, otherwise <code>-1</code>. >+ * @throws IOException An error occurs while reading the CSV file. >+ * @see #validateCSVFileWithDatapool(String, IDatapool, boolean, boolean, String) >+ */ > public void importCSV(IDatapool datapool, >- String csvFileName, >- boolean isFirstRowVariableNameType, >- boolean isFirstColEqClsName, >- String importEncoding, >- int numberOfColumns, >- int numberOfRows) >- throws IOException, CorruptCSVFileException >- { >- if(datapool == null || csvFileName == null) >- return; >+ String csvFilePath, >+ boolean isFirstRowVariableInfo, >+ boolean isFirstColumnEquivalenceClassInfo, >+ String encoding, >+ int numberOfColumns, >+ int numberOfRows) throws IOException{ > >- try >- { >- InputStreamReader inputStreamReader = null; >- if(importEncoding.length() == 0) >- inputStreamReader = new InputStreamReader(new FileInputStream(csvFileName)); //$NON-NLS-1$ >- else >- inputStreamReader = new InputStreamReader(new FileInputStream(csvFileName), importEncoding); //$NON-NLS-1$ >+ if((datapool != null) && (csvFilePath != null)){ >+ >+ BufferedReader bufferedReader = null; >+ >+ try{ >+ >+ if((encoding != null) && (encoding.trim().length() > 0)){ >+ bufferedReader = new CSVBufferedReader(new InputStreamReader(new FileInputStream(csvFilePath), (encoding.trim()))); >+ } >+ else{ >+ bufferedReader = new CSVBufferedReader(new InputStreamReader(new FileInputStream(csvFilePath))); >+ } >+ >+ String line = bufferedReader.readLine(); >+ >+ //Initialize to 1 since once line has already been read: >+ int lineCounter = 1; >+ >+ if(isFirstRowVariableInfo){ >+ >+ createVariablesFromFile(datapool, line, lineCounter, isFirstColumnEquivalenceClassInfo, numberOfColumns); >+ >+ line = bufferedReader.readLine(); >+ >+ lineCounter++; >+ } >+ else{ >+ createVariables(datapool, line, isFirstColumnEquivalenceClassInfo, numberOfColumns); >+ } > >- CSVBufferedReader bufferedReader = new CSVBufferedReader(inputStreamReader); >- String firstLine = bufferedReader.readLine(); >- >- if(isFirstRowVariableNameType) >- { >- createVariablesFromFile(datapool, firstLine, isFirstColEqClsName, numberOfColumns); >- firstLine = bufferedReader.readLine(); >- lineCounter++; >+ int recordCounter = 0; >+ >+ while((line != null) && ((numberOfRows == -1) || (recordCounter < numberOfRows))){ >+ >+ createRecord(datapool, line, lineCounter, isFirstColumnEquivalenceClassInfo); >+ >+ recordCounter++; >+ >+ line = bufferedReader.readLine(); >+ >+ lineCounter++; >+ } > } >- else >- createVariables(datapool, firstLine, isFirstColEqClsName, numberOfColumns); >- >- int recordCounter = 1; >- for(String line = firstLine; >- (line != null && (numberOfRows == -1 || recordCounter <= numberOfRows)); >- line = bufferedReader.readLine(), lineCounter++) >- { >- createRecord(datapool, line, isFirstColEqClsName); >- recordCounter++; >+ finally{ >+ >+ try { >+ >+ if(bufferedReader != null){ >+ bufferedReader.close(); >+ } >+ } >+ catch (IOException i) { >+ //Ignore since closing input stream reader. >+ } > } >- bufferedReader.close(); >- } >- catch(IOException e) >- { >- throw e; >- } >- catch(CorruptCSVFileException e) >- { >- throw e; >- } >- finally >- { >- lineCounter = 1; > } > } > >+ /** >+ * <p>Appends a Comma Separated Values (CSV) file to a datapool.</p> >+ * >+ * <p><b>Note</b>: The CSV file is assumed to be valid. To validate the CSV file >+ * with the datapool, call the {@link #validateCSVFileWithDatapool(String, IDatapool, boolean, boolean, String)} >+ * method.</p> >+ * >+ * @param datapool The datapool that the CSV file is appended to. >+ * @param csvFilePath The absolute path of the CSV file. >+ * @param isFirstRowVariableInfo If the first row of the CSV file contains the variable information (name/type), otherwise <code>false</code>. >+ * @param isFirstColumnEquivalenceClassInfo If the first column of the CSV file contains the equivalence class information (name/row index), otherwise <code>false</code>. >+ * @param encoding The encoding of the CSV file, otherwise <code>null</null>. >+ * @throws IOException An error occurs while reading the CSV file. >+ * @see #validateCSVFileWithDatapool(String, IDatapool, boolean, boolean, String) >+ */ > public void appendFromCSV(IDatapool datapool, >- String csvFileName, >- boolean isFirstRowVariableNameType, >- boolean isFirstColEqClsName, >- String importEncoding) >- throws IOException, CorruptCSVFileException >- { >- if(datapool == null || csvFileName == null) >- return; >+ String csvFilePath, >+ boolean isFirstRowVariableInfo, >+ boolean isFirstColumnEquivalenceClassInfo, >+ String encoding) throws IOException { > >- try >- { >- InputStreamReader inputStreamReader = null; >- if(importEncoding.length() == 0) >- inputStreamReader = new InputStreamReader(new FileInputStream(csvFileName)); //$NON-NLS-1$ >- else >- inputStreamReader = new InputStreamReader(new FileInputStream(csvFileName), importEncoding); //$NON-NLS-1$ >+ if((datapool != null) && (csvFilePath != null)){ >+ >+ BufferedReader bufferedReader = null; >+ >+ try{ >+ >+ if((encoding != null) && (encoding.trim().length() > 0)){ >+ bufferedReader = new CSVBufferedReader(new InputStreamReader(new FileInputStream(csvFilePath), (encoding.trim()))); >+ } >+ else{ >+ bufferedReader = new CSVBufferedReader(new InputStreamReader(new FileInputStream(csvFilePath))); >+ } >+ >+ String line = bufferedReader.readLine(); >+ >+ //Initialize to 1 since once line has already been read: >+ int lineCounter = 1; >+ >+ if(isFirstRowVariableInfo){ >+ >+ line = bufferedReader.readLine(); >+ >+ lineCounter++; >+ } > >- CSVBufferedReader bufferedReader = new CSVBufferedReader(inputStreamReader); >- String firstLine = bufferedReader.readLine(); >- if(isFirstRowVariableNameType) >- { >- firstLine = bufferedReader.readLine(); >- lineCounter++; >+ while(line != null){ >+ >+ createRecord(datapool, line, lineCounter, isFirstColumnEquivalenceClassInfo); >+ >+ line = bufferedReader.readLine(); >+ >+ lineCounter++; >+ } > } >- >- int recordCounter = 1; >- for(String line = firstLine; >- line != null; >- line = bufferedReader.readLine(), lineCounter++) >- { >- createRecord(datapool, line, isFirstColEqClsName); >- recordCounter++; >+ finally{ >+ >+ try { >+ >+ if(bufferedReader != null){ >+ bufferedReader.close(); >+ } >+ } >+ catch (IOException i) { >+ //Ignore since closing input stream reader. >+ } > } >- bufferedReader.close(); >- } >- catch(IOException e) >- { >- throw e; >- } >- catch(CorruptCSVFileException e) >- { >- throw e; >- } >- finally >- { >- lineCounter = 1; > } > } > >- public boolean exportCSV(IDatapool datapool, >- String csvFileName, >- boolean includeVariables, >- boolean includeEquivalenceClassNames, >+ /** >+ * <p>Exports a datapool to a Comma Separated Values (CSV) file.</p> >+ * >+ * @param datapool The datapool that is exported to the CSV file. >+ * @param csvFilePath The absolute path of the CSV file. >+ * @param includeVariableInfo If the first row of the CSV file contains the variable information (name/type), otherwise <code>false</code>. >+ * @param includeEquivalenceClassInfo If the first column of the CSV file contains the equivalence class information (name/row index), otherwise <code>false</code>. >+ * @param includeTags If the cell values are enclosed in tags, otherwise <code>false</code>. >+ * @param encoding The encoding of the CSV file, otherwise <code>null</null>. >+ * @throws IOException An error occurs while writing the CSV file. >+ */ >+ public void exportCSV(IDatapool datapool, >+ String csvFilePath, >+ boolean includeVariableInfo, >+ boolean includeEquivalenceClassInfo, > boolean includeTags, >- String exportEncoding) >- { >- if(datapool == null || csvFileName == null) >- return false; >- try >- { >- OutputStreamWriter outputStreamWriter = null; >- if(exportEncoding.length() == 0) >- outputStreamWriter = new OutputStreamWriter(new FileOutputStream(csvFileName)); //$NON-NLS-1$ >- else >- outputStreamWriter = new OutputStreamWriter(new FileOutputStream(csvFileName), exportEncoding); //$NON-NLS-1$ >- BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter); >- if(includeVariables) >- writeVariables(datapool, bufferedWriter, true, includeEquivalenceClassNames); >- writeRecords(datapool, bufferedWriter, includeEquivalenceClassNames, includeTags); >- bufferedWriter.close(); >- } >- catch(IOException e) >- { >- Status status = new Status(IStatus.ERROR, UiPlugin.getID(), IResourceStatus.ERROR,e.getMessage(), e); >- ErrorDialog.openError(Display.getCurrent().getActiveShell(), UiPluginResourceBundle.W_ERROR, null, status); >- return false; >+ String encoding) throws IOException{ >+ >+ if((datapool != null) && (csvFilePath != null)){ >+ >+ BufferedWriter bufferedWriter = null; >+ >+ try{ >+ >+ if((encoding != null) && (encoding.trim().length() > 0)){ >+ bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFilePath), (encoding.trim()))); >+ } >+ else{ >+ bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFilePath))); >+ } >+ >+ if(includeVariableInfo){ >+ writeVariables(datapool, bufferedWriter, true, includeEquivalenceClassInfo); >+ } >+ >+ writeRecords(datapool, bufferedWriter, includeEquivalenceClassInfo, includeTags); >+ } >+ finally{ >+ >+ try { >+ >+ if(bufferedWriter != null){ >+ bufferedWriter.close(); >+ } >+ } >+ catch (IOException i) { >+ //Ignore since closing input stream reader. >+ } >+ } > } >- finally >- { >- lineCounter = 1; >- } >- return true; > } > >- private void createVariablesFromFile(IDatapool datapool, String variableString, boolean ignoreFirst, int numberOfColumns) throws CorruptCSVFileException >+ private void createVariablesFromFile(IDatapool datapool, String variableString, int lineNumber, boolean ignoreFirst, int numberOfColumns) > { > boolean first = true; > int counter = 1; >@@ -537,28 +655,7 @@ > type = nameTypePair.substring(separatorIndex + 2); > } > >- if(!DatapoolUtilities.getInstance().isVariableNameUnique(datapool, name, null)) >- { >- Object[] messageElements = {String.valueOf(lineCounter), >- UiPluginResourceBundle.DATA_COL_DLG_ERROR_NAME_NOT_UNIQUE}; >- String error = NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, messageElements); >- throw new CorruptCSVFileException(error); >- } >- if(!DatapoolUtilities.getInstance().isVariableNameValid(name)) >- { >- Object[] messageElements = {String.valueOf(lineCounter), >- UiPluginResourceBundle.DATA_COL_DLG_ERROR_NAME_NOT_VALID}; >- String error = NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, messageElements); >- throw new CorruptCSVFileException(error); >- >- } >- if(!DatapoolUtilities.getInstance().isVariableTypeValid(type)) >- { >- Object[] messageElements = {String.valueOf(lineCounter), >- UiPluginResourceBundle.DATA_COL_DLG_ERROR_TYPE_NOT_VALID}; >- String error = NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, messageElements); >- throw new CorruptCSVFileException(error); >- } >+ > IDatapoolVariable variable = datapool.constructVariable(); > variable.setName(name); > IDatapoolSuggestedType suggestedType = (IDatapoolSuggestedType)variable.getSuggestedType(); >@@ -585,107 +682,73 @@ > } > } > >- private void createRecord(IDatapool datapool, String recordString, boolean useSpecifiedEC) throws CorruptCSVFileException >- { >+ private void createRecord(IDatapool datapool, String recordString, int lineNumber, boolean useSpecifiedEquivalenceClass) { >+ > CSVTokenizer tokenizer = new CSVTokenizer(recordString); > IDatapoolEquivalenceClass equivalenceClass = null; >- String recordIndexStr = null; > int recordIndex = -1; > > //Note: Check if the current token is not empty since the tokenizer returns empty tokens. >- if(useSpecifiedEC && tokenizer.hasMoreTokens() && tokenizer.currentToken().trim().length() > 0) >- { >- String ecName = tokenizer.nextToken(); >- int separatorIndex = ecName.indexOf(CSVTokenizer.TWO_COLONS); >+ if((useSpecifiedEquivalenceClass) && (tokenizer.hasMoreTokens()) && (tokenizer.currentToken().trim().length() > 0)){ >+ >+ String equivalenceClassName = tokenizer.nextToken(); >+ int separatorIndex = equivalenceClassName.indexOf(CSVTokenizer.TWO_COLONS); > >- if(separatorIndex >= 0) >- { >- try >- { >- recordIndexStr = ecName.substring(separatorIndex + 2); >- Number number = NumberFormat.getInstance().parse(recordIndexStr); >- recordIndex = number.intValue(); >+ if(separatorIndex != -1){ >+ >+ try{ >+ recordIndex = Integer.parseInt(equivalenceClassName.substring(separatorIndex + CSVTokenizer.TWO_COLONS.length())); > } >- catch(Exception e) >- { >+ catch(NumberFormatException n){ >+ //Ignore and append the record. > } >- ecName = ecName.substring(0, separatorIndex); >+ >+ equivalenceClassName = equivalenceClassName.substring(0, separatorIndex); > } >+ >+ int equivalenceClassIndex = datapool.getEquivalenceClassIndex(equivalenceClassName); > >- if(!DatapoolUtilities.getInstance().isEquivalenceClassNameValid(ecName)) >- { >- Object[] messageElements = {String.valueOf(lineCounter), >- UiPluginResourceBundle.DATA_ROW_GRP_DLG_ERROR_NAME_NOT_VALID}; >- String error = NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, messageElements); >- throw new CorruptCSVFileException(error); >- } >- int ecIndex = datapool.getEquivalenceClassIndex(ecName); >- if(ecIndex >= 0) >- equivalenceClass = (IDatapoolEquivalenceClass)datapool.getEquivalenceClass(ecIndex); >- else >- { >+ if(equivalenceClassIndex == -1){ >+ > equivalenceClass = datapool.constructEquivalenceClass(); >- equivalenceClass.setName(ecName); >+ equivalenceClass.setName(equivalenceClassName); >+ > datapool.appendEquivalenceClass(equivalenceClass); >+ } >+ else{ >+ equivalenceClass = ((IDatapoolEquivalenceClass)(datapool.getEquivalenceClass(equivalenceClassIndex))); > } > } >- else >- { >- // by default, import all records into the default equivalence class. >- if(datapool.getEquivalenceClassCount() == 0) >- { >+ else{ >+ >+ //By default, import all records into the default equivalence class: >+ if(datapool.getEquivalenceClassCount() == 0){ >+ > equivalenceClass = datapool.constructEquivalenceClass(); >+ > datapool.appendEquivalenceClass(equivalenceClass); > } >- else >- { >- int defaultIndex = datapool.getDefaultEquivalenceClassIndex(); >- defaultIndex = defaultIndex < 0 ? 0 : defaultIndex; >- equivalenceClass = (IDatapoolEquivalenceClass)datapool.getEquivalenceClass(defaultIndex); >+ else{ >+ equivalenceClass = (IDatapoolEquivalenceClass)datapool.getEquivalenceClass(Math.max(0, datapool.getDefaultEquivalenceClassIndex())); > } > } >- List cellValues = new ArrayList(); >- while(tokenizer.hasMoreTokens()) >- { >- String cellValue = tokenizer.nextToken(); >- cellValues.add(cellValue); >- } > >- String[] recordValues = new String[cellValues.size()]; >- for(int i = 0; i < cellValues.size(); i++) >- { >- recordValues[i] = (String)cellValues.get(i); >+ //Resolve the remaining cells from the record: >+ List cells = new ArrayList(); >+ >+ while(tokenizer.hasMoreTokens()){ >+ cells.add(tokenizer.nextToken()); > } >- IDatapoolRecord record = equivalenceClass.constructRecord(recordValues); >- if(recordIndex != -1) >- { >- IDatapoolRecord existingRecord = null; >- try >- { >- existingRecord = (IDatapoolRecord)equivalenceClass.getRecord(recordIndex); >- } >- catch(Exception e) >- { >- } >- if(existingRecord != null) >- { >- Object[] messageElements = {String.valueOf(lineCounter), >- UiPluginResourceBundle.DATA_CSV_ERROR_RECORD_INDEX_DUP}; >- String error = NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, messageElements); >- throw new CorruptCSVFileException(error); >- } >- if(recordIndex > equivalenceClass.getRecordCount()) >- { >- Object[] messageElements = {String.valueOf(lineCounter), >- UiPluginResourceBundle.DATA_CSV_ERROR_RECORD_INDEX_ORDER}; >- String error = NLS.bind(UiPluginResourceBundle.DATA_CSV_LINE, messageElements); >- throw new CorruptCSVFileException(error); >- } >- else >- equivalenceClass.insertRecord(record, recordIndex); >+ >+ IDatapoolRecord record = equivalenceClass.constructRecord(((String[])(cells.toArray(new String[cells.size()])))); >+ int recordCount = equivalenceClass.getRecordCount(); >+ >+ if((recordIndex > -1) && (recordIndex < recordCount) && (equivalenceClass.getRecord(recordIndex) == null)){ >+ equivalenceClass.insertRecord(record, recordIndex); > } >- else >+ else{ > equivalenceClass.appendRecord(record); >+ } > } > > private void writeVariables(IDatapool datapool, BufferedWriter writer, boolean includeTypes, boolean includeEquivalenceClasses) >Index: src/org/eclipse/hyades/test/ui/internal/resources/UiPluginResourceBundle.java >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/resources/UiPluginResourceBundle.java,v >retrieving revision 1.27 >diff -u -r1.27 UiPluginResourceBundle.java >--- src/org/eclipse/hyades/test/ui/internal/resources/UiPluginResourceBundle.java 7 Aug 2008 15:21:59 -0000 1.27 >+++ src/org/eclipse/hyades/test/ui/internal/resources/UiPluginResourceBundle.java 11 Nov 2008 23:27:03 -0000 >@@ -19,7 +19,7 @@ > * > * > * @author Paul E. Slauenwhite >- * @version August 7, 2008 >+ * @version November 11, 2008 > * @since March 15, 2007 > */ > public final class UiPluginResourceBundle extends NLS { >@@ -216,7 +216,6 @@ > public static String DATA_DLG_FIRST_ELEMENT; > public static String DATA_CSV_LINE; > public static String DATA_CSV_ERROR_RECORD_INDEX_DUP; >- public static String DATA_CSV_ERROR_RECORD_INDEX_ORDER; > public static String DATA_DEL_VAR_DLG_TITLE; > public static String DATA_DEL_VAR_DLG_SEL; > public static String DATA_ADD_ROW_OPTION_BEFORE; >Index: src/org/eclipse/hyades/test/ui/internal/resources/messages.properties >=================================================================== >RCS file: /cvsroot/tptp/test/org.eclipse.hyades.test.ui/src/org/eclipse/hyades/test/ui/internal/resources/messages.properties,v >retrieving revision 1.40 >diff -u -r1.40 messages.properties >--- src/org/eclipse/hyades/test/ui/internal/resources/messages.properties 7 Aug 2008 15:21:59 -0000 1.40 >+++ src/org/eclipse/hyades/test/ui/internal/resources/messages.properties 11 Nov 2008 23:27:03 -0000 >@@ -270,8 +270,6 @@ > DATA_CSV_LINE = CSV file line {0}: {1} > #IWAT0221E > DATA_CSV_ERROR_RECORD_INDEX_DUP = Duplicate record. >-#IWAT0222E >-DATA_CSV_ERROR_RECORD_INDEX_ORDER = Record not in proper order. > > # Delete Variable Dialog > DATA_DEL_VAR_DLG_TITLE = Delete Variable >#P org.eclipse.tptp.platform.models >Index: src-test/org/eclipse/hyades/models/common/datapool/impl/messages.properties >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.models/src-test/org/eclipse/hyades/models/common/datapool/impl/messages.properties,v >retrieving revision 1.6 >diff -u -r1.6 messages.properties >--- src-test/org/eclipse/hyades/models/common/datapool/impl/messages.properties 21 Jan 2008 18:49:55 -0000 1.6 >+++ src-test/org/eclipse/hyades/models/common/datapool/impl/messages.properties 11 Nov 2008 23:27:06 -0000 >@@ -16,7 +16,6 @@ > Common_DatapoolFactoryImpl.23=IWAT3058E Error while accessing iterator > Common_DatapoolFactoryImpl.25=IWAT3059E Datapool Iterator could not be opened > Common_DatapoolFactoryImpl.26=IWAT3060E Datapool Iterator could not be opened >-DPLCellImpl.18 =IWAT3061E No extensions found for tag > DPLEquivalenceClassImpl.1 =IWAT3062E Attempt to enter duplicate records into an equivalence class > DPLEquivalenceClassImpl.2 =IWAT3063E Record reordering attempt with wrong number of records specified > DPLRecordImpl.1 =IWAT3064E Nonexistent Variable Index Used >Index: src-test/org/eclipse/hyades/models/common/datapool/impl/DPLCellImpl.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.models/src-test/org/eclipse/hyades/models/common/datapool/impl/DPLCellImpl.java,v >retrieving revision 1.14 >diff -u -r1.14 DPLCellImpl.java >--- src-test/org/eclipse/hyades/models/common/datapool/impl/DPLCellImpl.java 9 May 2008 21:38:48 -0000 1.14 >+++ src-test/org/eclipse/hyades/models/common/datapool/impl/DPLCellImpl.java 11 Nov 2008 23:27:06 -0000 >@@ -17,6 +17,8 @@ > package org.eclipse.hyades.models.common.datapool.impl; > > import java.util.Map; >+import java.util.regex.Matcher; >+import java.util.regex.Pattern; > > import org.eclipse.emf.common.notify.Notification; > import org.eclipse.emf.ecore.EClass; >@@ -25,7 +27,6 @@ > import org.eclipse.emf.ecore.impl.EObjectImpl; > import org.eclipse.hyades.edit.datapool.IDatapoolRecord; > import org.eclipse.hyades.edit.datapool.IDatapoolVariable; >-import org.eclipse.hyades.execution.runtime.datapool.DatapoolException; > import org.eclipse.hyades.execution.runtime.datapool.IDatapoolEvaluatorExt; > import org.eclipse.hyades.models.common.datapool.Common_DatapoolPackage; > import org.eclipse.hyades.models.common.datapool.DPLCell; >@@ -33,8 +34,6 @@ > import org.eclipse.hyades.models.common.datapool.util.DPLPasswordCollection; > import org.eclipse.hyades.models.common.util.DatapoolUtil; > import org.eclipse.hyades.models.common.util.EncryptionManager; >-import org.eclipse.hyades.models.common.util.XMLParserUtil; >-import org.w3c.dom.Document; > > /** > * <!-- begin-user-doc --> >@@ -301,58 +300,67 @@ > return (org.eclipse.hyades.execution.runtime.datapool.IDatapoolRecord)this.eContainer(); > } > >- private static final String XML_AMPERSAND = "&"; //$NON-NLS-1$ >- private static final String AMPERSAND = "&"; //$NON-NLS-1$ >- > /** >- * The value associated with the cell is returned. >+ * <p>Pre-compiled pattern for matching the open/close tag names and enclosed >+ * character data of an XML fragment. For example:</p> >+ * >+ * <p><code><[white space]OPEN_TAG_NAME[white space]>CHARACTER_DATA</[white space]CLOSE_TAG_NAME[white space]></code></p> > * >- * @return The value associated with the cell is returned. >+ * <p>The open tag name is in the first group, the character data is in the second group, and >+ * the close tag name is in the third group.</p> >+ * >+ * <p>Note, the input string is assumed to be trimmed.</p> > */ >- public Object getCellValue() >- { >- if (this.getValue() == null) >- return null; >- >- String internalValue; >+ private static final Pattern XML_FRAGMENT_PATTERN = Pattern.compile("<\\s*(\\w+)\\s*>(.*)</\\s*(\\w+)\\s*>"); //$NON-NLS-1$ >+ private static final String START_LITERAL = "<Literal>"; //$NON-NLS-1$ >+ private static final String END_LITERAL = "</Literal>"; //$NON-NLS-1$ > >- internalValue = this.getValue().trim(); >+ /** >+ * The value associated with the cell is returned. >+ * >+ * @return The value associated with the cell is returned. >+ */ >+ public Object getCellValue(){ > >- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=117932 >- // performance optimization. Try unwrapping the <Literal> tags first for literal cell values to avoid xml parsing >- // All cell values are treated literal when no evaluator is present. >- if(internalValue.startsWith(START_LITERAL) && internalValue.endsWith(END_LITERAL)) >- { >- return decryptValue(internalValue.substring(START_LITERAL.length(), (internalValue.length() - END_LITERAL.length()))); >- } >- >- internalValue = internalValue.replaceAll(AMPERSAND, XML_AMPERSAND); >- String tag = null, val = null; >+ String cellValue = getValue(); > >- //get the tag and value from the XML fragment >- try { >- Document doc = XMLParserUtil.parse(internalValue); >- tag = doc.getFirstChild().getNodeName(); >- DPLLogImpl.log("Tag: " + tag); //$NON-NLS-1$ >- val = doc.getFirstChild().getFirstChild().getNodeValue(); >- DPLLogImpl.log("Val: " + val); //$NON-NLS-1$ >- } >- catch (Throwable t) { >- DPLLogImpl.log(t.getMessage()); >- } >- >- //try to find extension for evaluating tag >- try >- { >- IDatapoolEvaluatorExt evaluator = DatapoolUtil.findDatapoolEvaluator(tag); >- if(evaluator != null) >- return decryptValue(evaluator.evaluate(val)); >+ if(cellValue == null){ >+ return null; > } >- catch (Exception e) { >- DPLLogImpl.log(e.getMessage()); >+ >+ String trimmedCellValue = cellValue.trim(); >+ >+ //Performance optimization to determine if an XML fragment cell value (e.g. <[tag]>[value]</[tag]>): >+ if(trimmedCellValue.startsWith("<")) { >+ >+ //Performance optimization for unwrapping literal cell values (e.g. <Literal>[value]</Literal>): >+ if((trimmedCellValue.startsWith(START_LITERAL)) && (trimmedCellValue.endsWith(END_LITERAL))){ >+ return (decryptValue(trimmedCellValue.substring((START_LITERAL.length()), (trimmedCellValue.length() - END_LITERAL.length())))); >+ } >+ >+ try { >+ >+ //Parse the cell value: >+ Matcher matcher = XML_FRAGMENT_PATTERN.matcher(trimmedCellValue); >+ >+ //Determine if an XML fragment cell value: >+ if(matcher.matches()){ >+ >+ //Resolve the datapool evaluator for the XML tag: >+ IDatapoolEvaluatorExt evaluator = DatapoolUtil.findDatapoolEvaluator(matcher.group(1)); >+ >+ //Determine if the datapool evaluator exists for the XML tag: >+ if(evaluator != null){ >+ return (decryptValue(evaluator.evaluate(matcher.group(2)))); >+ } >+ } >+ } >+ catch (Throwable t) { >+ //Ignore since an invalid/unsupported tag. >+ } > } >- >- return decryptValue(this.getValue()); >+ >+ return (decryptValue(cellValue)); > } > > /** >@@ -491,62 +499,47 @@ > /** > * Replace the value associated with the cell. > * >- * @param value The value to be associated with this cell. >- * >+ * @param value The value to be associated with this cell. > * @see #getCellValue() > */ >- public void setCellValue(Object value) >- { >- if(value == null) >- { >- this.setValue(""); >- return; >+ public void setCellValue(Object cellObject){ >+ >+ if(cellObject == null){ >+ setValue(""); > } >+ else{ >+ >+ String cellValue = cellObject.toString(); >+ String trimmedCellValue = cellValue.trim(); > >- String tag = null, val = null; >- >- if(value.toString().indexOf("<") != -1) //$NON-NLS-1$ >- { >- //get the tag and value from the XML fragment >- try { >- Document doc = XMLParserUtil.parse(value.toString()); >- tag = doc.getFirstChild().getNodeName(); >- val = doc.getFirstChild().getFirstChild().getNodeValue(); >- } >- catch (Throwable t) >- { >- } >+ //Performance optimization to determine if an XML fragment cell value (e.g. <[tag]>[value]</[tag]>): >+ if(trimmedCellValue.startsWith("<")) { >+ >+ try { >+ >+ //Parse the cell value: >+ Matcher matcher = XML_FRAGMENT_PATTERN.matcher(trimmedCellValue); >+ >+ //Determine if an XML fragment cell value and a datapool evaluator exists for the tag: >+ if((matcher.matches()) && (DatapoolUtil.findDatapoolEvaluator(matcher.group(1)) != null)){ >+ >+ setValue(cellValue); >+ >+ return; >+ } >+ } >+ catch (Throwable t) { >+ //Ignore since an invalid/unsupported tag. >+ } >+ } >+ >+ if((trimmedCellValue.startsWith(START_LITERAL)) && (trimmedCellValue.endsWith(END_LITERAL))){ >+ setValue(cellValue); >+ } >+ else{ >+ setValue(wrapAsLiteral(cellValue)); >+ } > } >- >- //try to find extension for evaluating tag >- try >- { >- if(tag != null && val != null) >- { >- IDatapoolEvaluatorExt evaluator = DatapoolUtil.findDatapoolEvaluator(tag); >- if(evaluator != null) >- { >- this.setValue(value.toString()); >- return; >- } >- } >- >- //no extension point found which would match tag - throw exception >- throw new DatapoolException(Messages.getString("DPLCellImpl.18") + tag); //$NON-NLS-1$ >- } >- catch (Throwable t) >- { >- String stringValue = value.toString(); >- int index = stringValue.indexOf(START_LITERAL); >- if(index == -1) >- { >- String wrappedValue = wrapAsLiteral(value.toString()); >- this.setValue(wrappedValue); >- return; >- } >- this.setValue(stringValue); >- return; >- } > } > > /** >@@ -559,10 +552,6 @@ > return this.getCellValue(); > } > >- >- private static final String START_LITERAL = "<Literal>"; //$NON-NLS-1$ >- private static final String END_LITERAL = "</Literal>"; //$NON-NLS-1$ >- > /* > * Wraps the text in tags that indicate the text is a literal. All cell > * values in this release are literals. Returns the wrapped string.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 249588
:
116938
| 117601 |
118161
|
118162