From: <mwl...@us...> - 2009-02-19 16:46:31
|
Revision: 860 http://cishell.svn.sourceforge.net/cishell/?rev=860&view=rev Author: mwlinnem Date: 2009-02-19 16:44:58 +0000 (Thu, 19 Feb 2009) Log Message: ----------- Minor cleanup. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-01-26 20:40:11 UTC (rev 859) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-02-19 16:44:58 UTC (rev 860) @@ -135,7 +135,6 @@ "Sorry, the file format: *."+fileExtension+" is not yet supported. \n"+ "Please send your requests to cis...@li.... \n" +"Thank you."); - } //<filename>[.<data model type>][.<index>] Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2009-01-26 20:40:11 UTC (rev 859) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2009-02-19 16:44:58 UTC (rev 860) @@ -1,6 +1,5 @@ package org.cishell.reference.gui.persistence.load; -//standard java import java.util.Dictionary; import java.util.Enumeration; import java.util.Hashtable; @@ -34,7 +33,7 @@ printPreferences(properties); } - private void printPreferences(Dictionary properties) { + private void printPreferences(Dictionary properties) { System.out.println(" Preferences are as follows for File Load:"); if (properties == null) { System.out.println(" Dictionary is null!"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tan...@us...> - 2009-03-04 15:54:49
|
Revision: 864 http://cishell.svn.sourceforge.net/cishell/?rev=864&view=rev Author: tankchintan Date: 2009-03-04 15:54:38 +0000 (Wed, 04 Mar 2009) Log Message: ----------- Refactored the code for File > Load mechanism suitably.Made changes in all the input file validators to include detailed comments. Fixed the non-validation issue for the ISI file format.on trying to load a file without any extension does not give an error but displays another dialog box for selecting the File Loader e.g. Bibtex, Pajek, ISI etc. Validation is performed on selected file loader throwing either ERROR or loading the file with that loader. Code Reviewed By Micah Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadDataChooser.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-02-20 18:58:20 UTC (rev 863) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-03-04 15:54:38 UTC (rev 864) @@ -24,220 +24,302 @@ * @author Weixia(Bonnie) Huang (hu...@in...) */ public class FileLoad implements Algorithm { - - private final LogService logger; - private final GUIBuilderService guiBuilder; - - private BundleContext bContext; - private CIShellContext ciContext; - private static String defaultLoadDirectory; - - public FileLoad(CIShellContext ciContext, BundleContext bContext, Dictionary prefProperties) { - this.ciContext = ciContext; - this.bContext = bContext; - logger = (LogService) ciContext.getService(LogService.class.getName()); - guiBuilder = (GUIBuilderService)ciContext.getService(GUIBuilderService.class.getName()); - - //unpack preference properties - if (defaultLoadDirectory == null) { - defaultLoadDirectory = (String) prefProperties.get("loadDir"); - } - } - - public Data[] execute() throws AlgorithmExecutionException { - //prepare to run load dialog in GUI thread - - IWorkbenchWindow window = getFirstWorkbenchWindow(); - Display display = PlatformUI.getWorkbench().getDisplay(); - FileLoadRunnable fileLoader = new FileLoadRunnable (window); - - //run load dialog in gui thread. + private final LogService logger; + private final GUIBuilderService guiBuilder; - if (Thread.currentThread() != display.getThread()) { - display.syncExec(fileLoader); + private BundleContext bundleContext; + private CIShellContext ciShellContext; + private static String defaultLoadDirectory; + + public FileLoad(CIShellContext ciContext, BundleContext bContext, + Dictionary prefProperties) { + this.ciShellContext = ciContext; + this.bundleContext = bContext; + logger = (LogService) ciContext.getService(LogService.class.getName()); + guiBuilder = (GUIBuilderService) ciContext + .getService(GUIBuilderService.class.getName()); + + // unpack preference properties + if (defaultLoadDirectory == null) { + defaultLoadDirectory = (String) prefProperties.get("loadDir"); + } + } + + public Data[] execute() throws AlgorithmExecutionException { + // prepare to run load dialog in GUI thread + + IWorkbenchWindow window = getFirstWorkbenchWindow(); + Display display = PlatformUI.getWorkbench().getDisplay(); + FileLoadRunnable fileLoader = new FileLoadRunnable(window); + + // run load dialog in gui thread. + + if (Thread.currentThread() != display.getThread()) { + display.syncExec(fileLoader); } else { fileLoader.run(); } - - //return loaded file data - - Data[] loadedFileData = extractLoadedFileData(fileLoader); - return loadedFileData; - } - - final class FileLoadRunnable implements Runnable{ - boolean loadFileSuccess = false; - IWorkbenchWindow window; - //this is how we return values from the runnable - public ArrayList returnList = new ArrayList(); - - FileLoadRunnable (IWorkbenchWindow window){ - this.window = window; - } - - public void run (){ - FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); -// if (currentDir == null) { -// currentDir = new File(System.getProperty("osgi.install.area").replace("file:","") -// + "sampledata"); -// -// if (!currentDir.exists()) { -// currentDir = new File(System.getProperty("osgi.install.area").replace("file:","") -// + "sampledata" +File.separator + "anything"); -// } -// } - System.err.println("defaultLoadDirectory is " + defaultLoadDirectory); - File currentDir = new File(defaultLoadDirectory); //? good way to do this? - String absolutePath = currentDir.getAbsolutePath(); - System.err.println("absolutePath:" + absolutePath); - String name = currentDir.getName(); - System.err.println("name:" + name); - dialog.setFilterPath(absolutePath); - // dialog.setFilterPath(name); - dialog.setText("Select a File"); - String fileName = dialog.open(); - System.out.println("Resulting file name!:" + fileName); - if (fileName == null) { - return; - } - - - File file = new File(fileName); - if (file.isDirectory()) { - System.out.println("directory"); - defaultLoadDirectory = file.getAbsolutePath(); - } else { - - // File parentFile = file.getParentFile(); - // if (parentFile != null) { - System.out.println("file"); - defaultLoadDirectory = file.getParentFile().getAbsolutePath(); - // } - } - - String fileExtension = getFileExtension(file).toLowerCase(); - String filter = "(&(type=validator)(in_data=file-ext:"+fileExtension+"))"; - try { - // set the properties for the resource descriptor. - // note that this relies on the fact that the compression is set - // to nocompression by default. + // return loaded file data - // get all the service references of converters that can load this type of file. - ServiceReference[] serviceRefList = bContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), filter); - + Data[] loadedFileData = extractLoadedFileData(fileLoader); + return loadedFileData; + } - // no converters found means the file format is not supported - if (serviceRefList == null || serviceRefList.length == 0){ - guiBuilder.showError("Unsupported File Format", "Sorry, the file format: *."+fileExtension+" is not yet supported.", - "Sorry, the file format: *."+fileExtension+" is not yet supported. \n"+ - "Please send your requests to cis...@li.... \n" - +"Thank you."); - } - - //<filename>[.<data model type>][.<index>] - // only one persister found, so load the model - else if (serviceRefList.length == 1){ - AlgorithmFactory persister = (AlgorithmFactory)bContext.getService(serviceRefList[0]); - Data[] dm = new Data[]{new BasicData(file.getPath(), String.class.getName()) }; - dm = persister.createAlgorithm(dm, null, ciContext).execute(); - if (dm != null){ - loadFileSuccess = true; - logger.log(LogService.LOG_INFO, "Loaded: "+file.getPath()); - for (int i=0; i<dm.length; i++) - returnList.add(dm[i]); - } - - - } - - // lots of persisters found, return the chooser - else if (serviceRefList.length > 1){ -// new LoadDataChooser("Load", file, window.getShell(), -// ciContext, bContext, serviceRefList, returnList).open(); - for (int index=0; index<serviceRefList.length; index++){ - AlgorithmFactory persister = (AlgorithmFactory)bContext.getService(serviceRefList[index]); - Data[] dm = new Data[]{new BasicData(file.getPath(), String.class.getName()) }; - dm = persister.createAlgorithm(dm, null, ciContext).execute(); - if (dm != null ){ - loadFileSuccess = true; - logger.log(LogService.LOG_INFO, "Loaded: "+file.getPath()); - for (int i=0; i<dm.length; i++){ - returnList.add(dm[i]); - } - break; - } - } + final class FileLoadRunnable implements Runnable { + boolean loadFileSuccess = false; + IWorkbenchWindow window; + // this is how we return values from the runnable + public ArrayList selectedServicesForLoadedFileList = new ArrayList(); - } - /* - * Bonnie: I commented out the following functions since when - * the application failed to load an nwb file, etc, the reader - * has report the error. It does not need this second error display. - * But maybe not all file readers will generate the error display if - * a failure occurs... - */ -/* if (serviceRefList != null){ - if(serviceRefList.length >0 && !loadFileSuccess){ - guiBuilder.showError("Can Not Load The File", - "Sorry, it's very possible that you have a wrong file format," + - "since the file can not be loaded to the application.", - - "Please check Data Formats that this application can support at "+ - "https://nwb.slis.indiana.edu/community/?n=Algorithms.HomePage." + - "And send your requests or report the problem to "+ - "cis...@li.... \n"+"Thank you."); - } + FileLoadRunnable(IWorkbenchWindow window) { + this.window = window; + } - } -*/ + public void run() { + FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); + // if (currentDir == null) { + // currentDir = new + // File(System.getProperty("osgi.install.area").replace("file:","") + // + "sampledata"); + // + // if (!currentDir.exists()) { + // currentDir = new + // File(System.getProperty("osgi.install.area").replace("file:","") + // + "sampledata" +File.separator + "anything"); + // } + // } + System.err.println("defaultLoadDirectory is " + + defaultLoadDirectory); + File currentDir = new File(defaultLoadDirectory); // ? good way to + // do this? + String absolutePath = currentDir.getAbsolutePath(); + System.err.println("absolutePath:" + absolutePath); + String name = currentDir.getName(); + System.err.println("name:" + name); + dialog.setFilterPath(absolutePath); + // dialog.setFilterPath(name); + dialog.setText("Select a File"); + String fileName = dialog.open(); + System.out.println("Resulting file name!:" + fileName); + if (fileName == null) { + return; + } + File file = new File(fileName); + if (file.isDirectory()) { + System.out.println("directory"); + defaultLoadDirectory = file.getAbsolutePath(); + } else { - }catch (Exception e){ - throw new RuntimeException(e); - } + // File parentFile = file.getParentFile(); + // if (parentFile != null) { + System.out.println("file"); + defaultLoadDirectory = file.getParentFile().getAbsolutePath(); + // } + } - }//end run() - - public String getFileExtension(File theFile) { - String fileName = theFile.getName() ; - String extension ; - if (fileName.lastIndexOf(".") != -1) - extension = fileName.substring(fileName.lastIndexOf(".")+1) ; - else - extension = "" ; - return extension ; - } - } //end class - - private IWorkbenchWindow getFirstWorkbenchWindow() throws AlgorithmExecutionException { - final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - if (windows.length ==0){ - throw new AlgorithmExecutionException("Cannot obtain workbench window needed to open dialog."); - } else { - return windows[0]; - } - } - - private Data[] extractLoadedFileData(FileLoadRunnable dataUpdater) throws AlgorithmExecutionException { - Data[] loadedFileData; - try { - if (!dataUpdater.returnList.isEmpty()){ - int size = dataUpdater.returnList.size(); - loadedFileData = new Data[size]; - for(int index=0; index<size; index++){ - loadedFileData[index]=(Data)dataUpdater.returnList.get(index); - } - return loadedFileData; - } - else { - this.logger.log(LogService.LOG_WARNING, "File loading canceled"); - return new Data[0]; - } - } catch (Throwable e2) { - throw new AlgorithmExecutionException(e2); - } - } + String fileExtension = getFileExtension(file).toLowerCase(); + + /* + * This filter is used to filter out all the services which are not, + * 1. validators 2. validators but for output file functionality + * Hence only input file functionality validators are allowed. + */ + + String preLoadValidatorFilter = "(&(type=validator)(in_data=file-ext:" + + fileExtension + "))"; + try { + + // get all the service references of validators that can load + // this type of file. + ServiceReference[] serviceReferences = bundleContext + .getAllServiceReferences(AlgorithmFactory.class + .getName(), preLoadValidatorFilter); + + /* + * This use case is for input files selected that are, 1. + * without any file extensions 2. with file extensions that do + * not match any service "in_data" field. + */ + + if (serviceReferences == null || serviceReferences.length == 0) { + + /* + * This filter is used to accept only those services which + * are, 1. type = validators and, 2. which have non-empty + * format_name and, 3. which have non-empty in_data field. + * this is used so that all the validators for output file + * functionality are filtered out. + */ + + String validatorFilter = "(&(type=validator)(format_name=*)(in_data=file-ext:*))"; + + ServiceReference[] allValidators = bundleContext + .getAllServiceReferences(AlgorithmFactory.class + .getName(), validatorFilter); + + /* + * SelectedFileServiceSelector is used to create a GUI for + * selecting a service for the selected file from a list of + * applicable services. On selection of a service it calls + * the validator for that service. If the validator passes + * it it goes ahead and loads the file appropriately else it + * throws error message asking the user to select other + * service. + * + * This modifies the selectedServicesForLoadedFileList, + * which is the placeholder for all the verified/ applicable + * services for a selected/loaded file. + */ + + new SelectedFileServiceSelector("Load", file, window + .getShell(), ciShellContext, bundleContext, + allValidators, selectedServicesForLoadedFileList) + .open(); + } + + /* + * This use case is for input files selected that have only one + * applicable service. In this case the system goes ahead and + * loads the file with that service. + */ + + else if (serviceReferences.length == 1) { + AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext + .getService(serviceReferences[0]); + Data[] outputDataAfterValidation; + Data[] inputDataForValidation = new Data[] { new BasicData( + file.getPath(), String.class.getName()) }; + outputDataAfterValidation = selectedValidatorExecutor + .createAlgorithm(inputDataForValidation, null, + ciShellContext).execute(); + + /* + * outputDataAfterValidation = null implies that file was + * not loaded properly. + */ + + if (outputDataAfterValidation != null) { + loadFileSuccess = true; + logger.log(LogService.LOG_INFO, "Loaded: " + + file.getPath()); + for (int i = 0; i < outputDataAfterValidation.length; i++) + selectedServicesForLoadedFileList + .add(outputDataAfterValidation[i]); + } + + } + + /* + * This use case is for input files selected that have more than + * one applicable services. For e.g. ".xml" can be xgmml, + * graphml, treeml. TODO: Right now this is handled by going + * over all the selected services and loading the file with a + * service that did not fail the validation test. For e.g. for a + * ".xml" file which is treeml it will try out first graphml + * then treeml. This will throw error on graphml which can be + * resolved. A better approach will be to display + * SelectedFileServiceSelector with graphml, treeml & xgmml + * options. + */ + + else if (serviceReferences.length > 1) { + for (int index = 0; index < serviceReferences.length; index++) { + Data[] outputDataAfterValidation; + AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext + .getService(serviceReferences[index]); + Data[] inputDataForValidation = new Data[] { new BasicData( + file.getPath(), String.class.getName()) }; + outputDataAfterValidation = selectedValidatorExecutor + .createAlgorithm(inputDataForValidation, null, + ciShellContext).execute(); + if (outputDataAfterValidation != null) { + loadFileSuccess = true; + logger.log(LogService.LOG_INFO, "Loaded: " + + file.getPath()); + for (int i = 0; i < outputDataAfterValidation.length; i++) { + selectedServicesForLoadedFileList + .add(outputDataAfterValidation[i]); + } + break; + } + } + + } + /* + * Bonnie: I commented out the following functions since when + * the application failed to load an nwb file, etc, the reader + * has report the error. It does not need this second error + * display. But maybe not all file readers will generate the + * error display if a failure occurs... + */ + /* + * if (serviceRefList != null){ if(serviceRefList.length >0 && + * !loadFileSuccess){ + * guiBuilder.showError("Can Not Load The File", + * "Sorry, it's very possible that you have a wrong file format," + * + "since the file can not be loaded to the application.", + * + * "Please check Data Formats that this application can support at " + * + + * "https://nwb.slis.indiana.edu/community/?n=Algorithms.HomePage." + * + "And send your requests or report the problem to "+ + * "cis...@li.... \n"+"Thank you."); + * } + * + * } + */ + + } catch (Exception e) { + throw new RuntimeException(e); + } + + }// end run() + + public String getFileExtension(File theFile) { + String fileName = theFile.getName(); + String extension; + if (fileName.lastIndexOf(".") != -1) + extension = fileName.substring(fileName.lastIndexOf(".") + 1); + else + extension = ""; + return extension; + } + } // end class + + private IWorkbenchWindow getFirstWorkbenchWindow() + throws AlgorithmExecutionException { + final IWorkbenchWindow[] windows = PlatformUI.getWorkbench() + .getWorkbenchWindows(); + if (windows.length == 0) { + throw new AlgorithmExecutionException( + "Cannot obtain workbench window needed to open dialog."); + } else { + return windows[0]; + } + } + + private Data[] extractLoadedFileData(FileLoadRunnable dataUpdater) + throws AlgorithmExecutionException { + Data[] loadedFileData; + try { + if (!dataUpdater.selectedServicesForLoadedFileList.isEmpty()) { + int size = dataUpdater.selectedServicesForLoadedFileList.size(); + loadedFileData = new Data[size]; + for (int index = 0; index < size; index++) { + loadedFileData[index] = (Data) dataUpdater.selectedServicesForLoadedFileList + .get(index); + } + return loadedFileData; + } else { + this.logger + .log(LogService.LOG_WARNING, "File loading canceled"); + return new Data[0]; + } + } catch (Throwable e2) { + throw new AlgorithmExecutionException(e2); + } + } } \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadDataChooser.java 2009-02-20 18:58:20 UTC (rev 863) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadDataChooser.java 2009-03-04 15:54:38 UTC (rev 864) @@ -1,208 +0,0 @@ -/* - * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research - * and Education in Information Visualization (http://iv.slis.indiana.edu/). - * - * Created on Jan 24, 2005 at Indiana University. - */ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.util.ArrayList; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.data.BasicData; -import org.cishell.framework.data.Data; -import org.cishell.reference.gui.common.AbstractDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FillLayout; -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.List; -import org.eclipse.swt.widgets.Shell; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; - -/** - * - * @author Team IVC (Weixia Huang, James Ellis) - */ -public class LoadDataChooser extends AbstractDialog { - private File theFile; - private LogService logger; - - private ServiceReference[] persisterArray; - private List persisterList; - private StyledText detailPane; - private CIShellContext ciContext; - private BundleContext bContext; - private ArrayList returnList; - - private static final String[] details_prop_names = - {"format_name", "supported_file_extension", "format_description", - "restorable_model_name", "restorable_model_description" }; - private static final String[] details_prop_name_descriptions = - {"Format name", "Supported file extension", "Format description", - "Restorable model name", "Restorable model description" }; - - public LoadDataChooser(String title, File theFile, - Shell parent, CIShellContext ciContext, BundleContext bContext, - ServiceReference[] persisterArray, ArrayList returnList){ - super(parent, title, AbstractDialog.QUESTION); - this.ciContext = ciContext; - this.bContext = bContext; - this.persisterArray = persisterArray; - this.returnList = returnList; - - this.theFile = theFile; - - this.logger = (LogService) ciContext.getService(LogService.class.getName()); -//shall this part be moved out of the code? - setDescription("The file you have selected can be loaded" - + " using the following formats.\n" - + "Please select one of them."); - setDetails("This dialog allows the user to choose among all available " + - "formats for loading the selected data model. Choose any of the formats " + - "to continue loading the dataset."); - } - - private Composite initGUI(Composite parent) { - Composite content = new Composite(parent, SWT.NONE); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - content.setLayout(layout); - - Group persisterGroup = new Group(content, SWT.NONE); -//shall this label be moved out of the code? - persisterGroup.setText("Loaded by"); - persisterGroup.setLayout(new FillLayout()); - GridData persisterListGridData = new GridData(GridData.FILL_BOTH); - persisterListGridData.widthHint = 200; - persisterGroup.setLayoutData(persisterListGridData); - - persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); -// initPersisterArray(); - initPersisterList(); - persisterList.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - List list = (List)e.getSource(); - int selection = list.getSelectionIndex(); - if(selection != -1){ - updateDetailPane(persisterArray[selection]); - } - } - }); - - Group detailsGroup = new Group(content, SWT.NONE); -// shall this label be moved out of the code? - detailsGroup.setText("Details"); - detailsGroup.setLayout(new FillLayout()); - GridData detailsGridData = new GridData(GridData.FILL_BOTH); - detailsGridData.widthHint = 200; - detailsGroup.setLayoutData(detailsGridData); - - detailPane = initDetailPane(detailsGroup); - - persisterList.setSelection(0); - updateDetailPane(persisterArray[0]); - - return content; - } - - private void initPersisterList(){ - for (int i = 0; i < persisterArray.length; ++i) { - - String name = (String)persisterArray[i].getProperty("converter_name"); - - // if someone was sloppy enough to not provide a name, then use the - // name of the class instead. - if (name == null || name.length() == 0) - name = persisterArray[i].getClass().getName(); - persisterList.add(name); - } - } - - - private StyledText initDetailPane(Group detailsGroup) { - StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); - detailPane.setEditable(false); - detailPane.getCaret().setVisible(false); - return detailPane; - } - - private void updateDetailPane(ServiceReference persister) { - - detailPane.setText(""); - for (int i=0; i<details_prop_names.length; i++){ - String val = (String) persister.getProperty(details_prop_names[i]); - - StyleRange styleRange = new StyleRange(); - styleRange.start = detailPane.getText().length(); - detailPane.append(details_prop_name_descriptions[i] + ":\n"); - styleRange.length = details_prop_names[i].length() + 1; - styleRange.fontStyle = SWT.BOLD; - detailPane.setStyleRange(styleRange); - - detailPane.append(val + "\n"); - - } - - } - - private void selectionMade(int selectedIndex) { - AlgorithmFactory persister =(AlgorithmFactory) bContext.getService(persisterArray[selectedIndex]); - Data[] dm = null; - try { - dm = new Data[]{new BasicData(theFile.getPath(),String.class.getName())}; - dm = persister.createAlgorithm(dm, null, ciContext).execute(); - } catch (Throwable e) { - this.logger.log(LogService.LOG_ERROR, "Error occurred while executing selection", e); - e.printStackTrace(); - } - - if (dm != null) { - logger.log(LogService.LOG_INFO, "Loaded: "+theFile.getPath()); - - for(int i = 0; i<dm.length; i++){ - returnList.add(dm[i]); - } - close(true); - } else { - logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); - } - } - - public void createDialogButtons(Composite parent) { - Button select = new Button(parent, SWT.PUSH); - select.setText("Select"); - select.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - int index = persisterList.getSelectionIndex(); - if(index != -1){ - selectionMade(index); - } - } - }); - - Button cancel = new Button(parent, SWT.NONE); - cancel.setText("Cancel"); - cancel.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - close(false); - } - }); - } - - public Composite createContent(Composite parent) { - return initGUI(parent); - } -} Copied: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java (from rev 863, trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadDataChooser.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java 2009-03-04 15:54:38 UTC (rev 864) @@ -0,0 +1,212 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Jan 24, 2005 at Indiana University. + */ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; +import java.util.ArrayList; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.data.BasicData; +import org.cishell.framework.data.Data; +import org.cishell.reference.gui.common.AbstractDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +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.List; +import org.eclipse.swt.widgets.Shell; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; + +/** + * + * @author Team IVC (Weixia Huang, James Ellis) + */ +public class SelectedFileServiceSelector extends AbstractDialog { + private File selectedFile; + private LogService logger; + + private ServiceReference[] persisterArray; + private List persisterList; + private StyledText detailPane; + private CIShellContext ciShellContext; + private BundleContext bundleContext; + private ArrayList returnList; + + private static final String[] details_prop_names = + {"format_name", "supported_file_extension", "format_description", + "restorable_model_name", "restorable_model_description" }; + private static final String[] details_prop_name_descriptions = + {"Format name", "Supported file extension", "Format description", + "Restorable model name", "Restorable model description" }; + + public SelectedFileServiceSelector(String title, File theFile, + Shell parent, CIShellContext ciContext, BundleContext bContext, + ServiceReference[] persisterArray, ArrayList returnList){ + super(parent, title, AbstractDialog.QUESTION); + this.ciShellContext = ciContext; + this.bundleContext = bContext; + this.persisterArray = persisterArray; + this.returnList = returnList; + + this.selectedFile = theFile; + + this.logger = (LogService) ciContext.getService(LogService.class.getName()); + //shall this part be moved out of the code? + setDescription("The file you have selected can be loaded" + + " using the following formats.\n" + + "Please select one of them."); + setDetails("This dialog allows the user to choose among all available " + + "formats for loading the selected data model. Choose any of the formats " + + "to continue loading the dataset."); + } + + private Composite initGUI(Composite parent) { + Composite content = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + content.setLayout(layout); + + Group persisterGroup = new Group(content, SWT.NONE); + //shall this label be moved out of the code? + persisterGroup.setText("Loaded by"); + persisterGroup.setLayout(new FillLayout()); + GridData persisterListGridData = new GridData(GridData.FILL_BOTH); + persisterListGridData.widthHint = 200; + persisterGroup.setLayoutData(persisterListGridData); + + persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); + // initPersisterArray(); + initPersisterList(); + persisterList.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + List list = (List)e.getSource(); + int selection = list.getSelectionIndex(); + if(selection != -1){ + updateDetailPane(persisterArray[selection]); + } + } + }); + + Group detailsGroup = new Group(content, SWT.NONE); + // shall this label be moved out of the code? + detailsGroup.setText("Details"); + detailsGroup.setLayout(new FillLayout()); + GridData detailsGridData = new GridData(GridData.FILL_BOTH); + detailsGridData.widthHint = 200; + detailsGroup.setLayoutData(detailsGridData); + + detailPane = initDetailPane(detailsGroup); + + persisterList.setSelection(0); + updateDetailPane(persisterArray[0]); + + return content; + } + + private void initPersisterList(){ + for (int i = 0; i < persisterArray.length; ++i) { + + String name = (String)persisterArray[i].getProperty("converter_name"); + + // if someone was sloppy enough to not provide a name, then use the + // name of the class instead. + if (name == null || name.length() == 0) + name = persisterArray[i].getClass().getName(); + persisterList.add(name); + } + } + + + private StyledText initDetailPane(Group detailsGroup) { + StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); + detailPane.setEditable(false); + detailPane.getCaret().setVisible(false); + return detailPane; + } + + private void updateDetailPane(ServiceReference persister) { + + detailPane.setText(""); + for (int i=0; i<details_prop_names.length; i++){ + String val = (String) persister.getProperty(details_prop_names[i]); + + StyleRange styleRange = new StyleRange(); + styleRange.start = detailPane.getText().length(); + detailPane.append(details_prop_name_descriptions[i] + ":\n"); + styleRange.length = details_prop_names[i].length() + 1; + styleRange.fontStyle = SWT.BOLD; + detailPane.setStyleRange(styleRange); + + detailPane.append(val + "\n"); + + } + + } + + private void selectionMade(int selectedIndex) { + AlgorithmFactory persister =(AlgorithmFactory) bundleContext.getService(persisterArray[selectedIndex]); + Data[] dataManager = null; + boolean loadSuccess = false; + + try { + dataManager = new Data[]{new BasicData(selectedFile.getPath(),String.class.getName())}; + dataManager = persister.createAlgorithm(dataManager, null, ciShellContext).execute(); + loadSuccess = true; + } catch (Throwable e) { + this.logger.log(LogService.LOG_ERROR, "Error occurred while executing selection", e); + e.printStackTrace(); + loadSuccess = false; + } + + if (dataManager != null && loadSuccess) { + logger.log(LogService.LOG_INFO, "Loaded: "+selectedFile.getPath()); + + for(int i = 0; i<dataManager.length; i++){ + returnList.add(dataManager[i]); + } + close(true); + } else { + logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); + } + } + + public void createDialogButtons(Composite parent) { + Button select = new Button(parent, SWT.PUSH); + select.setText("Select"); + select.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + int index = persisterList.getSelectionIndex(); + if(index != -1){ + selectionMade(index); + } + } + }); + + Button cancel = new Button(parent, SWT.NONE); + cancel.setText("Cancel"); + cancel.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + close(false); + } + }); + } + + public Composite createContent(Composite parent) { + return initGUI(parent); + } +} Property changes on: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java ___________________________________________________________________ Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tan...@us...> - 2009-03-06 23:42:10
|
Revision: 865 http://cishell.svn.sourceforge.net/cishell/?rev=865&view=rev Author: tankchintan Date: 2009-03-06 23:41:41 +0000 (Fri, 06 Mar 2009) Log Message: ----------- Refactored the code for File > Load mechanism suitably. Made changes in all the input file validators to include detailed comments. Added ambiguous_extension field to all the validators that have ambgiuous_extension. for e.g. a CSV file can be a plain csv, NSF or SCOPUS. modified the codebase to handle the use cases generated by these. Code Reviewed By Micah Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-03-04 15:54:38 UTC (rev 864) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-03-06 23:41:41 UTC (rev 865) @@ -17,6 +17,7 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; @@ -32,13 +33,17 @@ private CIShellContext ciShellContext; private static String defaultLoadDirectory; + private final static String FILTER_EXTENSION_ALL = "*"; + private final static String FILTER_AMBIGUOUS = "&(type=validator)(format_name=*)(in_data=file-ext:*)"; + private final static String FILTER_IN_DATA = "&(type=validator)(format_name=*)"; + public FileLoad(CIShellContext ciContext, BundleContext bContext, Dictionary prefProperties) { this.ciShellContext = ciContext; this.bundleContext = bContext; logger = (LogService) ciContext.getService(LogService.class.getName()); guiBuilder = (GUIBuilderService) ciContext - .getService(GUIBuilderService.class.getName()); + .getService(GUIBuilderService.class.getName()); // unpack preference properties if (defaultLoadDirectory == null) { @@ -90,32 +95,25 @@ // + "sampledata" +File.separator + "anything"); // } // } - System.err.println("defaultLoadDirectory is " - + defaultLoadDirectory); File currentDir = new File(defaultLoadDirectory); // ? good way to - // do this? + // do this? String absolutePath = currentDir.getAbsolutePath(); - System.err.println("absolutePath:" + absolutePath); String name = currentDir.getName(); - System.err.println("name:" + name); dialog.setFilterPath(absolutePath); // dialog.setFilterPath(name); dialog.setText("Select a File"); String fileName = dialog.open(); - System.out.println("Resulting file name!:" + fileName); if (fileName == null) { return; } File file = new File(fileName); if (file.isDirectory()) { - System.out.println("directory"); defaultLoadDirectory = file.getAbsolutePath(); } else { // File parentFile = file.getParentFile(); // if (parentFile != null) { - System.out.println("file"); defaultLoadDirectory = file.getParentFile().getAbsolutePath(); // } } @@ -123,44 +121,71 @@ String fileExtension = getFileExtension(file).toLowerCase(); /* - * This filter is used to filter out all the services which are not, + * This filter is used to filter out all the services which are NOT, * 1. validators 2. validators but for output file functionality * Hence only input file functionality validators are allowed. */ - String preLoadValidatorFilter = "(&(type=validator)(in_data=file-ext:" - + fileExtension + "))"; try { // get all the service references of validators that can load // this type of file. - ServiceReference[] serviceReferences = bundleContext - .getAllServiceReferences(AlgorithmFactory.class - .getName(), preLoadValidatorFilter); + ServiceReference[] selectedFileServiceReferences = null; + + if(fileExtension != null && fileExtension.length() > 0) { + selectedFileServiceReferences = getApplicableServiceReferences( + FILTER_IN_DATA, fileExtension); + } + /* * This use case is for input files selected that are, 1. * without any file extensions 2. with file extensions that do * not match any service "in_data" field. */ - if (serviceReferences == null || serviceReferences.length == 0) { + if ((selectedFileServiceReferences == null || selectedFileServiceReferences.length == 0)) { /* * This filter is used to accept only those services which * are, 1. type = validators and, 2. which have non-empty * format_name and, 3. which have non-empty in_data field. - * this is used so that all the validators for output file - * functionality are filtered out. + * or, 3. which have empty in_data field and non-empty + * ambiguous_extension field. This is used so that all the + * validators for output file functionality are filtered + * out. */ - String validatorFilter = "(&(type=validator)(format_name=*)(in_data=file-ext:*))"; + ServiceReference[] potentialValidators = null; - ServiceReference[] allValidators = bundleContext - .getAllServiceReferences(AlgorithmFactory.class - .getName(), validatorFilter); + /* + * This is used to find validators that support ambiguous + * extensions for the provided file extension. There are + * good chances that the file selected does not have any + * file extension, this is handled by below case. + */ + if (fileExtension != null && fileExtension.length() > 0) { + + potentialValidators = getApplicableServiceReferences( + FILTER_AMBIGUOUS, fileExtension); + + } + /* + * If no services are found then provide for all the + * validators list. + */ + + if (potentialValidators == null + || potentialValidators.length == 0) { + + potentialValidators = getApplicableServiceReferences( + FILTER_IN_DATA, FILTER_EXTENSION_ALL); + + } + + /* * SelectedFileServiceSelector is used to create a GUI for * selecting a service for the selected file from a list of * applicable services. On selection of a service it calls @@ -176,79 +201,93 @@ new SelectedFileServiceSelector("Load", file, window .getShell(), ciShellContext, bundleContext, - allValidators, selectedServicesForLoadedFileList) - .open(); + potentialValidators, + selectedServicesForLoadedFileList).open(); } /* * This use case is for input files selected that have only one - * applicable service. In this case the system goes ahead and - * loads the file with that service. + * applicable service. Special case where the file extension + * belongs to ambiguous file extension group like csv is also + * handled. In the simple case system goes ahead and loads the + * file with that service. */ - else if (serviceReferences.length == 1) { - AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext - .getService(serviceReferences[0]); - Data[] outputDataAfterValidation; - Data[] inputDataForValidation = new Data[] { new BasicData( - file.getPath(), String.class.getName()) }; - outputDataAfterValidation = selectedValidatorExecutor - .createAlgorithm(inputDataForValidation, null, - ciShellContext).execute(); + else if (selectedFileServiceReferences.length == 1) { /* - * outputDataAfterValidation = null implies that file was - * not loaded properly. + * To check for the files with ambiguous file extension a + * seperate list of service references is created. */ - if (outputDataAfterValidation != null) { - loadFileSuccess = true; - logger.log(LogService.LOG_INFO, "Loaded: " - + file.getPath()); - for (int i = 0; i < outputDataAfterValidation.length; i++) - selectedServicesForLoadedFileList - .add(outputDataAfterValidation[i]); + ServiceReference[] selectedFileAmbiguousValidators = getApplicableServiceReferences( + FILTER_AMBIGUOUS, fileExtension); + + /* + * If allAmbiguousValidators is not empty then the system + * provides a dialog box to select from the available + * validators. In this case CSV, NSF & SCOPUS + */ + + if ((selectedFileAmbiguousValidators != null && selectedFileAmbiguousValidators.length > 0)) { + new SelectedFileServiceSelector("Load", file, window + .getShell(), ciShellContext, bundleContext, + selectedFileAmbiguousValidators, + selectedServicesForLoadedFileList).open(); } - } + /* + * If allAmbiguousValidators is not empty we go forward with + * normal work flow of loading the file with selected file + * format. + */ - /* - * This use case is for input files selected that have more than - * one applicable services. For e.g. ".xml" can be xgmml, - * graphml, treeml. TODO: Right now this is handled by going - * over all the selected services and loading the file with a - * service that did not fail the validation test. For e.g. for a - * ".xml" file which is treeml it will try out first graphml - * then treeml. This will throw error on graphml which can be - * resolved. A better approach will be to display - * SelectedFileServiceSelector with graphml, treeml & xgmml - * options. - */ + else { - else if (serviceReferences.length > 1) { - for (int index = 0; index < serviceReferences.length; index++) { + AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext + .getService(selectedFileServiceReferences[0]); Data[] outputDataAfterValidation; - AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext - .getService(serviceReferences[index]); Data[] inputDataForValidation = new Data[] { new BasicData( file.getPath(), String.class.getName()) }; outputDataAfterValidation = selectedValidatorExecutor - .createAlgorithm(inputDataForValidation, null, - ciShellContext).execute(); + .createAlgorithm(inputDataForValidation, null, + ciShellContext).execute(); + + /* + * outputDataAfterValidation = null implies that file + * was not loaded properly. + */ + if (outputDataAfterValidation != null) { loadFileSuccess = true; logger.log(LogService.LOG_INFO, "Loaded: " + file.getPath()); - for (int i = 0; i < outputDataAfterValidation.length; i++) { + for (int i = 0; i < outputDataAfterValidation.length; i++) selectedServicesForLoadedFileList - .add(outputDataAfterValidation[i]); - } - break; + .add(outputDataAfterValidation[i]); } } } + /* + * This use case is for input files selected that have more than + * one applicable services. For e.g. ".xml" can be xgmml, + * graphml, treeml. This now triggers the + * SelectedFileServiceSelector dialog & can be used to select + * any one of the available services for that particular file + * extension. + */ + + else if (selectedFileServiceReferences.length > 1) { + + new SelectedFileServiceSelector("Load", file, window + .getShell(), ciShellContext, bundleContext, + selectedFileServiceReferences, + selectedServicesForLoadedFileList).open(); + + } + /* * Bonnie: I commented out the following functions since when * the application failed to load an nwb file, etc, the reader * has report the error. It does not need this second error @@ -278,6 +317,49 @@ }// end run() + /** + * @param selectedFileServiceReferencesFilter + * @param fileExtensionManipulations + * @return + * @throws InvalidSyntaxException + */ + private ServiceReference[] getApplicableServiceReferences( + String selectedFileServiceReferencesFilter, + String fileExtensionManipulations) + throws InvalidSyntaxException { + + String appliedValidatorFilter = getValidatorFilter( + selectedFileServiceReferencesFilter, + fileExtensionManipulations); + + ServiceReference[] selectedFileServiceReferences = bundleContext + .getAllServiceReferences(AlgorithmFactory.class.getName(), + appliedValidatorFilter); + + return selectedFileServiceReferences; + + } + + private String getValidatorFilter( + String selectedFileServiceReferencesFilter, + String fileExtensionManipulations) { + + if (selectedFileServiceReferencesFilter.equals(FILTER_IN_DATA)) { + return "(" + selectedFileServiceReferencesFilter + + "(in_data=file-ext:" + fileExtensionManipulations + + ")" + + ")"; + + } else if (selectedFileServiceReferencesFilter.equals(FILTER_AMBIGUOUS)) { + return "(" + selectedFileServiceReferencesFilter + + "(ambiguous_extension=" + fileExtensionManipulations + + ")" + + ")"; + } + + return null; + } + public String getFileExtension(File theFile) { String fileName = theFile.getName(); String extension; @@ -290,9 +372,9 @@ } // end class private IWorkbenchWindow getFirstWorkbenchWindow() - throws AlgorithmExecutionException { + throws AlgorithmExecutionException { final IWorkbenchWindow[] windows = PlatformUI.getWorkbench() - .getWorkbenchWindows(); + .getWorkbenchWindows(); if (windows.length == 0) { throw new AlgorithmExecutionException( "Cannot obtain workbench window needed to open dialog."); @@ -302,7 +384,7 @@ } private Data[] extractLoadedFileData(FileLoadRunnable dataUpdater) - throws AlgorithmExecutionException { + throws AlgorithmExecutionException { Data[] loadedFileData; try { if (!dataUpdater.selectedServicesForLoadedFileList.isEmpty()) { @@ -310,12 +392,12 @@ loadedFileData = new Data[size]; for (int index = 0; index < size; index++) { loadedFileData[index] = (Data) dataUpdater.selectedServicesForLoadedFileList - .get(index); + .get(index); } return loadedFileData; } else { this.logger - .log(LogService.LOG_WARNING, "File loading canceled"); + .log(LogService.LOG_WARNING, "File loading canceled"); return new Data[0]; } } catch (Throwable e2) { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java 2009-03-04 15:54:38 UTC (rev 864) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java 2009-03-06 23:41:41 UTC (rev 865) @@ -46,13 +46,20 @@ private BundleContext bundleContext; private ArrayList returnList; - private static final String[] details_prop_names = - {"format_name", "supported_file_extension", "format_description", - "restorable_model_name", "restorable_model_description" }; - private static final String[] details_prop_name_descriptions = - {"Format name", "Supported file extension", "Format description", - "Restorable model name", "Restorable model description" }; + private static final String[] DETAILS_ITEM_KEY = + {"format_name", "supported_file_extension", "format_description" }; + /* + * Other possible keys could be restorable_model_name, restorable_model_description + * */ + + private static final String[] DETAILS_ITEM_KEY_DISPLAY_VALUE = + {"Format name", "Supported file extension", "Format description"}; + + /* + * Other possible keys display values could be "Restorable model name", "Restorable model description" + * */ + public SelectedFileServiceSelector(String title, File theFile, Shell parent, CIShellContext ciContext, BundleContext bContext, ServiceReference[] persisterArray, ArrayList returnList){ @@ -142,13 +149,13 @@ private void updateDetailPane(ServiceReference persister) { detailPane.setText(""); - for (int i=0; i<details_prop_names.length; i++){ - String val = (String) persister.getProperty(details_prop_names[i]); + for (int i=0; i<DETAILS_ITEM_KEY.length; i++){ + String val = (String) persister.getProperty(DETAILS_ITEM_KEY[i]); StyleRange styleRange = new StyleRange(); styleRange.start = detailPane.getText().length(); - detailPane.append(details_prop_name_descriptions[i] + ":\n"); - styleRange.length = details_prop_names[i].length() + 1; + detailPane.append(DETAILS_ITEM_KEY_DISPLAY_VALUE[i] + ":\n"); + styleRange.length = DETAILS_ITEM_KEY[i].length() + 1; styleRange.fontStyle = SWT.BOLD; detailPane.setStyleRange(styleRange); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-05-27 17:45:00
|
Revision: 867 http://cishell.svn.sourceforge.net/cishell/?rev=867&view=rev Author: mwlinnem Date: 2009-05-27 17:44:50 +0000 (Wed, 27 May 2009) Log Message: ----------- Reworked code that handles loading files for ambiguous file extensions. Reviewed by Patrick. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java Copied: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java (from rev 866, trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2009-05-27 17:44:50 UTC (rev 867) @@ -0,0 +1,219 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Jan 24, 2005 at Indiana University. + */ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; +import java.util.ArrayList; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.data.BasicData; +import org.cishell.framework.data.Data; +import org.cishell.reference.gui.common.AbstractDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +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.List; +import org.eclipse.swt.widgets.Shell; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; + +/** + * + * @author Team IVC (Weixia Huang, James Ellis) + */ +public class FileFormatSelector extends AbstractDialog { + private File selectedFile; + private LogService logger; + + private ServiceReference[] persisterArray; + private List persisterList; +// private StyledText detailPane; + private CIShellContext ciShellContext; + private BundleContext bundleContext; + private ArrayList returnList; + +// private static final String[] DETAILS_ITEM_KEY = +// {"format_name", "supported_file_extension", "format_description" }; + + /* + * Other possible keys could be restorable_model_name, restorable_model_description + * */ + +// private static final String[] DETAILS_ITEM_KEY_DISPLAY_VALUE = +// {"Format name", "Supported file extension", "Format description"}; + + /* + * Other possible keys display values could be "Restorable model name", "Restorable model description" + * */ + + public FileFormatSelector(String title, File theFile, + Shell parent, CIShellContext ciContext, BundleContext bContext, + ServiceReference[] persisterArray, ArrayList returnList){ + super(parent, title, AbstractDialog.QUESTION); + this.ciShellContext = ciContext; + this.bundleContext = bContext; + this.persisterArray = persisterArray; + this.returnList = returnList; + + this.selectedFile = theFile; + + this.logger = (LogService) ciContext.getService(LogService.class.getName()); + //shall this part be moved out of the code? + setDescription("The file you have selected can be loaded" + + " using one or more of the following formats.\n" + + "Please select the format you would like to try."); + setDetails("This dialog allows the user to choose among all available " + + "formats for loading the selected data model. Choose any of the formats " + + "to continue loading the dataset."); + } + + private Composite initGUI(Composite parent) { + Composite content = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + content.setLayout(layout); + + Group persisterGroup = new Group(content, SWT.NONE); + //shall this label be moved out of the code? + persisterGroup.setText("Load as..."); + persisterGroup.setLayout(new FillLayout()); + GridData persisterListGridData = new GridData(GridData.FILL_BOTH); + persisterListGridData.widthHint = 200; + persisterGroup.setLayoutData(persisterListGridData); + + persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); + // initPersisterArray(); + initPersisterList(); + persisterList.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + List list = (List)e.getSource(); + int selection = list.getSelectionIndex(); + if(selection != -1){ +// updateDetailPane(persisterArray[selection]); + } + } + }); + +// Group detailsGroup = new Group(content, SWT.NONE); +// // shall this label be moved out of the code? +// detailsGroup.setText("Details"); +// detailsGroup.setLayout(new FillLayout()); +// GridData detailsGridData = new GridData(GridData.FILL_BOTH); +// detailsGridData.widthHint = 200; +// detailsGroup.setLayoutData(detailsGridData); +// +// detailPane = initDetailPane(detailsGroup); +// +// persisterList.setSelection(0); +// updateDetailPane(persisterArray[0]); + + return content; + } + + private void initPersisterList(){ + for (int i = 0; i < persisterArray.length; ++i) { + + String name = (String)persisterArray[i].getProperty("label"); + + // if someone was sloppy enough to not provide a name, then use the + // name of the class instead. + if (name == null || name.length() == 0) + name = persisterArray[i].getClass().getName(); + persisterList.add(name); + } + } + + +// private StyledText initDetailPane(Group detailsGroup) { +// StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); +// detailPane.setEditable(false); +// detailPane.getCaret().setVisible(false); +// return detailPane; +// } + +// private void updateDetailPane(ServiceReference persister) { +// +// detailPane.setText(""); +// for (int i=0; i<DETAILS_ITEM_KEY.length; i++){ +// String val = (String) persister.getProperty(DETAILS_ITEM_KEY[i]); +// +// StyleRange styleRange = new StyleRange(); +// styleRange.start = detailPane.getText().length(); +// detailPane.append(DETAILS_ITEM_KEY_DISPLAY_VALUE[i] + ":\n"); +// styleRange.length = DETAILS_ITEM_KEY[i].length() + 1; +// styleRange.fontStyle = SWT.BOLD; +// detailPane.setStyleRange(styleRange); +// +// detailPane.append(val + "\n"); +// +// } +// +// } + + private void selectionMade(int selectedIndex) { + AlgorithmFactory persister =(AlgorithmFactory) bundleContext.getService(persisterArray[selectedIndex]); + Data[] dataManager = null; + boolean loadSuccess = false; + + try { + dataManager = new Data[]{new BasicData(selectedFile.getPath(),String.class.getName())}; + dataManager = persister.createAlgorithm(dataManager, null, ciShellContext).execute(); + loadSuccess = true; + } catch (Throwable e) { + this.logger.log(LogService.LOG_ERROR, "Error occurred while executing selection", e); + e.printStackTrace(); + loadSuccess = false; + } + + if (dataManager != null && loadSuccess) { + logger.log(LogService.LOG_INFO, "Loaded: "+selectedFile.getPath()); + + for(int i = 0; i<dataManager.length; i++){ + returnList.add(dataManager[i]); + } + close(true); + } else { + logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); + } + } + + public void createDialogButtons(Composite parent) { + Button select = new Button(parent, SWT.PUSH); + select.setText("Select"); + select.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + int index = persisterList.getSelectionIndex(); + if(index != -1){ + selectionMade(index); + } + } + }); + + Button cancel = new Button(parent, SWT.NONE); + cancel.setText("Cancel"); + cancel.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + close(false); + } + }); + } + + public Composite createContent(Composite parent) { + return initGUI(parent); + } +} Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-04-24 22:00:50 UTC (rev 866) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-05-27 17:44:50 UTC (rev 867) @@ -21,29 +21,19 @@ import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; -/* - * @author Weixia(Bonnie) Huang (hu...@in...) - */ public class FileLoad implements Algorithm { private final LogService logger; - private final GUIBuilderService guiBuilder; private BundleContext bundleContext; private CIShellContext ciShellContext; private static String defaultLoadDirectory; - private final static String FILTER_EXTENSION_ALL = "*"; - private final static String FILTER_AMBIGUOUS = "&(type=validator)(format_name=*)(in_data=file-ext:*)"; - private final static String FILTER_IN_DATA = "&(type=validator)(format_name=*)"; - public FileLoad(CIShellContext ciContext, BundleContext bContext, Dictionary prefProperties) { this.ciShellContext = ciContext; this.bundleContext = bContext; logger = (LogService) ciContext.getService(LogService.class.getName()); - guiBuilder = (GUIBuilderService) ciContext - .getService(GUIBuilderService.class.getName()); // unpack preference properties if (defaultLoadDirectory == null) { @@ -75,291 +65,158 @@ final class FileLoadRunnable implements Runnable { boolean loadFileSuccess = false; IWorkbenchWindow window; + // this is how we return values from the runnable - public ArrayList selectedServicesForLoadedFileList = new ArrayList(); + public ArrayList loadedFiles_ReturnParameter = new ArrayList(); FileLoadRunnable(IWorkbenchWindow window) { this.window = window; } + /* + * Let the user chose which file to load, + * Let the user choose the file type (if it is ambiguous), + * and then actually load and validate the file. + */ public void run() { - FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); - // if (currentDir == null) { - // currentDir = new - // File(System.getProperty("osgi.install.area").replace("file:","") - // + "sampledata"); - // - // if (!currentDir.exists()) { - // currentDir = new - // File(System.getProperty("osgi.install.area").replace("file:","") - // + "sampledata" +File.separator + "anything"); - // } - // } - File currentDir = new File(defaultLoadDirectory); // ? good way to - // do this? - String absolutePath = currentDir.getAbsolutePath(); - String name = currentDir.getName(); - dialog.setFilterPath(absolutePath); - // dialog.setFilterPath(name); - dialog.setText("Select a File"); - String fileName = dialog.open(); - if (fileName == null) { - return; - } + try { + // Prepare to ask the user which file to load. - File file = new File(fileName); - if (file.isDirectory()) { - defaultLoadDirectory = file.getAbsolutePath(); - } else { + FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); + File currentDir = new File(defaultLoadDirectory); + String absolutePath = currentDir.getAbsolutePath(); + dialog.setFilterPath(absolutePath); + dialog.setText("Select a File"); - // File parentFile = file.getParentFile(); - // if (parentFile != null) { - defaultLoadDirectory = file.getParentFile().getAbsolutePath(); - // } - } + // Determine which file to load. - String fileExtension = getFileExtension(file).toLowerCase(); + String nameOfFileToLoad = dialog.open(); + if (nameOfFileToLoad == null) { + return; + } - /* - * This filter is used to filter out all the services which are NOT, - * 1. validators 2. validators but for output file functionality - * Hence only input file functionality validators are allowed. - */ + // Actually load the file. - try { + File file = new File(nameOfFileToLoad); - // get all the service references of validators that can load - // this type of file. + if (file.isDirectory()) { + defaultLoadDirectory = file.getAbsolutePath(); + } else { + defaultLoadDirectory = file.getParentFile().getAbsolutePath(); + } - ServiceReference[] selectedFileServiceReferences = null; + //Validate the loaded file, "casting" it to a certain MIME type. - if(fileExtension != null && fileExtension.length() > 0) { - selectedFileServiceReferences = getApplicableServiceReferences( - FILTER_IN_DATA, fileExtension); - } - - /* - * This use case is for input files selected that are, 1. - * without any file extensions 2. with file extensions that do - * not match any service "in_data" field. - */ + // Extract the file's file extension. - if ((selectedFileServiceReferences == null || selectedFileServiceReferences.length == 0)) { + String fileExtension = getFileExtension(file).toLowerCase(); - /* - * This filter is used to accept only those services which - * are, 1. type = validators and, 2. which have non-empty - * format_name and, 3. which have non-empty in_data field. - * or, 3. which have empty in_data field and non-empty - * ambiguous_extension field. This is used so that all the - * validators for output file functionality are filtered - * out. - */ + // Get all the validators which support this file extension... - ServiceReference[] potentialValidators = null; + ServiceReference[] supportingValidators = getSupportingValidators(fileExtension); - /* - * This is used to find validators that support ambiguous - * extensions for the provided file extension. There are - * good chances that the file selected does not have any - * file extension, this is handled by below case. - */ + // If there are no supporting validators... + if (supportingValidators.length == 0) { + // Let the user choose from all the validators available. - if (fileExtension != null && fileExtension.length() > 0) { + ServiceReference[] allValidators = getAllValidators(); - potentialValidators = getApplicableServiceReferences( - FILTER_AMBIGUOUS, fileExtension); - - } - - /* - * If no services are found then provide for all the - * validators list. - */ - - if (potentialValidators == null - || potentialValidators.length == 0) { - - potentialValidators = getApplicableServiceReferences( - FILTER_IN_DATA, FILTER_EXTENSION_ALL); - - } - - /* - * SelectedFileServiceSelector is used to create a GUI for - * selecting a service for the selected file from a list of - * applicable services. On selection of a service it calls - * the validator for that service. If the validator passes - * it it goes ahead and loads the file appropriately else it - * throws error message asking the user to select other - * service. - * - * This modifies the selectedServicesForLoadedFileList, - * which is the placeholder for all the verified/ applicable - * services for a selected/loaded file. - */ - - new SelectedFileServiceSelector("Load", file, window - .getShell(), ciShellContext, bundleContext, - potentialValidators, - selectedServicesForLoadedFileList).open(); + new FileFormatSelector("Load", file, window.getShell(), + ciShellContext, bundleContext, allValidators, + loadedFiles_ReturnParameter).open(); } - /* - * This use case is for input files selected that have only one - * applicable service. Special case where the file extension - * belongs to ambiguous file extension group like csv is also - * handled. In the simple case system goes ahead and loads the - * file with that service. - */ + // If there is just one supporting validator... + if (supportingValidators.length == 1) { + // Just use that validator to validate the file. + + ServiceReference onlyPossibleValidator = supportingValidators[0]; + AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext + .getService(onlyPossibleValidator); + Data[] outputDataAfterValidation; + Data[] inputDataForValidation = new Data[] { new BasicData( + file.getPath(), String.class.getName()) }; + outputDataAfterValidation = selectedValidatorExecutor + .createAlgorithm(inputDataForValidation, null, + ciShellContext).execute(); - else if (selectedFileServiceReferences.length == 1) { - /* - * To check for the files with ambiguous file extension a - * seperate list of service references is created. + * outputDataAfterValidation = null implies that file + * was not loaded properly. */ - ServiceReference[] selectedFileAmbiguousValidators = getApplicableServiceReferences( - FILTER_AMBIGUOUS, fileExtension); - - /* - * If allAmbiguousValidators is not empty then the system - * provides a dialog box to select from the available - * validators. In this case CSV, NSF & SCOPUS - */ - - if ((selectedFileAmbiguousValidators != null && selectedFileAmbiguousValidators.length > 0)) { - new SelectedFileServiceSelector("Load", file, window - .getShell(), ciShellContext, bundleContext, - selectedFileAmbiguousValidators, - selectedServicesForLoadedFileList).open(); + if (outputDataAfterValidation != null) { + loadFileSuccess = true; + logger.log(LogService.LOG_INFO, "Loaded: " + + file.getPath()); + for (int i = 0; i < outputDataAfterValidation.length; i++) + loadedFiles_ReturnParameter. + add(outputDataAfterValidation[i]); } - - /* - * If allAmbiguousValidators is not empty we go forward with - * normal work flow of loading the file with selected file - * format. - */ - - else { - - AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext - .getService(selectedFileServiceReferences[0]); - Data[] outputDataAfterValidation; - Data[] inputDataForValidation = new Data[] { new BasicData( - file.getPath(), String.class.getName()) }; - outputDataAfterValidation = selectedValidatorExecutor - .createAlgorithm(inputDataForValidation, null, - ciShellContext).execute(); - - /* - * outputDataAfterValidation = null implies that file - * was not loaded properly. - */ - - if (outputDataAfterValidation != null) { - loadFileSuccess = true; - logger.log(LogService.LOG_INFO, "Loaded: " - + file.getPath()); - for (int i = 0; i < outputDataAfterValidation.length; i++) - selectedServicesForLoadedFileList - .add(outputDataAfterValidation[i]); - } - } - } - /* - * This use case is for input files selected that have more than - * one applicable services. For e.g. ".xml" can be xgmml, - * graphml, treeml. This now triggers the - * SelectedFileServiceSelector dialog & can be used to select - * any one of the available services for that particular file - * extension. - */ + // If there is more than one supporting validator... + if (supportingValidators.length > 1) { + // Let the user choose which validator they want to use. - else if (selectedFileServiceReferences.length > 1) { - - new SelectedFileServiceSelector("Load", file, window - .getShell(), ciShellContext, bundleContext, - selectedFileServiceReferences, - selectedServicesForLoadedFileList).open(); - + new FileFormatSelector("Load", file, window.getShell(), + ciShellContext, bundleContext, supportingValidators, + loadedFiles_ReturnParameter).open(); } - /* - * Bonnie: I commented out the following functions since when - * the application failed to load an nwb file, etc, the reader - * has report the error. It does not need this second error - * display. But maybe not all file readers will generate the - * error display if a failure occurs... - */ - /* - * if (serviceRefList != null){ if(serviceRefList.length >0 && - * !loadFileSuccess){ - * guiBuilder.showError("Can Not Load The File", - * "Sorry, it's very possible that you have a wrong file format," - * + "since the file can not be loaded to the application.", - * - * "Please check Data Formats that this application can support at " - * + - * "https://nwb.slis.indiana.edu/community/?n=Algorithms.HomePage." - * + "And send your requests or report the problem to "+ - * "cis...@li.... \n"+"Thank you."); - * } - * - * } - */ } catch (Exception e) { throw new RuntimeException(e); } - - }// end run() - - /** - * @param selectedFileServiceReferencesFilter - * @param fileExtensionManipulations - * @return - * @throws InvalidSyntaxException - */ - private ServiceReference[] getApplicableServiceReferences( - String selectedFileServiceReferencesFilter, - String fileExtensionManipulations) - throws InvalidSyntaxException { - - String appliedValidatorFilter = getValidatorFilter( - selectedFileServiceReferencesFilter, - fileExtensionManipulations); - - ServiceReference[] selectedFileServiceReferences = bundleContext - .getAllServiceReferences(AlgorithmFactory.class.getName(), - appliedValidatorFilter); - - return selectedFileServiceReferences; - } - - private String getValidatorFilter( - String selectedFileServiceReferencesFilter, - String fileExtensionManipulations) { - - if (selectedFileServiceReferencesFilter.equals(FILTER_IN_DATA)) { - return "(" + selectedFileServiceReferencesFilter - + "(in_data=file-ext:" + fileExtensionManipulations - + ")" + - ")"; - - } else if (selectedFileServiceReferencesFilter.equals(FILTER_AMBIGUOUS)) { - return "(" + selectedFileServiceReferencesFilter - + "(ambiguous_extension=" + fileExtensionManipulations - + ")" + - ")"; + + private ServiceReference[] getSupportingValidators(String fileExtension) { + try { + String ldapQuery = "(& (type=validator)" + + "(|" + + "(in_data=file-ext:" + fileExtension + ")" + + "(also_validates=" + fileExtension + ")" + + "))"; + + ServiceReference[] supportingValidators = + bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), + ldapQuery); + + + if (supportingValidators == null) { + //(better to return a list of length zero than null) + supportingValidators = new ServiceReference[]{}; + } + + return supportingValidators; + + + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + return new ServiceReference[]{}; } - - return null; } - + + private ServiceReference[] getAllValidators() { + try { + ServiceReference[] allValidators = + bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), + "(&(type=validator)(in_data=file-ext:*))"); + + if (allValidators == null) { + //(better to return a list of length zero than null) + allValidators = new ServiceReference[]{}; + } + + return allValidators; + + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + return new ServiceReference[]{}; + } + } + public String getFileExtension(File theFile) { String fileName = theFile.getName(); String extension; @@ -369,7 +226,7 @@ extension = ""; return extension; } - } // end class + } private IWorkbenchWindow getFirstWorkbenchWindow() throws AlgorithmExecutionException { @@ -387,11 +244,11 @@ throws AlgorithmExecutionException { Data[] loadedFileData; try { - if (!dataUpdater.selectedServicesForLoadedFileList.isEmpty()) { - int size = dataUpdater.selectedServicesForLoadedFileList.size(); + if (!dataUpdater.loadedFiles_ReturnParameter.isEmpty()) { + int size = dataUpdater.loadedFiles_ReturnParameter.size(); loadedFileData = new Data[size]; for (int index = 0; index < size; index++) { - loadedFileData[index] = (Data) dataUpdater.selectedServicesForLoadedFileList + loadedFileData[index] = (Data) dataUpdater.loadedFiles_ReturnParameter .get(index); } return loadedFileData; Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java 2009-04-24 22:00:50 UTC (rev 866) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/SelectedFileServiceSelector.java 2009-05-27 17:44:50 UTC (rev 867) @@ -1,219 +0,0 @@ -/* - * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research - * and Education in Information Visualization (http://iv.slis.indiana.edu/). - * - * Created on Jan 24, 2005 at Indiana University. - */ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.util.ArrayList; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.data.BasicData; -import org.cishell.framework.data.Data; -import org.cishell.reference.gui.common.AbstractDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FillLayout; -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.List; -import org.eclipse.swt.widgets.Shell; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; - -/** - * - * @author Team IVC (Weixia Huang, James Ellis) - */ -public class SelectedFileServiceSelector extends AbstractDialog { - private File selectedFile; - private LogService logger; - - private ServiceReference[] persisterArray; - private List persisterList; - private StyledText detailPane; - private CIShellContext ciShellContext; - private BundleContext bundleContext; - private ArrayList returnList; - - private static final String[] DETAILS_ITEM_KEY = - {"format_name", "supported_file_extension", "format_description" }; - - /* - * Other possible keys could be restorable_model_name, restorable_model_description - * */ - - private static final String[] DETAILS_ITEM_KEY_DISPLAY_VALUE = - {"Format name", "Supported file extension", "Format description"}; - - /* - * Other possible keys display values could be "Restorable model name", "Restorable model description" - * */ - - public SelectedFileServiceSelector(String title, File theFile, - Shell parent, CIShellContext ciContext, BundleContext bContext, - ServiceReference[] persisterArray, ArrayList returnList){ - super(parent, title, AbstractDialog.QUESTION); - this.ciShellContext = ciContext; - this.bundleContext = bContext; - this.persisterArray = persisterArray; - this.returnList = returnList; - - this.selectedFile = theFile; - - this.logger = (LogService) ciContext.getService(LogService.class.getName()); - //shall this part be moved out of the code? - setDescription("The file you have selected can be loaded" - + " using the following formats.\n" - + "Please select one of them."); - setDetails("This dialog allows the user to choose among all available " + - "formats for loading the selected data model. Choose any of the formats " + - "to continue loading the dataset."); - } - - private Composite initGUI(Composite parent) { - Composite content = new Composite(parent, SWT.NONE); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - content.setLayout(layout); - - Group persisterGroup = new Group(content, SWT.NONE); - //shall this label be moved out of the code? - persisterGroup.setText("Loaded by"); - persisterGroup.setLayout(new FillLayout()); - GridData persisterListGridData = new GridData(GridData.FILL_BOTH); - persisterListGridData.widthHint = 200; - persisterGroup.setLayoutData(persisterListGridData); - - persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); - // initPersisterArray(); - initPersisterList(); - persisterList.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - List list = (List)e.getSource(); - int selection = list.getSelectionIndex(); - if(selection != -1){ - updateDetailPane(persisterArray[selection]); - } - } - }); - - Group detailsGroup = new Group(content, SWT.NONE); - // shall this label be moved out of the code? - detailsGroup.setText("Details"); - detailsGroup.setLayout(new FillLayout()); - GridData detailsGridData = new GridData(GridData.FILL_BOTH); - detailsGridData.widthHint = 200; - detailsGroup.setLayoutData(detailsGridData); - - detailPane = initDetailPane(detailsGroup); - - persisterList.setSelection(0); - updateDetailPane(persisterArray[0]); - - return content; - } - - private void initPersisterList(){ - for (int i = 0; i < persisterArray.length; ++i) { - - String name = (String)persisterArray[i].getProperty("converter_name"); - - // if someone was sloppy enough to not provide a name, then use the - // name of the class instead. - if (name == null || name.length() == 0) - name = persisterArray[i].getClass().getName(); - persisterList.add(name); - } - } - - - private StyledText initDetailPane(Group detailsGroup) { - StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); - detailPane.setEditable(false); - detailPane.getCaret().setVisible(false); - return detailPane; - } - - private void updateDetailPane(ServiceReference persister) { - - detailPane.setText(""); - for (int i=0; i<DETAILS_ITEM_KEY.length; i++){ - String val = (String) persister.getProperty(DETAILS_ITEM_KEY[i]); - - StyleRange styleRange = new StyleRange(); - styleRange.start = detailPane.getText().length(); - detailPane.append(DETAILS_ITEM_KEY_DISPLAY_VALUE[i] + ":\n"); - styleRange.length = DETAILS_ITEM_KEY[i].length() + 1; - styleRange.fontStyle = SWT.BOLD; - detailPane.setStyleRange(styleRange); - - detailPane.append(val + "\n"); - - } - - } - - private void selectionMade(int selectedIndex) { - AlgorithmFactory persister =(AlgorithmFactory) bundleContext.getService(persisterArray[selectedIndex]); - Data[] dataManager = null; - boolean loadSuccess = false; - - try { - dataManager = new Data[]{new BasicData(selectedFile.getPath(),String.class.getName())}; - dataManager = persister.createAlgorithm(dataManager, null, ciShellContext).execute(); - loadSuccess = true; - } catch (Throwable e) { - this.logger.log(LogService.LOG_ERROR, "Error occurred while executing selection", e); - e.printStackTrace(); - loadSuccess = false; - } - - if (dataManager != null && loadSuccess) { - logger.log(LogService.LOG_INFO, "Loaded: "+selectedFile.getPath()); - - for(int i = 0; i<dataManager.length; i++){ - returnList.add(dataManager[i]); - } - close(true); - } else { - logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); - } - } - - public void createDialogButtons(Composite parent) { - Button select = new Button(parent, SWT.PUSH); - select.setText("Select"); - select.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - int index = persisterList.getSelectionIndex(); - if(index != -1){ - selectionMade(index); - } - } - }); - - Button cancel = new Button(parent, SWT.NONE); - cancel.setText("Cancel"); - cancel.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - close(false); - } - }); - } - - public Composite createContent(Composite parent) { - return initGUI(parent); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-03-25 21:47:00
|
Revision: 1058 http://cishell.svn.sourceforge.net/cishell/?rev=1058&view=rev Author: fugu13 Date: 2010-03-25 21:46:54 +0000 (Thu, 25 Mar 2010) Log Message: ----------- File loading fixed up for demo, reviewed by Katy and Joseph. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2010-03-22 20:04:57 UTC (rev 1057) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2010-03-25 21:46:54 UTC (rev 1058) @@ -13,6 +13,7 @@ import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.common.AbstractDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; @@ -206,7 +207,9 @@ this.logger.log(LogService.LOG_INFO, "Loaded: " + this.selectedFile.getPath()); for (int ii = 0; ii < data.length; ii++) { - this.returnList.add(data[ii]); + Data dataItem = data[ii]; + FileLoad.relabelWithFilename(dataItem, selectedFile); + this.returnList.add(dataItem); } close(true); Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2010-03-22 20:04:57 UTC (rev 1057) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2010-03-25 21:46:54 UTC (rev 1058) @@ -10,6 +10,7 @@ import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; @@ -49,6 +50,19 @@ } } } + + protected static void relabelWithFilename(Data data, File file) { + File absoluteFile = file.getAbsoluteFile(); + File parent = absoluteFile.getParentFile(); + String prefix; + String parentName = parent.getName(); + if(parentName.trim().length() == 0) { + prefix = File.separator; + } else { + prefix = "..." + File.separator + parentName + File.separator; + } + data.getMetadata().put(DataProperty.LABEL, prefix + absoluteFile.getName()); + } public Data[] execute() throws AlgorithmExecutionException { // prepare to run load dialog in GUI thread @@ -158,9 +172,11 @@ loadFileSuccess = true; logger.log(LogService.LOG_INFO, "Loaded: " + file.getPath()); - for (int i = 0; i < outputDataAfterValidation.length; i++) - loadedFiles_ReturnParameter. - add(outputDataAfterValidation[i]); + for (int i = 0; i < outputDataAfterValidation.length; i++) { + Data data = outputDataAfterValidation[i]; + relabelWithFilename(data, file); + loadedFiles_ReturnParameter.add(data); + } } } @@ -177,7 +193,9 @@ throw new RuntimeException(e); } } + + private ServiceReference[] getSupportingValidators(String fileExtension) { try { String ldapQuery = "(& (type=validator)" + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-05-28 19:41:45
|
Revision: 1070 http://cishell.svn.sourceforge.net/cishell/?rev=1070&view=rev Author: pataphil Date: 2010-05-28 19:41:39 +0000 (Fri, 28 May 2010) Log Message: ----------- * File Load algorithm now passes ProgressMonitor to wrapped validators if they implement ProgressTrackable. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-05-28 19:40:20 UTC (rev 1069) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-05-28 19:41:39 UTC (rev 1070) @@ -69,7 +69,8 @@ return null; } else { - return FileValidator.validateFile(file, validator, this.ciShellContext, this.logger); + return FileValidator.validateFile( + file, validator, this.progressMonitor, this.ciShellContext, this.logger); } } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java 2010-05-28 19:40:20 UTC (rev 1069) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java 2010-05-28 19:41:39 UTC (rev 1070) @@ -1,10 +1,14 @@ package org.cishell.reference.gui.persistence.load; import java.io.File; +import java.util.Hashtable; import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.algorithm.ProgressMonitor; +import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; import org.osgi.service.log.LogService; @@ -13,24 +17,25 @@ public static Data[] validateFile( File file, AlgorithmFactory validator, + ProgressMonitor progressMonitor, CIShellContext ciShellContext, LogService logger) throws AlgorithmExecutionException { Data[] validationData = new Data[] { new BasicData(file.getPath(), String.class.getName()) }; - Data[] validatedData = validator.createAlgorithm( - validationData, null, ciShellContext).execute(); + Algorithm algorithm = validator.createAlgorithm( + validationData, new Hashtable<String, Object>(), ciShellContext); + if ((progressMonitor != null) && (algorithm instanceof ProgressTrackable)) { + ProgressTrackable progressTrackable = (ProgressTrackable)algorithm; + progressTrackable.setProgressMonitor(progressMonitor); + } + + Data[] validatedData = algorithm.execute(); + if (validatedData != null) { logger.log(LogService.LOG_INFO, "Loaded: " + file.getPath()); } return validatedData; -// } catch (AlgorithmExecutionException e) { -// String logMessage = -// "An error occurred while attempting to load your file " + -// "with the format you chose."; -// this.logger.log(LogService.LOG_ERROR, logMessage, e); -// this.thrownException = e; -// } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-07-14 15:33:24
|
Revision: 882 http://cishell.svn.sourceforge.net/cishell/?rev=882&view=rev Author: mwlinnem Date: 2009-07-14 15:33:20 +0000 (Tue, 14 Jul 2009) Log Message: ----------- Fixed FileLoad to work decently if preference service is not present. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-06-25 20:35:42 UTC (rev 881) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2009-07-14 15:33:20 UTC (rev 882) @@ -37,7 +37,17 @@ // unpack preference properties if (defaultLoadDirectory == null) { - defaultLoadDirectory = (String) prefProperties.get("loadDir"); + + /* + * get the default load directory from preferences, + * if it has been set. + */ + Object result = prefProperties.get("loadDir"); + if (result != null) { + defaultLoadDirectory = (String) result; + } else { + defaultLoadDirectory = ""; + } } } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2009-06-25 20:35:42 UTC (rev 881) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2009-07-14 15:33:20 UTC (rev 882) @@ -30,22 +30,22 @@ public void updated(Dictionary properties) throws ConfigurationException { this.properties = properties; - printPreferences(properties); + //printPreferences(properties); } - private void printPreferences(Dictionary properties) { - System.out.println(" Preferences are as follows for File Load:"); - if (properties == null) { - System.out.println(" Dictionary is null!"); - } else { - Enumeration propertiesKeys = properties.keys(); - - while (propertiesKeys.hasMoreElements()) { - String propertiesKey = (String) propertiesKeys.nextElement(); - - Object propertiesValue = properties.get(propertiesKey); - System.out.println(" " + propertiesKey + ":" + propertiesValue); - } - } - } +// private void printPreferences(Dictionary properties) { +// System.out.println(" Preferences are as follows for File Load:"); +// if (properties == null) { +// System.out.println(" Dictionary is null!"); +// } else { +// Enumeration propertiesKeys = properties.keys(); +// +// while (propertiesKeys.hasMoreElements()) { +// String propertiesKey = (String) propertiesKeys.nextElement(); +// +// Object propertiesValue = properties.get(propertiesKey); +// System.out.println(" " + propertiesKey + ":" + propertiesValue); +// } +// } +// } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-05-28 20:09:59
|
Revision: 1071 http://cishell.svn.sourceforge.net/cishell/?rev=1071&view=rev Author: pataphil Date: 2010-05-28 20:09:51 +0000 (Fri, 28 May 2010) Log Message: ----------- * File Load now operates exactly as before, only better. (The user is prompted to select a format/validator until one succeeds or File Load is canceled.) Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-05-28 19:41:39 UTC (rev 1070) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-05-28 20:09:51 UTC (rev 1071) @@ -1,7 +1,6 @@ package org.cishell.reference.gui.persistence.load; import java.io.File; -import java.util.Collection; import java.util.Dictionary; import org.cishell.framework.CIShellContext; @@ -43,35 +42,11 @@ } public Data[] execute() throws AlgorithmExecutionException { - // Prepare to run load dialog in GUI thread. - IWorkbenchWindow window = getFirstWorkbenchWindow(); Display display = PlatformUI.getWorkbench().getDisplay(); - FileLoadUserInputRunnable userInputGetter = new FileLoadUserInputRunnable( - window, this.bundleContext, this.ciShellContext); + File file = getFileToLoadFromUser(window, display); - // Run load dialog in GUI thread. - - if (Thread.currentThread() != display.getThread()) { - display.syncExec(userInputGetter); - } else { - userInputGetter.run(); - } - - // Return loaded file data. - - File file = userInputGetter.getFile(); - AlgorithmFactory validator = userInputGetter.getValidator(); - - if ((file == null) || (validator == null)) { - String logMessage = "File loading canceled"; - this.logger.log(LogService.LOG_WARNING, logMessage); - - return null; - } else { - return FileValidator.validateFile( - file, validator, this.progressMonitor, this.ciShellContext, this.logger); - } + return validateFile(window, display, file); } public ProgressMonitor getProgressMonitor() { @@ -86,7 +61,7 @@ return StringUtilities.emptyStringIfNull(preferences.get(LOAD_DIRECTORY_PREFERENCE_KEY)); } - private static IWorkbenchWindow getFirstWorkbenchWindow() throws AlgorithmExecutionException { + private IWorkbenchWindow getFirstWorkbenchWindow() throws AlgorithmExecutionException { final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); if (windows.length == 0) { @@ -96,4 +71,59 @@ return windows[0]; } } + + private File getFileToLoadFromUser(IWorkbenchWindow window, Display display) { + FileSelectorRunnable fileSelector = new FileSelectorRunnable(window); + + if (Thread.currentThread() != display.getThread()) { + display.syncExec(fileSelector); + } else { + fileSelector.run(); + } + + return fileSelector.getFile(); + } + + private Data[] validateFile(IWorkbenchWindow window, Display display, File file) + throws AlgorithmExecutionException { + AlgorithmFactory validator = null; + boolean shouldTryValidator = true; + + while (shouldTryValidator) { + try { + validator = getValidatorFromUser(window, display, file); + + if ((file == null) || (validator == null)) { + String logMessage = "File loading canceled"; + this.logger.log(LogService.LOG_WARNING, logMessage); + + shouldTryValidator = false; + } else { + return FileValidator.validateFile( + file, validator, this.progressMonitor, this.ciShellContext, this.logger); + } + } catch (Throwable e) { + String logMessage = + "The chosen file is not compatible with the chosen file. " + + "Please try a different format or cancel."; + this.logger.log(LogService.LOG_ERROR, logMessage); + } + } + + return null; + } + + private AlgorithmFactory getValidatorFromUser( + IWorkbenchWindow window, Display display, File file) { + ValidatorSelectorRunnable validatorSelector = + new ValidatorSelectorRunnable(window, this.bundleContext, file); + + if (Thread.currentThread() != display.getThread()) { + display.syncExec(validatorSelector); + } else { + validatorSelector.run(); + } + + return validatorSelector.getValidator(); + } } \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java 2010-05-28 19:41:39 UTC (rev 1070) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java 2010-05-28 20:09:51 UTC (rev 1071) @@ -1,147 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.utilities.FileUtilities; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.ui.IWorkbenchWindow; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; - -public final class FileLoadUserInputRunnable implements Runnable { - private IWorkbenchWindow window; - private BundleContext bundleContext; - private CIShellContext ciShellContext; - private File file; - private AlgorithmFactory validator; - - public FileLoadUserInputRunnable( - IWorkbenchWindow window, BundleContext bundleContext, CIShellContext ciShellContext) { - this.window = window; - this.bundleContext = bundleContext; - this.ciShellContext = ciShellContext; - } - - public File getFile() { - return this.file; - } - - public AlgorithmFactory getValidator() { - return this.validator; - } - - public void run() { - this.file = getFileFromUser(); - - if (file == null) { - return; - } else if (this.file.isDirectory()) { - FileLoadAlgorithm.defaultLoadDirectory = this.file.getAbsolutePath(); - } else { - FileLoadAlgorithm.defaultLoadDirectory = this.file.getParentFile().getAbsolutePath(); - } - - // Validate the loaded file, "casting" it to a certain MIME type. - - // Extract the file's file extension. - - String fileExtension = - FileUtilities.getFileExtension(this.file).toLowerCase().substring(1); - - // TODO split here? - - // Get all the validators which support this file extension... - - ServiceReference[] supportingValidators = getSupportingValidators(fileExtension); - - // If there are no supporting validators... - if (supportingValidators.length == 0) { - // Let the user choose from all the validators available. - - ServiceReference[] allValidators = getAllValidators(); - - FileFormatSelector validatorSelector = new FileFormatSelector( - "Load", window.getShell(), this.bundleContext, allValidators); - validatorSelector.open(); - this.validator = validatorSelector.getValidator(); - } else if (supportingValidators.length == 1) { - ServiceReference onlyPossibleValidator = supportingValidators[0]; - this.validator = - (AlgorithmFactory)this.bundleContext.getService(onlyPossibleValidator); - } - - if (supportingValidators.length > 1) { - FileFormatSelector validatorSelector = new FileFormatSelector( - "Load", window.getShell(), this.bundleContext, supportingValidators); - validatorSelector.open(); - this.validator = validatorSelector.getValidator(); - } - } - - private File getFileFromUser() { - FileDialog fileDialog = createFileDialog(); - String fileName = fileDialog.open(); - - if (fileName == null) { - return null; - } else { - return new File(fileName); - } - } - - private FileDialog createFileDialog() { - File currentDirectory = new File(FileLoadAlgorithm.defaultLoadDirectory); - String absolutePath = currentDirectory.getAbsolutePath(); - FileDialog fileDialog = new FileDialog(this.window.getShell(), SWT.OPEN); - fileDialog.setFilterPath(absolutePath); - fileDialog.setText("Select a File"); - - return fileDialog; - } - - private ServiceReference[] getSupportingValidators(String fileExtension) { - try { - String validatorsQuery = - "(& (type=validator)" + - "(|" + - "(in_data=file-ext:" + fileExtension + ")" + - "(also_validates=" + fileExtension + ")" + - "))"; - - ServiceReference[] supportingValidators = this.bundleContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), validatorsQuery); - - if (supportingValidators == null) { - return new ServiceReference[0]; - } else { - return supportingValidators; - } - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - - return new ServiceReference[]{}; - } - } - - private ServiceReference[] getAllValidators() { - try { - String validatorsQuery = "(&(type=validator)(in_data=file-ext:*))"; - ServiceReference[] allValidators = this.bundleContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), validatorsQuery); - - if (allValidators == null) { - return new ServiceReference[0]; - } else { - return allValidators; - } - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - - return new ServiceReference[0]; - } - } -} \ No newline at end of file Copied: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java (from rev 1068, trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java 2010-05-28 20:09:51 UTC (rev 1071) @@ -0,0 +1,54 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.ui.IWorkbenchWindow; + +public final class FileSelectorRunnable implements Runnable { + private IWorkbenchWindow window; + + private File file; + + public FileSelectorRunnable(IWorkbenchWindow window) { + this.window = window; + } + + public File getFile() { + return this.file; + } + + public void run() { + this.file = getFileFromUser(); + + if (this.file == null) { + return; + } else if (this.file.isDirectory()) { + FileLoadAlgorithm.defaultLoadDirectory = this.file.getAbsolutePath(); + } else { + FileLoadAlgorithm.defaultLoadDirectory = this.file.getParentFile().getAbsolutePath(); + } + } + + private File getFileFromUser() { + FileDialog fileDialog = createFileDialog(); + String fileName = fileDialog.open(); + + if (fileName == null) { + return null; + } else { + return new File(fileName); + } + } + + private FileDialog createFileDialog() { + File currentDirectory = new File(FileLoadAlgorithm.defaultLoadDirectory); + String absolutePath = currentDirectory.getAbsolutePath(); + FileDialog fileDialog = new FileDialog(this.window.getShell(), SWT.OPEN); + fileDialog.setFilterPath(absolutePath); + fileDialog.setText("Select a File"); + + return fileDialog; + } +} \ No newline at end of file Property changes on: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java 2010-05-28 20:09:51 UTC (rev 1071) @@ -0,0 +1,101 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; + +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.utilities.FileUtilities; +import org.eclipse.ui.IWorkbenchWindow; +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +public final class ValidatorSelectorRunnable implements Runnable { + private IWorkbenchWindow window; + private BundleContext bundleContext; + + private File file; + private AlgorithmFactory validator; + + public ValidatorSelectorRunnable( + IWorkbenchWindow window, BundleContext bundleContext, File file) { + this.window = window; + this.bundleContext = bundleContext; + this.file = file; + } + + public AlgorithmFactory getValidator() { + return this.validator; + } + + public void run() { + String fileExtension = + FileUtilities.getFileExtension(this.file).toLowerCase().substring(1); + + ServiceReference[] supportingValidators = getSupportingValidators(fileExtension); + + // If there are no supporting validators... + if (supportingValidators.length == 0) { + // Let the user choose from all the validators available. + + ServiceReference[] allValidators = getAllValidators(); + + FileFormatSelector validatorSelector = new FileFormatSelector( + "Load", window.getShell(), this.bundleContext, allValidators); + validatorSelector.open(); + this.validator = validatorSelector.getValidator(); + } else if (supportingValidators.length == 1) { + ServiceReference onlyPossibleValidator = supportingValidators[0]; + this.validator = + (AlgorithmFactory)this.bundleContext.getService(onlyPossibleValidator); + } + + if (supportingValidators.length > 1) { + FileFormatSelector validatorSelector = new FileFormatSelector( + "Load", window.getShell(), this.bundleContext, supportingValidators); + validatorSelector.open(); + this.validator = validatorSelector.getValidator(); + } + } + + private ServiceReference[] getSupportingValidators(String fileExtension) { + try { + String validatorsQuery = + "(& (type=validator)" + + "(|" + + "(in_data=file-ext:" + fileExtension + ")" + + "(also_validates=" + fileExtension + ")" + + "))"; + + ServiceReference[] supportingValidators = this.bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), validatorsQuery); + + if (supportingValidators == null) { + return new ServiceReference[0]; + } else { + return supportingValidators; + } + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + + return new ServiceReference[]{}; + } + } + + private ServiceReference[] getAllValidators() { + try { + String validatorsQuery = "(&(type=validator)(in_data=file-ext:*))"; + ServiceReference[] allValidators = this.bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), validatorsQuery); + + if (allValidators == null) { + return new ServiceReference[0]; + } else { + return allValidators; + } + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + + return new ServiceReference[0]; + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-01-27 20:52:09
|
Revision: 1194 http://cishell.svn.sourceforge.net/cishell/?rev=1194&view=rev Author: pataphil Date: 2011-01-27 20:52:02 +0000 (Thu, 27 Jan 2011) Log Message: ----------- * Users can now load multiple files at a time. * Reviewed by Joseph. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2011-01-20 14:31:35 UTC (rev 1193) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2011-01-27 20:52:02 UTC (rev 1194) @@ -6,8 +6,9 @@ */ package org.cishell.reference.gui.persistence.load; +import java.io.File; + import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.common.AbstractDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; @@ -50,16 +51,17 @@ String title, Shell parent, BundleContext bundleContext, - ServiceReference[] validatorReferences) { + ServiceReference[] validatorReferences, + File file) { super(parent, title, AbstractDialog.QUESTION); this.bundleContext = bundleContext; this.validatorReferences = validatorReferences; // Shall this part be moved out of the code? - setDescription( - "The file you have selected can be loaded" + - " using one or more of the following formats.\n" + - "Please select the format you would like to try."); + String descriptionFormat = + "The file \'%s\' can be loaded using one or more of the following formats.%s" + + "Please select the format you would like to try."; + setDescription(String.format(descriptionFormat, file.getAbsolutePath())); setDetails( "This dialog allows the user to choose among all available " + "formats for loading the selected data model. Choose any of the formats " + Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-01-20 14:31:35 UTC (rev 1193) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-01-27 20:52:02 UTC (rev 1194) @@ -2,6 +2,8 @@ import java.io.File; import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collection; import java.util.Dictionary; import org.cishell.framework.CIShellContext; @@ -45,13 +47,21 @@ public Data[] execute() throws AlgorithmExecutionException { IWorkbenchWindow window = getFirstWorkbenchWindow(); Display display = PlatformUI.getWorkbench().getDisplay(); - File file = getFileToLoadFromUser(window, display); + File[] files = getFilesToLoadFromUser(window, display); - if (file != null) { - Data[] validatedFileData = validateFile(window, display, file); - Data[] labeledFileData = labelFileData(file, validatedFileData); + if ((files != null) && (files.length != 0)) { + Collection<Data> finalLabeledFileData = new ArrayList<Data>(); - return labeledFileData; + for (File file : files) { + Data[] validatedFileData = validateFile(window, display, file); + Data[] labeledFileData = labelFileData(file, validatedFileData); + + for (Data data : labeledFileData) { + finalLabeledFileData.add(data); + } + } + + return finalLabeledFileData.toArray(new Data[0]); } else { return null; } @@ -80,7 +90,7 @@ } } - private File getFileToLoadFromUser(IWorkbenchWindow window, Display display) { + private File[] getFilesToLoadFromUser(IWorkbenchWindow window, Display display) { FileSelectorRunnable fileSelector = new FileSelectorRunnable(window); if (Thread.currentThread() != display.getThread()) { @@ -89,7 +99,7 @@ fileSelector.run(); } - return fileSelector.getFile(); + return fileSelector.getFiles(); } private Data[] validateFile(IWorkbenchWindow window, Display display, File file) { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java 2011-01-20 14:31:35 UTC (rev 1193) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java 2011-01-27 20:52:02 UTC (rev 1194) @@ -9,45 +9,57 @@ public final class FileSelectorRunnable implements Runnable { private IWorkbenchWindow window; - private File file; + private File[] files; public FileSelectorRunnable(IWorkbenchWindow window) { this.window = window; } - public File getFile() { - return this.file; + public File[] getFiles() { + return this.files; } public void run() { - this.file = getFileFromUser(); + this.files = getFilesFromUser(); - if (this.file == null) { + if (this.files.length == 0) { return; - } else if (this.file.isDirectory()) { - FileLoadAlgorithm.defaultLoadDirectory = this.file.getAbsolutePath(); + /*} else if (this.files[0].isDirectory()) { + // TODO Can we kill this branch? + FileLoadAlgorithm.defaultLoadDirectory = this.files[0].getAbsolutePath(); */ } else { - FileLoadAlgorithm.defaultLoadDirectory = this.file.getParentFile().getAbsolutePath(); + FileLoadAlgorithm.defaultLoadDirectory = + this.files[0].getParentFile().getAbsolutePath(); } } - private File getFileFromUser() { + private File[] getFilesFromUser() { FileDialog fileDialog = createFileDialog(); - String fileName = fileDialog.open(); + fileDialog.open(); + String path = fileDialog.getFilterPath(); + String[] fileNames = fileDialog.getFileNames(); + // TODO: Ask Angela about the order here, i.e. should they be sorted alphabetically? - if (fileName == null) { - return null; + if ((fileNames == null) || (fileNames.length == 0)) { + return new File[0]; } else { - return new File(fileName); + File[] files = new File[fileNames.length]; + + for (int ii = 0; ii < fileNames.length; ii++) { + String fullFileName = path + File.separator + fileNames[ii]; + files[ii] = new File(fullFileName); + } + + return files; } } private FileDialog createFileDialog() { File currentDirectory = new File(FileLoadAlgorithm.defaultLoadDirectory); String absolutePath = currentDirectory.getAbsolutePath(); - FileDialog fileDialog = new FileDialog(this.window.getShell(), SWT.OPEN); + FileDialog fileDialog = new FileDialog(this.window.getShell(), SWT.OPEN | SWT.MULTI); fileDialog.setFilterPath(absolutePath); - fileDialog.setText("Select a File"); + fileDialog.setText("Select Files"); return fileDialog; } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java 2011-01-20 14:31:35 UTC (rev 1193) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java 2011-01-27 20:52:02 UTC (rev 1194) @@ -40,7 +40,7 @@ ServiceReference[] allValidators = getAllValidators(); FileFormatSelector validatorSelector = new FileFormatSelector( - "Load", window.getShell(), this.bundleContext, allValidators); + "Load", window.getShell(), this.bundleContext, allValidators, this.file); validatorSelector.open(); this.validator = validatorSelector.getValidator(); } else if (supportingValidators.length == 1) { @@ -51,7 +51,7 @@ if (supportingValidators.length > 1) { FileFormatSelector validatorSelector = new FileFormatSelector( - "Load", window.getShell(), this.bundleContext, supportingValidators); + "Load", window.getShell(), this.bundleContext, supportingValidators, this.file); validatorSelector.open(); this.validator = validatorSelector.getValidator(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-02-09 18:22:58
|
Revision: 1202 http://cishell.svn.sourceforge.net/cishell/?rev=1202&view=rev Author: pataphil Date: 2011-02-09 18:22:52 +0000 (Wed, 09 Feb 2011) Log Message: ----------- * Cleaned file loading algorithm code (related to the service). Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-02-08 22:28:02 UTC (rev 1201) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-02-09 18:22:52 UTC (rev 1202) @@ -1,6 +1,5 @@ package org.cishell.reference.gui.persistence.load; -import java.io.File; import java.util.Dictionary; import org.cishell.app.service.fileloader.FileLoadException; @@ -11,18 +10,10 @@ import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.Data; -import org.cishell.utilities.StringUtilities; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; import org.osgi.framework.BundleContext; import org.osgi.service.log.LogService; public class FileLoadAlgorithm implements Algorithm, ProgressTrackable { - public static final String LOAD_DIRECTORY_PREFERENCE_KEY = "loadDir"; - - public static String defaultLoadDirectory; - private final LogService logger; private FileLoaderService fileLoader; private BundleContext bundleContext; @@ -38,11 +29,6 @@ (FileLoaderService) ciShellContext.getService(FileLoaderService.class.getName()); this.ciShellContext = ciShellContext; this.bundleContext = bundleContext; - - // This is not done upon declaration because the preference service may not have started. - if (FileLoadAlgorithm.defaultLoadDirectory == null) { - FileLoadAlgorithm.defaultLoadDirectory = determineDefaultLoadDirectory(preferences); - } } public Data[] execute() throws AlgorithmExecutionException { @@ -61,31 +47,4 @@ public void setProgressMonitor(ProgressMonitor progressMonitor) { this.progressMonitor = progressMonitor; } - - private static String determineDefaultLoadDirectory(Dictionary<String, Object> preferences) { - return StringUtilities.emptyStringIfNull(preferences.get(LOAD_DIRECTORY_PREFERENCE_KEY)); - } - - private IWorkbenchWindow getFirstWorkbenchWindow() throws AlgorithmExecutionException { - final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - - if (windows.length == 0) { - throw new AlgorithmExecutionException( - "Cannot obtain workbench window needed to open dialog."); - } else { - return windows[0]; - } - } - - private File[] getFilesToLoadFromUser(IWorkbenchWindow window, Display display) { - FileSelectorRunnable fileSelector = new FileSelectorRunnable(window); - - if (Thread.currentThread() != display.getThread()) { - display.syncExec(fileSelector); - } else { - fileSelector.run(); - } - - return fileSelector.getFiles(); - } } \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java 2011-02-08 22:28:02 UTC (rev 1201) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileSelectorRunnable.java 2011-02-09 18:22:52 UTC (rev 1202) @@ -1,66 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.ui.IWorkbenchWindow; - -public final class FileSelectorRunnable implements Runnable { - private IWorkbenchWindow window; - - private File[] files; - - public FileSelectorRunnable(IWorkbenchWindow window) { - this.window = window; - } - - public File[] getFiles() { - return this.files; - } - - public void run() { - this.files = getFilesFromUser(); - - if (this.files.length == 0) { - return; - /*} else if (this.files[0].isDirectory()) { - // TODO Can we kill this branch? - FileLoadAlgorithm.defaultLoadDirectory = this.files[0].getAbsolutePath(); */ - } else { - FileLoadAlgorithm.defaultLoadDirectory = - this.files[0].getParentFile().getAbsolutePath(); - } - } - - private File[] getFilesFromUser() { - FileDialog fileDialog = createFileDialog(); - fileDialog.open(); - String path = fileDialog.getFilterPath(); - String[] fileNames = fileDialog.getFileNames(); - // TODO: Ask Angela about the order here, i.e. should they be sorted alphabetically? - - if ((fileNames == null) || (fileNames.length == 0)) { - return new File[0]; - } else { - File[] files = new File[fileNames.length]; - - for (int ii = 0; ii < fileNames.length; ii++) { - String fullFileName = path + File.separator + fileNames[ii]; - files[ii] = new File(fullFileName); - } - - return files; - } - } - - private FileDialog createFileDialog() { - File currentDirectory = new File(FileLoadAlgorithm.defaultLoadDirectory); - String absolutePath = currentDirectory.getAbsolutePath(); - FileDialog fileDialog = new FileDialog(this.window.getShell(), SWT.OPEN | SWT.MULTI); - fileDialog.setFilterPath(absolutePath); - fileDialog.setText("Select Files"); - - return fileDialog; - } -} \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java 2011-02-08 22:28:02 UTC (rev 1201) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java 2011-02-09 18:22:52 UTC (rev 1202) @@ -1,41 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.util.Hashtable; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmExecutionException; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.algorithm.ProgressMonitor; -import org.cishell.framework.algorithm.ProgressTrackable; -import org.cishell.framework.data.BasicData; -import org.cishell.framework.data.Data; -import org.osgi.service.log.LogService; - -public final class FileValidator { - public static Data[] validateFile( - File file, - AlgorithmFactory validator, - ProgressMonitor progressMonitor, - CIShellContext ciShellContext, - LogService logger) throws AlgorithmExecutionException { - Data[] validationData = - new Data[] { new BasicData(file.getPath(), String.class.getName()) }; - Algorithm algorithm = validator.createAlgorithm( - validationData, new Hashtable<String, Object>(), ciShellContext); - - if ((progressMonitor != null) && (algorithm instanceof ProgressTrackable)) { - ProgressTrackable progressTrackable = (ProgressTrackable)algorithm; - progressTrackable.setProgressMonitor(progressMonitor); - } - - Data[] validatedData = algorithm.execute(); - - if (validatedData != null) { - logger.log(LogService.LOG_INFO, "Loaded: " + file.getPath()); - } - - return validatedData; - } -} \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java 2011-02-08 22:28:02 UTC (rev 1201) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java 2011-02-09 18:22:52 UTC (rev 1202) @@ -1,84 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Dictionary; - -import org.cishell.framework.data.BasicData; -import org.cishell.framework.data.Data; -import org.cishell.framework.data.DataProperty; -import org.cishell.utilities.dictionary.DictionaryUtilities; - -public class PrettyLabeler { - public static Data[] relabelWithFileName(Data[] data, File file) { - File absoluteFile = file.getAbsoluteFile(); - File parent = absoluteFile.getParentFile(); - - // TODO parent == null - - String prefix; - String parentName = parent.getName(); - if (parentName.trim().length() == 0) { - prefix = File.separator; - } else { - prefix = "..." + File.separator + parentName + File.separator; - } - - Collection<Data> newData = new ArrayList<Data>(data.length); - - /* TODO: This isn't actually correct. - * It will assign the same label to all of the data items if we ever do this. - */ - for (Data datum : data) { - Dictionary<String, Object> labeledDatumMetadata = - DictionaryUtilities.copy(datum.getMetadata()); - Data labeledDatum = - new BasicData(labeledDatumMetadata, datum.getData(), datum.getFormat()); - labeledDatumMetadata.put(DataProperty.LABEL, prefix + absoluteFile.getName()); - newData.add(labeledDatum); - } - - return newData.toArray(new Data[0]); - } - - /** - * Support Hierarchy structure labeling. The algorithm will avoid labeling - * on children. - * @param data - data that need to relabel - * @param file - file that contains filename to be used for relabeling - * @return the processed data with new labels - */ - public static Data[] relabelWithFileNameHierarchy(Data[] data, File file) { - File absoluteFile = file.getAbsoluteFile(); - File parent = absoluteFile.getParentFile(); - - String prefix; - String parentName = parent.getName(); - if (parentName.trim().length() == 0) { - prefix = File.separator; - } else { - prefix = "..." + File.separator + parentName + File.separator; - } - - Collection<Data> possibleParents = new ArrayList<Data>(data.length); - - for (Data datum : data) { - Dictionary<String, Object> labeledDatumMetadata = datum.getMetadata(); - Data dataParent = getParent(labeledDatumMetadata); - if (!possibleParents.contains(dataParent)) { - labeledDatumMetadata.put(DataProperty.LABEL, prefix + absoluteFile.getName()); - } - possibleParents.add(datum); - } - - return data; - } - - /* - * Get the parent of the data - */ - private static Data getParent(Dictionary<String, Object> labeledDatumMetadata) { - return (Data) labeledDatumMetadata.get(DataProperty.PARENT); - } -} \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java 2011-02-08 22:28:02 UTC (rev 1201) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ValidatorSelectorRunnable.java 2011-02-09 18:22:52 UTC (rev 1202) @@ -1,101 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; - -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.utilities.FileUtilities; -import org.eclipse.ui.IWorkbenchWindow; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; - -public final class ValidatorSelectorRunnable implements Runnable { - private IWorkbenchWindow window; - private BundleContext bundleContext; - - private File file; - private AlgorithmFactory validator; - - public ValidatorSelectorRunnable( - IWorkbenchWindow window, BundleContext bundleContext, File file) { - this.window = window; - this.bundleContext = bundleContext; - this.file = file; - } - - public AlgorithmFactory getValidator() { - return this.validator; - } - - public void run() { - String fileExtension = - FileUtilities.getFileExtension(this.file).toLowerCase().substring(1); - - ServiceReference[] supportingValidators = getSupportingValidators(fileExtension); - - // If there are no supporting validators... - if (supportingValidators.length == 0) { - // Let the user choose from all the validators available. - - ServiceReference[] allValidators = getAllValidators(); - - FileFormatSelector validatorSelector = new FileFormatSelector( - "Load", window.getShell(), this.bundleContext, allValidators, this.file); - validatorSelector.open(); - this.validator = validatorSelector.getValidator(); - } else if (supportingValidators.length == 1) { - ServiceReference onlyPossibleValidator = supportingValidators[0]; - this.validator = - (AlgorithmFactory)this.bundleContext.getService(onlyPossibleValidator); - } - - if (supportingValidators.length > 1) { - FileFormatSelector validatorSelector = new FileFormatSelector( - "Load", window.getShell(), this.bundleContext, supportingValidators, this.file); - validatorSelector.open(); - this.validator = validatorSelector.getValidator(); - } - } - - private ServiceReference[] getSupportingValidators(String fileExtension) { - try { - String validatorsQuery = - "(& (type=validator)" + - "(|" + - "(in_data=file-ext:" + fileExtension + ")" + - "(also_validates=" + fileExtension + ")" + - "))"; - - ServiceReference[] supportingValidators = this.bundleContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), validatorsQuery); - - if (supportingValidators == null) { - return new ServiceReference[0]; - } else { - return supportingValidators; - } - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - - return new ServiceReference[]{}; - } - } - - private ServiceReference[] getAllValidators() { - try { - String validatorsQuery = "(&(type=validator)(in_data=file-ext:*))"; - ServiceReference[] allValidators = this.bundleContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), validatorsQuery); - - if (allValidators == null) { - return new ServiceReference[0]; - } else { - return allValidators; - } - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - - return new ServiceReference[0]; - } - } -} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |