You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(7) |
Aug
|
Sep
(46) |
Oct
(102) |
Nov
(10) |
Dec
(21) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(1) |
Feb
(3) |
Mar
(14) |
Apr
(9) |
May
(12) |
Jun
(4) |
Jul
(40) |
Aug
(60) |
Sep
(38) |
Oct
(2) |
Nov
(1) |
Dec
(42) |
2008 |
Jan
(23) |
Feb
(29) |
Mar
(107) |
Apr
(27) |
May
(3) |
Jun
(1) |
Jul
(15) |
Aug
(7) |
Sep
(19) |
Oct
|
Nov
(2) |
Dec
|
2009 |
Jan
(36) |
Feb
(4) |
Mar
(2) |
Apr
(1) |
May
(1) |
Jun
(15) |
Jul
(30) |
Aug
(32) |
Sep
(11) |
Oct
(21) |
Nov
(12) |
Dec
(15) |
2010 |
Jan
(29) |
Feb
(9) |
Mar
(25) |
Apr
|
May
(7) |
Jun
(5) |
Jul
(21) |
Aug
(32) |
Sep
(10) |
Oct
(8) |
Nov
(29) |
Dec
(8) |
2011 |
Jan
(9) |
Feb
(35) |
Mar
(11) |
Apr
(4) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(30) |
2012 |
Jan
(5) |
Feb
(7) |
Mar
(10) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
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. |
From: <pat...@us...> - 2011-02-08 22:28:08
|
Revision: 1201 http://cishell.svn.sourceforge.net/cishell/?rev=1201&view=rev Author: pataphil Date: 2011-02-08 22:28:02 +0000 (Tue, 08 Feb 2011) Log Message: ----------- FileLoaderServiceImpl.preferences is now defaulted to an empty Hashtable (to avoid NullPointerExceptions). Modified Paths: -------------- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java 2011-02-08 22:24:17 UTC (rev 1200) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java 2011-02-08 22:28:02 UTC (rev 1201) @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Dictionary; import java.util.HashSet; +import java.util.Hashtable; import org.cishell.app.service.fileloader.FileLoadException; import org.cishell.app.service.fileloader.FileLoadListener; @@ -27,7 +28,7 @@ public static final String LOAD_DIRECTORY_PREFERENCE_KEY = "loadDir"; public static String defaultLoadDirectory = ""; - private Dictionary preferences; + private Dictionary preferences = new Hashtable(); private Collection<FileLoadListener> listeners = new HashSet<FileLoadListener>(); public void registerListener(FileLoadListener listener) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-02-08 22:24:24
|
Revision: 1200 http://cishell.svn.sourceforge.net/cishell/?rev=1200&view=rev Author: pataphil Date: 2011-02-08 22:24:17 +0000 (Tue, 08 Feb 2011) Log Message: ----------- * The File Loader Service now actually calls its file load listeners. Modified Paths: -------------- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java 2011-02-08 18:42:31 UTC (rev 1199) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java 2011-02-08 22:24:17 UTC (rev 1200) @@ -66,7 +66,16 @@ LogService logger, ProgressMonitor progressMonitor, File[] files) throws FileLoadException { - return loadFilesInternal(bundleContext, ciShellContext, logger, progressMonitor, files); + Data[] loadedFileData = + loadFilesInternal(bundleContext, ciShellContext, logger, progressMonitor, files); + + for (File file : files) { + for (FileLoadListener listener : this.listeners) { + listener.fileLoaded(file); + } + } + + return loadedFileData; } public Data[] loadFile( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-02-08 18:42:37
|
Revision: 1199 http://cishell.svn.sourceforge.net/cishell/?rev=1199&view=rev Author: pataphil Date: 2011-02-08 18:42:31 +0000 (Tue, 08 Feb 2011) Log Message: ----------- * Styled text helpers now return created StyledRange objects. Modified Paths: -------------- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/SWTUtilities.java Modified: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/SWTUtilities.java =================================================================== --- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/SWTUtilities.java 2011-02-08 17:58:33 UTC (rev 1198) +++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/SWTUtilities.java 2011-02-08 18:42:31 UTC (rev 1199) @@ -1,5 +1,8 @@ package org.cishell.utility.swt; +import java.util.Collection; +import java.util.HashSet; + import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; @@ -8,17 +11,37 @@ import org.eclipse.swt.widgets.Display; public class SWTUtilities { + public static final Color DEFAULT_BACKGROUND_COLOR = + new Color(Display.getDefault(), 255, 255, 255); /* * Append the given string to the console with the given color, this will do the job of * checking for URLs within the string and registering the proper listeners on them as well. */ - public static void appendStringWithURL( + public static Collection<StyleRange> appendStringWithURL( StyledText textField, URLClickedListener urlListener, URLMouseCursorListener urlCursorListener, String message, Color normalColor, Color urlColor) { + return appendStringWithURL( + textField, + urlListener, + urlCursorListener, + message, + DEFAULT_BACKGROUND_COLOR, + normalColor, + urlColor); + } + + public static Collection<StyleRange> appendStringWithURL( + StyledText textField, + URLClickedListener urlListener, + URLMouseCursorListener urlCursorListener, + String message, + Color backgroundColor, + Color normalColor, + Color urlColor) { //find a URL in the message @@ -52,18 +75,46 @@ } - syncedStyledPrint(textField, message.substring(0, index), normalColor, SWT.NORMAL); + StyleRange preURLStyle = syncedStyledPrint( + textField, message.substring(0, index), backgroundColor, normalColor, SWT.NORMAL); urlListener.addURL(textField.getText().length(), url); urlCursorListener.addURL(textField.getText().length(), url); - syncedStyledPrint(textField, url, urlColor, SWT.BOLD); - appendStringWithURL( + StyleRange urlStyle = + syncedStyledPrint(textField, url, backgroundColor, urlColor, SWT.BOLD); + Collection<StyleRange> postURLStyles = appendStringWithURL( textField, urlListener, urlCursorListener, message.substring(index + url.length()), - normalColor,urlColor); + backgroundColor, + normalColor, + urlColor); + + Collection<StyleRange> finalStyles = new HashSet<StyleRange>(); + + if (preURLStyle != null) { + finalStyles.add(preURLStyle); + } + + if (urlStyle != null) { + finalStyles.add(urlStyle); + } + + finalStyles.addAll(postURLStyles); + + return finalStyles; } else { - syncedStyledPrint(textField, message, normalColor, SWT.NORMAL); + StyleRange style = syncedStyledPrint( + textField, message, backgroundColor, normalColor, SWT.NORMAL); + + if (style != null) { + Collection<StyleRange> finalStyles = new HashSet<StyleRange>(); + finalStyles.add(style); + + return finalStyles; + } else { + return new HashSet<StyleRange>(); + } } } @@ -72,16 +123,29 @@ * append it to the StyledText control. */ - public static void syncedStyledPrint( - final StyledText textField, final String message, final Color color, final int style) { + public static StyleRange syncedStyledPrint( + StyledText textField, String message, Color color, int style) { + return syncedStyledPrint(textField, message, DEFAULT_BACKGROUND_COLOR, color, style); + } + + public static StyleRange syncedStyledPrint( + final StyledText textField, + final String message, + final Color backgroundColor, + final Color color, + final int style) { + final StyleRange[] styleRange = new StyleRange[1]; Display.getDefault().syncExec(new Runnable() { - public void run(){ - styledPrint(textField, message, color, style); + public void run() { + styleRange[0] = styledPrint(textField, message, color, style); } }); + + return styleRange[0]; } - public static void styledPrint(StyledText textField, String message, Color color, int style) { + public static StyleRange styledPrint( + StyledText textField, String message, Color color, int style) { if (!textField.isDisposed()) { textField.append(message); @@ -94,10 +158,14 @@ // This makes it autoscroll. textField.setTopIndex(textField.getLineCount()); + + return styleRange; + } else { + return null; } } - public static void printURL( + public static StyleRange printURL( Composite parent, StyledText textField, String url, @@ -105,19 +173,13 @@ Color color, int style) { URLClickedListener urlClickedListener = new URLClickedListener(textField); - URLMouseCursorListener urlCursorListener = - new URLMouseCursorListener(parent, textField); + URLMouseCursorListener urlCursorListener = new URLMouseCursorListener(parent, textField); textField.addMouseListener(urlClickedListener); textField.addMouseMoveListener(urlCursorListener); - urlClickedListener.addURL( - textField.getText().length(), url, displayURL); - urlCursorListener.addURL( - textField.getText().length(), url, displayURL); - SWTUtilities.styledPrint( - textField, - displayURL, - color, - style); + urlClickedListener.addURL(textField.getText().length(), url, displayURL); + urlCursorListener.addURL(textField.getText().length(), url, displayURL); + + return styledPrint(textField, displayURL, color, style); } } \ 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-02-08 17:58:40
|
Revision: 1198 http://cishell.svn.sourceforge.net/cishell/?rev=1198&view=rev Author: pataphil Date: 2011-02-08 17:58:33 +0000 (Tue, 08 Feb 2011) Log Message: ----------- * Removed FileLoaderAlgorithm and things its dependents. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 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/OSGI-INF/fileloader.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2011-02-08 17:58:33 UTC (rev 1198) @@ -7,6 +7,7 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Import-Package: org.cishell.app.service.datamanager;version="1.0.0", + org.cishell.app.service.fileloader, org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -26,15 +26,18 @@ import org.cishell.app.service.datamanager.DataManagerListener; import org.cishell.app.service.datamanager.DataManagerService; +import org.cishell.app.service.fileloader.FileLoaderService; +import org.cishell.framework.CIShellContext; +import org.cishell.framework.CIShellContextDelegate; import org.cishell.framework.LocalCIShellContext; +import org.cishell.framework.ServiceReferenceDelegate; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.data.BasicData; +import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.workspace.CIShellApplication; -import org.cishell.utilities.AlgorithmUtilities; import org.cishell.utilities.StringUtilities; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IMenuManager; @@ -198,6 +201,10 @@ getSite().setSelectionProvider(new DataModelSelectionProvider()); + setupDataManagerViewForDragAndDrop(parent); + } + + private void setupDataManagerViewForDragAndDrop(Composite parent) { DropTarget dropTarget = new DropTarget(parent.getParent(), DND.DROP_DEFAULT | DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { FileTransfer.getInstance() }); @@ -211,37 +218,55 @@ fileNames = (String[]) event.data; Collection<File> flattenedFileStructure = flattenDraggedFileStructures(fileNames); - Collection<Data> dataForProcessing = new ArrayList<Data>(); - for (File file : flattenedFileStructure) { - dataForProcessing.add(new BasicData(file, "")); - } - - AlgorithmFactory fileLoaderFactory = - AlgorithmUtilities.getAlgorithmFactoryByPID( - "org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm", - Activator.context); + ServiceReference fileLoaderServiceReference = + Activator.context.getServiceReference(FileLoaderService.class.getName()); + FileLoaderService fileLoader = + (FileLoaderService) Activator.context.getService( + fileLoaderServiceReference); DataManagerService dataManager = (DataManagerService) Activator.context.getService( Activator.context.getServiceReference( DataManagerService.class.getName())); - try { - Data[] inputData = fileLoaderFactory.createAlgorithm( - dataForProcessing.toArray(new Data[0]), - new Hashtable<String, Object>(), - new LocalCIShellContext(Activator.context)).execute(); + ServiceReference dataManagerServiceReference = + Activator.context.getServiceReference(DataManagerService.class.getName()); - for (Data inputDatum : inputData) { - dataManager.addData(inputDatum); + for (File file : flattenedFileStructure) { + /* TODO: Eventually use the AlgorithmInvocationService for this + * kind of stuff? + */ + ServiceReference uniqueServiceReference = new ServiceReferenceDelegate( + dataManagerServiceReference); + CIShellContext ciShellContext = new CIShellContextDelegate( + uniqueServiceReference, new LocalCIShellContext(Activator.context)); + LogService uniqueLogger = + (LogService) ciShellContext.getService(LogService.class.getName()); + + try { + Data[] inputData = fileLoader.loadFile( + Activator.context, + ciShellContext, + uniqueLogger, + ProgressMonitor.NULL_MONITOR, + file); + + for (Data inputDatum : inputData) { + inputDatum.getMetadata().put( + DataProperty.SERVICE_REFERENCE, uniqueServiceReference); + dataManager.addData(inputDatum); + } + } catch (Throwable e) { + String format = + "An error occurred when loading your files.%n" + + "Please include the following when reporting this:%n%s"; + String logMessage = + String.format(format, StringUtilities.getStackTraceAsString(e)); + /* TODO: This is a spot where we might need to use a different + * LogService object (for when we want log highlighting). + */ + uniqueLogger.log(LogService.LOG_ERROR, logMessage); } - } catch (Throwable e) { - String format = - "An error occurred when loading your files.%n" + - "Please include the following when reporting this:%n%s"; - String logMessage = - String.format(format, StringUtilities.getStackTraceAsString(e)); - AbstractDataManagerView.this.logger.log(LogService.LOG_ERROR, logMessage); } } } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-08 17:58:33 UTC (rev 1198) @@ -24,7 +24,7 @@ org.osgi.service.metatype;version="1.1.0", org.osgi.service.prefs;version="1.1.0" X-AutoStart: true -Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml, OSGI-INF/fileloader.xml +Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml Require-Bundle: org.eclipse.swt, org.eclipse.ui Bundle-RequiredExecutionEnvironment: J2SE-1.5 Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,8 +0,0 @@ -#menu_path=File/start -label=File Loader -description=This does the actual loading of files from the file system and loads them to Data Model window. -in_data=null -out_data=java.lang.Object -service.pid=org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm -remoteable=true -documentation_url=http://wiki.slis.indiana.edu:8080/display/ALGDOC/Data+Formats \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<component name="org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm.component" immediate="false"> - <implementation class="org.cishell.reference.gui.persistence.load.FileLoaderAlgorithmFactory"/> - <properties entry="OSGI-INF/fileloader.properties"/> - <reference name="LOG" interface="org.osgi.service.log.LogService"/> - <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> - - <service> - <provide interface="org.cishell.framework.algorithm.AlgorithmFactory"/> - </service> -</component> \ No newline at end of file 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 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -52,31 +52,6 @@ } catch (FileLoadException e) { throw new AlgorithmExecutionException(e.getMessage(), e); } -// IWorkbenchWindow window = getFirstWorkbenchWindow(); -// Display display = PlatformUI.getWorkbench().getDisplay(); -// File[] files = getFilesToLoadFromUser(window, display); -// -// if (files != null) { -//// try { -// return new FileLoaderAlgorithm( -// this.bundleContext, -// files, -// this.ciShellContext, -// this.logger, -// this.progressMonitor).execute(); -//// } catch (Throwable e) { -//// String format = -//// "The chosen file is not compatible with this format. " + -//// "Check that your file is correctly formatted or try another validator. " + -//// "The reason is: %s"; -//// String logMessage = String.format(format, e.getMessage()); -//// this.logger.log(LogService.LOG_ERROR, logMessage, e); -//// -//// return null; -//// } -// } else { -// return null; -// } } public ProgressMonitor getProgressMonitor() { Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,131 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; - -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.data.Data; -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 FileLoaderAlgorithm implements Algorithm { - private BundleContext bundleContext; - private File[] filesToLoad; - private CIShellContext ciShellContext; - private LogService logger; - private ProgressMonitor progressMonitor; - - public FileLoaderAlgorithm( - BundleContext bundleContext, - File[] filesToLoad, - CIShellContext ciShellContext, - LogService logger, - ProgressMonitor progressMonitor) { - this.bundleContext = bundleContext; - this.filesToLoad = filesToLoad; - this.ciShellContext = ciShellContext; - this.logger = logger; - this.progressMonitor = progressMonitor; - } - - public Data[] execute() throws AlgorithmExecutionException { - IWorkbenchWindow window = getFirstWorkbenchWindow(); - Display display = PlatformUI.getWorkbench().getDisplay(); - - if ((this.filesToLoad != null) && (this.filesToLoad.length != 0)) { - Collection<Data> finalLabeledFileData = new ArrayList<Data>(); - - for (File file : this.filesToLoad) { - try { - Data[] validatedFileData = validateFile(window, display, file); - Data[] labeledFileData = labelFileData(file, validatedFileData); - - for (Data data : labeledFileData) { - finalLabeledFileData.add(data); - } - } catch (Throwable e) { - String format = - "The chosen file is not compatible with this format. " + - "Check that your file is correctly formatted or try another validator. " + - "The reason is: %s"; - String logMessage = String.format(format, e.getMessage()); - this.logger.log(LogService.LOG_ERROR, logMessage, e); - } - } - - return finalLabeledFileData.toArray(new Data[0]); - } else { - return null; - } - } - - 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[] validateFile(IWorkbenchWindow window, Display display, File file) - throws AlgorithmExecutionException { - AlgorithmFactory validator = null; - validator = getValidatorFromUser(window, display, file); - - if ((file == null) || (validator == null)) { - String logMessage = "File loading canceled"; - this.logger.log(LogService.LOG_WARNING, logMessage); - } else { - try { - return FileValidator.validateFile( - file, validator, this.progressMonitor, this.ciShellContext, this.logger); - } catch (AlgorithmExecutionException e) { - if ((e.getCause() != null) - && (e.getCause() instanceof UnsupportedEncodingException)) { - String format = - "This file cannot be loaded; it uses the unsupported character " + - "encoding %s."; - String logMessage = String.format(format, e.getCause().getMessage()); - this.logger.log(LogService.LOG_ERROR, logMessage); - } else { - throw e; - } - } - } - - return new Data[0]; - } - - private Data[] labelFileData(File file, Data[] validatedFileData) { - Data[] labeledFileData = - PrettyLabeler.relabelWithFileNameHierarchy(validatedFileData, file); - - return labeledFileData; - } - - 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/FileLoaderAlgorithmFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,40 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.util.Dictionary; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.algorithm.ProgressMonitor; -import org.cishell.framework.data.Data; -import org.osgi.framework.BundleContext; -import org.osgi.service.component.ComponentContext; -import org.osgi.service.log.LogService; - -public class FileLoaderAlgorithmFactory implements AlgorithmFactory { - private BundleContext bundleContext; - private LogService logger; - - protected void activate(ComponentContext componentContext) { - this.bundleContext = componentContext.getBundleContext(); - this.logger = (LogService) this.bundleContext.getService( - this.bundleContext.getServiceReference(LogService.class.getName())); - } - - public Algorithm createAlgorithm( - Data[] data, Dictionary<String, Object> parameters, CIShellContext ciShellContext) { - File[] filesToLoad = new File[data.length]; - - for (int ii = 0; ii < data.length; ii++) { - filesToLoad[ii] = (File) data[ii].getData(); - } - - return new FileLoaderAlgorithm( - this.bundleContext, - filesToLoad, - ciShellContext, - this.logger, - ProgressMonitor.NULL_MONITOR); - } -} \ 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-02-08 17:28:03
|
Revision: 1197 http://cishell.svn.sourceforge.net/cishell/?rev=1197&view=rev Author: pataphil Date: 2011-02-08 17:27:54 +0000 (Tue, 08 Feb 2011) Log Message: ----------- * Added drag-and-drop file loading functionality. * Reviewed by Micah. * Refactored file loading to be done via service instead of explicitly through an algorithm. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java trunk/core/org.cishell.framework/META-INF/MANIFEST.MF trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java trunk/core/org.cishell.reference/META-INF/MANIFEST.MF trunk/core/org.cishell.reference/build.properties Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/ trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadException.java trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadListener.java trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java trunk/core/org.cishell.framework/src/org/cishell/framework/CIShellContextDelegate.java trunk/core/org.cishell.framework/src/org/cishell/framework/LogServiceDelegate.java trunk/core/org.cishell.framework/src/org/cishell/framework/ServiceReferenceDelegate.java trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java trunk/core/org.cishell.reference/OSGI-INF/ trunk/core/org.cishell.reference/OSGI-INF/fileloader.properties trunk/core/org.cishell.reference/OSGI-INF/fileloader.xml trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileFormatSelector.java trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileSelectorRunnable.java trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileValidator.java trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/PrettyLabeler.java trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/ValidatorSelectorRunnable.java Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) @@ -13,6 +13,7 @@ org.cishell.reference.gui.datamanager, org.cishell.reference.gui.workspace, org.cishell.service.guibuilder;version="1.0.0", + org.cishell.utilities, org.osgi.service.log;version="1.3.0" Export-Package: org.cishell.reference.gui.datamanager Bundle-ActivationPolicy: lazy Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -13,6 +13,9 @@ * ***************************************************************************/ package org.cishell.reference.gui.datamanager; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; @@ -23,13 +26,16 @@ import org.cishell.app.service.datamanager.DataManagerListener; import org.cishell.app.service.datamanager.DataManagerService; +import org.cishell.framework.LocalCIShellContext; import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmCanceledException; import org.cishell.framework.algorithm.AlgorithmExecutionException; 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.workspace.CIShellApplication; +import org.cishell.utilities.AlgorithmUtilities; +import org.cishell.utilities.StringUtilities; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.viewers.ISelection; @@ -41,6 +47,12 @@ import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.KeyAdapter; @@ -185,7 +197,89 @@ } getSite().setSelectionProvider(new DataModelSelectionProvider()); + + DropTarget dropTarget = + new DropTarget(parent.getParent(), DND.DROP_DEFAULT | DND.DROP_MOVE); + dropTarget.setTransfer(new Transfer[] { FileTransfer.getInstance() }); + dropTarget.addDropListener(new DropTargetAdapter() { + @Override + public void drop(DropTargetEvent event) { + String fileNames[] = null; + FileTransfer fileTransfer = FileTransfer.getInstance(); + + if (fileTransfer.isSupportedType(event.currentDataType)) { + fileNames = (String[]) event.data; + Collection<File> flattenedFileStructure = + flattenDraggedFileStructures(fileNames); + Collection<Data> dataForProcessing = new ArrayList<Data>(); + + for (File file : flattenedFileStructure) { + dataForProcessing.add(new BasicData(file, "")); + } + + AlgorithmFactory fileLoaderFactory = + AlgorithmUtilities.getAlgorithmFactoryByPID( + "org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm", + Activator.context); + DataManagerService dataManager = + (DataManagerService) Activator.context.getService( + Activator.context.getServiceReference( + DataManagerService.class.getName())); + + try { + Data[] inputData = fileLoaderFactory.createAlgorithm( + dataForProcessing.toArray(new Data[0]), + new Hashtable<String, Object>(), + new LocalCIShellContext(Activator.context)).execute(); + + for (Data inputDatum : inputData) { + dataManager.addData(inputDatum); + } + } catch (Throwable e) { + String format = + "An error occurred when loading your files.%n" + + "Please include the following when reporting this:%n%s"; + String logMessage = + String.format(format, StringUtilities.getStackTraceAsString(e)); + AbstractDataManagerView.this.logger.log(LogService.LOG_ERROR, logMessage); + } + } + } + }); } + + private Collection<File> flattenDraggedFileStructures(String[] fileNames) { + Collection<File> flattenedFileStructure = new ArrayList<File>(); + + for (String fileName : fileNames) { + flattenedFileStructure.addAll(flattenDraggedFileStructure(fileName)); + } + + return flattenedFileStructure; + } + + private Collection<File> flattenDraggedFileStructure(String fileName) { + File file = new File(fileName); + + if (file.isFile()) { + Collection<File> flattenedFileStructure = new ArrayList<File>(); + flattenedFileStructure.add(file); + + return flattenedFileStructure; + } else if (file.isDirectory()) { + Collection<File> flattenedFileStructure = new ArrayList<File>(); + + for (String childFileName : file.list()) { + String completeChildFileName = String.format( + "%s%s%s", fileName, File.separator, childFileName); + flattenedFileStructure.addAll(flattenDraggedFileStructure(completeChildFileName)); + } + + return flattenedFileStructure; + } else { + return new ArrayList<File>(); + } + } public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.STARTED) { Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -18,7 +18,7 @@ // The plug-in ID public static final String PLUGIN_ID = "org.cishell.reference.gui.datamanager"; - private static BundleContext context; + public static BundleContext context; // The shared instance private static Activator plugin; Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) @@ -5,6 +5,7 @@ Bundle-Version: 1.0.0 Bundle-ClassPath: . Import-Package: org.cishell.app.service.datamanager, + org.cishell.app.service.fileloader, org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", @@ -23,7 +24,7 @@ org.osgi.service.metatype;version="1.1.0", org.osgi.service.prefs;version="1.1.0" X-AutoStart: true -Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml +Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml, OSGI-INF/fileloader.xml Require-Bundle: org.eclipse.swt, org.eclipse.ui Bundle-RequiredExecutionEnvironment: J2SE-1.5 Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,8 @@ +#menu_path=File/start +label=File Loader +description=This does the actual loading of files from the file system and loads them to Data Model window. +in_data=null +out_data=java.lang.Object +service.pid=org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm +remoteable=true +documentation_url=http://wiki.slis.indiana.edu:8080/display/ALGDOC/Data+Formats \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm.component" immediate="false"> + <implementation class="org.cishell.reference.gui.persistence.load.FileLoaderAlgorithmFactory"/> + <properties entry="OSGI-INF/fileloader.properties"/> + <reference name="LOG" interface="org.osgi.service.log.LogService"/> + <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> + + <service> + <provide interface="org.cishell.framework.algorithm.AlgorithmFactory"/> + </service> +</component> \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2011-02-08 17:27:54 UTC (rev 1197) @@ -1,7 +1,7 @@ menu_path=File/start label=Load... shortcut=ctrl+alt+o -description=This allows users to select file from the file system and load it to Data Model window +description=This allows users to select files from the file system and load them to Data Model window. in_data=null out_data=java.lang.Object service.pid=org.cishell.reference.gui.persistence.load.FileLoadAlgorithm Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml 2011-02-08 17:27:54 UTC (rev 1197) @@ -1,14 +1,14 @@ -<?xml version="1.0" encoding="UTF-8"?> -<component name="org.cishell.reference.gui.persistence.load.FileLoadAlgorithm.component" immediate="false"> - <implementation class="org.cishell.reference.gui.persistence.load.FileLoadFactory"/> - <properties entry="OSGI-INF/load.properties"/> - <reference name="LOG" interface="org.osgi.service.log.LogService"/> - <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> - - <service> - <provide interface= - "org.cishell.framework.algorithm.AlgorithmFactory"/> - <provide interface= - "org.osgi.service.cm.ManagedService"/> - </service> +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.reference.gui.persistence.load.FileLoadAlgorithm.component" immediate="false"> + <implementation class="org.cishell.reference.gui.persistence.load.FileLoadFactory"/> + <properties entry="OSGI-INF/load.properties"/> + <reference name="LOG" interface="org.osgi.service.log.LogService"/> + <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> + + <service> + <provide interface= + "org.cishell.framework.algorithm.AlgorithmFactory"/> + <provide interface= + "org.osgi.service.cm.ManagedService"/> + </service> </component> \ No newline at end of file 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-04 16:25:21 UTC (rev 1196) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -1,15 +1,13 @@ package org.cishell.reference.gui.persistence.load; import java.io.File; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; import java.util.Dictionary; +import org.cishell.app.service.fileloader.FileLoadException; +import org.cishell.app.service.fileloader.FileLoaderService; 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.Data; @@ -26,6 +24,7 @@ public static String defaultLoadDirectory; private final LogService logger; + private FileLoaderService fileLoader; private BundleContext bundleContext; private CIShellContext ciShellContext; private ProgressMonitor progressMonitor = ProgressMonitor.NULL_MONITOR; @@ -34,7 +33,9 @@ CIShellContext ciShellContext, BundleContext bundleContext, Dictionary<String, Object> preferences) { - this.logger = (LogService)ciShellContext.getService(LogService.class.getName()); + this.logger = (LogService) ciShellContext.getService(LogService.class.getName()); + this.fileLoader = + (FileLoaderService) ciShellContext.getService(FileLoaderService.class.getName()); this.ciShellContext = ciShellContext; this.bundleContext = bundleContext; @@ -45,26 +46,37 @@ } public Data[] execute() throws AlgorithmExecutionException { - IWorkbenchWindow window = getFirstWorkbenchWindow(); - Display display = PlatformUI.getWorkbench().getDisplay(); - File[] files = getFilesToLoadFromUser(window, display); - - if ((files != null) && (files.length != 0)) { - Collection<Data> finalLabeledFileData = new ArrayList<Data>(); - - 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; + try { + return this.fileLoader.loadFilesFromUserSelection( + this.bundleContext, this.ciShellContext, this.logger, this.progressMonitor); + } catch (FileLoadException e) { + throw new AlgorithmExecutionException(e.getMessage(), e); } +// IWorkbenchWindow window = getFirstWorkbenchWindow(); +// Display display = PlatformUI.getWorkbench().getDisplay(); +// File[] files = getFilesToLoadFromUser(window, display); +// +// if (files != null) { +//// try { +// return new FileLoaderAlgorithm( +// this.bundleContext, +// files, +// this.ciShellContext, +// this.logger, +// this.progressMonitor).execute(); +//// } catch (Throwable e) { +//// String format = +//// "The chosen file is not compatible with this format. " + +//// "Check that your file is correctly formatted or try another validator. " + +//// "The reason is: %s"; +//// String logMessage = String.format(format, e.getMessage()); +//// this.logger.log(LogService.LOG_ERROR, logMessage, e); +//// +//// return null; +//// } +// } else { +// return null; +// } } public ProgressMonitor getProgressMonitor() { @@ -101,62 +113,4 @@ return fileSelector.getFiles(); } - - private Data[] validateFile(IWorkbenchWindow window, Display display, File file) { - AlgorithmFactory validator = null; - - try { - validator = getValidatorFromUser(window, display, file); - - if ((file == null) || (validator == null)) { - String logMessage = "File loading canceled"; - this.logger.log(LogService.LOG_WARNING, logMessage); - } else { - try { - return FileValidator.validateFile( - file, validator, this.progressMonitor, this.ciShellContext, this.logger); - } catch (AlgorithmExecutionException e) { - if ((e.getCause() != null) - && (e.getCause() instanceof UnsupportedEncodingException)) { - String format = - "This file cannot be loaded; it uses the unsupported character " + - "encoding %s."; - String logMessage = String.format(format, e.getCause().getMessage()); - this.logger.log(LogService.LOG_ERROR, logMessage); - } else { - throw e; - } - } - } - } catch (Throwable e) { - String logMessage = - "The chosen file is not compatible with this format. " + - "Check that your file is correctly formatted or try another validator. " + - "The reason is: " + e.getMessage(); - this.logger.log(LogService.LOG_ERROR, logMessage); - } - - return new Data[0]; - } - - private Data[] labelFileData(File file, Data[] validatedFileData) { - Data[] labeledFileData = PrettyLabeler.relabelWithFileNameHierarchy( - validatedFileData, file); - - return labeledFileData; - } - - 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 Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,131 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collection; + +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.data.Data; +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 FileLoaderAlgorithm implements Algorithm { + private BundleContext bundleContext; + private File[] filesToLoad; + private CIShellContext ciShellContext; + private LogService logger; + private ProgressMonitor progressMonitor; + + public FileLoaderAlgorithm( + BundleContext bundleContext, + File[] filesToLoad, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor) { + this.bundleContext = bundleContext; + this.filesToLoad = filesToLoad; + this.ciShellContext = ciShellContext; + this.logger = logger; + this.progressMonitor = progressMonitor; + } + + public Data[] execute() throws AlgorithmExecutionException { + IWorkbenchWindow window = getFirstWorkbenchWindow(); + Display display = PlatformUI.getWorkbench().getDisplay(); + + if ((this.filesToLoad != null) && (this.filesToLoad.length != 0)) { + Collection<Data> finalLabeledFileData = new ArrayList<Data>(); + + for (File file : this.filesToLoad) { + try { + Data[] validatedFileData = validateFile(window, display, file); + Data[] labeledFileData = labelFileData(file, validatedFileData); + + for (Data data : labeledFileData) { + finalLabeledFileData.add(data); + } + } catch (Throwable e) { + String format = + "The chosen file is not compatible with this format. " + + "Check that your file is correctly formatted or try another validator. " + + "The reason is: %s"; + String logMessage = String.format(format, e.getMessage()); + this.logger.log(LogService.LOG_ERROR, logMessage, e); + } + } + + return finalLabeledFileData.toArray(new Data[0]); + } else { + return null; + } + } + + 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[] validateFile(IWorkbenchWindow window, Display display, File file) + throws AlgorithmExecutionException { + AlgorithmFactory validator = null; + validator = getValidatorFromUser(window, display, file); + + if ((file == null) || (validator == null)) { + String logMessage = "File loading canceled"; + this.logger.log(LogService.LOG_WARNING, logMessage); + } else { + try { + return FileValidator.validateFile( + file, validator, this.progressMonitor, this.ciShellContext, this.logger); + } catch (AlgorithmExecutionException e) { + if ((e.getCause() != null) + && (e.getCause() instanceof UnsupportedEncodingException)) { + String format = + "This file cannot be loaded; it uses the unsupported character " + + "encoding %s."; + String logMessage = String.format(format, e.getCause().getMessage()); + this.logger.log(LogService.LOG_ERROR, logMessage); + } else { + throw e; + } + } + } + + return new Data[0]; + } + + private Data[] labelFileData(File file, Data[] validatedFileData) { + Data[] labeledFileData = + PrettyLabeler.relabelWithFileNameHierarchy(validatedFileData, file); + + return labeledFileData; + } + + 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 Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,40 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; +import java.util.Dictionary; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.algorithm.ProgressMonitor; +import org.cishell.framework.data.Data; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.log.LogService; + +public class FileLoaderAlgorithmFactory implements AlgorithmFactory { + private BundleContext bundleContext; + private LogService logger; + + protected void activate(ComponentContext componentContext) { + this.bundleContext = componentContext.getBundleContext(); + this.logger = (LogService) this.bundleContext.getService( + this.bundleContext.getServiceReference(LogService.class.getName())); + } + + public Algorithm createAlgorithm( + Data[] data, Dictionary<String, Object> parameters, CIShellContext ciShellContext) { + File[] filesToLoad = new File[data.length]; + + for (int ii = 0; ii < data.length; ii++) { + filesToLoad[ii] = (File) data[ii].getData(); + } + + return new FileLoaderAlgorithm( + this.bundleContext, + filesToLoad, + ciShellContext, + this.logger, + ProgressMonitor.NULL_MONITOR); + } +} \ No newline at end of file Modified: trunk/core/org.cishell.framework/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.framework/META-INF/MANIFEST.MF 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/core/org.cishell.framework/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) @@ -5,11 +5,13 @@ Bundle-Version: 1.0.0 Bundle-Vendor: Cyberinfrastructure for Network Science Center Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: org.osgi.framework, +Import-Package: org.eclipse.osgi.framework.internal.core, + org.osgi.framework, org.osgi.service.log, org.osgi.service.metatype, org.osgi.service.prefs Export-Package: org.cishell.app.service.datamanager;version="1.0.0", + org.cishell.app.service.fileloader, org.cishell.app.service.scheduler;version="1.0.0", org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", Added: trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadException.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadException.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadException.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,21 @@ +package org.cishell.app.service.fileloader; + +public class FileLoadException extends Exception { + private static final long serialVersionUID = 1L; + + public FileLoadException(String message, Throwable exception) { + super(message, exception); + } + + public FileLoadException(Throwable exception) { + super(exception); + } + + public FileLoadException(String message) { + super(message); + } + + public FileLoadException() { + this("Algorithm canceled by user."); + } +} Added: trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadListener.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadListener.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoadListener.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,7 @@ +package org.cishell.app.service.fileloader; + +import java.io.File; + +public interface FileLoadListener { + void fileLoaded(File file); +} \ No newline at end of file Added: trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/app/service/fileloader/FileLoaderService.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,32 @@ +package org.cishell.app.service.fileloader; + +import java.io.File; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.ProgressMonitor; +import org.cishell.framework.data.Data; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +public interface FileLoaderService { + public void registerListener(FileLoadListener listener); + public void unregisterListener(FileLoadListener listener); + + public Data[] loadFilesFromUserSelection( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor) throws FileLoadException; + public Data[] loadFiles( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor, + File[] files) throws FileLoadException; + public Data[] loadFile( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor, + File file) throws FileLoadException; +} \ No newline at end of file Added: trunk/core/org.cishell.framework/src/org/cishell/framework/CIShellContextDelegate.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/CIShellContextDelegate.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/CIShellContextDelegate.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,25 @@ +package org.cishell.framework; + +import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; + +public class CIShellContextDelegate implements CIShellContext { + private ServiceReference uniqueServiceReference; + private CIShellContext actualCIShellContext; + + public CIShellContextDelegate( + ServiceReference uniqueServiceReference, CIShellContext actualCIShellContext) { + this.uniqueServiceReference = uniqueServiceReference; + this.actualCIShellContext = actualCIShellContext; + } + + public Object getService(String service) { + if (LogService.class.getName().equals(service)) { + return new LogServiceDelegate( + this.uniqueServiceReference, + (LogService) this.actualCIShellContext.getService(service)); + } else { + return this.actualCIShellContext.getService(service); + } + } +} \ No newline at end of file Added: trunk/core/org.cishell.framework/src/org/cishell/framework/LogServiceDelegate.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/LogServiceDelegate.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/LogServiceDelegate.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,32 @@ +package org.cishell.framework; + +import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; + +public class LogServiceDelegate implements LogService { + private ServiceReference uniqueServiceReference; + private LogService actualLogService; + + public LogServiceDelegate( + ServiceReference uniqueServiceReference, LogService actualLogService) { + this.uniqueServiceReference = uniqueServiceReference; + this.actualLogService = actualLogService; + } + + public void log(int level, String message) { + this.actualLogService.log(this.uniqueServiceReference, level, message); + } + + public void log(int level, String message, Throwable exception) { + this.actualLogService.log(this.uniqueServiceReference, level, message, exception); + } + + public void log(ServiceReference serviceReference, int level, String message) { + this.actualLogService.log(serviceReference, level, message); + } + + public void log( + ServiceReference serviceReference, int level, String message, Throwable exception) { + this.actualLogService.log(serviceReference, level, message, exception); + } +} \ No newline at end of file Added: trunk/core/org.cishell.framework/src/org/cishell/framework/ServiceReferenceDelegate.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/ServiceReferenceDelegate.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/ServiceReferenceDelegate.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,86 @@ +package org.cishell.framework; + +import java.lang.reflect.Field; + +import org.eclipse.osgi.framework.internal.core.ServiceReferenceImpl; +import org.eclipse.osgi.framework.internal.core.ServiceRegistrationImpl; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceReference; + +public class ServiceReferenceDelegate extends ServiceReferenceImpl { + public static final String REGISTRATION_FIELD_NAME = + "org.eclipse.osgi.framework.internal.core.ServiceReferenceImpl.registration"; + + private static int nextUniqueID = 0; + + private ServiceReference actualServiceReference; + private int uniqueID; + + public ServiceReferenceDelegate(ServiceReference actualServiceReference) { + super(getServiceRegistration(actualServiceReference)); + this.actualServiceReference = actualServiceReference; + this.uniqueID = nextUniqueID; + nextUniqueID++; + + } + + public Object getProperty(String key) { + return this.actualServiceReference.getProperty(key); + } + + public String[] getPropertyKeys() { + return this.actualServiceReference.getPropertyKeys(); + } + + public Bundle getBundle() { + return this.actualServiceReference.getBundle(); + } + + public Bundle[] getUsingBundles() { + return this.actualServiceReference.getUsingBundles(); + } + + public boolean isAssignableTo(Bundle bundle, String className) { + return this.actualServiceReference.isAssignableTo(bundle, className); + } + + @Override + public int compareTo(Object reference) { + if (reference instanceof ServiceReferenceDelegate) { + ServiceReferenceDelegate otherDelegate = (ServiceReferenceDelegate) reference; + + return new Integer(this.uniqueID).compareTo(new Integer(otherDelegate.uniqueID)); + } else { + return this.actualServiceReference.compareTo(reference); + } + } + + @Override + public int hashCode() { + return this.actualServiceReference.hashCode() + new Integer(this.uniqueID).hashCode(); + } + + // TODO: Totally, disginstingly hacky. + private static ServiceRegistrationImpl getServiceRegistration( + ServiceReference actualServiceReference) { + try { + Field[] fields = actualServiceReference.getClass().getDeclaredFields(); + +// for (Field field : fields) { +// System.err.println(field); +// } + Field registrationField = fields[0]; +// actualServiceReference.getClass().getField(REGISTRATION_FIELD_NAME); + boolean isAccessible = registrationField.isAccessible(); + registrationField.setAccessible(true); + Object serviceRegistration = registrationField.get(actualServiceReference); + registrationField.setAccessible(isAccessible); + + return (ServiceRegistrationImpl) serviceRegistration; + } catch (IllegalAccessException e) { + throw new RuntimeException(e.getMessage(), e); + } /* catch (NoSuchFieldException e) { + throw new RuntimeException(e.getMessage(), e); + } */ + } +} \ No newline at end of file Added: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory2.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,7 @@ +package org.cishell.framework.algorithm; + +import org.osgi.framework.ServiceReference; + +public interface AlgorithmFactory2 { + public void setServiceReference(ServiceReference serviceReference); +} \ No newline at end of file Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -60,6 +60,9 @@ * it. The type associated with this property is of type {@link Boolean}. */ public static final String MODIFIED = "Modified"; + + // TODO: Document me. + public static final String SERVICE_REFERENCE = "ServiceReference"; /** Says this data model is abstractly a matrix */ public static String MATRIX_TYPE = "Matrix"; Modified: trunk/core/org.cishell.reference/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.reference/META-INF/MANIFEST.MF 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/core/org.cishell.reference/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) @@ -3,21 +3,28 @@ Bundle-SymbolicName: org.cishell.reference Bundle-Version: 1.0.0 Import-Package: org.cishell.app.service.datamanager;version="1.0.0", + org.cishell.app.service.fileloader, org.cishell.app.service.scheduler;version="1.0.0", org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", + org.cishell.reference.gui.common, org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", org.osgi.framework, + org.osgi.service.cm;version="1.2.0", org.osgi.service.log, org.osgi.service.metatype;version="1.1.0", org.osgi.service.prefs Export-Package: org.cishell.reference.app.service.algorithminvocation, org.cishell.reference.app.service.datamanager, + org.cishell.reference.app.service.fileloader, org.cishell.reference.app.service.scheduler, org.cishell.reference.service.conversion, org.cishell.reference.service.metatype -Eclipse-LazyStart: true -Require-Bundle: edu.uci.ics.jung +Require-Bundle: edu.uci.ics.jung, + org.eclipse.swt, + org.eclipse.ui +Service-Component: OSGI-INF/fileloader.xml Bundle-RequiredExecutionEnvironment: J2SE-1.5 +X-AutoStart: true Added: trunk/core/org.cishell.reference/OSGI-INF/fileloader.properties =================================================================== --- trunk/core/org.cishell.reference/OSGI-INF/fileloader.properties (rev 0) +++ trunk/core/org.cishell.reference/OSGI-INF/fileloader.properties 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,11 @@ +#menu_path=File/start +#label=Load... +#shortcut=ctrl+alt+o +#description=This allows users to select files from the file system and load them to Data Model window. +#in_data=null +#out_data=java.lang.Object +service.pid=org.cishell.reference.app.service.fileloader.FileLoadServiceImpl +remoteable=true +prefs_published=local +receive_prefs=true +#documentation_url=http://wiki.slis.indiana.edu:8080/display/ALGDOC/Data+Formats \ No newline at end of file Added: trunk/core/org.cishell.reference/OSGI-INF/fileloader.xml =================================================================== --- trunk/core/org.cishell.reference/OSGI-INF/fileloader.xml (rev 0) +++ trunk/core/org.cishell.reference/OSGI-INF/fileloader.xml 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.reference.app.service.fileloader.FileLoaderServiceImpl.component" immediate="true"> + <implementation class="org.cishell.reference.app.service.fileloader.FileLoaderServiceImpl"/> + <service> + <provide interface="org.osgi.service.cm.ManagedService"/> + <provide interface="org.cishell.app.service.fileloader.FileLoaderService"/> + </service> +</component> \ No newline at end of file Modified: trunk/core/org.cishell.reference/build.properties =================================================================== --- trunk/core/org.cishell.reference/build.properties 2011-02-04 16:25:21 UTC (rev 1196) +++ trunk/core/org.cishell.reference/build.properties 2011-02-08 17:27:54 UTC (rev 1197) @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + OSGI-INF/ Added: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileFormatSelector.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileFormatSelector.java (rev 0) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileFormatSelector.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,190 @@ +package org.cishell.reference.app.service.fileloader; + +import java.io.File; + +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.reference.gui.common.AbstractDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +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; + +public class FileFormatSelector extends AbstractDialog { + private BundleContext bundleContext; + private AlgorithmFactory validator; + private ServiceReference[] validatorReferences; + private List validatorList; + +// 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, + Shell parent, + BundleContext bundleContext, + ServiceReference[] validatorReferences, + File file) { + super(parent, title, AbstractDialog.QUESTION); + this.bundleContext = bundleContext; + this.validatorReferences = validatorReferences; + + // Shall this part be moved out of the code? + String descriptionFormat = + "The file \'%s\' can be loaded using one or more of the following formats.%n" + + "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 " + + "to continue loading the dataset."); + } + + public AlgorithmFactory getValidator() { + return this.validator; + } + + private Composite initializeGUI(Composite parent) { + Composite content = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + content.setLayout(layout); + + Group validatorGroup = new Group(content, SWT.NONE); + // Shall this label be moved out of the code? + validatorGroup.setText("Load as..."); + validatorGroup.setLayout(new FillLayout()); + GridData validatorListGridData = new GridData(GridData.FILL_BOTH); + validatorListGridData.widthHint = 200; + validatorGroup.setLayoutData(validatorListGridData); + + this.validatorList = new List(validatorGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); + // initPersisterArray(); + initializePersisterList(); + this.validatorList.addMouseListener(new MouseAdapter() { + public void mouseDoubleClick(MouseEvent mouseEvent) { + List list = (List)mouseEvent.getSource(); + int selection = list.getSelectionIndex(); + + if (selection != -1) { + selectionMade(selection); + } + } + }); + + this.validatorList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent selectionEvent) { + List list = (List)selectionEvent.getSource(); + int selection = list.getSelectionIndex(); + + if (selection != -1) { + // updateDetailPane(validatorReferences[selection]); + } + } + }); + + validatorList.setSelection(0); + + return content; + } + + private void initializePersisterList() { + for (int ii = 0; ii < this.validatorReferences.length; ++ii) { + String name = (String)this.validatorReferences[ii].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 = this.validatorReferences[ii].getClass().getName(); + } + + this.validatorList.add(name); + } + } + + private void selectionMade(int selectedIndex) { + this.validator = + (AlgorithmFactory)this.bundleContext.getService(this.validatorReferences[selectedIndex]); + close(true); +// AlgorithmFactory validator = +// (AlgorithmFactory)this.bundleContext.getService(this.persisterArray[selectedIndex]); +// Data[] data = null; +// boolean loadSuccess = false; +// +// try { +// data = +// new Data[] { new BasicData(this.selectedFile.getPath(), String.class.getName()) }; +// data = validator.createAlgorithm(data, null, this.ciShellContext).execute(); +// loadSuccess = true; +// } catch (Throwable exception) { +// this.logger.log( +// LogService.LOG_ERROR, "Error occurred while executing selection", exception); +// exception.printStackTrace(); +// loadSuccess = false; +// } +// +// if ((data != null) && loadSuccess) { +// this.logger.log(LogService.LOG_INFO, "Loaded: " + this.selectedFile.getPath()); +// +// for (int ii = 0; ii < data.length; ii++) { +// this.returnList.add(data[ii]); +// } +// +// close(true); +// } else { +// this.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 selectionEvent) { + int index = FileFormatSelector.this.validatorList.getSelectionIndex(); + + if (index != -1) { + selectionMade(index); + } + } + }); + select.setFocus(); + + Button cancel = new Button(parent, SWT.NONE); + cancel.setText("Cancel"); + cancel.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent selectionEvent) { + close(false); + } + }); + } + + public Composite createContent(Composite parent) { + return initializeGUI(parent); + } +} Added: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java (rev 0) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileLoaderServiceImpl.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,223 @@ +package org.cishell.reference.app.service.fileloader; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Dictionary; +import java.util.HashSet; + +import org.cishell.app.service.fileloader.FileLoadException; +import org.cishell.app.service.fileloader.FileLoadListener; +import org.cishell.app.service.fileloader.FileLoaderService; +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmExecutionException; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.algorithm.ProgressMonitor; +import org.cishell.framework.data.Data; +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.cm.ConfigurationException; +import org.osgi.service.cm.ManagedService; +import org.osgi.service.log.LogService; + +public class FileLoaderServiceImpl implements FileLoaderService, ManagedService { + public static final String LOAD_DIRECTORY_PREFERENCE_KEY = "loadDir"; + public static String defaultLoadDirectory = ""; + + private Dictionary preferences; + private Collection<FileLoadListener> listeners = new HashSet<FileLoadListener>(); + + public void registerListener(FileLoadListener listener) { + this.listeners.add(listener); + } + + public void unregisterListener(FileLoadListener listener) { + if (this.listeners.contains(listener)) { + this.listeners.remove(listener); + } + } + + public Data[] loadFilesFromUserSelection( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor) throws FileLoadException { + if ("".equals(defaultLoadDirectory)) { + defaultLoadDirectory = determineDefaultLoadDirectory(); + } + + IWorkbenchWindow window = getFirstWorkbenchWindow(); + Display display = PlatformUI.getWorkbench().getDisplay(); + File[] files = getFilesToLoadFromUser(window, display); + + if (files != null) { + return loadFiles(bundleContext, ciShellContext, logger, progressMonitor, files); + } else { + return null; + } + } + + public Data[] loadFiles( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor, + File[] files) throws FileLoadException { + return loadFilesInternal(bundleContext, ciShellContext, logger, progressMonitor, files); + } + + public Data[] loadFile( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor, + File file) throws FileLoadException { + return loadFiles( + bundleContext, ciShellContext, logger, progressMonitor, new File[] { file }); + } + + public void updated(Dictionary preferences) throws ConfigurationException { + if (preferences != null) { + this.preferences = preferences; + } + } + + private String determineDefaultLoadDirectory() { + if (this.preferences != null) { + Object directoryPreference = preferences.get(LOAD_DIRECTORY_PREFERENCE_KEY); + + if (directoryPreference != null) { + return directoryPreference.toString(); + } else { + return ""; + } + } else { + return ""; + } + } + + private Data[] loadFilesInternal( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor, + File[] files) throws FileLoadException { + IWorkbenchWindow window = getFirstWorkbenchWindow(); + Display display = PlatformUI.getWorkbench().getDisplay(); + + if ((files != null) && (files.length != 0)) { + Collection<Data> finalLabeledFileData = new ArrayList<Data>(); + + for (File file : files) { + try { + Data[] validatedFileData = validateFile( + bundleContext, + ciShellContext, + logger, + progressMonitor, + window, + display, + file); + Data[] labeledFileData = labelFileData(file, validatedFileData); + + for (Data data : labeledFileData) { + finalLabeledFileData.add(data); + } + } catch (Throwable e) { + String format = + "The chosen file is not compatible with this format. " + + "Check that your file is correctly formatted or try another validator. " + + "The reason is: %s"; + String logMessage = String.format(format, e.getMessage()); + logger.log(LogService.LOG_ERROR, logMessage, e); + } + } + + return finalLabeledFileData.toArray(new Data[0]); + } else { + return null; + } + } + + private IWorkbenchWindow getFirstWorkbenchWindow() throws FileLoadException { + final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); + + if (windows.length == 0) { + throw new FileLoadException( + "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(); + } + + private Data[] validateFile( + BundleContext bundleContext, + CIShellContext ciShellContext, + LogService logger, + ProgressMonitor progressMonitor, + IWorkbenchWindow window, + Display display, + File file) throws AlgorithmExecutionException { + AlgorithmFactory validator = null; + validator = getValidatorFromUser(bundleContext, window, display, file); + + if ((file == null) || (validator == null)) { + String logMessage = "File loading canceled"; + logger.log(LogService.LOG_WARNING, logMessage); + } else { + try { + return FileValidator.validateFile( + file, validator, progressMonitor, ciShellContext, logger); + } catch (AlgorithmExecutionException e) { + if ((e.getCause() != null) + && (e.getCause() instanceof UnsupportedEncodingException)) { + String format = + "This file cannot be loaded; it uses the unsupported character " + + "encoding %s."; + String logMessage = String.format(format, e.getCause().getMessage()); + logger.log(LogService.LOG_ERROR, logMessage); + } else { + throw e; + } + } + } + + return new Data[0]; + } + + private Data[] labelFileData(File file, Data[] validatedFileData) { + Data[] labeledFileData = + PrettyLabeler.relabelWithFileNameHierarchy(validatedFileData, file); + + return labeledFileData; + } + + private AlgorithmFactory getValidatorFromUser( + BundleContext bundleContext, IWorkbenchWindow window, Display display, File file) { + ValidatorSelectorRunnable validatorSelector = + new ValidatorSelectorRunnable(window, bundleContext, file); + + if (Thread.currentThread() != display.getThread()) { + display.syncExec(validatorSelector); + } else { + validatorSelector.run(); + } + + return validatorSelector.getValidator(); + } +} \ No newline at end of file Added: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileSelectorRunnable.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileSelectorRunnable.java (rev 0) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileSelectorRunnable.java 2011-02-08 17:27:54 UTC (rev 1197) @@ -0,0 +1,63 @@ +package org.cishell.reference.app.service.fileloader; + +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 { + FileLoaderServiceImpl.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(FileLoaderServiceImpl.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 Added: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/fileloader/FileValidator.java =================================================================== --- trunk/core/org.cis... [truncated message content] |
From: <pat...@us...> - 2011-02-04 16:25:28
|
Revision: 1196 http://cishell.svn.sourceforge.net/cishell/?rev=1196&view=rev Author: pataphil Date: 2011-02-04 16:25:21 +0000 (Fri, 04 Feb 2011) Log Message: ----------- * Fixed a string formatting bug. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.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-02-04 14:43:09 UTC (rev 1195) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2011-02-04 16:25:21 UTC (rev 1196) @@ -59,7 +59,7 @@ // Shall this part be moved out of the code? String descriptionFormat = - "The file \'%s\' can be loaded using one or more of the following formats.%s" + + "The file \'%s\' can be loaded using one or more of the following formats.%n" + "Please select the format you would like to try."; setDescription(String.format(descriptionFormat, file.getAbsolutePath())); setDetails( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-02-04 14:43:16
|
Revision: 1195 http://cishell.svn.sourceforge.net/cishell/?rev=1195&view=rev Author: pataphil Date: 2011-02-04 14:43:09 +0000 (Fri, 04 Feb 2011) Log Message: ----------- * Minor code cleanup. Modified Paths: -------------- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java Modified: trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2011-01-27 20:52:02 UTC (rev 1194) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2011-02-04 14:43:09 UTC (rev 1195) @@ -57,7 +57,7 @@ public static final String IN_FILE_PLACEHOLDER = "inFile"; private String ALGORITHM; - private String ALGORITHM_MACOSX_PPC; + private String macOSX_PPC_DirectoryPath; private String MACOSX; private String ALGORITHM_WIN32; private String WIN32; @@ -65,51 +65,68 @@ private String LINUX; private String ALGORITHM_DEFAULT; - protected final String algDirPath; - protected final String tempDirPath; - protected final Data[] data; - protected Dictionary parameters; - protected Properties props; - protected CIShellContext ciContext; - protected ProgressMonitor monitor; - protected BundleContext bContext; - protected String algName; + private String algorithmDirectoryPath; + private String temporaryDirectoryPath; + private Data[] data; + private Dictionary<String, Object> parameters; + private Properties properties; + private CIShellContext ciShellContext; + private ProgressMonitor monitor; + private BundleContext bundleContext; + private String algorithmName; - public StaticExecutableRunner(BundleContext bContext, CIShellContext ciContext, Properties props, - Dictionary parameters, Data[] data, ProgressMonitor monitor, String algName) throws IOException { + public StaticExecutableRunner( + BundleContext bundleContext, + CIShellContext ciShellContext, + Properties properties, + Dictionary<String, Object> parameters, + Data[] data, + ProgressMonitor monitor, + String algorithmName) throws IOException { + // Assign normal member variables. - // assign normal member-variables - - this.bContext = bContext; - this.ciContext = ciContext; - this.props = props; + this.bundleContext = bundleContext; + this.ciShellContext = ciShellContext; + this.properties = properties; this.parameters = parameters; this.data = data; this.monitor = monitor; - this.algName = algName; + this.algorithmName = algorithmName; - // determine directory paths for each platform, based on algName + // Determine directory paths for each platform, based on algorithmName. - ALGORITHM = algName + "/"; - ALGORITHM_MACOSX_PPC = ALGORITHM + "macosx.ppc/"; - MACOSX = "macosx"; - ALGORITHM_WIN32 = ALGORITHM + "win32/"; - WIN32 = "win32"; - ALGORITHM_LINUX_X86 = ALGORITHM + "linux.x86/"; - LINUX = "linux"; - ALGORITHM_DEFAULT = ALGORITHM + "default/"; + this.ALGORITHM = algorithmName + "/"; + this.macOSX_PPC_DirectoryPath = ALGORITHM + "macosx.ppc/"; + this.MACOSX = "macosx"; + this.ALGORITHM_WIN32 = ALGORITHM + "win32/"; + this.WIN32 = "win32"; + this.ALGORITHM_LINUX_X86 = ALGORITHM + "linux.x86/"; + this.LINUX = "linux"; + this.ALGORITHM_DEFAULT = ALGORITHM + "default/"; // if a constructor variable was null, use a null object version of it if possible - if (monitor == null) this.monitor = ProgressMonitor.NULL_MONITOR; - if (data == null) data = new Data[0]; - if (parameters == null) parameters = new Hashtable(); + if (this.monitor == null) { + this.monitor = ProgressMonitor.NULL_MONITOR; + } - // make a temporary directory to run the executable in + if (this.data == null) { + this.data = new Data[0]; + } - tempDirPath = makeTempDirectory(); + if (this.parameters == null) { + this.parameters = new Hashtable<String, Object>(); + } - algDirPath = tempDirPath + File.separator + props.getProperty("Algorithm-Directory") + File.separator; + // Make a temporary directory to run the executable in. + + this.temporaryDirectoryPath = makeTemporaryDirectory(); + this.algorithmDirectoryPath = String.format( + "%s%s%s%s", + temporaryDirectoryPath, + File.separator, + properties.getProperty("Algorithm-Directory"), + File.separator); } /** @@ -117,18 +134,19 @@ */ public Data[] execute() throws AlgorithmExecutionException { copyFilesUsedByExecutableIntoDir(getTempDirectory()); - makeDirExecutable(algDirPath); + makeDirExecutable(algorithmDirectoryPath); - String[] commandLineArguments = createCommandLineArguments(algDirPath, data, parameters); + String[] commandLineArguments = + createCommandLineArguments(algorithmDirectoryPath, this.data, this.parameters); - File[] rawOutput = executeProgram(commandLineArguments, algDirPath); + File[] rawOutput = executeProgram(commandLineArguments, algorithmDirectoryPath); return formatAsData(rawOutput); } private void copyFilesUsedByExecutableIntoDir(File dir) throws AlgorithmExecutionException { try { - Enumeration e = bContext.getBundle().getEntryPaths("/" + algName); + Enumeration e = bundleContext.getBundle().getEntryPaths("/" + algorithmName); Set entries = new HashSet(); @@ -140,11 +158,11 @@ } } - dir = new File(dir.getPath() + File.separator + algName); + dir = new File(dir.getPath() + File.separator + algorithmName); dir.mkdirs(); - String os = bContext.getProperty("osgi.os"); - String arch = bContext.getProperty("osgi.arch"); + String os = bundleContext.getProperty("osgi.os"); + String arch = bundleContext.getProperty("osgi.arch"); String path = null; @@ -159,8 +177,8 @@ // but override with platform idiosyncracies if (os.equals(WIN32) && entries.contains(ALGORITHM_WIN32)) { path = ALGORITHM_WIN32; - } else if (os.equals(MACOSX) && entries.contains(ALGORITHM_MACOSX_PPC)) { - path = ALGORITHM_MACOSX_PPC; + } else if (os.equals(MACOSX) && entries.contains(macOSX_PPC_DirectoryPath)) { + path = macOSX_PPC_DirectoryPath; } else if (os.equals(LINUX) && entries.contains(ALGORITHM_LINUX_X86)) { path = ALGORITHM_LINUX_X86; } @@ -187,7 +205,7 @@ // FIXME: Surely java has a way to do this!!!! if (new File("/bin/chmod").exists()) { try { - String executable = baseDir + props.getProperty("executable"); + String executable = baseDir + properties.getProperty("executable"); Runtime.getRuntime().exec("/bin/chmod +x " + executable).waitFor(); } catch (IOException e) { throw new AlgorithmExecutionException(e); @@ -295,7 +313,7 @@ } protected Data[] formatAsData(File[] files) { - String outData = (String) props.get(AlgorithmProperty.OUT_DATA); + String outData = (String) properties.get(AlgorithmProperty.OUT_DATA); // if out data is null then it returns no data if (("" + outData).trim().equalsIgnoreCase(AlgorithmProperty.NULL_DATA)) { @@ -317,7 +335,7 @@ } for (int i = 0; i < data.length; i++) { - String file = props.getProperty("outFile[" + i + "]", null); + String file = properties.getProperty("outFile[" + i + "]", null); if (i < formats.length) { File f = (File) nameToFileMap.remove(file); @@ -325,10 +343,10 @@ if (f != null) { data[i] = new BasicData(f, formats[i]); - String label = props.getProperty("outFile[" + i + "].label", f.getName()); + String label = properties.getProperty("outFile[" + i + "].label", f.getName()); data[i].getMetadata().put(DataProperty.LABEL, label); - String type = props.getProperty("outFile[" + i + "].type", DataProperty.OTHER_TYPE); + String type = properties.getProperty("outFile[" + i + "].type", DataProperty.OTHER_TYPE); type = type.trim(); if (type.equalsIgnoreCase(DataProperty.MATRIX_TYPE)) { type = DataProperty.MATRIX_TYPE; @@ -387,7 +405,7 @@ protected StringBuffer log(int logLevel, StringBuffer buffer) { if (buffer.indexOf("\n") != -1) { // any new newlines to output? - LogService log = (LogService) ciContext.getService(LogService.class.getName()); + LogService log = (LogService) ciShellContext.getService(LogService.class.getName()); int lastGoodIndex = 0; int fromIndex = 0; @@ -420,23 +438,25 @@ return buffer; } - protected String[] createCommandLineArguments(String algDir, Data[] data, Dictionary parameters) { - String template = "" + props.getProperty("template"); - String[] cmdarray = template.split("\\s"); + protected String[] createCommandLineArguments( + String algorithmDirectory, Data[] data, Dictionary<String, Object> parameters) { + String template = "" + this.properties.getProperty("template"); + String[] commands = template.split("\\s"); - for (int i = 0; i < cmdarray.length; i++) { - cmdarray[i] = substituteVars(cmdarray[i], data, parameters); + for (int ii = 0; ii < commands.length; ii++) { + commands[ii] = substituteVars(commands[ii], data, parameters); } // TODO: Expanded later to support .cmd and other extensions - if (!new File(algDir + cmdarray[0]).exists()) { - if (new File(algDir + cmdarray[0] + ".bat").exists()) { - cmdarray[0] = cmdarray[0] + ".bat"; + if (!new File(algorithmDirectory + commands[0]).exists()) { + if (new File(algorithmDirectory + commands[0] + ".bat").exists()) { + commands[0] = commands[0] + ".bat"; } } - cmdarray[0] = algDir + cmdarray[0]; - return cmdarray; + commands[0] = algorithmDirectory + commands[0]; + + return commands; } // replaces place-holder variables in the template with the actual arguments the executable needs to work. @@ -444,9 +464,10 @@ // (also, real values like "6" or "dog" instead of placeholders for parameters) protected String substituteVars(String str, Data[] data, Dictionary parameters) { str = str.replaceAll( - "\\$\\{" + EXECUTABLE_PLACEHOLDER + "\\}", props.getProperty(EXECUTABLE_PLACEHOLDER)); + "\\$\\{" + EXECUTABLE_PLACEHOLDER + "\\}", properties.getProperty(EXECUTABLE_PLACEHOLDER)); for (int ii = 0; ii < data.length; ii++) { + System.err.println(data[0]); String label = data[0].getMetadata().get(DataProperty.LABEL).toString(); String escapedLabel = label.replaceAll("\\\\", "/"); str = str.replaceAll( @@ -479,10 +500,10 @@ } public File getTempDirectory() { - return new File(tempDirPath); + return new File(temporaryDirectoryPath); } - protected String makeTempDirectory() throws IOException { + protected String makeTemporaryDirectory() throws IOException { File sessionDir = Activator.getTempDirectory(); File dir = File.createTempFile("StaticExecutableRunner-", "", sessionDir); @@ -493,7 +514,7 @@ } private void copyDir(File dir, String dirPath, int depth) throws IOException { - Enumeration e = bContext.getBundle().getEntryPaths(dirPath); + Enumeration e = bundleContext.getBundle().getEntryPaths(dirPath); // dirPath = dirPath.replace('/', File.separatorChar); @@ -515,7 +536,7 @@ } private void copyFile(File dir, String path) throws IOException { - URL entry = bContext.getBundle().getEntry(path); + URL entry = bundleContext.getBundle().getEntry(path); // path = path.replace('/', File.separatorChar); String file = getName(path); 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-01-20 14:31:41
|
Revision: 1193 http://cishell.svn.sourceforge.net/cishell/?rev=1193&view=rev Author: pataphil Date: 2011-01-20 14:31:35 +0000 (Thu, 20 Jan 2011) Log Message: ----------- * Converters now print exception stack traces to the developer console (to assist with debugging). Modified Paths: -------------- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2011-01-19 18:42:55 UTC (rev 1192) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2011-01-20 14:31:35 UTC (rev 1193) @@ -66,8 +66,10 @@ try { data = algorithm.execute(); } catch (AlgorithmExecutionException e) { + e.printStackTrace(); throw new ConversionException(e.getMessage(), e); } catch (Exception e) { + e.printStackTrace(); throw new ConversionException( "Unexpected error: " + e.getMessage(), e); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-01-19 18:43:01
|
Revision: 1192 http://cishell.svn.sourceforge.net/cishell/?rev=1192&view=rev Author: pataphil Date: 2011-01-19 18:42:55 +0000 (Wed, 19 Jan 2011) Log Message: ----------- * Parameter dialogs should now display parameters in the order they were added. Modified Paths: -------------- trunk/core/org.cishell.reference/src/org/cishell/reference/service/metatype/BasicObjectClassDefinition.java Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/metatype/BasicObjectClassDefinition.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/metatype/BasicObjectClassDefinition.java 2011-01-11 17:26:18 UTC (rev 1191) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/metatype/BasicObjectClassDefinition.java 2011-01-19 18:42:55 UTC (rev 1192) @@ -10,8 +10,9 @@ public class BasicObjectClassDefinition implements ObjectClassDefinition { - List attributeDefinitionsOptional = new ArrayList(); - List attributeDefinitionsRequired = new ArrayList(); + List<AttributeDefinition> optionalAttributeDefinitions = new ArrayList<AttributeDefinition>(); + List<AttributeDefinition> requiredAttributeDefinitions = new ArrayList<AttributeDefinition>(); + List<AttributeDefinition> allAttributeDefinitions = new ArrayList<AttributeDefinition>(); private String ID; private String name; private String description; @@ -25,38 +26,31 @@ } public void addAttributeDefinition(int flag, AttributeDefinition definition) { - if(flag == REQUIRED) { - this.attributeDefinitionsRequired.add(definition); - } else if(flag == OPTIONAL) { - this.attributeDefinitionsOptional.add(definition); + if (flag == REQUIRED) { + this.requiredAttributeDefinitions.add(definition); + } else if (flag == OPTIONAL) { + this.optionalAttributeDefinitions.add(definition); } + + this.allAttributeDefinitions.add(definition); } - - + public AttributeDefinition[] getAttributeDefinitions(int flag) { + List<AttributeDefinition> results = new ArrayList<AttributeDefinition>(); - List results = new ArrayList(); - - if(flag == REQUIRED || flag == ALL) { - results.addAll(this.attributeDefinitionsRequired); + if (flag == REQUIRED) { + results.addAll(this.requiredAttributeDefinitions); + } else if (flag == OPTIONAL) { + results.addAll(this.optionalAttributeDefinitions); + } else { + results.addAll(this.allAttributeDefinitions); } - if(flag == OPTIONAL || flag == ALL) { - results.addAll(this.attributeDefinitionsOptional); - - } - return makeArray(results); } - private AttributeDefinition[] makeArray(List definitions) { - AttributeDefinition[] result = new AttributeDefinition[definitions.size()]; - - for(int ii = 0; ii < definitions.size(); ii++) { - result[ii] = (AttributeDefinition) definitions.get(ii); - } - - return result; + private AttributeDefinition[] makeArray(List<AttributeDefinition> definitions) { + return definitions.toArray(new AttributeDefinition[0]); } public String getDescription() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-01-11 17:26:27
|
Revision: 1191 http://cishell.svn.sourceforge.net/cishell/?rev=1191&view=rev Author: pataphil Date: 2011-01-11 17:26:18 +0000 (Tue, 11 Jan 2011) Log Message: ----------- * Added ${data_label[x]} placeholder syntax support to static executable config.properties files (for: http://cns-jira.slis.indiana.edu/browse/SCISQUARED-354 ) * Reviewed by Joseph. Modified Paths: -------------- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java Modified: trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2011-01-10 02:34:09 UTC (rev 1190) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2011-01-11 17:26:18 UTC (rev 1191) @@ -52,6 +52,10 @@ * @author Bruce Herr (bh...@bh...) */ public class StaticExecutableRunner implements Algorithm { + public static final String EXECUTABLE_PLACEHOLDER = "executable"; + public static final String DATA_LABEL_PLACEHOLDER = "data_label"; + public static final String IN_FILE_PLACEHOLDER = "inFile"; + private String ALGORITHM; private String ALGORITHM_MACOSX_PPC; private String MACOSX; @@ -439,17 +443,23 @@ // (real names of files instead of inFile[i], for instance) // (also, real values like "6" or "dog" instead of placeholders for parameters) protected String substituteVars(String str, Data[] data, Dictionary parameters) { - str = str.replaceAll("\\$\\{executable\\}", props.getProperty("executable")); + str = str.replaceAll( + "\\$\\{" + EXECUTABLE_PLACEHOLDER + "\\}", props.getProperty(EXECUTABLE_PLACEHOLDER)); - for (int i = 0; i < data.length; i++) { - File inFile = (File)data[i].getData(); + for (int ii = 0; ii < data.length; ii++) { + String label = data[0].getMetadata().get(DataProperty.LABEL).toString(); + String escapedLabel = label.replaceAll("\\\\", "/"); + str = str.replaceAll( + "\\$\\{" + DATA_LABEL_PLACEHOLDER + "\\[" + ii + "\\]\\}", escapedLabel); + + File inFile = (File)data[ii].getData(); String filePath = inFile.getAbsolutePath(); if (File.separatorChar == '\\') { filePath = filePath.replace(File.separatorChar, '/'); } - str = str.replaceAll("\\$\\{inFile\\[" + i + "\\]\\}", filePath); + str = str.replaceAll("\\$\\{" + IN_FILE_PLACEHOLDER + "\\[" + ii + "\\]\\}", filePath); if (File.separatorChar == '\\') { str = str.replace('/', File.separatorChar); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-01-10 02:34:15
|
Revision: 1190 http://cishell.svn.sourceforge.net/cishell/?rev=1190&view=rev Author: pataphil Date: 2011-01-10 02:34:09 +0000 (Mon, 10 Jan 2011) Log Message: ----------- * Fixed bug introduced by removing ManagedService as an implemented class in SaveFactory. (Added ManagedService implementation back in.) Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2011-01-07 18:41:48 UTC (rev 1189) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2011-01-10 02:34:09 UTC (rev 1190) @@ -7,6 +7,8 @@ import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; import org.cishell.service.conversion.DataConversionService; +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedService; /** * Create a Save object @@ -15,7 +17,7 @@ * no final file:X->file-ext:* converter. * */ -public class SaveFactory implements AlgorithmFactory { +public class SaveFactory implements AlgorithmFactory, ManagedService { public Algorithm createAlgorithm( Data[] data, Dictionary<String, Object> parameters, CIShellContext ciShellContext) { Data inputData = data[0]; @@ -25,4 +27,7 @@ return new Save(inputData, ciShellContext, conversionManager); } + + @SuppressWarnings("unchecked") + public void updated(Dictionary properties) throws ConfigurationException {} } \ 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-07 18:41:55
|
Revision: 1189 http://cishell.svn.sourceforge.net/cishell/?rev=1189&view=rev Author: pataphil Date: 2011-01-07 18:41:48 +0000 (Fri, 07 Jan 2011) Log Message: ----------- * http://cns-jira.slis.indiana.edu/browse/SCISQUARED-360 * Also cleaned up code a little, as I read through it. * Reviewed by Joseph. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2011-01-06 16:37:08 UTC (rev 1188) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2011-01-07 18:41:48 UTC (rev 1189) @@ -22,11 +22,6 @@ import org.eclipse.swt.widgets.Shell; import org.osgi.service.log.LogService; -/** - * Persist the file to disk for the user - * - * @author Team - */ public class FileSaver { public static final String FILE_EXTENSION_PREFIX = "file-ext:"; @@ -37,17 +32,11 @@ private GUIBuilderService guiBuilder; private LogService log; - - /** - * Initializes services to output messages - * - * @param parent - * @param ciShellContext - */ - public FileSaver(Shell parent, CIShellContext context){ + public FileSaver(Shell parent, CIShellContext ciShellContext) { this.parent = parent; - this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); - this.log = (LogService) context.getService(LogService.class.getName()); + this.guiBuilder = + (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); + this.log = (LogService) ciShellContext.getService(LogService.class.getName()); } /** @@ -69,15 +58,17 @@ */ private boolean isSaveFileValid(File file) { boolean valid = false; + if (file.isDirectory()) { String message = "Destination cannot be a directory. Please choose a file"; guiBuilder.showError("Invalid Destination", message, ""); valid = false; } else if (file.exists()) { valid = confirmFileOverwrite(file); + } else { + valid = true; } - else - valid = true ; + return valid; } @@ -89,10 +80,10 @@ * @return Whether or not the save was successful */ public boolean save(Converter converter, Data data) { - String outDataStr = - (String) converter.getProperties().get(AlgorithmProperty.OUT_DATA); + String outDataStr = (String) converter.getProperties().get(AlgorithmProperty.OUT_DATA); String ext = ""; + if (outDataStr.startsWith(FILE_EXTENSION_PREFIX)) { ext = outDataStr.substring(FILE_EXTENSION_PREFIX.length()); } @@ -103,14 +94,13 @@ } FileDialog dialog = new FileDialog(parent, SWT.SAVE); - + if (currentDir == null) { - currentDir = new File(System.getProperty("user.home") + File.separator - + "anything"); + currentDir = new File(System.getProperty("user.home") + File.separator + "anything"); } + dialog.setFilterPath(currentDir.getPath()); - - + if (ext != null && !ext.equals("*")) { dialog.setFilterExtensions(new String[]{"*." + ext}); } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2011-01-06 16:37:08 UTC (rev 1188) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2011-01-07 18:41:48 UTC (rev 1189) @@ -1,7 +1,5 @@ package org.cishell.reference.gui.persistence.save; -import java.util.Dictionary; - import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; @@ -11,60 +9,43 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -/** - * Save algorithm for persisting a data object - * - * @author bmarkine - */ + public class Save implements Algorithm { public static final String ANY_FILE_EXTENSION = "file-ext:*"; public static final String SAVE_DIALOG_TITLE = "Save"; - private Data[] data; - private CIShellContext context; + private Data data; + private CIShellContext ciShellContext; + private Shell parentShell; private DataConversionService conversionManager; - - /** - * Sets up default services for the algorithm - * - * @param data The data array to persist - * @param parameters Parameters for the algorithm - * @param ciShellContext Provides services to CIShell services - */ - public Save(Data[] data, Dictionary parameters, CIShellContext context) { + + public Save( + Data data, CIShellContext ciShellContext, DataConversionService conversionManager) { this.data = data; - this.context = context; + this.ciShellContext = ciShellContext; - this.conversionManager = (DataConversionService) - context.getService(DataConversionService.class.getName()); + this.conversionManager = conversionManager; } - /** - * @return Null when successful - */ public Data[] execute() throws AlgorithmExecutionException { - Data outData = data[0]; - - tryToSave(outData, ANY_FILE_EXTENSION); + tryToSave(this.data, ANY_FILE_EXTENSION); return null; } private void tryToSave(final Data outData, String outFormat) throws AlgorithmExecutionException { - final Converter[] converters = - conversionManager.findConverters(outData, outFormat); + final Converter[] converters = conversionManager.findConverters(outData, outFormat); + if (converters.length == 0) { - throw new AlgorithmExecutionException( - "Error: Calculated an empty converter chain."); + throw new AlgorithmExecutionException("Error: Calculated an empty converter chain."); } - - parentShell = - PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); - if (parentShell.isDisposed()) { - throw new AlgorithmExecutionException( - "Attempted to use disposed parent shell."); + + this.parentShell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); + + if (this.parentShell.isDisposed()) { + throw new AlgorithmExecutionException("Attempted to use disposed parent shell."); } try { @@ -73,18 +54,17 @@ if (converters.length == 1) { // Only one possible choice in how to save data. Do it. Converter onlyConverter = converters[0]; - final FileSaver saver = - new FileSaver(parentShell, context); + FileSaver saver = new FileSaver(Save.this.parentShell, ciShellContext); saver.save(onlyConverter, outData); } else { // Multiple ways to save the data. Let user choose. - SaveDataChooser saveChooser = - new SaveDataChooser(outData, - parentShell, - converters, - SAVE_DIALOG_TITLE, - context); - saveChooser.createContent(new Shell(parentShell)); + SaveDataChooser saveChooser = new SaveDataChooser( + outData, + Save.this.parentShell, + converters, + SAVE_DIALOG_TITLE, + Save.this.ciShellContext); + saveChooser.createContent(new Shell(Save.this.parentShell)); saveChooser.open(); } } @@ -98,7 +78,7 @@ if (Thread.currentThread() == Display.getDefault().getThread()) { run.run(); } else { - parentShell.getDisplay().syncExec(run); + this.parentShell.getDisplay().syncExec(run); } } } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2011-01-06 16:37:08 UTC (rev 1188) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2011-01-07 18:41:48 UTC (rev 1189) @@ -3,13 +3,10 @@ import java.util.Dictionary; import org.cishell.framework.CIShellContext; -import org.cishell.framework.LocalCIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; -import org.osgi.service.cm.ConfigurationException; -import org.osgi.service.cm.ManagedService; -import org.osgi.service.component.ComponentContext; +import org.cishell.service.conversion.DataConversionService; /** * Create a Save object @@ -18,32 +15,14 @@ * no final file:X->file-ext:* converter. * */ -public class SaveFactory implements AlgorithmFactory, ManagedService { - private CIShellContext ciShellContext; +public class SaveFactory implements AlgorithmFactory { + public Algorithm createAlgorithm( + Data[] data, Dictionary<String, Object> parameters, CIShellContext ciShellContext) { + Data inputData = data[0]; + DataConversionService conversionManager = + (DataConversionService) ciShellContext.getService( + DataConversionService.class.getName()); - /** - * Create a local CIShell ciShellContext - * @param componentContext The current CIShell ciShellContext - */ - protected void activate(ComponentContext componentContext) { - ciShellContext = - new LocalCIShellContext(componentContext.getBundleContext()); + return new Save(inputData, ciShellContext, conversionManager); } - - public void updated(Dictionary properties) throws ConfigurationException { - } - - /** - * Create a Save algorithm - * @param data The data objects to save - * @param parameters The parameters for the algorithm - * @param ciShellContext Reference to services provided by CIShell - * @return An instance of the Save algorithm - */ - public Algorithm createAlgorithm(Data[] data, - Dictionary parameters, - CIShellContext ciShellContext) { - this.ciShellContext = ciShellContext; - return new Save(data, parameters, ciShellContext); - } } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2011-01-06 16:37:08 UTC (rev 1188) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2011-01-07 18:41:48 UTC (rev 1189) @@ -1,7 +1,5 @@ package org.cishell.reference.gui.persistence.view; -import java.util.Dictionary; - import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; @@ -19,27 +17,25 @@ private LogService logger; public FileView( - Data[] data, Dictionary parameters, CIShellContext context) { + Data[] data, + CIShellContext ciShellContext, + DataConversionService conversionManager, + LogService logger) { this.dataToView = data; - this.ciShellContext = context; - - this.conversionManager = (DataConversionService)context.getService( - DataConversionService.class.getName()); - this.logger = (LogService)context.getService(LogService.class.getName()); + this.ciShellContext = ciShellContext; + this.conversionManager = conversionManager; + this.logger = logger; } public Data[] execute() throws AlgorithmExecutionException { - for (int ii = 0; ii < this.dataToView.length; ii++) { + for (Data data : this.dataToView) { try { - FileViewer.viewDataFile(this.dataToView[ii], - this.ciShellContext, - this.conversionManager, - this.logger); + FileViewer.viewDataFile( + data, this.ciShellContext, this.conversionManager, this.logger); } catch (FileViewingException fileViewingException) { - String logMessage = - "Error: Unable to view data \"" + - this.dataToView[ii].getMetadata().get(DataProperty.LABEL) + - "\"."; + String logMessage = String.format( + "Error: Unable to view data \"%s\".", + data.getMetadata().get(DataProperty.LABEL)); this.logger.log(LogService.LOG_ERROR, logMessage); } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java 2011-01-06 16:37:08 UTC (rev 1188) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java 2011-01-07 18:41:48 UTC (rev 1189) @@ -6,12 +6,18 @@ import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; +import org.cishell.service.conversion.DataConversionService; +import org.osgi.service.log.LogService; public class FileViewFactory implements AlgorithmFactory { - public Algorithm createAlgorithm(Data[] data, - Dictionary parameters, - CIShellContext ciShellContext) { - return new FileView(data, parameters, ciShellContext); + public Algorithm createAlgorithm( + Data[] data, Dictionary<String, Object> parameters, CIShellContext ciShellContext) { + DataConversionService conversionManager = + (DataConversionService) ciShellContext.getService( + DataConversionService.class.getName()); + LogService logger = (LogService) ciShellContext.getService(LogService.class.getName()); + + return new FileView(data, ciShellContext, conversionManager, logger); } } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2011-01-06 16:37:08 UTC (rev 1188) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2011-01-07 18:41:48 UTC (rev 1189) @@ -2,8 +2,11 @@ import java.io.File; import java.io.IOException; +import java.util.Dictionary; +import java.util.Enumeration; import org.cishell.framework.CIShellContext; +import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.persistence.view.core.exceptiontypes.ConvertDataForViewingException; @@ -36,11 +39,11 @@ public static final String ANY_FILE_FORMAT_PATTERN = "(file:.*)|(file-ext:.*)"; - public static void viewDataFile(Data data, - CIShellContext ciShellContext, - DataConversionService conversionManager, - LogService logger) - throws FileViewingException { + public static void viewDataFile( + Data data, + CIShellContext ciShellContext, + DataConversionService conversionManager, + LogService logger) throws FileViewingException { viewDataFileWithProgram(data, "", ciShellContext, conversionManager, logger); } @@ -49,11 +52,9 @@ String customFileExtension, CIShellContext ciShellContext, DataConversionService converterManager, - LogService logger) - throws FileViewingException { - FileWithExtension fileWithExtension = - convertDataForViewing(data, ciShellContext, converterManager, - logger); + LogService logger) throws FileViewingException { + FileWithExtension fileWithExtension = convertDataForViewing( + data, ciShellContext, converterManager, logger); viewFileWithExtension(fileWithExtension, customFileExtension); } @@ -64,16 +65,18 @@ LogService logger) throws FileViewingException { try { String dataFormat = data.getFormat(); - //TODO: Add image viewing support here (shouldn't be too hard) + // TODO: Add image viewing support here (shouldn't be too hard). if (dataIsDB(data, converterManager)) { try { - Data genericDBData = converterManager.convert(data, Database.GENERIC_DB_MIME_TYPE); - Database genericDatabase = (Database) genericDBData.getData(); + Data genericDBData = + converterManager.convert(data, Database.GENERIC_DB_MIME_TYPE); + Database genericDatabase = (Database) genericDBData.getData(); + + File dbSchemaOverview = + DatabaseSchemaOverviewGenerator.generateDatabaseSchemaOverview( + genericDatabase); - File dbSchemaOverview = - DatabaseSchemaOverviewGenerator.generateDatabaseSchemaOverview(genericDatabase); - - return new FileWithExtension(dbSchemaOverview, TXT_FILE_EXTENSION); + return new FileWithExtension(dbSchemaOverview, TXT_FILE_EXTENSION); } catch (ConversionException e) { //continue attempts to view for other formats } catch (Exception e) { @@ -85,13 +88,12 @@ } if (isCSVFormat(data)) { /* - * The data is already a CSV file, so it just needs to - * be copied. + * The data is already a CSV file, so it just needs to be copied. */ try { File csvFileForViewing = FileUtilities.createTemporaryFileCopy( - (File)data.getData(), + (File) data.getData(), TEMPORARY_CSV_FILE_NAME, CSV_FILE_EXTENSION); @@ -110,16 +112,14 @@ File preparedFileForViewing = prepareFileForViewing( data, CSV_FILE_EXTENSION, converterManager); - return new FileWithExtension( - preparedFileForViewing, CSV_FILE_EXTENSION); + return new FileWithExtension(preparedFileForViewing, CSV_FILE_EXTENSION); } else if (dataIsFile(data, dataFormat)) { /* * The data is already a text-based file, so it just needs to * be copied to a temporary file for viewing in the default * text-viewing program. */ - return new FileWithExtension( - prepareTextFileForViewing(data), TXT_FILE_EXTENSION); + return new FileWithExtension(prepareTextFileForViewing(data), TXT_FILE_EXTENSION); } else if (convertersExist( data, ANY_FILE_EXTENSION_FILTER, converterManager)) { /* @@ -128,29 +128,24 @@ * text-viewing program. */ return new FileWithExtension( - convertDataToTextFile( - data, converterManager, ciShellContext), + convertDataToTextFile(data, converterManager, ciShellContext), "txt"); } else { - String exceptionMessage = - "No converters exist for the data \"" + - data.getMetadata().get(DataProperty.LABEL) + - "\"."; - + String exceptionMessage = String.format( + "No converters exist for the data \"%s\".", + data.getMetadata().get(DataProperty.LABEL)); + throw new ConvertDataForViewingException(exceptionMessage); } - } catch (ConvertDataForViewingException - convertDataForViewingException) { - String exceptionMessage = - "There was a problem when preparing the data \"" + - data.getMetadata().get(DataProperty.LABEL) + - "\" for viewing."; + } catch (ConvertDataForViewingException e) { + String exceptionMessage = String.format( + "There was a problem when preparing the data \"%s\" for viewing.", + data.getMetadata().get(DataProperty.LABEL)); - throw new FileViewingException( - exceptionMessage, convertDataForViewingException); + throw new FileViewingException(exceptionMessage, e); } } - + private static void viewFileWithExtension( FileWithExtension fileWithExtension, String customFileExtension) throws FileViewingException { @@ -160,47 +155,33 @@ executeProgramWithFile(program, fileWithExtension.file); } catch (NoProgramFoundException noProgramFoundException) { - String exceptionMessage = - "Could not view the file \"" + - fileWithExtension.file.getAbsolutePath() + - "\" because no viewing program could be found for it."; + String exceptionMessage = String.format( + "Could not view the file \"%s\" because no viewing program could be found for it.", + fileWithExtension.file.getAbsolutePath()); - throw new FileViewingException( - exceptionMessage, noProgramFoundException); + throw new FileViewingException(exceptionMessage, noProgramFoundException); } } - + private static boolean isCSVFormat(Data data) { String dataFormat = data.getFormat(); - if (dataFormat.startsWith(CSV_MIME_TYPE) || - dataFormat.startsWith(CSV_FILE_EXT)) { + if (dataFormat.startsWith(CSV_MIME_TYPE) || dataFormat.startsWith(CSV_FILE_EXT)) { return true; } else { return false; } } - - /*private static boolean dataIsCSVCompatibleFile( - Data data, - DataConversionService converterManager) { - return convertersExist(data, CSV_FILE_EXT, converterManager); - }*/ - - private static boolean dataIsCSVCompatible( - Data data, - DataConversionService converterManager) { - if (isCSVFormat(data) || - convertersExist(data, CSV_FILE_EXT, converterManager)) { + + private static boolean dataIsCSVCompatible(Data data, DataConversionService converterManager) { + if (isCSVFormat(data) || convertersExist(data, CSV_FILE_EXT, converterManager)) { return true; } else { return false; } } - - private static boolean dataIsDB ( - Data data, - DataConversionService converterManager) { + + private static boolean dataIsDB(Data data, DataConversionService converterManager) { if (has_DB_MimeType_Prefix(data) || convertersExist(data, Database.GENERIC_DB_MIME_TYPE, converterManager)) { return true; @@ -208,11 +189,11 @@ return false; } } - + private static boolean has_DB_MimeType_Prefix(Data data) { return data.getFormat().startsWith(Database.DB_MIME_TYPE_PREFIX); } - + private static boolean dataIsFile(Data data, String dataFormat) { if (data.getData() instanceof File || dataFormat.startsWith(ANY_MIME_TYPE) || @@ -222,51 +203,45 @@ return false; } } - + private static boolean convertersExist( - Data data, - String targetFormat, - DataConversionService conversionManager) { - final Converter[] converters = - conversionManager.findConverters(data, targetFormat); - + Data data, String targetFormat, DataConversionService conversionManager) { + final Converter[] converters = conversionManager.findConverters(data, targetFormat); + if (converters.length > 0) { return true; } else { return false; } } - + private static File prepareFileForViewing( Data originalData, String fileExtension, - DataConversionService converterManager) - throws ConvertDataForViewingException { - String dataLabel = - (String)originalData.getMetadata().get(DataProperty.LABEL); - + DataConversionService converterManager) throws ConvertDataForViewingException { + String dataLabel = (String) originalData.getMetadata().get(DataProperty.LABEL); + try { - String fileExtensionMimeType = - FILE_EXTENSION_MIME_TYPE_PREFIX + fileExtension; + String fileExtensionMimeType = FILE_EXTENSION_MIME_TYPE_PREFIX + fileExtension; File convertedFile = convertToFile( originalData, fileExtensionMimeType, converterManager); String fileName = FileUtilities.extractFileName(dataLabel); + String cleanedFileName = FileUtilities.replaceInvalidFilenameCharacters(fileName); return FileUtilities.createTemporaryFileCopy( - convertedFile, fileName, fileExtension); - } catch (ConversionException convertingDataToFileException) { - String exceptionMessage = - "A ConversionException occurred when converting the data \"" + - dataLabel + - "\" to " + fileExtension + "."; + convertedFile, cleanedFileName, fileExtension); + } catch (ConversionException e) { + String exceptionMessage = String.format( + "A ConversionException occurred when converting the data \"%s\" to %s.", + dataLabel, + fileExtension); - throw new ConvertDataForViewingException( - exceptionMessage, convertingDataToFileException); + throw new ConvertDataForViewingException(exceptionMessage, e); } catch (FileCopyingException temporaryFileCopyingException) { - String exceptionMessage = - "A FileCopyingException occurred when converting the data \"" + - dataLabel + - "\" to " + fileExtension + "."; + String exceptionMessage = String.format( + "A FileCopyingException occurred when converting the data \"%s\" to %s.", + dataLabel, + fileExtension); throw new ConvertDataForViewingException( exceptionMessage, temporaryFileCopyingException); @@ -275,8 +250,7 @@ private static File prepareTextFileForViewing(Data originalData) throws ConvertDataForViewingException { - String dataLabel = - (String)originalData.getMetadata().get(DataProperty.LABEL); + String dataLabel = (String)originalData.getMetadata().get(DataProperty.LABEL); String dataFormat = originalData.getFormat(); String suggestedFileName = FileUtilities.extractFileName(dataLabel); String cleanedSuggestedFileName = @@ -284,9 +258,8 @@ String fileExtension = FileUtilities.extractExtension(dataFormat); try { - File fileToView = FileUtilities. - createTemporaryFileInDefaultTemporaryDirectory( - cleanedSuggestedFileName, fileExtension); + File fileToView = FileUtilities.createTemporaryFileInDefaultTemporaryDirectory( + cleanedSuggestedFileName, fileExtension); FileUtilities.copyFile((File)originalData.getData(), fileToView); return fileToView; @@ -306,8 +279,7 @@ private static File convertDataToTextFile( Data originalData, DataConversionService converterManager, - CIShellContext ciShellContext) - throws ConvertDataForViewingException { + CIShellContext ciShellContext) throws ConvertDataForViewingException { final Converter[] converters = converterManager.findConverters( originalData, ANY_FILE_EXTENSION_FILTER); @@ -317,20 +289,15 @@ * the conversion. */ try { - return convertToFile( - originalData, converters[0]); - } - catch (ConversionException - convertDataToFileAndPrepareForViewingException) { - String exceptionMessage = - "A ConversionException occurred when converting the " + - "data \"" + - originalData.getMetadata().get(DataProperty.LABEL) + - "\" to a file format."; + return convertToFile(originalData, converters[0]); + } catch (ConversionException e) { + String format = + "A ConversionException occurred when converting the data \"%s\" " + + "to a file format."; + String exceptionMessage = String.format( + format, originalData.getMetadata().get(DataProperty.LABEL)); - throw new ConvertDataForViewingException( - exceptionMessage, - convertDataToFileAndPrepareForViewingException); + throw new ConvertDataForViewingException(exceptionMessage, e); } } else { /* @@ -341,25 +308,20 @@ return convertDataBasedOffUserChosenConverter( originalData, converters, ciShellContext); } catch (ConversionException conversionException) { - String exceptionMessage = - "A ConversionException occurred when converting the " + - "data \"" + - originalData.getMetadata().get(DataProperty.LABEL) + - "\"."; + String exceptionMessage = String.format( + "A ConversionException occurred when converting the data \"%s\".", + originalData.getMetadata().get(DataProperty.LABEL)); - throw new ConvertDataForViewingException( - exceptionMessage, conversionException); - } catch (UserCanceledDataViewSelectionException - userCanceledDataViewSelectionException) { - String exceptionMessage = + throw new ConvertDataForViewingException(exceptionMessage, conversionException); + } catch (UserCanceledDataViewSelectionException e) { + String format = "A UserCanceledDataViewSelectionException occurred " + "when the user did not choose a converter for the " + - "data \"" + - originalData.getMetadata().get(DataProperty.LABEL) + - "\"."; + "data \"%s\"."; + String exceptionMessage = String.format( + format, originalData.getMetadata().get(DataProperty.LABEL)); - throw new ConvertDataForViewingException( - exceptionMessage, userCanceledDataViewSelectionException); + throw new ConvertDataForViewingException(exceptionMessage, e); } } } @@ -432,10 +394,11 @@ } - private static File convertToFile(Data data, Converter converter) - throws ConversionException { - Data newData = converter.convert(data); - return (File)newData.getData(); + private static File convertToFile(Data data, Converter converter) throws ConversionException { + Data dataWithCleanedLabelForConversion = cloneDataWithCleanedLabelForConversion(data); + Data newData = converter.convert(dataWithCleanedLabelForConversion); + + return (File) newData.getData(); } private static File convertDataBasedOffUserChosenConverter( @@ -527,6 +490,25 @@ this.selectedConverter = viewDataChooser.getSelectedConverter(); } } + + private static Data cloneDataWithCleanedLabelForConversion(Data originalData) { + Data clonedData = new BasicData(originalData.getData(), originalData.getFormat()); + Dictionary<String, Object> originalMetadata = originalData.getMetadata(); + Dictionary<String, Object> clonedMetadata = clonedData.getMetadata(); + + for (Enumeration<String> keys = originalMetadata.keys(); keys.hasMoreElements();) { + String key = keys.nextElement(); + + if (DataProperty.LABEL.equals(key)) { + clonedMetadata.put(key, FileUtilities.replaceInvalidFilenameCharacters( + (String) originalMetadata.get(key))); + } else { + clonedMetadata.put(key, originalMetadata.get(key)); + } + } + + return clonedData; + } private static class FileWithExtension { public final File file; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-01-06 16:37:15
|
Revision: 1188 http://cishell.svn.sourceforge.net/cishell/?rev=1188&view=rev Author: pataphil Date: 2011-01-06 16:37:08 +0000 (Thu, 06 Jan 2011) Log Message: ----------- * Added NumberUtilities.interpretObjectAsNumber * Minor cleaned-up in NumberUtilities and TableUtilities * Reviewed by Joseph Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2011-01-03 19:46:56 UTC (rev 1187) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2011-01-06 16:37:08 UTC (rev 1188) @@ -2,25 +2,120 @@ import java.text.DecimalFormat; import java.text.Format; +import java.text.NumberFormat; +import java.text.ParseException; public class NumberUtilities { public static final String UNROUNDED_DECIMAL_PATTERN = "#.############################"; public static final String NOT_A_NUMBER_PREFIX = "NOT A NUMBER"; + + public static final String EMPTY_CELL_MESSAGE = "An empty number cell was found."; + + public static Number interpretObjectAsNumber(Object object) + throws NumberFormatException, ParseException { + if (object instanceof Number) { + Number number = (Number) object; + + return number; + } else if (object instanceof short[]) { + short[] objectAsShortArray = (short[]) object; + + if (objectAsShortArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return new Short(objectAsShortArray[0]); + } + } else if (object instanceof Short[]) { + Short[] objectAsShortArray = (Short[]) object; + + if (objectAsShortArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return objectAsShortArray[0]; + } + } else if (object instanceof int[]) { + int[] objectAsIntArray = (int[]) object; + + if (objectAsIntArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return new Integer(objectAsIntArray[0]); + } + } else if (object instanceof Integer[]) { + Integer[] objectAsIntegerArray = (Integer[]) object; + + if (objectAsIntegerArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return objectAsIntegerArray[0]; + } + } else if (object instanceof long[]) { + long[] objectAsLongArray = (long[]) object; + + if (objectAsLongArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return new Long(objectAsLongArray[0]); + } + } else if (object instanceof Long[]) { + Long[] objectAsLongArray = (Long[]) object; + + if (objectAsLongArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return objectAsLongArray[0]; + } + } else if (object instanceof float[]) { + float[] objectAsFloatArray = (float[]) object; + + if (objectAsFloatArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return new Float(objectAsFloatArray[0]); + } + } else if (object instanceof Float[]) { + Float[] objectAsFloatArray = (Float[]) object; + + if (objectAsFloatArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return objectAsFloatArray[0]; + } + } else if (object instanceof double[]) { + double[] objectAsDoubleArray = (double[]) object; + + if (objectAsDoubleArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return new Double(objectAsDoubleArray[0]); + } + } else if (object instanceof Double[]) { + Double[] objectAsDoubleArray = (Double[]) object; + + if (objectAsDoubleArray.length == 0) { + throw new NumberFormatException(EMPTY_CELL_MESSAGE); + } else { + return objectAsDoubleArray[0]; + } + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + + return numberFormat.parse(object.toString()); + } public static Double interpretObjectAsDouble(Object object) throws NumberFormatException { - final String EMPTY_CELL_MESSAGE = "An empty number cell was found."; - // TODO: These if's are a result of a "bug" in Prefuse's. // CSV Table Reader, which interprets a column as being an array type // if it has empty cells. if (object instanceof Number) { - Number number = (Number)object; + Number number = (Number) object; return new Double(number.doubleValue()); } else if (object instanceof short[]) { - short[] objectAsShortArray = (short[])object; + short[] objectAsShortArray = (short[]) object; if (objectAsShortArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -28,7 +123,7 @@ return new Double(objectAsShortArray[0]); } } else if (object instanceof Short[]) { - Short[] objectAsShortArray = (Short[])object; + Short[] objectAsShortArray = (Short[]) object; if (objectAsShortArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -36,7 +131,7 @@ return new Double(objectAsShortArray[0].doubleValue()); } } else if (object instanceof int[]) { - int[] objectAsIntArray = (int[])object; + int[] objectAsIntArray = (int[]) object; if (objectAsIntArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -44,7 +139,7 @@ return new Double(objectAsIntArray[0]); } } else if (object instanceof Integer[]) { - Integer[] objectAsIntegerArray = (Integer[])object; + Integer[] objectAsIntegerArray = (Integer[]) object; if (objectAsIntegerArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -52,7 +147,7 @@ return new Double(objectAsIntegerArray[0].doubleValue()); } } else if (object instanceof long[]) { - long[] objectAsLongArray = (long[])object; + long[] objectAsLongArray = (long[]) object; if (objectAsLongArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -60,7 +155,7 @@ return new Double(objectAsLongArray[0]); } } else if (object instanceof Long[]) { - Long[] objectAsLongArray = (Long[])object; + Long[] objectAsLongArray = (Long[]) object; if (objectAsLongArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -68,7 +163,7 @@ return new Double(objectAsLongArray[0].doubleValue()); } } else if (object instanceof float[]) { - float[] objectAsFloatArray = (float[])object; + float[] objectAsFloatArray = (float[]) object; if (objectAsFloatArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -76,7 +171,7 @@ return new Double(objectAsFloatArray[0]); } } else if (object instanceof Float[]) { - Float[] objectAsFloatArray = (Float[])object; + Float[] objectAsFloatArray = (Float[]) object; if (objectAsFloatArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -84,7 +179,7 @@ return new Double(objectAsFloatArray[0].doubleValue()); } } else if (object instanceof double[]) { - double[] objectAsDoubleArray = (double[])object; + double[] objectAsDoubleArray = (double[]) object; if (objectAsDoubleArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); @@ -92,7 +187,7 @@ return new Double(objectAsDoubleArray[0]); } } else if (object instanceof Double[]) { - Double[] objectAsDoubleArray = (Double[])object; + Double[] objectAsDoubleArray = (Double[]) object; if (objectAsDoubleArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2011-01-03 19:46:56 UTC (rev 1187) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2011-01-06 16:37:08 UTC (rev 1188) @@ -11,6 +11,50 @@ import prefuse.util.collections.IntIterator; public class TableUtilities { + public static final Class<?>[] POSSIBLE_NUMBER_CLASSES = { + byte.class, + byte[].class, + Byte.class, + Byte[].class, + short.class, + short[].class, + Short.class, + Short[].class, + int.class, + int[].class, + Integer.class, + Integer[].class, + long.class, + long[].class, + Long.class, + Long[].class, + float.class, + float[].class, + Float.class, + Float[].class, + double.class, + double[].class, + Double.class, + Double[].class + }; + + public static final Class<?>[] POSSIBLE_INTEGER_CLASSES = { + int.class, + Integer.class, + int[].class, + Integer[].class + }; + + public static final Class<?>[] POSSIBLE_DATE_CLASSES = { + Date.class, + int.class, + Integer.class, + String.class, + int[].class, + Integer[].class, + String[].class, + }; + public static Table copyTable(Table oldTable) { Schema oldSchema = oldTable.getSchema(); Table newTable = oldSchema.instantiate(); @@ -87,61 +131,17 @@ public static String[] getValidNumberColumnNamesInTable(Table table) throws ColumnNotFoundException { - Class<?>[] possibleNumberClasses = { - byte.class, - byte[].class, - Byte.class, - Byte[].class, - short.class, - short[].class, - Short.class, - Short[].class, - int.class, - int[].class, - Integer.class, - Integer[].class, - long.class, - long[].class, - Long.class, - Long[].class, - float.class, - float[].class, - Float.class, - Float[].class, - double.class, - double[].class, - Double.class, - Double[].class - }; - - return filterSchemaColumnNamesByClasses(table.getSchema(), possibleNumberClasses); + return filterSchemaColumnNamesByClasses(table.getSchema(), POSSIBLE_NUMBER_CLASSES); } public static String[] getValidIntegerColumnNamesInTable(Table table) throws ColumnNotFoundException { - Class<?>[] possibleIntegerClasses = { - int.class, - Integer.class, - int[].class, - Integer[].class - }; - - return filterSchemaColumnNamesByClasses(table.getSchema(), possibleIntegerClasses); + return filterSchemaColumnNamesByClasses(table.getSchema(), POSSIBLE_INTEGER_CLASSES); } public static String[] getValidDateColumnNamesInTable(Table table) throws ColumnNotFoundException { - Class<?>[] possibleDateClasses = { - Date.class, - int.class, - Integer.class, - String.class, - int[].class, - Integer[].class, - String[].class, - }; - - return filterSchemaColumnNamesByClasses(table.getSchema(), possibleDateClasses); + return filterSchemaColumnNamesByClasses(table.getSchema(), POSSIBLE_DATE_CLASSES); } public static String[] filterSchemaColumnNamesByClasses( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-01-03 19:47:03
|
Revision: 1187 http://cishell.svn.sourceforge.net/cishell/?rev=1187&view=rev Author: pataphil Date: 2011-01-03 19:46:56 +0000 (Mon, 03 Jan 2011) Log Message: ----------- * Reverting. Modified Paths: -------------- trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF Modified: trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF =================================================================== --- trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF 2011-01-03 18:53:09 UTC (rev 1186) +++ trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF 2011-01-03 19:46:56 UTC (rev 1187) @@ -29,5 +29,5 @@ Require-Bundle: org.eclipse.swt, org.eclipse.ui, edu.uci.ics.jung, - prefuse, + org.prefuse.lib, org.cishell.testing.convertertester.core.new Modified: trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF =================================================================== --- trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF 2011-01-03 18:53:09 UTC (rev 1186) +++ trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF 2011-01-03 19:46:56 UTC (rev 1187) @@ -13,7 +13,7 @@ org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0", org.osgi.service.prefs;version="1.1.0" -Require-Bundle: prefuse +Require-Bundle: org.prefuse.lib Export-Package: org.cishell.testing.convertertester.core.converter.graph, org.cishell.testing.convertertester.core.tester.graphcomparison, org.cishell.testing.convertertester.core.tester2, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-01-03 18:53:15
|
Revision: 1186 http://cishell.svn.sourceforge.net/cishell/?rev=1186&view=rev Author: pataphil Date: 2011-01-03 18:53:09 +0000 (Mon, 03 Jan 2011) Log Message: ----------- * Changed references from org.prefuse.lib to prefuse. Modified Paths: -------------- trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF Modified: trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF =================================================================== --- trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF 2010-12-28 03:10:49 UTC (rev 1185) +++ trunk/testing/org.cishell.testing.convertertester.algorithm/META-INF/MANIFEST.MF 2011-01-03 18:53:09 UTC (rev 1186) @@ -29,5 +29,5 @@ Require-Bundle: org.eclipse.swt, org.eclipse.ui, edu.uci.ics.jung, - org.prefuse.lib, + prefuse, org.cishell.testing.convertertester.core.new Modified: trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF =================================================================== --- trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF 2010-12-28 03:10:49 UTC (rev 1185) +++ trunk/testing/org.cishell.testing.convertertester.core.new/META-INF/MANIFEST.MF 2011-01-03 18:53:09 UTC (rev 1186) @@ -13,7 +13,7 @@ org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0", org.osgi.service.prefs;version="1.1.0" -Require-Bundle: org.prefuse.lib +Require-Bundle: prefuse Export-Package: org.cishell.testing.convertertester.core.converter.graph, org.cishell.testing.convertertester.core.tester.graphcomparison, org.cishell.testing.convertertester.core.tester2, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-12-28 03:10:56
|
Revision: 1185 http://cishell.svn.sourceforge.net/cishell/?rev=1185&view=rev Author: pataphil Date: 2010-12-28 03:10:49 +0000 (Tue, 28 Dec 2010) Log Message: ----------- * Changed nwb.slis.indiana.edu to nwb.cns.iu.edu to try to fix the builds. Modified Paths: -------------- trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties trunk/core/org.cishell.docs.draft-spec/src/draft-specification/draft-spec.tex trunk/core/org.cishell.docs.intro/src/resources.tex trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml Added Paths: ----------- trunk/clients/scripting/org.cishell.reference.scripting/.pydevproject Added: trunk/clients/scripting/org.cishell.reference.scripting/.pydevproject =================================================================== --- trunk/clients/scripting/org.cishell.reference.scripting/.pydevproject (rev 0) +++ trunk/clients/scripting/org.cishell.reference.scripting/.pydevproject 2010-12-28 03:10:49 UTC (rev 1185) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?eclipse-pydev version="1.0"?> + +<pydev_project> +<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> +<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property> +</pydev_project> Modified: trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties 2010-12-22 21:52:31 UTC (rev 1184) +++ trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties 2010-12-28 03:10:49 UTC (rev 1185) @@ -9,4 +9,4 @@ author=Chintan Tank implementers=Chintan Tank integrators=Chintan Tank -documentation_url=https://nwb.slis.indiana.edu/community/?n=File.ConverterGraph \ No newline at end of file +documentation_url=https://nwb.cns.iu.edu/community/?n=File.ConverterGraph \ No newline at end of file Modified: trunk/core/org.cishell.docs.draft-spec/src/draft-specification/draft-spec.tex =================================================================== --- trunk/core/org.cishell.docs.draft-spec/src/draft-specification/draft-spec.tex 2010-12-22 21:52:31 UTC (rev 1184) +++ trunk/core/org.cishell.docs.draft-spec/src/draft-specification/draft-spec.tex 2010-12-28 03:10:49 UTC (rev 1185) @@ -422,7 +422,7 @@ \end{figure} \footnotetext[5]{http://sourceforge.net/projects/ivc} -\footnotetext[6]{http://nwb.slis.indiana.edu} +\footnotetext[6]{http://nwb.cns.iu.edu} The CIShell Framework should work beautifully with a GUI client. The previous iterations of this project were all GUI based, so by far this is the most Modified: trunk/core/org.cishell.docs.intro/src/resources.tex =================================================================== --- trunk/core/org.cishell.docs.intro/src/resources.tex 2010-12-22 21:52:31 UTC (rev 1184) +++ trunk/core/org.cishell.docs.intro/src/resources.tex 2010-12-28 03:10:49 UTC (rev 1185) @@ -1,7 +1,7 @@ \begin{thebibliography}{3} \bibitem{cishell}{CIShell Homepage: http://cishell.org} -\bibitem{nwb}{NWB Homepage: http://nwb.slis.indiana.edu} -\bibitem{nwbCommunityWiki}{NWB Community: https://nwb.slis.indiana.edu/community} +\bibitem{nwb}{NWB Homepage: http://nwb.cns.iu.edu} +\bibitem{nwbCommunityWiki}{NWB Community: https://nwb.cns.iu.edu/community} \bibitem{osgi}{OSGi: http://www.osgi.org} \bibitem{eclipse}{Eclipse: http://www.eclipse.org} \end{thebibliography} \ No newline at end of file Modified: trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml =================================================================== --- trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-12-22 21:52:31 UTC (rev 1184) +++ trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-12-28 03:10:49 UTC (rev 1185) @@ -191,7 +191,7 @@ <param name="target" value="plugins"/> <param name="element.id" value="org.prefuse.lib"/> <param name="project.name" value="/plugins/libs/prefuselib"/> - <param name="url" value="http://nwb.slis.indiana.edu/svn/nwb/trunk"/> + <param name="url" value="http://nwb.cns.iu.edu/svn/nwb/trunk"/> </antcall> <antcall target="svn.co"> <param name="target" value="plugins"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-12-22 21:52:37
|
Revision: 1184 http://cishell.svn.sourceforge.net/cishell/?rev=1184&view=rev Author: kongchinhua Date: 2010-12-22 21:52:31 +0000 (Wed, 22 Dec 2010) Log Message: ----------- Update documentation url to new wiki page Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2010-12-22 17:32:19 UTC (rev 1183) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2010-12-22 21:52:31 UTC (rev 1184) @@ -8,4 +8,4 @@ remoteable=true prefs_published=local receive_prefs=true -documentation_url=https://nwb.slis.indiana.edu/community/?n=DataFormats.HomePage \ No newline at end of file +documentation_url=http://wiki.slis.indiana.edu:8080/display/ALGDOC/Data+Formats \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2010-12-22 17:32:19 UTC (rev 1183) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2010-12-22 21:52:31 UTC (rev 1184) @@ -7,4 +7,5 @@ service.pid=org.cishell.reference.gui.persistence.save.Save remoteable=true prefs_published=local -receive_prefs=true \ No newline at end of file +receive_prefs=true +documentation_url=http://wiki.slis.indiana.edu:8080/display/ALGDOC/Data+Formats \ 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: <jrb...@us...> - 2010-12-22 17:32:25
|
Revision: 1183 http://cishell.svn.sourceforge.net/cishell/?rev=1183&view=rev Author: jrbibers Date: 2010-12-22 17:32:19 +0000 (Wed, 22 Dec 2010) Log Message: ----------- Updating FileUtilities.extractExtension(String format). Previously it attempted to derive the extension from the MIME type assuming it began with "file:text/". For a type like "file:application/pajeknet" it would return an empty string. We attempt to handle this better now with a Map from MIME types to extensions (excluding the case "file:text/foo" -> "foo" as we default to this). Reviewed by Patrick. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2010-12-21 22:59:56 UTC (rev 1182) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2010-12-22 17:32:19 UTC (rev 1183) @@ -24,10 +24,28 @@ import org.osgi.service.log.LogService; +import com.google.common.collect.ImmutableMap; + public class FileUtilities { public static final int READ_TEXT_FILE_BUFFER_SIZE = 1024; public static final String DEFAULT_STREAM_TO_FILE_NAME = "stream_"; + /** Don't bother with "file:text/foo" -> "foo", we can find those automatically. */ + public static final ImmutableMap<String, String> MIME_TYPE_TO_FILE_EXTENSION = + new ImmutableMap.Builder<String, String>() + .put("file:application/pajekmat", "mat") + .put("file:application/pajeknet", "net") + .put("file:application/parvis", "stf") // TODO: This is a guess. + .put("file:text/bibtex", "bib") + .put("file:text/compartmentalmodel", "mdl") + .put("file:text/coord", "nwb") + .put("file:text/grace", "grace.dat") + .put("file:text/intsim", "int") + .put("file:text/plain", "txt") + .put("file:text/plot", "plot.dat") + .put("file:text/referbib", "refer") + .build(); + /* * Return a File pointing to the directory specified in * temporaryDirectoryPath, creating the directory if it doesn't @@ -395,16 +413,28 @@ return tempFile; } + /* TODO: We should really have explicit piece of metadata that says what + * the extension is, as this method is not guaranteed to yield the + * correct extension. + */ public static String extractExtension(String format) { String extension = ""; - /* TODO: We should really have explicit piece of metadata that says what - * the extension is, as this method is not guaranteed to yield the - * correct extension. - */ - if (format.startsWith("file:text/")) { - extension = "." + format.substring("file:text/".length()); - } else if (format.startsWith("file-ext:")) { - extension = "." + format.substring("file-ext:".length()); + + if (format.startsWith("file-ext:")) { + extension = format.substring("file-ext:".length()); + } else if (format.startsWith("file:")) { + if (MIME_TYPE_TO_FILE_EXTENSION.containsKey(format)) { + // Unless explicitly set.. + extension = MIME_TYPE_TO_FILE_EXTENSION.get(format); + } else { + if (format.contains("/")) { + // Whatever follows "/" + extension = format.substring(format.indexOf("/") + 1); + } else { + // Whatever follows "file:" + extension = format.substring("file:".length()); + } + } } extension = extension.replace('+', '.'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-12-21 23:00:03
|
Revision: 1182 http://cishell.svn.sourceforge.net/cishell/?rev=1182&view=rev Author: kongchinhua Date: 2010-12-21 22:59:56 +0000 (Tue, 21 Dec 2010) Log Message: ----------- remove checkstyle builder Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/.project Modified: trunk/core/org.cishell.reference.service.database/.project =================================================================== --- trunk/core/org.cishell.reference.service.database/.project 2010-12-21 22:48:38 UTC (rev 1181) +++ trunk/core/org.cishell.reference.service.database/.project 2010-12-21 22:59:56 UTC (rev 1182) @@ -1,34 +1,32 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.cishell.reference.service.database</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> - </natures> -</projectDescription> +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.cishell.reference.service.database</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-12-21 22:48:44
|
Revision: 1181 http://cishell.svn.sourceforge.net/cishell/?rev=1181&view=rev Author: kongchinhua Date: 2010-12-21 22:48:38 +0000 (Tue, 21 Dec 2010) Log Message: ----------- remove from repository Removed Paths: ------------- trunk/core/org.cishell.reference.service.database/.checkstyle Deleted: trunk/core/org.cishell.reference.service.database/.checkstyle =================================================================== --- trunk/core/org.cishell.reference.service.database/.checkstyle 2010-12-20 22:16:06 UTC (rev 1180) +++ trunk/core/org.cishell.reference.service.database/.checkstyle 2010-12-21 22:48:38 UTC (rev 1181) @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<fileset-config file-format-version="1.2.0" simple-config="true"> - <fileset name="all" enabled="true" check-config-name="CNS Checks (Eclipse)" local="false"> - <file-match-pattern match-pattern="." include-pattern="true"/> - </fileset> -</fileset-config> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-12-20 22:16:14
|
Revision: 1180 http://cishell.svn.sourceforge.net/cishell/?rev=1180&view=rev Author: kongchinhua Date: 2010-12-20 22:16:06 +0000 (Mon, 20 Dec 2010) Log Message: ----------- - Add ArrayUtilities.copyOf() to support expend array while copy - Use Arrays.copyOf instead of ArrayUtilities.copyOf due to JRE1.5 doesn't support Arrays.copyOf - Fixed style guide warnings in ArrayUtilities.java - Reviewed by Joseph Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2010-12-16 22:44:07 UTC (rev 1179) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2010-12-20 22:16:06 UTC (rev 1180) @@ -3,7 +3,11 @@ import java.util.Iterator; import java.util.List; -public class ArrayUtilities { +public final class ArrayUtilities { + + private ArrayUtilities() { + } + public static int indexOf(Object[] array, Object target) { for (int ii = 0; ii < array.length; ii++) { if (array[ii].equals(target)) { @@ -14,12 +18,12 @@ return -1; } - public static void swapFirstMatchToFront(Object[] array, List targets) { - for (Iterator targetsIt = targets.iterator(); targetsIt.hasNext();) { + public static void swapFirstMatchToFront(Object[] array, List<?> targets) { + for (Iterator<?> targetsIt = targets.iterator(); targetsIt.hasNext();) { Object target = targetsIt.next(); int index = ArrayUtilities.indexOf(array, target); - if ( index != -1 ) { + if (index != -1) { swap(array, 0, index); return; } @@ -42,6 +46,31 @@ return clone; } + + /** + * This method will return a shadow copy of the given array with the desired size. + * If the given disiredSize exceeds the original array size, the remaining items + * will be filled with empty string. + * @param array - The original array to be copied + * @param desiredSize - The desired size of the new array + * @return The new copy of the original array with the desired size + */ + public static String[] copyOf(String[] array, int desiredSize) { + String[] newArray = new String[desiredSize]; + int copiedSize = Math.min(array.length, desiredSize); + + /* Copy items from the original array to new array */ + for (int i = 0; i < copiedSize; i++) { + newArray[i] = array[i]; + } + + /* Fill the extra items will empty string if there are */ + for (int i = copiedSize; i < desiredSize; i++) { + newArray[i] = ""; + } + + return newArray; + } // TODO: Find a better place to put this? public static <T> boolean allAreNull(T... objects) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-12-16 22:44:14
|
Revision: 1179 http://cishell.svn.sourceforge.net/cishell/?rev=1179&view=rev Author: kongchinhua Date: 2010-12-16 22:44:07 +0000 (Thu, 16 Dec 2010) Log Message: ----------- Add executeAlgorithm() to AlgorithmUtilities class to support non-progress monitoring execution Fix Database ISI loading issue on Load and Clean Change the Generic load to use Load and Clean by default Remove Load and Clean ISI from menu Create PrettyLabels method to support hierarchy labeling Reviewed by Micah 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/PrettyLabeler.java trunk/core/org.cishell.utilities/.project trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.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-12-13 18:48:52 UTC (rev 1178) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-12-16 22:44:07 UTC (rev 1179) @@ -130,7 +130,8 @@ } private Data[] labelFileData(File file, Data[] validatedFileData) { - Data[] labeledFileData = PrettyLabeler.relabelWithFileName(validatedFileData, file); + Data[] labeledFileData = PrettyLabeler.relabelWithFileNameHierarchy( + validatedFileData, file); return labeledFileData; } Modified: 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 2010-12-13 18:48:52 UTC (rev 1178) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java 2010-12-16 22:44:07 UTC (rev 1179) @@ -41,4 +41,44 @@ 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 Modified: trunk/core/org.cishell.utilities/.project =================================================================== --- trunk/core/org.cishell.utilities/.project 2010-12-13 18:48:52 UTC (rev 1178) +++ trunk/core/org.cishell.utilities/.project 2010-12-16 22:44:07 UTC (rev 1179) @@ -20,9 +20,15 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.jdt.core.javanature</nature> + <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> </natures> </projectDescription> Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java 2010-12-13 18:48:52 UTC (rev 1178) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java 2010-12-16 22:44:07 UTC (rev 1179) @@ -117,6 +117,9 @@ } } + /* + * Use this to execute algorithm with progress monitoring + */ @SuppressWarnings("unchecked") // Dictionary<String, Object> public static Data[] executeAlgorithm( AlgorithmFactory algorithmFactory, @@ -136,4 +139,17 @@ return result; } + + /* + * Use this to execute algorithm without progress monitoring + */ + public static Data[] executeAlgorithm( + AlgorithmFactory algorithmFactory, + Data[] data, + Dictionary parameters, + CIShellContext ciShellContext) + throws AlgorithmExecutionException { + + return executeAlgorithm(algorithmFactory, null, data, parameters, ciShellContext); + } } \ No newline at end of file Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2010-12-13 18:48:52 UTC (rev 1178) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2010-12-16 22:44:07 UTC (rev 1179) @@ -367,7 +367,7 @@ } if (!extension.startsWith(".")) { - extension = extension + "."; + extension = "." + extension; } String tempPath = System.getProperty("java.io.tmpdir"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-12-13 18:48:59
|
Revision: 1178 http://cishell.svn.sourceforge.net/cishell/?rev=1178&view=rev Author: pataphil Date: 2010-12-13 18:48:52 +0000 (Mon, 13 Dec 2010) Log Message: ----------- * Added StringUtilities.mapToString. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-11-27 03:47:24 UTC (rev 1177) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-12-13 18:48:52 UTC (rev 1178) @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import java.util.regex.Pattern; @@ -391,4 +392,16 @@ return writer.toString(); } + + public static String mapToString(Map<?, ?> map, String mapSeparator, String separator) { + List<String> mappedStrings = new ArrayList<String>(); + + for (Object key : map.keySet()) { + String mappedString = + String.format("%s%s%s", key.toString(), mapSeparator, map.get(key).toString()); + mappedStrings.add(mappedString); + } + + return implodeList(mappedStrings, separator); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |