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. |