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...> - 2009-11-05 21:00:05
|
Revision: 977 http://cishell.svn.sourceforge.net/cishell/?rev=977&view=rev Author: pataphil Date: 2009-11-05 20:59:55 +0000 (Thu, 05 Nov 2009) Log Message: ----------- * Added FileUtilities.loadFileFromClassPath. Not reviewed since it's so simple. 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 2009-11-03 20:01:05 UTC (rev 976) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-11-05 20:59:55 UTC (rev 977) @@ -9,6 +9,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; import java.nio.channels.FileChannel; import javax.imageio.ImageIO; @@ -225,6 +227,13 @@ } } + public static File loadFileFromClassPath(Class clazz, String filePath) + throws URISyntaxException { + URL fileURL = clazz.getResource(filePath); + + return new File(fileURL.toURI()); + } + private static File ensureDirectoryExists(String directoryPath) { File directory = new File(directoryPath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-11-03 20:01:27
|
Revision: 976 http://cishell.svn.sourceforge.net/cishell/?rev=976&view=rev Author: jrbibers Date: 2009-11-03 20:01:05 +0000 (Tue, 03 Nov 2009) Log Message: ----------- Added new constructor for BasicDataPlus. This plug-in is intended to be 1.4 compatible and so should not use the new-in-1.5 String method contains. Use in NumberUtilities was corrected to test indexOf != -1. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java 2009-10-30 19:58:48 UTC (rev 975) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java 2009-11-03 20:01:05 UTC (rev 976) @@ -32,8 +32,19 @@ } /** + * The type of inner is assumed to be the toString value of its Class. * * @param inner The object wrapped by this Data. + * @param parent The parent of inner. + */ + public BasicDataPlus(Object inner, Data parent) { + this(inner); + setParent(parent); + } + + /** + * + * @param inner The object wrapped by this Data. * @param type The _TYPE constant from {@link DataProperty} * that best characterizes the type of inner. * @param parent The parent of inner. Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-30 19:58:48 UTC (rev 975) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-11-03 20:01:05 UTC (rev 976) @@ -119,7 +119,7 @@ */ public static String convertToDecimalNotation(String numberAsString) { // Check for a scientific notation delimiter. - if (numberAsString.contains("E") || numberAsString.contains("e")) { + if (numberAsString.indexOf("E") != -1 || numberAsString.indexOf("e") != -1) { Format format = new DecimalFormat(UNROUNDED_DECIMAL_PATTERN); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-30 19:59:10
|
Revision: 975 http://cishell.svn.sourceforge.net/cishell/?rev=975&view=rev Author: pataphil Date: 2009-10-30 19:58:48 +0000 (Fri, 30 Oct 2009) Log Message: ----------- * Added NumberUtilities.convertToDecimalNotation (both versions). * Note the TODO about updating the plot/csv converter plugin. * Reviewed by Joseph. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-27 22:03:00 UTC (rev 974) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-30 19:58:48 UTC (rev 975) @@ -1,6 +1,13 @@ package org.cishell.utilities; +import java.text.DecimalFormat; +import java.text.Format; + public class NumberUtilities { + public static final String UNROUNDED_DECIMAL_PATTERN = + "#.############################"; + public static final String NOT_A_NUMBER_PREFIX = "NOT A NUMBER"; + public static Double interpretObjectAsDouble(Object object) throws NumberFormatException { final String EMPTY_CELL_MESSAGE = "An empty number cell was found."; @@ -12,104 +19,84 @@ Number number = (Number)object; return new Double(number.doubleValue()); - } - else if (object instanceof short[]) { + } else if (object instanceof short[]) { short[] objectAsShortArray = (short[])object; if (objectAsShortArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsShortArray[0]); } - } - else if (object instanceof Short[]) { + } else if (object instanceof Short[]) { Short[] objectAsShortArray = (Short[])object; if (objectAsShortArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsShortArray[0].doubleValue()); } - } - else if (object instanceof int[]) { + } else if (object instanceof int[]) { int[] objectAsIntArray = (int[])object; if (objectAsIntArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsIntArray[0]); } - } - else if (object instanceof Integer[]) { + } else if (object instanceof Integer[]) { Integer[] objectAsIntegerArray = (Integer[])object; if (objectAsIntegerArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsIntegerArray[0].doubleValue()); } - } - else if (object instanceof long[]) { + } else if (object instanceof long[]) { long[] objectAsLongArray = (long[])object; if (objectAsLongArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsLongArray[0]); } - } - else if (object instanceof Long[]) { + } else if (object instanceof Long[]) { Long[] objectAsLongArray = (Long[])object; if (objectAsLongArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsLongArray[0].doubleValue()); } - } - else if (object instanceof float[]) { + } else if (object instanceof float[]) { float[] objectAsFloatArray = (float[])object; if (objectAsFloatArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsFloatArray[0]); } - } - else if (object instanceof Float[]) { + } else if (object instanceof Float[]) { Float[] objectAsFloatArray = (Float[])object; if (objectAsFloatArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsFloatArray[0].doubleValue()); } - } - else if (object instanceof double[]) { + } else if (object instanceof double[]) { double[] objectAsDoubleArray = (double[])object; if (objectAsDoubleArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return new Double(objectAsDoubleArray[0]); } - } - else if (object instanceof Double[]) { + } else if (object instanceof Double[]) { Double[] objectAsDoubleArray = (Double[])object; if (objectAsDoubleArray.length == 0) { throw new NumberFormatException(EMPTY_CELL_MESSAGE); - } - else { + } else { return objectAsDoubleArray[0]; } } @@ -118,4 +105,31 @@ return new Double(objectAsString); } + + // TODO: Make the plot/csv converter use these versions. + public static String convertToDecimalNotation(double number) { + String numberAsString = new Double(number).toString(); + + return convertToDecimalNotation(numberAsString); + } + + /* + * If numberAsString holds a number in scientific notation, + * convert it to decimal notation. + */ + public static String convertToDecimalNotation(String numberAsString) { + // Check for a scientific notation delimiter. + if (numberAsString.contains("E") || numberAsString.contains("e")) { + Format format = + new DecimalFormat(UNROUNDED_DECIMAL_PATTERN); + + try { + return format.format(new Double(numberAsString)); + } catch (NumberFormatException numberFormatException) { + return NOT_A_NUMBER_PREFIX + " (" + numberAsString + ")"; + } + } else { + return numberAsString; + } + } } \ 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...> - 2009-10-27 22:03:11
|
Revision: 974 http://cishell.svn.sourceforge.net/cishell/?rev=974&view=rev Author: jrbibers Date: 2009-10-27 22:03:00 +0000 (Tue, 27 Oct 2009) Log Message: ----------- Added AlgorithmUtilities method for trying to parse filenames from the DataProperty.LABEL from a Data. It chains up through DataProperty.PARENT until one is found or we reach the topmost parent. Restructured the mutateParameters package and updated dependent plug-ins to reflect this. Added a new AttributeDefinitionTransformer for setting default values. Reviewed by Patrick. Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultDefaultValueTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultValueTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DefaultDropdownTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownTransformer.java Removed Paths: ------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2009-10-27 22:03:00 UTC (rev 974) @@ -18,4 +18,6 @@ prefuse.util, prefuse.util.collections Export-Package: org.cishell.utilities, - org.cishell.utilities.mutateParameter + org.cishell.utilities.mutateParameter, + org.cishell.utilities.mutateParameter.defaultvalue, + org.cishell.utilities.mutateParameter.dropdown Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java 2009-10-27 22:03:00 UTC (rev 974) @@ -1,13 +1,16 @@ package org.cishell.utilities; +import java.io.File; +import java.util.Dictionary; + 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.osgi.framework.BundleContext; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; - public class AlgorithmUtilities { // TODO: ISILoadAndCleanAlgorithmFactory should use this? // It's copied directly from it (and cleaned up a little bit)... @@ -53,4 +56,64 @@ data[0].getData(), data[0].getFormat()) }; } + + /** + * Check data's label for something that looks like a file path. + * If found, try to extract a filename. + * If either bit fails, check same on the parent data, if present. + * The first filename-y text found this way is returned. + * If we fail all the way to the top parent (that is, data == null), return the empty string. + * + * @param data From whose label and parent labels to attempt filename extractions. + * @return A guess at the filename from data's label or its (transitively) parent labels. + * null when none can be found. + */ + /* TODO: A superior approach might be to define a new "standard" metadata + * property (i.e. DataProperty.ORIGINAL_DATASET or something). + * When searching for the source data (file)name, that new property would + * take precedent, and guessSourceDataFilename would be a default. + * To do this properly, the File Load algorithm would need to set this new + * property to the filename the user chose. On the same token, upon + * receiving a new data item, the Data Manager algorithm would set this new + * property to the data item's label if not set already. + */ + public static String guessSourceDataFilename(Data data) { + if (data == null) { + return ""; + } + + Dictionary metadata = data.getMetadata(); + String label = (String) metadata.get(DataProperty.LABEL); + Data parent = (Data) metadata.get(DataProperty.PARENT); + + if (label != null && label.indexOf(File.separator) != -1) { + /* If fileSeparator is a single backslash, + * escape it for the split() regular expression. + */ + String escapedFileSeparator = File.separator; + if ("\\".equals(escapedFileSeparator)) { + escapedFileSeparator = "\\\\"; + } + + String[] pathTokens = label.split(escapedFileSeparator); + + String guessedFilename = pathTokens[pathTokens.length - 1]; + + int lastExtensionSeparatorIndex = guessedFilename.lastIndexOf("."); + if (lastExtensionSeparatorIndex != -1) { + // Part before the extension ("foo" for "foo.bar"). + String guessedNameProper = + guessedFilename.substring(0, lastExtensionSeparatorIndex); + // ".bar" for "foo.bar". + String guessedExtension = guessedFilename.substring(lastExtensionSeparatorIndex); + String[] extensionTokens = guessedExtension.split("\\s+"); + + return guessedNameProper + extensionTokens[0]; + } else { + return guessSourceDataFilename(parent); + } + } else { + return guessSourceDataFilename(parent); + } + } } \ No newline at end of file Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2009-10-27 22:03:00 UTC (rev 974) @@ -6,15 +6,16 @@ import org.cishell.reference.service.metatype.BasicObjectClassDefinition; import org.cishell.utilities.mutateParameter.AttributeDefinitionTransformer; -import org.cishell.utilities.mutateParameter.NullDropdownTransformer; import org.cishell.utilities.mutateParameter.ObjectClassDefinitionTransformer; +import org.cishell.utilities.mutateParameter.defaultvalue.DefaultDefaultValueTransformer; +import org.cishell.utilities.mutateParameter.dropdown.DefaultDropdownTransformer; import org.osgi.service.metatype.AttributeDefinition; import org.osgi.service.metatype.ObjectClassDefinition; import prefuse.data.Table; public class MutateParameterUtilities { - /* TODO The mutateParameter subpackage is meant to eliminate all of the loops + /* TODO The mutateParameter subpackage is meant to replace most of the loops * that invoke the formFooAttributeDefinition methods. */ @@ -98,7 +99,7 @@ final String[] optionLabels, final String[] optionValues) { AttributeDefinitionTransformer transformer = - new NullDropdownTransformer() { + new DefaultDropdownTransformer() { public boolean shouldTransform(AttributeDefinition ad) { return true; } @@ -138,9 +139,9 @@ final String[] optionLabels, final String[] optionValues) { AttributeDefinitionTransformer dropdownTransformer = - new NullDropdownTransformer() { + new DefaultDropdownTransformer() { public boolean shouldTransform(AttributeDefinition ad) { - return parameterID.equals(ad.getID()); + return ad.getID().equals(parameterID); } public String[] transformOptionLabels( @@ -153,10 +154,27 @@ } }; - return ObjectClassDefinitionTransformer.apply(dropdownTransformer, - oldOCD); + return ObjectClassDefinitionTransformer.apply(dropdownTransformer, oldOCD); } + public static BasicObjectClassDefinition mutateDefaultValue( + ObjectClassDefinition oldOCD, + final String parameterID, + final String defaultValue) { + AttributeDefinitionTransformer transformer = + new DefaultDefaultValueTransformer() { + public boolean shouldTransform(AttributeDefinition ad) { + return ad.getID().equals(parameterID); + } + + public String transformDefaultValue(String[] oldDefaultValue) { + return defaultValue; + } + }; + + return ObjectClassDefinitionTransformer.apply(transformer, oldOCD); + } + public static BasicObjectClassDefinition createNewParameters( ObjectClassDefinition oldParameters) { try { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -2,9 +2,8 @@ import org.osgi.service.metatype.AttributeDefinition; -/* There would be one implementation of this interface for each useful - * constructor of BasicAttributeDefinition, where the transform is defined as in - * DropdownTransformer. +/** + * This interface and its sub-interfaces correspond to constructors of BasicObjectClassDefinition. */ public interface AttributeDefinitionTransformer { public boolean shouldTransform(AttributeDefinition ad); Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java 2009-10-27 22:03:00 UTC (rev 974) @@ -1,127 +0,0 @@ -package org.cishell.utilities.mutateParameter; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.cishell.utilities.ArrayUtilities; -import org.osgi.service.metatype.AttributeDefinition; -import org.osgi.service.metatype.ObjectClassDefinition; - -/* For aggregating and applying DropdownTransforms. - * Many convenience methods are given to support arrays vs. Lists - * and default vs. no default. - * The core functionality - * is in add(final String, final String[], final String[]) - * and mutate(ObjectClassDefinition) - */ -public class DropdownMutator { - private List transforms; - - public DropdownMutator() { - transforms = new ArrayList(); - } - - public ObjectClassDefinition mutate(ObjectClassDefinition ocd) { - return ObjectClassDefinitionTransformer.transform(ocd, transforms); - } - - public void add(String id, List options, String defaultOption) { - add(id, swapToFront(options, defaultOption)); - } - - public void add(String id, List options) { - add(id, options, options); - } - - public void add(String id, - List optionLabels, - String defaultOptionLabel, - List optionValues, - String defaultOptionValue) { - add(id, - swapToFront(optionLabels, defaultOptionLabel), - swapToFront(optionValues, defaultOptionValue)); - } - - public void add(String id, List optionLabels, List optionValues) { - add(id, - (String[]) optionLabels.toArray(new String[0]), - (String[]) optionValues.toArray(new String[0])); - } - - public void add(String id, String[] options, String defaultOption) { - add(id, swapToFront(options, defaultOption)); - } - - public void add(String id, String[] options) { - add(id, options, options); - } - - public void add(final String id, - final String[] optionLabels, - String defaultOptionLabel, - final String[] optionValues, - String defaultOptionValue) { - add(id, - swapToFront(optionLabels, defaultOptionLabel), - swapToFront(optionValues, defaultOptionValue)); - } - - public void add(final String id, - final String[] optionLabels, - final String[] optionValues) { - transforms.add( - new NullDropdownTransformer() { - public boolean shouldTransform(AttributeDefinition ad) { - return id.equals(ad.getID()); - } - - public String[] transformOptionLabels(String[] oldOptionLabels) { - return optionLabels; - } - - public String[] transformOptionValues(String[] oldOptionValues) { - return optionValues; - } - }); - } - - private static List swapToFront(List list, String target) { - if (list.contains(target)) { - int targetIndex = list.indexOf(target); - - List swappedList = new ArrayList(list.size()); - - for (Iterator listIt = list.iterator(); listIt.hasNext();) { - swappedList.add(listIt.next()); - } - - swappedList.set(0, list.get(targetIndex)); - swappedList.set(targetIndex, list.get(0)); - - return swappedList; - } else { - return list; - } - } - - private static String[] swapToFront(String[] array, String target) { - int targetIndex = ArrayUtilities.indexOf(array, target); - - if (targetIndex != -1) { - String[] swappedArray = new String[array.length]; - - for (int ii = 0; ii < array.length; ii++) { - swappedArray[ii] = array[ii]; - } - - swappedArray[0] = array[targetIndex]; - swappedArray[targetIndex] = array[0]; - - return swappedArray; - } else { - return array; - } - } -} Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -1,27 +0,0 @@ -package org.cishell.utilities.mutateParameter; - -import org.cishell.reference.service.metatype.BasicAttributeDefinition; -import org.osgi.service.metatype.AttributeDefinition; - -public abstract class DropdownTransformer - implements AttributeDefinitionTransformer { - public AttributeDefinition transform(AttributeDefinition oldAD) { - if (shouldTransform(oldAD)) { - return - new BasicAttributeDefinition( - transformID(oldAD.getID()), - transformName(oldAD.getName()), - transformDescription(oldAD.getDescription()), - transformType(oldAD.getType()), - transformOptionLabels(oldAD.getOptionLabels()), - transformOptionValues(oldAD.getOptionValues())); - } - else { - return oldAD; - } - } - - public abstract String[] transformOptionLabels(String[] oldOptionLabels); - public abstract String[] transformOptionValues(String[] oldOptionValues); -} - Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -1,38 +0,0 @@ -package org.cishell.utilities.mutateParameter; - -import org.osgi.service.metatype.AttributeDefinition; - -/* A dropdown-forming AttributeDefinition transformer which by default - * performs no transformation. - * This is a convenient access to DropdownTransformer where you may override - * methods to transform only the arguments that you wish to modify. - * The typical case would be extending shouldTransform (think of as a filter), - * transformOptionLabels, and transformOptionValues. - */ -public abstract class NullDropdownTransformer extends DropdownTransformer { - public abstract boolean shouldTransform(AttributeDefinition ad); - - public String transformID(String oldID) { - return oldID; - } - - public String transformName(String oldName) { - return oldName; - } - - public String transformDescription(String oldDescription) { - return oldDescription; - } - - public int transformType(int oldType) { - return oldType; - } - - public String[] transformOptionLabels(String[] oldOptionLabels) { - return oldOptionLabels; - } - - public String[] transformOptionValues(String[] oldOptionValues) { - return oldOptionValues; - } -} \ No newline at end of file Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2009-10-21 19:17:41 UTC (rev 973) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -16,7 +16,6 @@ * "Atomic" to exclude blanket filters like ObjectClassDefinition.ALL. * @see ObjectClassDefinition#REQUIRED * @see ObjectClassDefinition#OPTIONAL - * @see ObjectClassDefinition#ALL */ public static final List ATOMIC_ATTRIBUTE_DEFINITION_FILTERS; static { Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultDefaultValueTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultDefaultValueTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultDefaultValueTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -0,0 +1,41 @@ +package org.cishell.utilities.mutateParameter.defaultvalue; + +import org.osgi.service.metatype.AttributeDefinition; + +/** + * Default Default-Value Transformer (the first in the sense of this being the simplest + * implementation of DefaultValueTransformer. + * <p/> + * A (single-valued) default-value-setting AttributeDefinition transformer + * which by default performs no transformation. + * <p/> + * This is a convenient access to DefaultValueTransformer where you may override + * methods to transform only the arguments that you wish to modify. + * The typical case would be extending shouldTransform (think of as a filter) + * and transformDefaultValue. + * + * @see org.cishell.utilities.MutateParameterUtilities#mutateDefaultValue(ObjectClassDefinition, String, String) + */ +public abstract class DefaultDefaultValueTransformer extends DefaultValueTransformer { + public abstract boolean shouldTransform(AttributeDefinition ad); + + public String transformDescription(String oldDescription) { + return oldDescription; + } + + public String transformID(String oldID) { + return oldID; + } + + public String transformName(String oldName) { + return oldName; + } + + public int transformType(int oldType) { + return oldType; + } + + public String transformDefaultValue(String oldDefaultValue) { + return oldDefaultValue; + } +} Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultValueTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultValueTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/defaultvalue/DefaultValueTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -0,0 +1,26 @@ +package org.cishell.utilities.mutateParameter.defaultvalue; + +import org.cishell.reference.service.metatype.BasicAttributeDefinition; +import org.cishell.utilities.mutateParameter.AttributeDefinitionTransformer; +import org.osgi.service.metatype.AttributeDefinition; + +public abstract class DefaultValueTransformer implements AttributeDefinitionTransformer { + /** + * @see BasicAttributeDefinition#BasicAttributeDefinition(String, String, String, int, String) + */ + public AttributeDefinition transform(AttributeDefinition oldAD) { + if (shouldTransform(oldAD)) { + return + new BasicAttributeDefinition( + transformID(oldAD.getID()), + transformName(oldAD.getName()), + transformDescription(oldAD.getDescription()), + transformType(oldAD.getType()), + transformDefaultValue(oldAD.getDefaultValue())); + } else { + return oldAD; + } + } + + public abstract String transformDefaultValue(String[] oldDefaultValue); +} Copied: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DefaultDropdownTransformer.java (from rev 972, trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java) =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DefaultDropdownTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DefaultDropdownTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -0,0 +1,40 @@ +package org.cishell.utilities.mutateParameter.dropdown; + +import org.osgi.service.metatype.AttributeDefinition; + +/** + * A dropdown-forming AttributeDefinition transformer which by default performs no transformation. + * This is a convenient access to DropdownTransformer where you may override + * methods to transform only the arguments that you wish to modify. + * The typical case would be extending shouldTransform (think of as a filter), + * transformOptionLabels, and transformOptionValues. + * + * @see org.cishell.utilities.MutateParameterUtilities#mutateToDropdown(ObjectClassDefinition, String, String[], String[]) + */ +public abstract class DefaultDropdownTransformer extends DropdownTransformer { + public abstract boolean shouldTransform(AttributeDefinition ad); + + public String transformID(String oldID) { + return oldID; + } + + public String transformName(String oldName) { + return oldName; + } + + public String transformDescription(String oldDescription) { + return oldDescription; + } + + public int transformType(int oldType) { + return oldType; + } + + public String[] transformOptionLabels(String[] oldOptionLabels) { + return oldOptionLabels; + } + + public String[] transformOptionValues(String[] oldOptionValues) { + return oldOptionValues; + } +} \ No newline at end of file Copied: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java (from rev 972, trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java) =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java 2009-10-27 22:03:00 UTC (rev 974) @@ -0,0 +1,128 @@ +package org.cishell.utilities.mutateParameter.dropdown; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.cishell.utilities.ArrayUtilities; +import org.cishell.utilities.mutateParameter.ObjectClassDefinitionTransformer; +import org.osgi.service.metatype.AttributeDefinition; +import org.osgi.service.metatype.ObjectClassDefinition; + +/* For aggregating and applying DropdownTransforms. + * Many convenience methods are given to support arrays vs. Lists + * and default vs. no default. + * The core functionality + * is in add(final String, final String[], final String[]) + * and mutate(ObjectClassDefinition) + */ +public class DropdownMutator { + private List transforms; + + public DropdownMutator() { + transforms = new ArrayList(); + } + + public ObjectClassDefinition mutate(ObjectClassDefinition ocd) { + return ObjectClassDefinitionTransformer.transform(ocd, transforms); + } + + public void add(String id, List options, String defaultOption) { + add(id, swapToFront(options, defaultOption)); + } + + public void add(String id, List options) { + add(id, options, options); + } + + public void add(String id, + List optionLabels, + String defaultOptionLabel, + List optionValues, + String defaultOptionValue) { + add(id, + swapToFront(optionLabels, defaultOptionLabel), + swapToFront(optionValues, defaultOptionValue)); + } + + public void add(String id, List optionLabels, List optionValues) { + add(id, + (String[]) optionLabels.toArray(new String[0]), + (String[]) optionValues.toArray(new String[0])); + } + + public void add(String id, String[] options, String defaultOption) { + add(id, swapToFront(options, defaultOption)); + } + + public void add(String id, String[] options) { + add(id, options, options); + } + + public void add(final String id, + final String[] optionLabels, + String defaultOptionLabel, + final String[] optionValues, + String defaultOptionValue) { + add(id, + swapToFront(optionLabels, defaultOptionLabel), + swapToFront(optionValues, defaultOptionValue)); + } + + public void add(final String id, + final String[] optionLabels, + final String[] optionValues) { + transforms.add( + new DefaultDropdownTransformer() { + public boolean shouldTransform(AttributeDefinition ad) { + return id.equals(ad.getID()); + } + + public String[] transformOptionLabels(String[] oldOptionLabels) { + return optionLabels; + } + + public String[] transformOptionValues(String[] oldOptionValues) { + return optionValues; + } + }); + } + + private static List swapToFront(List list, String target) { + if (list.contains(target)) { + int targetIndex = list.indexOf(target); + + List swappedList = new ArrayList(list.size()); + + for (Iterator listIt = list.iterator(); listIt.hasNext();) { + swappedList.add(listIt.next()); + } + + swappedList.set(0, list.get(targetIndex)); + swappedList.set(targetIndex, list.get(0)); + + return swappedList; + } else { + return list; + } + } + + private static String[] swapToFront(String[] array, String target) { + int targetIndex = ArrayUtilities.indexOf(array, target); + + if (targetIndex != -1) { + String[] swappedArray = new String[array.length]; + + for (int ii = 0; ii < array.length; ii++) { + swappedArray[ii] = array[ii]; + } + + swappedArray[0] = array[targetIndex]; + swappedArray[targetIndex] = array[0]; + + return swappedArray; + } else { + return array; + } + } +} Copied: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownTransformer.java (from rev 972, trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java) =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownTransformer.java 2009-10-27 22:03:00 UTC (rev 974) @@ -0,0 +1,31 @@ +package org.cishell.utilities.mutateParameter.dropdown; + +import org.cishell.reference.service.metatype.BasicAttributeDefinition; +import org.cishell.utilities.mutateParameter.AttributeDefinitionTransformer; +import org.osgi.service.metatype.AttributeDefinition; + +public abstract class DropdownTransformer + implements AttributeDefinitionTransformer { + /** + * @see BasicAttributeDefinition#BasicAttributeDefinition(String, String, String, int, String[], String[]) + */ + public AttributeDefinition transform(AttributeDefinition oldAD) { + if (shouldTransform(oldAD)) { + return + new BasicAttributeDefinition( + transformID(oldAD.getID()), + transformName(oldAD.getName()), + transformDescription(oldAD.getDescription()), + transformType(oldAD.getType()), + transformOptionLabels(oldAD.getOptionLabels()), + transformOptionValues(oldAD.getOptionValues())); + } + else { + return oldAD; + } + } + + public abstract String[] transformOptionLabels(String[] oldOptionLabels); + public abstract String[] transformOptionValues(String[] oldOptionValues); +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-10-21 19:17:49
|
Revision: 973 http://cishell.svn.sourceforge.net/cishell/?rev=973&view=rev Author: jrbibers Date: 2009-10-21 19:17:41 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Added CIShell utility class "BasicDataPlus", which extends BasicData to add convenience constructors and methods. Hoping this will find use among developers when returning Data[] from the execute method of new Algorithms. Reviewed by Micah. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java 2009-10-21 19:17:41 UTC (rev 973) @@ -0,0 +1,87 @@ +package org.cishell.utilities; + +import org.cishell.framework.data.BasicData; +import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; + +/** + * Subclass adding only convenience methods and constructors, + * chiefly to the Dictionary of properties (metadata). + * <p/> + * These changes would be made to {@link Data} and {@link BasicData} + * rather than tacking on a subclass, but we are eager to keep existing code operable. + * <p/> + * Mind the difference between "format" and "type"! + */ +public class BasicDataPlus extends BasicData { + /** + * @param inner The object wrapped by this Data. + * @param format See {@link org.cishell.framework.data.Data#getFormat()}. + */ + public BasicDataPlus(Object inner, String format) { + super(inner, format); + } + + /** + * The inner data's format is assumed to be the toString value of its Class. + * + * @param inner The datum wrapped by this object. + */ + public BasicDataPlus(Object inner) { + this(inner, inner.getClass().toString()); + } + + /** + * + * @param inner The object wrapped by this Data. + * @param type The _TYPE constant from {@link DataProperty} + * that best characterizes the type of inner. + * @param parent The parent of inner. + */ + public BasicDataPlus(Object inner, String type, Data parent) { + this(inner); + setType(type); + setParent(parent); + } + + /** + * @see DataProperty#LABEL + */ + public void setLabel(String label) { + getMetadata().put(DataProperty.LABEL, label); + } + + /** + * @see DataProperty#SHORT_LABEL + */ + public void setShortLabel(String shortLabel) { + getMetadata().put(DataProperty.SHORT_LABEL, shortLabel); + } + + /** + * @see DataProperty#PARENT + */ + public void setParent(Data parent) { + getMetadata().put(DataProperty.PARENT, parent); + } + + /** + * @see DataProperty#TYPE + */ + public void setType(String type) { + getMetadata().put(DataProperty.TYPE, type); + } + + /** + * @see DataProperty#MODIFIED + */ + public void setModified(boolean modified) { + getMetadata().put(DataProperty.MODIFIED, new Boolean(modified)); + } + public void markAsModified() { + setModified(true); + } + public void markAsUnmodified() { + setModified(false); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-20 17:37:11
|
Revision: 972 http://cishell.svn.sourceforge.net/cishell/?rev=972&view=rev Author: pataphil Date: 2009-10-20 17:37:04 +0000 (Tue, 20 Oct 2009) Log Message: ----------- DateUtilities.parseDate now has flavors where the year can be "fixed". (Java's built-in Date class subtracts 1900 from the year by default; parseDate optionally "fixes" the year by adding 1900 back to it.) Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-19 18:50:27 UTC (rev 971) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-20 17:37:04 UTC (rev 972) @@ -223,33 +223,50 @@ }; public static Date parseDate(String dateString) throws ParseException { + return parseDate(dateString, true); + } + + public static Date parseDate(String dateString, boolean fixYear) + throws ParseException { return (parseDate(dateString, MONTH_DAY_YEAR_DATE_FORMATS)); } public static Date parseDate(String dateString, String suggestedDateFormat) throws ParseException { + return parseDate(dateString, suggestedDateFormat, true); + } + + public static Date parseDate( + String dateString, String suggestedDateFormat, boolean fixYear) + throws ParseException { if (MONTH_DAY_YEAR_DATE_FORMAT.equals(suggestedDateFormat)) { - return parseDate(dateString, MONTH_DAY_YEAR_DATE_FORMATS); + return parseDate(dateString, MONTH_DAY_YEAR_DATE_FORMATS, fixYear); } else if (DAY_MONTH_YEAR_DATE_FORMAT.equals(suggestedDateFormat)) { - return parseDate(dateString, DAY_MONTH_YEAR_DATE_FORMATS); + return parseDate(dateString, DAY_MONTH_YEAR_DATE_FORMATS, fixYear); } else { DateFormat[] dateFormats = new DateFormat[] { new SimpleDateFormat(suggestedDateFormat) }; - return parseDate(dateString, dateFormats); + return parseDate(dateString, dateFormats, fixYear); } } public static Date parseDate(String dateString, DateFormat[] dateFormats) throws ParseException { + return parseDate(dateString, dateFormats, true); + } + + public static Date parseDate( + String dateString, DateFormat[] dateFormats, boolean fixYear) + throws ParseException { for (int ii = 0; ii < dateFormats.length; ii++) { try { DateFormat format = dateFormats[ii]; format.setLenient(false); Date date = format.parse(dateString); - if (date.getYear() < 1900) { + if (fixYear && (date.getYear() < 1900)) { date.setYear(date.getYear() + 1900); } @@ -274,6 +291,12 @@ public static Date interpretObjectAsDate(Object object, String dateFormat) throws ParseException { + return interpretObjectAsDate(object, dateFormat, true); + } + + public static Date interpretObjectAsDate( + Object object, String dateFormat, boolean fixYear) + throws ParseException { final String EMPTY_DATE_MESSAGE = "An empty date was found."; String objectAsString = object.toString(); @@ -355,37 +378,9 @@ } } - return parseDate(objectAsString, dateFormat); + return parseDate(objectAsString, dateFormat, fixYear); } -// private java.util.Date parseDate(String dateString) -// throws AlgorithmExecutionException { -// for (DateFormat format : MONTH_DAY_YEAR_DATE_FORMATS) { -// try { -// format.setLenient(false); -// java.util.Date date = format.parse(dateString); -// //WE PARSED THE DATE SUCCESSFULLY (if we get to this point)! -// //Finish up our processing and return the date. -// -// //TODO: Methinks this is a hack we should eliminate -// if (date.getYear() < 1900) -// date.setYear(date.getYear() + 1900); -// java.sql.Date dateForSQL = new java.sql.Date(date.getTime()); -// return dateForSQL; -// } catch (ParseException e) { -// continue; -// } -// } -// -// //we could not parse the date with any of the accepted formats. -// -// String exceptionMessage = -// "Could not parse the field " + -// "'" + dateString + "'" + -// " as a date. Aborting the algorithm."; -// throw new AlgorithmExecutionException(exceptionMessage); -// } - private static Date fixDateYear(Date date) { if (date.getYear() < 1900) { Date fixedDate = (Date)date.clone(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-10-19 18:50:40
|
Revision: 971 http://cishell.svn.sourceforge.net/cishell/?rev=971&view=rev Author: jrbibers Date: 2009-10-19 18:50:27 +0000 (Mon, 19 Oct 2009) Log Message: ----------- The suggested filename in the file save dialog is now checked for invalid filename characters (like ? or *). Any found are replaced with a #. Suggested filenames are produced from the item's label in the data manager. Since the label may contain characters which are not valid in filenames (like a quotation mark), previously the suggested filename could have been invalid and so the file save dialog would open with no suggestion. Now the user should always get a suggested filename. Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 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/FileUtil.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-10-19 04:53:55 UTC (rev 970) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-10-19 18:50:27 UTC (rev 971) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs 2009-10-19 04:53:55 UTC (rev 970) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs 2009-10-19 18:50:27 UTC (rev 971) @@ -1,3 +0,0 @@ -#Wed Sep 27 14:27:31 EDT 2006 -eclipse.preferences.version=1 -pluginProject.extensions=false 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 2009-10-19 04:53:55 UTC (rev 970) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2009-10-19 18:50:27 UTC (rev 971) @@ -24,3 +24,4 @@ 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.4 Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-10-19 04:53:55 UTC (rev 970) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-10-19 18:50:27 UTC (rev 971) @@ -2,10 +2,37 @@ import java.io.File; import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; import org.osgi.service.log.LogService; public class FileUtil { + public static final char FILENAME_CHARACTER_REPLACEMENT = '#'; + + /* Attempt to enumerate characters which cannot be used to name a file. + * For our purposes, this should be as aggressive as sensible. + * This includes all such characters for modern Windows systems, plus %. + * Please add any others. + */ + public static final Collection INVALID_FILENAME_CHARACTERS; + static { + Collection s = new HashSet(); + s.add(new Character('\\')); + s.add(new Character('/')); + s.add(new Character(':')); + s.add(new Character('*')); + s.add(new Character('?')); + s.add(new Character('"')); + s.add(new Character('<')); + s.add(new Character('>')); + s.add(new Character('|')); + s.add(new Character('%')); + INVALID_FILENAME_CHARACTERS = Collections.unmodifiableCollection(s); + } + private static int uniqueIntForTempFile = 1; public static File getTempFile(String fileName, String extension, LogService logger) { @@ -64,9 +91,22 @@ return extension; } - - public static String extractFileName(String fileLabel) { + + public static String replaceInvalidFilenameCharacters(String filename) { + String cleanedFilename = filename; + for (Iterator invalidCharacters = INVALID_FILENAME_CHARACTERS.iterator(); + invalidCharacters.hasNext();) { + char invalidCharacter = ((Character) invalidCharacters.next()).charValue(); + + cleanedFilename = + cleanedFilename.replace(invalidCharacter, FILENAME_CHARACTER_REPLACEMENT); + } + + return cleanedFilename; + } + + public static String extractFileName(String fileLabel) { //index variables will be -1 if index is not found. int descriptionEndIndex = fileLabel.lastIndexOf(":"); int filePathEndIndex = fileLabel.lastIndexOf(File.separator); @@ -75,9 +115,8 @@ //zero and none of the string will be cut off the front. int startIndex = Math.max(descriptionEndIndex, filePathEndIndex) + 1; - String fileNameWithExtension = fileLabel.substring(startIndex); + String fileNameWithExtension = fileLabel.substring(startIndex); - //find the first character of the file name extension. int extensionBeginIndex = fileNameWithExtension.lastIndexOf("."); @@ -93,8 +132,16 @@ } String fileNameWithoutExtension = fileNameWithExtension.substring(0, endIndex); - - String fileName = fileNameWithoutExtension; - return fileName; + + return fileNameWithoutExtension; } + + public static void main(String[] args) { +// String s = "Input data: CSV file: C:\\Documents and Settings\\katy\\Desktop\\NIH-Demo\\nih\\NIH-data\\NIH-NIGMS-PPBC-R01s,-FY08-Publications.csv"; + String s = "a\\b/c:d*e?f\"g<h>i|j"; + + System.out.println(replaceInvalidFilenameCharacters(s)); + + System.exit(0); + } } 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 2009-10-19 04:53:55 UTC (rev 970) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2009-10-19 18:50:27 UTC (rev 971) @@ -119,7 +119,9 @@ String fileLabel = (String)data.getMetadata().get(DataProperty.LABEL); String suggestedFileName = FileUtil.extractFileName(fileLabel); - dialog.setFileName(suggestedFileName + "." + ext); + String cleanedSuggestedFileName = + FileUtil.replaceInvalidFilenameCharacters(suggestedFileName); + dialog.setFileName(cleanedSuggestedFileName + "." + ext); // if (fileLabel == null) { // dialog.setFileName("*." + ext); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-19 04:54:03
|
Revision: 970 http://cishell.svn.sourceforge.net/cishell/?rev=970&view=rev Author: pataphil Date: 2009-10-19 04:53:55 +0000 (Mon, 19 Oct 2009) Log Message: ----------- Added StringUtilities.countOccurrencesOfChar and StringUtilities.multiply. 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 2009-10-17 20:09:31 UTC (rev 969) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-19 04:53:55 UTC (rev 970) @@ -98,4 +98,31 @@ return (trimmed.length() == 0); } + + public static int countOccurrencesOfChar( + CharSequence characters, char target) { + int count = 0; + + for (int ii = 0; ii < characters.length(); ii++) { + if (characters.charAt(ii) == target) { + count++; + } + } + + return count; + } + + public static String multiply(String target, int count) { + if (count < 1) { + return ""; + } else { + StringBuffer stringInProgress = new StringBuffer(); + + for (int ii = 0; ii < count; ii ++) { + stringInProgress.append(target); + } + + return stringInProgress.toString(); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-17 20:33:33
|
Revision: 968 http://cishell.svn.sourceforge.net/cishell/?rev=968&view=rev Author: pataphil Date: 2009-10-17 19:59:58 +0000 (Sat, 17 Oct 2009) Log Message: ----------- Changed contents of DateUtilities.MONTH_DAY_YEAR_DATE_FORMAT and DateUtilities.DAY_MONTH_YEAR_DATE_FORMAT to reflect Katy's requests. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-17 00:25:32 UTC (rev 967) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-17 19:59:58 UTC (rev 968) @@ -10,10 +10,10 @@ // TODO: Fix this class. public class DateUtilities { - public static final String MONTH_DAY_DATE_FORMAT = - "Month-Then-Day Date Format"; - public static final String DAY_MONTH_DATE_FORMAT = - "Day-Then-Month Date Format"; + public static final String MONTH_DAY_YEAR_DATE_FORMAT = + "Month-Day-Year Date Format"; + public static final String DAY_MONTH_YEAR_DATE_FORMAT = + "Day-Month-Year Date Format"; public final static double AVERAGE_MILLIS_PER_MONTH = (365.24 * 24 * 60 * 60 * 1000 / 12); @@ -225,11 +225,11 @@ public static Date parseDate(String dateString, String suggestedDateFormat) throws ParseException { /*System.err.println("suggestedDateFormat: " + suggestedDateFormat); - System.err.println("MONTH_DAY_DATE_FORMAT: " + MONTH_DAY_DATE_FORMAT); - System.err.println("DAY_MONTH_DATE_FORMAT: " + DAY_MONTH_DATE_FORMAT);*/ - if (MONTH_DAY_DATE_FORMAT.equals(suggestedDateFormat)) { + System.err.println("MONTH_DAY_YEAR_DATE_FORMAT: " + MONTH_DAY_YEAR_DATE_FORMAT); + System.err.println("DAY_MONTH_YEAR_DATE_FORMAT: " + DAY_MONTH_YEAR_DATE_FORMAT);*/ + if (MONTH_DAY_YEAR_DATE_FORMAT.equals(suggestedDateFormat)) { return parseDate(dateString, MONTH_DAY_DATE_FORMATS); - } else if (DAY_MONTH_DATE_FORMAT.equals(suggestedDateFormat)) { + } else if (DAY_MONTH_YEAR_DATE_FORMAT.equals(suggestedDateFormat)) { return parseDate(dateString, DAY_MONTH_DATE_FORMATS); } else { DateFormat[] dateFormats = new DateFormat[] { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-17 20:09:37
|
Revision: 969 http://cishell.svn.sourceforge.net/cishell/?rev=969&view=rev Author: pataphil Date: 2009-10-17 20:09:31 +0000 (Sat, 17 Oct 2009) Log Message: ----------- * Added version of DateUtilities.parseDate that uses a default suggestedDateFormat (MONTH_DAY_YEAR_DATE_FORMAT) to make edu.iu.scipolicy.converter.nsf.csv_to_db happy. * Also renamed date format arrays to include YEAR_ in their names. * Removed some commented-out System.err.println calls. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-17 19:59:58 UTC (rev 968) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-17 20:09:31 UTC (rev 969) @@ -175,7 +175,7 @@ } //TODO: These should be sorted so the first format checked is the most likely format, etc... - private static final DateFormat[] MONTH_DAY_DATE_FORMATS = { + private static final DateFormat[] MONTH_DAY_YEAR_DATE_FORMATS = { new SimpleDateFormat("MM-d-yy"), new SimpleDateFormat("MM-d-yyyy"), new SimpleDateFormat("MM-dd-yy"), @@ -198,7 +198,7 @@ DateFormat.getDateInstance(DateFormat.LONG), }; - private static final DateFormat[] DAY_MONTH_DATE_FORMATS = { + private static final DateFormat[] DAY_MONTH_YEAR_DATE_FORMATS = { DateFormat.getDateInstance(DateFormat.FULL), new SimpleDateFormat("d-MM-yy"), new SimpleDateFormat("d-MM-yyyy"), @@ -222,15 +222,16 @@ DateFormat.getDateInstance(DateFormat.LONG), }; + public static Date parseDate(String dateString) throws ParseException { + return (parseDate(dateString, MONTH_DAY_YEAR_DATE_FORMATS)); + } + public static Date parseDate(String dateString, String suggestedDateFormat) throws ParseException { - /*System.err.println("suggestedDateFormat: " + suggestedDateFormat); - System.err.println("MONTH_DAY_YEAR_DATE_FORMAT: " + MONTH_DAY_YEAR_DATE_FORMAT); - System.err.println("DAY_MONTH_YEAR_DATE_FORMAT: " + DAY_MONTH_YEAR_DATE_FORMAT);*/ if (MONTH_DAY_YEAR_DATE_FORMAT.equals(suggestedDateFormat)) { - return parseDate(dateString, MONTH_DAY_DATE_FORMATS); + return parseDate(dateString, MONTH_DAY_YEAR_DATE_FORMATS); } else if (DAY_MONTH_YEAR_DATE_FORMAT.equals(suggestedDateFormat)) { - return parseDate(dateString, DAY_MONTH_DATE_FORMATS); + return parseDate(dateString, DAY_MONTH_YEAR_DATE_FORMATS); } else { DateFormat[] dateFormats = new DateFormat[] { new SimpleDateFormat(suggestedDateFormat) @@ -359,7 +360,7 @@ // private java.util.Date parseDate(String dateString) // throws AlgorithmExecutionException { -// for (DateFormat format : MONTH_DAY_DATE_FORMATS) { +// for (DateFormat format : MONTH_DAY_YEAR_DATE_FORMATS) { // try { // format.setLenient(false); // java.util.Date date = format.parse(dateString); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-17 00:25:42
|
Revision: 967 http://cishell.svn.sourceforge.net/cishell/?rev=967&view=rev Author: pataphil Date: 2009-10-17 00:25:32 +0000 (Sat, 17 Oct 2009) Log Message: ----------- DateUtilities.parseDate now supports month-day or day-month formatted dates, as well as an arbitrary date format string. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-16 19:38:51 UTC (rev 966) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-17 00:25:32 UTC (rev 967) @@ -10,6 +10,11 @@ // TODO: Fix this class. public class DateUtilities { + public static final String MONTH_DAY_DATE_FORMAT = + "Month-Then-Day Date Format"; + public static final String DAY_MONTH_DATE_FORMAT = + "Day-Then-Month Date Format"; + public final static double AVERAGE_MILLIS_PER_MONTH = (365.24 * 24 * 60 * 60 * 1000 / 12); @@ -170,7 +175,30 @@ } //TODO: These should be sorted so the first format checked is the most likely format, etc... - private static final DateFormat[] ACCEPTED_DATE_FORMATS = { + private static final DateFormat[] MONTH_DAY_DATE_FORMATS = { + new SimpleDateFormat("MM-d-yy"), + new SimpleDateFormat("MM-d-yyyy"), + new SimpleDateFormat("MM-dd-yy"), + new SimpleDateFormat("MM-dd-yyyy"), + new SimpleDateFormat("MM/d/yy"), + new SimpleDateFormat("MM/dd/yy"), + new SimpleDateFormat("MM/d/yyyy"), + new SimpleDateFormat("MMM/dd/yyyy"), + new SimpleDateFormat("MMM-d-yy"), + new SimpleDateFormat("MMM-d-yyyy"), + new SimpleDateFormat("MMM-dd-yy"), + new SimpleDateFormat("MMM-dd-yyyy"), + new SimpleDateFormat("MMM/d/yy"), + new SimpleDateFormat("MMM/dd/yy"), + new SimpleDateFormat("MMM/d/yyyy"), + new SimpleDateFormat("MMM/dd/yyyy"), + new SimpleDateFormat("yyyy"), + DateFormat.getDateInstance(DateFormat.SHORT), + DateFormat.getDateInstance(DateFormat.MEDIUM), + DateFormat.getDateInstance(DateFormat.LONG), + }; + + private static final DateFormat[] DAY_MONTH_DATE_FORMATS = { DateFormat.getDateInstance(DateFormat.FULL), new SimpleDateFormat("d-MM-yy"), new SimpleDateFormat("d-MM-yyyy"), @@ -194,11 +222,29 @@ DateFormat.getDateInstance(DateFormat.LONG), }; - public static Date parseDate(String dateString) + public static Date parseDate(String dateString, String suggestedDateFormat) throws ParseException { - for (int ii = 0; ii < ACCEPTED_DATE_FORMATS.length; ii++) { + /*System.err.println("suggestedDateFormat: " + suggestedDateFormat); + System.err.println("MONTH_DAY_DATE_FORMAT: " + MONTH_DAY_DATE_FORMAT); + System.err.println("DAY_MONTH_DATE_FORMAT: " + DAY_MONTH_DATE_FORMAT);*/ + if (MONTH_DAY_DATE_FORMAT.equals(suggestedDateFormat)) { + return parseDate(dateString, MONTH_DAY_DATE_FORMATS); + } else if (DAY_MONTH_DATE_FORMAT.equals(suggestedDateFormat)) { + return parseDate(dateString, DAY_MONTH_DATE_FORMATS); + } else { + DateFormat[] dateFormats = new DateFormat[] { + new SimpleDateFormat(suggestedDateFormat) + }; + + return parseDate(dateString, dateFormats); + } + } + + public static Date parseDate(String dateString, DateFormat[] dateFormats) + throws ParseException { + for (int ii = 0; ii < dateFormats.length; ii++) { try { - DateFormat format = ACCEPTED_DATE_FORMATS[ii]; + DateFormat format = dateFormats[ii]; format.setLenient(false); Date date = format.parse(dateString); @@ -221,7 +267,12 @@ } public static Date interpretObjectAsDate(Object object) - throws ParseException{ + throws ParseException { + return interpretObjectAsDate(object, ""); + } + + public static Date interpretObjectAsDate(Object object, String dateFormat) + throws ParseException { final String EMPTY_DATE_MESSAGE = "An empty date was found."; String objectAsString = object.toString(); @@ -303,12 +354,12 @@ } } - return parseDate(objectAsString); + return parseDate(objectAsString, dateFormat); } // private java.util.Date parseDate(String dateString) // throws AlgorithmExecutionException { -// for (DateFormat format : ACCEPTED_DATE_FORMATS) { +// for (DateFormat format : MONTH_DAY_DATE_FORMATS) { // try { // format.setLenient(false); // java.util.Date date = format.parse(dateString); @@ -333,4 +384,15 @@ // " as a date. Aborting the algorithm."; // throw new AlgorithmExecutionException(exceptionMessage); // } + + private static Date fixDateYear(Date date) { + if (date.getYear() < 1900) { + Date fixedDate = (Date)date.clone(); + fixedDate.setYear(date.getYear() + 1900); + + return fixedDate; + } else { + return date; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-16 19:39:08
|
Revision: 966 http://cishell.svn.sourceforge.net/cishell/?rev=966&view=rev Author: pataphil Date: 2009-10-16 19:38:51 +0000 (Fri, 16 Oct 2009) Log Message: ----------- * Improved documentation of StringUtilities.interpretObjectAsString. * Added TODOs to reflect considerations by Joseph and Russell. (No time to do them now.) * Reviewed by Joseph. 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 2009-10-16 19:02:20 UTC (rev 965) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-16 19:38:51 UTC (rev 966) @@ -67,12 +67,20 @@ * Prefuse table columns are typed. If a column contains a null cell, * Prefuse types that column as an array type, and it then represents * null values with arrays of length 0. + * To handle this, this method returns: + * null if the object is actually null or array of length 0; + * just the first element of the array; or + * the result of the object's toString method. */ + // TODO: Rename to interpretAsString. + // TODO: Move these things to TableUtilities. + // TODO: Handle all cases, including all primitive array types and + // perhaps primitive box types (i.e. Integer). public static String interpretObjectAsString(Object object) { if (object == null) { return null; } else if (object instanceof String[]) { - String[] objectAsStringArray = (String[])object; + String[] objectAsStringArray = (String[]) object; if (objectAsStringArray.length == 0) { return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-16 19:02:28
|
Revision: 965 http://cishell.svn.sourceforge.net/cishell/?rev=965&view=rev Author: pataphil Date: 2009-10-16 19:02:20 +0000 (Fri, 16 Oct 2009) Log Message: ----------- * Added StringUtilities.interpretObjectAsString and StringUtilities.isEmptyOrWhiteSpace. * Reviewed by Joseph. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-14 21:27:55 UTC (rev 964) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-16 19:02:20 UTC (rev 965) @@ -82,7 +82,7 @@ endDate.getMonth(), endDate.getDate()); - return (int)startDateCalendar.diffDayPeriods(endDateCalendar); + return (int) startDateCalendar.diffDayPeriods(endDateCalendar); } public static int calculateMonthsBetween(Date startDate, Date endDate) { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-14 21:27:55 UTC (rev 964) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-16 19:02:20 UTC (rev 965) @@ -61,4 +61,33 @@ return (String[])filteredStrings.toArray(new String[0]); } + + /* + * This method is really meant to simplify working with Prefuse tables. + * Prefuse table columns are typed. If a column contains a null cell, + * Prefuse types that column as an array type, and it then represents + * null values with arrays of length 0. + */ + public static String interpretObjectAsString(Object object) { + if (object == null) { + return null; + } else if (object instanceof String[]) { + String[] objectAsStringArray = (String[])object; + + if (objectAsStringArray.length == 0) { + return null; + } else { + return objectAsStringArray[0]; + } + } else { + return object.toString(); + } + } + + // TODO Think about instead using a Pattern, "\s*". Don't have to though. + public static boolean isEmptyOrWhiteSpace(String test) { + String trimmed = test.trim(); + + return (trimmed.length() == 0); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-10-14 21:28:09
|
Revision: 964 http://cishell.svn.sourceforge.net/cishell/?rev=964&view=rev Author: jrbibers Date: 2009-10-14 21:27:55 +0000 (Wed, 14 Oct 2009) Log Message: ----------- Added TableUtilities.copyTable for copying prefuse Tables. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java 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/ArrayUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -16,7 +16,7 @@ public static void swapFirstMatchToFront(Object[] array, List targets) { for (Iterator targetsIt = targets.iterator(); targetsIt.hasNext();) { - Object target = (Object) targetsIt.next(); + Object target = targetsIt.next(); int index = ArrayUtilities.indexOf(array, target); if ( index != -1 ) { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java 2009-10-14 21:27:55 UTC (rev 964) @@ -12,7 +12,9 @@ * @copyright 2004 Paul Hill */ public class FAQCalendar extends GregorianCalendar { - /** + private static final long serialVersionUID = 1L; + + /** * All minutes have this many milliseconds except the last minute of the day on a day defined with * a leap second. */ Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -24,4 +24,4 @@ return bufferedImage; } -}; \ No newline at end of file +} \ No newline at end of file Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -20,7 +20,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsShortArray[0]); + return new Double(objectAsShortArray[0]); } } else if (object instanceof Short[]) { @@ -40,7 +40,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsIntArray[0]); + return new Double(objectAsIntArray[0]); } } else if (object instanceof Integer[]) { @@ -60,7 +60,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsLongArray[0]); + return new Double(objectAsLongArray[0]); } } else if (object instanceof Long[]) { @@ -80,7 +80,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsFloatArray[0]); + return new Double(objectAsFloatArray[0]); } } else if (object instanceof Float[]) { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -2,10 +2,12 @@ import java.util.ArrayList; import java.util.Date; +import java.util.Iterator; import java.util.List; import prefuse.data.Schema; import prefuse.data.Table; +import prefuse.data.Tuple; import prefuse.util.collections.IntIterator; public class TableUtilities { @@ -231,6 +233,9 @@ possibleNumberClasses); } + /** + * @deprecated Replace calls with schema.instantiate(). + */ public static Table createTableUsingSchema(Schema tableSchema) { final int numTableColumns = tableSchema.getColumnCount(); Table table = new Table(); @@ -293,4 +298,16 @@ return newTable; } + + public static Table copyTable(Table oldTable) { + Schema oldSchema = oldTable.getSchema(); + Table newTable = oldSchema.instantiate(); + + for (Iterator rowIt = oldTable.tuples(); rowIt.hasNext();) { + Tuple row = (Tuple) rowIt.next(); + newTable.addTuple(row); + } + + return newTable; + } } \ 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...> - 2009-10-13 18:01:14
|
Revision: 963 http://cishell.svn.sourceforge.net/cishell/?rev=963&view=rev Author: jrbibers Date: 2009-10-13 18:01:02 +0000 (Tue, 13 Oct 2009) Log Message: ----------- Fixes previous commit: two missing Integer boxings due to my JDK compliance being set to 1.5 (out of sync with the execution environment 1.4). Modified Paths: -------------- trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java Modified: trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs 2009-10-13 17:57:55 UTC (rev 962) +++ trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs 2009-10-13 18:01:02 UTC (rev 963) @@ -1,7 +1,12 @@ -#Fri Jan 16 16:03:38 EST 2009 +#Tue Oct 13 13:58:27 EDT 2009 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.source=1.3 Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java 2009-10-13 17:57:55 UTC (rev 962) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java 2009-10-13 18:01:02 UTC (rev 963) @@ -97,8 +97,8 @@ swappedList.add(listIt.next()); } - swappedList.set(0, (String) list.get(targetIndex)); - swappedList.set(targetIndex, (String) list.get(0)); + swappedList.set(0, list.get(targetIndex)); + swappedList.set(targetIndex, list.get(0)); return swappedList; } else { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2009-10-13 17:57:55 UTC (rev 962) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2009-10-13 18:01:02 UTC (rev 963) @@ -21,8 +21,8 @@ public static final List ATOMIC_ATTRIBUTE_DEFINITION_FILTERS; static { List l = new ArrayList(); - l.add(ObjectClassDefinition.REQUIRED); - l.add(ObjectClassDefinition.OPTIONAL); + l.add(new Integer(ObjectClassDefinition.REQUIRED)); + l.add(new Integer(ObjectClassDefinition.OPTIONAL)); ATOMIC_ATTRIBUTE_DEFINITION_FILTERS = Collections.unmodifiableList(l); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-10-13 17:58:04
|
Revision: 962 http://cishell.svn.sourceforge.net/cishell/?rev=962&view=rev Author: jrbibers Date: 2009-10-13 17:57:55 +0000 (Tue, 13 Oct 2009) Log Message: ----------- Corrected a design flaw in the mutateParameter utilities. To date, all parameters transformed using ObjectClassDefinitionTransformer have been uniformly written out with the attribute definition filter ObjectClassDefinition.REQUIRED. Now the transformer preserves each AttributeDefinition's original filter (currently one of ObjectClassDefinition.REQUIRED or ObjectClassDefinition.OPTIONAL, where this assumption is reflected in the constant ATOMIC_ATTRIBUTE_DEFINITION_FILTERS). This change should not alter the behavior of any plug-in currently depending on the mutateParameter utilities (since none, to my knowledge, have optional parameters). Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2009-10-12 18:29:29 UTC (rev 961) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2009-10-13 17:57:55 UTC (rev 962) @@ -3,7 +3,7 @@ Bundle-Name: Utilities Plug-in Bundle-SymbolicName: org.cishell.utilities Bundle-Version: 1.0.0 -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-RequiredExecutionEnvironment: J2SE-1.4 Import-Package: org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data, Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2009-10-12 18:29:29 UTC (rev 961) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2009-10-13 17:57:55 UTC (rev 962) @@ -1,5 +1,7 @@ package org.cishell.utilities.mutateParameter; +import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -9,10 +11,20 @@ import org.osgi.service.metatype.ObjectClassDefinition; public class ObjectClassDefinitionTransformer { - private static final int OUTGOING_ATTRIBUTES_FILTER = - ObjectClassDefinition.REQUIRED; - private static final int INCOMING_ATTRIBUTES_FILTER = - ObjectClassDefinition.ALL; + /** + * AttributeDefinition filters as described in ObjectClassDefinition. + * "Atomic" to exclude blanket filters like ObjectClassDefinition.ALL. + * @see ObjectClassDefinition#REQUIRED + * @see ObjectClassDefinition#OPTIONAL + * @see ObjectClassDefinition#ALL + */ + public static final List ATOMIC_ATTRIBUTE_DEFINITION_FILTERS; + static { + List l = new ArrayList(); + l.add(ObjectClassDefinition.REQUIRED); + l.add(ObjectClassDefinition.OPTIONAL); + ATOMIC_ATTRIBUTE_DEFINITION_FILTERS = Collections.unmodifiableList(l); + } /* Create newOCD from oldOCD by applying transformer * to each AttributeDefinition. @@ -23,12 +35,20 @@ BasicObjectClassDefinition newOCD = MutateParameterUtilities.createNewParameters(oldOCD); - AttributeDefinition[] oldADs = - oldOCD.getAttributeDefinitions(INCOMING_ATTRIBUTES_FILTER); - for (int ii = 0; ii < oldADs.length; ii++) { - newOCD.addAttributeDefinition( - OUTGOING_ATTRIBUTES_FILTER, - transformer.transform(oldADs[ii])); + // For each kind of AttributeDefinition filter .. + for (Iterator filterIt = ATOMIC_ATTRIBUTE_DEFINITION_FILTERS.iterator(); + filterIt.hasNext();) { + int filter = ((Integer) filterIt.next()).intValue(); + + // Grab all matching AttributeDefinitions and transform them. + AttributeDefinition[] oldADs = + oldOCD.getAttributeDefinitions(filter); + + for (int ii = 0; ii < oldADs.length; ii++) { + newOCD.addAttributeDefinition( + filter, + transformer.transform(oldADs[ii])); + } } return newOCD; @@ -42,6 +62,7 @@ for (Iterator it = transformers.iterator(); it.hasNext();) { AttributeDefinitionTransformer transformer = (AttributeDefinitionTransformer) it.next(); + newOCD = apply(transformer, newOCD); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-12 18:29:37
|
Revision: 961 http://cishell.svn.sourceforge.net/cishell/?rev=961&view=rev Author: pataphil Date: 2009-10-12 18:29:29 +0000 (Mon, 12 Oct 2009) Log Message: ----------- * Made file "View With..." use the same improved functionality as file "View". * Did a little bit of other refactoring. * Reviewed by Russell. * If time ever permits, the rest of this plugin should be refactored. Modified Paths: -------------- 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/core/FileViewer.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 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 2009-10-12 17:38:10 UTC (rev 960) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2009-10-12 18:29:29 UTC (rev 961) @@ -6,42 +6,44 @@ import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.persistence.view.core.FileViewer; -import org.cishell.service.conversion.ConversionException; +import org.cishell.reference.gui.persistence.view.core.exceptiontypes.FileViewingException; import org.cishell.service.conversion.DataConversionService; +import org.osgi.service.log.LogService; public class FileView implements Algorithm { private Data[] dataToView; private CIShellContext ciShellContext; private DataConversionService conversionManager; + private LogService logger; - public FileView(Data[] data, Dictionary parameters, CIShellContext context) { + public FileView( + Data[] data, Dictionary parameters, CIShellContext context) { this.dataToView = data; this.ciShellContext = context; - this.conversionManager = (DataConversionService) context - .getService(DataConversionService.class.getName()); + this.conversionManager = (DataConversionService)context.getService( + DataConversionService.class.getName()); + this.logger = (LogService)context.getService(LogService.class.getName()); } - - // Show the contents of a file to the user. public Data[] execute() throws AlgorithmExecutionException { - try { - for (int ii = 0; ii < this.dataToView.length; ii++) { + for (int ii = 0; ii < this.dataToView.length; ii++) { + try { FileViewer.viewDataFile(this.dataToView[ii], this.ciShellContext, this.conversionManager); + } catch (FileViewingException fileViewingException) { + String logMessage = + "Error: Unable to view data \"" + + this.dataToView[ii].getMetadata().get(DataProperty.LABEL) + + "\"."; + + this.logger.log(LogService.LOG_ERROR, logMessage); } - - return null; - } catch (ConversionException conversionException) { - String exceptionMessage = "Error: Unable to view data:\n " + - conversionException.getMessage(); - - throw new AlgorithmExecutionException( - exceptionMessage, conversionException); - } catch (Throwable thrownObject) { - throw new AlgorithmExecutionException(thrownObject); } + + return new Data[0]; } } \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-10-12 17:38:10 UTC (rev 960) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-10-12 18:29:29 UTC (rev 961) @@ -1,31 +0,0 @@ -package org.cishell.reference.gui.persistence.view; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.data.Data; -import org.cishell.reference.gui.persistence.save.SaveDataChooser; -import org.cishell.service.conversion.Converter; -import org.eclipse.swt.widgets.Shell; -import org.osgi.service.log.LogService; - -public class ViewDataChooser extends SaveDataChooser { - private Converter selectedConverter = null; - - public ViewDataChooser(String title, - Shell parent, - Data data, - Converter[] converters, - CIShellContext ciShellContext, - LogService logger){ - super(data, parent, converters, title, ciShellContext); - } - - protected void selectionMade(int selectedIndex) { - getShell().setVisible(false); - this.selectedConverter = converterArray[selectedIndex]; - close(true); - } - - public Converter getSelectedConverter() { - return this.selectedConverter; - } -} 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 2009-10-12 17:38:10 UTC (rev 960) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2009-10-12 18:29:29 UTC (rev 961) @@ -7,7 +7,6 @@ import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.persistence.FileUtil; -import org.cishell.reference.gui.persistence.view.ViewDataChooser; import org.cishell.reference.gui.persistence.view.core.exceptiontypes.ConvertDataForViewingException; import org.cishell.reference.gui.persistence.view.core.exceptiontypes.FileViewingException; import org.cishell.reference.gui.persistence.view.core.exceptiontypes.NoProgramFoundException; @@ -39,8 +38,8 @@ public static void viewDataFile(Data data, CIShellContext ciShellContext, DataConversionService conversionManager) - throws ConversionException, FileViewingException { - viewDataFileWithProgram(data, null, ciShellContext, conversionManager); + throws FileViewingException { + viewDataFileWithProgram(data, "", ciShellContext, conversionManager); } public static void viewDataFileWithProgram( @@ -134,7 +133,7 @@ FileWithExtension fileWithExtension, String customFileExtension) throws FileViewingException { try { - final Program program = selectProgramForFileExtension( + final Program program = selectChosenProgramForFileExtension( fileWithExtension.fileExtension, customFileExtension); executeProgramWithFile(program, fileWithExtension.file); @@ -326,37 +325,41 @@ } } - private static Program selectProgramForFileExtension( - final String fileExtension, final String customFileExtension) + private static Program selectChosenProgramForFileExtension( + final String defaultFileExtension, + final String customFileExtension) throws NoProgramFoundException { String chosenFileExtension = null; - if ((customFileExtension == null) || customFileExtension.equals("")) { - chosenFileExtension = fileExtension; + if (customFileExtension.equals("")) { + chosenFileExtension = defaultFileExtension; } else { chosenFileExtension = customFileExtension; } - final Program[] programHolder = new Program[1]; + Program chosenProgram = + getProgramForFileExtension(chosenFileExtension); - Display.getDefault().syncExec(new Runnable() { - public void run() { - programHolder[0] = - Program.findProgram(fileExtension); + if (chosenProgram != null) { + return chosenProgram; + } else { + /* + * The chosen program doesn't exist, so try to get the + * default viewer. + */ + Program defaultProgram = + getProgramForFileExtension(defaultFileExtension); + + if (defaultProgram != null) { + return defaultProgram; + } else { + String exceptionMessage = + "You do not have a valid viewer for the ." + + chosenFileExtension + + "file installed."; + + throw new NoProgramFoundException(exceptionMessage); } - }); - - Program program = programHolder[0]; - - if (program != null) { - return program; - } else { - String exceptionMessage = - "You do not have a valid viewer for the ." + - chosenFileExtension + - "file installed."; - - throw new NoProgramFoundException(exceptionMessage); } } @@ -423,6 +426,20 @@ } } + private static Program getProgramForFileExtension( + final String fileExtension) { + final Program[] programHolder = new Program[1]; + + Display.getDefault().syncExec(new Runnable() { + public void run() { + programHolder[0] = + Program.findProgram(fileExtension); + } + }); + + return programHolder[0]; + } + private final static class DataViewer implements Runnable { public static final String VIEW_DIALOG_TITLE = "View"; private Shell shellWindow; Copied: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java (from rev 960, trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java 2009-10-12 18:29:29 UTC (rev 961) @@ -0,0 +1,31 @@ +package org.cishell.reference.gui.persistence.view.core; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.data.Data; +import org.cishell.reference.gui.persistence.save.SaveDataChooser; +import org.cishell.service.conversion.Converter; +import org.eclipse.swt.widgets.Shell; +import org.osgi.service.log.LogService; + +public class ViewDataChooser extends SaveDataChooser { + private Converter selectedConverter = null; + + public ViewDataChooser(String title, + Shell parent, + Data data, + Converter[] converters, + CIShellContext ciShellContext, + LogService logger){ + super(data, parent, converters, title, ciShellContext); + } + + protected void selectionMade(int selectedIndex) { + getShell().setVisible(false); + this.selectedConverter = converterArray[selectedIndex]; + close(true); + } + + public Converter getSelectedConverter() { + return this.selectedConverter; + } +} Property changes on: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2009-10-12 17:38:10 UTC (rev 960) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2009-10-12 18:29:29 UTC (rev 961) @@ -1,290 +1,57 @@ package org.cishell.reference.gui.persistence.viewwith; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.channels.FileChannel; import java.util.Dictionary; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; -import org.cishell.service.conversion.ConversionException; -import org.cishell.service.conversion.Converter; +import org.cishell.framework.data.DataProperty; +import org.cishell.reference.gui.persistence.view.core.FileViewer; +import org.cishell.reference.gui.persistence.view.core.exceptiontypes.FileViewingException; import org.cishell.service.conversion.DataConversionService; -import org.cishell.service.guibuilder.GUIBuilderService; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; import org.osgi.service.log.LogService; -/* - * @author Felix Terkhorn (ter...@gm...), Weixia Huang (hu...@in...) - */ public class FileViewWith implements Algorithm { public static final String VIEW_WITH_PARAMETER_KEY = "viewWith"; private Data[] dataToView; private Dictionary parameters; - private CIShellContext context; + private CIShellContext ciShellContext; private DataConversionService conversionManager; - private static GUIBuilderService guiBuilder; private LogService logger; - private Program textProgram; - private Program wordProgram; - private Program webBrowserProgram; - private Program spreadsheetProgram; - private File temporaryFile; public FileViewWith(Data[] data, Dictionary parameters, CIShellContext context) { this.dataToView = data; this.parameters = parameters; - this.context = context; + this.ciShellContext = context; - conversionManager = (DataConversionService) context.getService( - DataConversionService.class.getName()); - - logger = (LogService)context.getService(LogService.class.getName()); - guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); + this.conversionManager = (DataConversionService)context.getService( + DataConversionService.class.getName()); + this.logger = (LogService)context.getService(LogService.class.getName()); } - - public File getTempFile(){ - File tempFile; - - String tempPath = System.getProperty("java.io.tmpdir"); - File tempDir = new File(tempPath + File.separator + "temp"); - - if (!tempDir.exists()) { - tempDir.mkdir(); - } - - try { - tempFile = File.createTempFile("xxx-Session-", ".txt", tempDir); - - } catch (IOException ioException) { - logger.log( - LogService.LOG_ERROR, ioException.toString(), ioException); - - String separator = File.separator; - String temporaryFileName = - tempPath + separator + "temp" + separator + "temp.txt"; - tempFile = new File(temporaryFileName); - } - - return tempFile; - } - public Data[] execute() throws AlgorithmExecutionException { - // TODO: Refactor this code so it and FileView use the same code. - boolean temporaryFileWasCreated = false; - String format; - String viewWithType = (String)parameters.get(VIEW_WITH_PARAMETER_KEY); - - Display display; - IWorkbenchWindow[] windows; - final Shell parentShell; - - windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - - if (windows.length == 0) { - return null; - } - - parentShell = windows[0].getShell(); - display = PlatformUI.getWorkbench().getDisplay(); - temporaryFile = getTempFile(); - - for (int ii = 0; ii < this.dataToView.length; ii++){ - Data data = this.dataToView[ii]; - Object theData = data.getData(); - format = data.getFormat(); - - if (theData instanceof File || - format.startsWith("file:text/") || - format.startsWith("file-ext:")){ - copy((File)data.getData(), temporaryFile); - temporaryFileWasCreated = true; - } else { - final Converter[] converters = - conversionManager.findConverters(data, "file-ext:*"); - if (converters.length == 1) { - /* - * If length is 1, use the unique path to save it directly - * and bring the text editor. - */ - - try { - Data newData = converters[0].convert(data); - copy((File)newData.getData(), temporaryFile); - temporaryFileWasCreated = true; - } catch (ConversionException conversionException) { - String warningMessage = - "Warning: Unable to convert to target save " + - "format (" + conversionException.getMessage() + - "). Will attempt to use other " + - "available converters."; - this.logger.log(LogService.LOG_WARNING, - warningMessage, - conversionException); - } - } else if (converters.length > 1) { - if (!parentShell.isDisposed()) { - try { - DataViewer dataViewer = - new DataViewer(parentShell, data, converters); - display.syncExec(dataViewer); - - temporaryFileWasCreated = dataViewer.isSaved; - temporaryFile = dataViewer.theFile; - } catch (Throwable thrownObject) { - throw new AlgorithmExecutionException( - thrownObject); - } - } - } - else { - String errorMessage = - "No valid converters for data type: " + - data.getData().getClass().getName(); - String errorDetail = - "Please install a plugin that will save the " + - "data type to a file"; - guiBuilder.showError( - "No Converters", errorMessage, errorDetail); - } - } - - //TODO: holy code duplication, batman! - Display.getDefault().syncExec(new Runnable() { - public void run() { - textProgram = Program.findProgram("txt"); - }}); - - Display.getDefault().syncExec(new Runnable() { - public void run() { - wordProgram = Program.findProgram("doc"); - }}); - - Display.getDefault().syncExec(new Runnable() { - public void run() { - webBrowserProgram = Program.findProgram("htm"); - }}); - - Display.getDefault().syncExec(new Runnable() { - public void run() { - spreadsheetProgram = Program.findProgram("csv"); - }}); - - if ((textProgram == null) && - (wordProgram == null) && - (webBrowserProgram == null) && - (webBrowserProgram == null)) { - String errorTitle = "No Viewers for TXT, DOC, or HTM"; - String errorMessage = - "No valid viewers for .txt, .doc, or .htm files. " + - "The file is located at: " + temporaryFile.getAbsolutePath(); - String errorDetail = - "Unable to open default text viewer. " + - "File is located at: " + - temporaryFile.getAbsolutePath(); - guiBuilder.showError( - errorTitle, errorMessage, errorDetail); - } - else { - if (temporaryFileWasCreated) { - final String filePath = temporaryFile.getAbsolutePath(); - - //TODO: . . . I already said "holy code duplication batman!", didn't I? - if (viewWithType.equals("txt")) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - textProgram.execute(filePath); - } - }); - } else if (viewWithType.equals("doc")) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - wordProgram.execute(filePath); - } - }); - } else if (viewWithType.equals("html")) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - webBrowserProgram.execute(filePath); - } - }); - } else if (viewWithType.equals("csv")) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - spreadsheetProgram.execute(filePath); - } - }); - } else { - Display.getDefault().syncExec(new Runnable() { - public void run() { - textProgram.execute(filePath); - } - }); - } - } - } - } - - return null; - } - - public static boolean copy(File in, File out) { - try { - FileInputStream fis = new FileInputStream(in); - FileOutputStream fos = new FileOutputStream(out); - - FileChannel readableChannel = fis.getChannel(); - FileChannel writableChannel = fos.getChannel(); - - writableChannel.truncate(0); - writableChannel.transferFrom(readableChannel, 0, readableChannel.size()); - fis.close(); - fos.close(); - - return true; - } - catch (IOException ioe) { - guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage()); - return false; - } - } - - final class DataViewer implements Runnable { - Shell shell; - boolean isSaved; - Data theData; - File theFile = getTempFile(); - Converter[] theConverters; - - DataViewer (Shell parentShell, Data data, Converter[] converters){ - this.shell = parentShell; - this.theData = data; - this.theConverters = converters; + for (int ii = 0; ii < this.dataToView.length; ii++) { + try { + FileViewer.viewDataFileWithProgram( + this.dataToView[ii], + viewWithType, + this.ciShellContext, + this.conversionManager); + } catch (FileViewingException fileViewingException) { + String logMessage = + "Error: Unable to view data \"" + + this.dataToView[ii].getMetadata().get(DataProperty.LABEL) + + "\"."; + + this.logger.log(LogService.LOG_ERROR, logMessage); + } } - - public void run() { - // lots of persisters found, return the chooser - ViewWithDataChooser vdc = new ViewWithDataChooser("View As...", theFile, shell, - theData, theConverters, context); - vdc.open(); - isSaved = vdc.isSaved(); - } - } - - - - + + return new Data[0]; + } } \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 2009-10-12 17:38:10 UTC (rev 960) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 2009-10-12 18:29:29 UTC (rev 961) @@ -1,50 +0,0 @@ -package org.cishell.reference.gui.persistence.viewwith; - -import java.io.File; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.data.Data; -import org.cishell.reference.gui.persistence.save.SaveDataChooser; -import org.cishell.service.conversion.ConversionException; -import org.cishell.service.conversion.Converter; -import org.eclipse.swt.widgets.Shell; - -/* - * @author Felix Terkhorn (ter...@gm...) - * - */ -public class ViewWithDataChooser extends SaveDataChooser { - private File tempFile; - private boolean isSaved = false; - private Data theData; - - public ViewWithDataChooser(String title, File tempFile, Shell parent, - Data data, Converter[] converters, CIShellContext context){ - super (data, parent, converters, title, context); - - this.tempFile = tempFile; - this.theData = data; - } - - protected void selectionMade(int selectedIndex){ - try { - getShell().setVisible(false); - final Converter converter = converterArray[selectedIndex]; - Data newData = converter.convert(theData); - //TODO: hey look, yet another copy method - isSaved = FileViewWith.copy((File)newData.getData(), tempFile); - close(true); - } catch (ConversionException e) { - //TODO: RuntimeExceptioN?!?!?! - throw new RuntimeException("Error: Unable to view data:\n " + e.getMessage(), e); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public boolean isSaved(){ - return isSaved; - } - - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-12 17:38:18
|
Revision: 960 http://cishell.svn.sourceforge.net/cishell/?rev=960&view=rev Author: pataphil Date: 2009-10-12 17:38:10 +0000 (Mon, 12 Oct 2009) Log Message: ----------- Removed commented-out code. Oops. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.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/view/ViewDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-10-12 17:37:06 UTC (rev 959) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-10-12 17:38:10 UTC (rev 960) @@ -7,12 +7,7 @@ import org.eclipse.swt.widgets.Shell; import org.osgi.service.log.LogService; -// TODO: Refactor this class. public class ViewDataChooser extends SaveDataChooser { - /*private boolean isSaved = false; - private LogService logger; - private Data theData; - private File outputFile;*/ private Converter selectedConverter = null; public ViewDataChooser(String title, @@ -21,50 +16,16 @@ Converter[] converters, CIShellContext ciShellContext, LogService logger){ - super (data, parent, converters, title, ciShellContext); - - /*this.theData = data; - this.logger = logger;*/ + super(data, parent, converters, title, ciShellContext); } - //TODO: replace this stuff with convertToFile -- specifically, just ahve this return the darn selected format. + protected void selectionMade(int selectedIndex) { getShell().setVisible(false); this.selectedConverter = converterArray[selectedIndex]; close(true); - /*final Converter selectedConverter = converterArray[selectedIndex]; - - try { - Data newData = selectedConverter.convert(theData); - String label = (String) newData.getMetadata().get(DataProperty.LABEL); - String fileName = FileUtil.extractFileName(label); - String extension = FileUtil.extractExtension(newData.getFormat()); - File tempFile = FileUtil.getTempFile(fileName, extension, logger); - - try { - FileUtilities.copyFile((File)newData.getData(), tempFile); - isSaved = true; - } catch (FileCopyingException fileCopyingException) { - logger.log(LogService.LOG_ERROR, "Error copying view for view:\n " + fileCopyingException.getMessage(), fileCopyingException); - return; - } - - outputFile = tempFile; - close(true); - } catch (ConversionException e) { - logger.log(LogService.LOG_ERROR, "Error: Unable to view data:\n " + e.getMessage(), e); - return; - }*/ } public Converter getSelectedConverter() { return this.selectedConverter; } - - /*public boolean isSaved(){ - return this.isSaved; - } - - public File getOutputFile() { - return this.outputFile; - }*/ } 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 2009-10-12 17:37:06 UTC (rev 959) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2009-10-12 17:38:10 UTC (rev 960) @@ -426,8 +426,6 @@ private final static class DataViewer implements Runnable { public static final String VIEW_DIALOG_TITLE = "View"; private Shell shellWindow; - /*private boolean isSaved; - private File outputFile;*/ private Converter selectedConverter; private Data data; private Converter[] converters; @@ -470,8 +468,6 @@ this.ciShellContext, this.logger); viewDataChooser.open(); - /*isSaved = viewDataChooser.isSaved(); - outputFile = viewDataChooser.getOutputFile();*/ this.selectedConverter = viewDataChooser.getSelectedConverter(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-12 17:37:23
|
Revision: 959 http://cishell.svn.sourceforge.net/cishell/?rev=959&view=rev Author: pataphil Date: 2009-10-12 17:37:06 +0000 (Mon, 12 Oct 2009) Log Message: ----------- * Improved "View" functionality so CSV-compatible data types (both file-based and in-memory) are viewed in Excel after conversion. * Also significantly refactored code. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 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/FileUtil.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/ViewDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ 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/exceptiontypes/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataForViewingException.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataToFileAndPrepareForViewingException.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertInMemoryDataToTextFileException.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/FileViewingException.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/NoProgramFoundException.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/PrepareTextFileForViewingException.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/UserCanceledDataViewSelectionException.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-10-12 17:37:06 UTC (rev 959) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2sdk1.4.2_19"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> 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 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2009-10-12 17:37:06 UTC (rev 959) @@ -13,6 +13,7 @@ org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", + org.cishell.utilities, org.osgi.framework;version="1.3.0", org.osgi.service.cm;version="1.2.0", org.osgi.service.component;version="1.0.0", Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-10-12 17:37:06 UTC (rev 959) @@ -6,10 +6,9 @@ import org.osgi.service.log.LogService; public class FileUtil { - private static int uniqueIntForTempFile = 1; - public static File getTempFile(String fileName, String extension, LogService logger){ + public static File getTempFile(String fileName, String extension, LogService logger) { File tempFile; if (fileName == null || fileName.equals("")) { 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 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2009-10-12 17:37:06 UTC (rev 959) @@ -1,48 +1,44 @@ package org.cishell.reference.gui.persistence.save; -import java.io.File; 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.algorithm.DataValidator; import org.cishell.framework.data.Data; -import org.cishell.service.conversion.Converter; -import org.cishell.service.conversion.DataConversionService; import org.osgi.service.component.ComponentContext; -import org.osgi.service.metatype.MetaTypeProvider; /** * Create a Save object * * TODO: Should also support if we can convert to file, but have * no final file:X->file-ext:* converter. - * - * @author bmarkine * */ public class SaveFactory implements AlgorithmFactory { - private CIShellContext context; + private CIShellContext ciShellContext; /** * Create a local CIShell context - * @param ctxt The current CIShell context + * @param componentContext The current CIShell context */ - protected void activate(ComponentContext ctxt) { - context = new LocalCIShellContext(ctxt.getBundleContext()); + protected void activate(ComponentContext componentContext) { + ciShellContext = + new LocalCIShellContext(componentContext.getBundleContext()); } /** * Create a Save algorithm * @param data The data objects to save * @param parameters The parameters for the algorithm - * @param context Reference to services provided by CIShell + * @param ciShellContext Reference to services provided by CIShell * @return An instance of the Save algorithm */ - public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { - this.context = context; - return new Save(data, parameters, context); + 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 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2009-10-12 17:37:06 UTC (rev 959) @@ -1,295 +1,47 @@ package org.cishell.reference.gui.persistence.view; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.channels.FileChannel; import java.util.Dictionary; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; -import org.cishell.framework.data.DataProperty; -import org.cishell.reference.gui.persistence.FileUtil; +import org.cishell.reference.gui.persistence.view.core.FileViewer; import org.cishell.service.conversion.ConversionException; -import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.osgi.service.log.LogService; -/* - * @author Weixia(Bonnie) Huang (hu...@in...) - */ public class FileView implements Algorithm { - public static final String ANY_FILE_EXTENSION_FILTER = "file-ext:*"; - private static final String CSV_FILE_EXT = "file-ext:csv"; - private static final String CSV_MIME_TYPE = "file:text/csv"; - public static final String FILE_EXTENSION_PREFIX = "file-ext:"; - public static final String ANY_TEXT_MIME_TYPE = "file:text/"; - private Data[] data; - private CIShellContext context; + private Data[] dataToView; + private CIShellContext ciShellContext; private DataConversionService conversionManager; - private LogService logger; - private Program program; - private File tempFile; - public FileView(Data[] data, Dictionary parameters, CIShellContext context) { - this.data = data; - this.context = context; + this.dataToView = data; + this.ciShellContext = context; this.conversionManager = (DataConversionService) context .getService(DataConversionService.class.getName()); - - this.logger = (LogService) context.getService(LogService.class.getName()); } - // Show the contents of a file to the user + // Show the contents of a file to the user. public Data[] execute() throws AlgorithmExecutionException { try { - boolean lastSaveSuccessful = false; - boolean isCSVFile = false; - String format; - - // For each data item we want to view... - for (int i = 0; i < data.length; i++) { - Object theData = data[i].getData(); - format = data[i].getFormat(); - String label = (String) data[i].getMetadata().get( - DataProperty.LABEL); - - // If it is a text file... - if (theData instanceof File - || format.startsWith(ANY_TEXT_MIME_TYPE) - || format.startsWith(FILE_EXTENSION_PREFIX)) { - - // If it is a CSV text file... - if (format.startsWith(CSV_MIME_TYPE) - || format.startsWith(CSV_FILE_EXT)) { - // Prepare to open it like a CSV file - tempFile = getTempFileCSV(); - isCSVFile = true; - } else { - // Prepare to open it like a normal text file - String fileName = FileUtil.extractFileName(label); - String extension = FileUtil.extractExtension(format); - tempFile = FileUtil.getTempFile(fileName, extension, - logger); - } - - // Copy out data into the temp file we just created. - copy((File) data[i].getData(), tempFile); - lastSaveSuccessful = true; - - } else { - /* The data item is in an in-memory format, and must be - * converted to a file format before the user can see it. - */ - final Converter[] convertersCSV = - conversionManager.findConverters(data[i], CSV_FILE_EXT); - - // If the data item can be converted to a CSV file, do so. - if (convertersCSV.length == 1) { - Data newDataCSV = convertersCSV[0].convert(data[i]); - tempFile = getTempFileCSV(); - isCSVFile = true; - copy((File) newDataCSV.getData(), tempFile); - lastSaveSuccessful = true; - - } else if (convertersCSV.length > 1) { - Data newDataCSV = convertersCSV[0].convert(data[i]); - for (int j = 1; j < convertersCSV.length; j++) { - newDataCSV = convertersCSV[j].convert(newDataCSV); - } - tempFile = getTempFileCSV(); - isCSVFile = true; - copy((File) newDataCSV.getData(), tempFile); - lastSaveSuccessful = true; - } else { // it cannot be converted to a .csv - - // try to convert it to any other file format - - final Converter[] converters = - conversionManager.findConverters( - data[i], ANY_FILE_EXTENSION_FILTER); - - // if it can't be converted to any file format... - if (converters.length < 1) { - // throw an error - throw new AlgorithmExecutionException( - "No valid converters for data type: " - + data[i].getData().getClass() - .getName() - + ". Please install a plugin that will save the data type to a file"); - } else if (converters.length == 1) { // if there is only - // file format - // it can be - // converted to - // go ahead and convert the data item to that format - Data newData = converters[0].convert(data[i]); - - String fileName = FileUtil.extractFileName(label); - String extension = FileUtil - .extractExtension(newData.getFormat()); - tempFile = FileUtil.getTempFile(fileName, - extension, logger); - copy((File) newData.getData(), tempFile); - lastSaveSuccessful = true; - } else { - // there is more than one format that the data - // item could be converted to - // let the user choose - // (get some eclipse UI stuff that we need to open - // the data viewer) - - Display display; - IWorkbenchWindow[] windows; - final Shell parentShell; - - windows = PlatformUI.getWorkbench() - .getWorkbenchWindows(); - if (windows.length == 0) { - throw new AlgorithmExecutionException( - "Cannot get workbench window."); - } - parentShell = windows[0].getShell(); - display = PlatformUI.getWorkbench().getDisplay(); - - // (open the data viewer, which lets the user choose - // which format they want to see the data item in.) - - if (!parentShell.isDisposed()) { - DataViewer dataViewer = new DataViewer( - parentShell, data[i], converters); - display.syncExec(dataViewer); - lastSaveSuccessful = dataViewer.isSaved; - tempFile = dataViewer.outputFile; - } - } - } - } - - // If it's a CSV file - if (isCSVFile) {// TC181 - // prepare to open the file with the default csv program - Display.getDefault().syncExec(new Runnable() { - public void run() { - program = Program.findProgram("csv"); - } - }); - } else { - // Prepare to open it with the standard text editor. - Display.getDefault().syncExec( - new Runnable() { - public void run() { - program = Program.findProgram("txt"); - } - } - ); - } - - // If we can't find any program to open the file... - if (program == null) { - throw new AlgorithmExecutionException( - "No valid text viewer for the .txt file. " - + "The file is located at: " - + tempFile.getAbsolutePath() - + ". Unable to open default text viewer. " - + "File is located at: " - + tempFile.getAbsolutePath()); - } else { - // We found a program to open the file. Open it. - if (lastSaveSuccessful == true) { - Display.getDefault().syncExec( - new Runnable() { - public void run() { - program.execute(tempFile.getAbsolutePath()); - } - } - ); - } - } + for (int ii = 0; ii < this.dataToView.length; ii++) { + FileViewer.viewDataFile(this.dataToView[ii], + this.ciShellContext, + this.conversionManager); } return null; - } catch (ConversionException e) { + } catch (ConversionException conversionException) { + String exceptionMessage = "Error: Unable to view data:\n " + + conversionException.getMessage(); + throw new AlgorithmExecutionException( - "Error: Unable to view data:\n " + e.getMessage(), e); - } catch (Throwable e) { - throw new AlgorithmExecutionException(e); + exceptionMessage, conversionException); + } catch (Throwable thrownObject) { + throw new AlgorithmExecutionException(thrownObject); } } - - public File getTempFileCSV() { - File tempFile; - - String tempPath = System.getProperty("java.io.tmpdir"); - File tempDir = new File(tempPath + File.separator + "temp"); - if (!tempDir.exists()) - tempDir.mkdir(); - try { - tempFile = File.createTempFile("xxx-Session-", ".csv", tempDir); - - } catch (IOException e) { - logger.log(LogService.LOG_ERROR, e.toString(), e); - tempFile = new File(tempPath + File.separator + "temp" - + File.separator + "temp.csv"); - - } - return tempFile; - } - - public static boolean copy(File in, File out) - throws AlgorithmExecutionException { - try { - FileInputStream fis = new FileInputStream(in); - FileOutputStream fos = new FileOutputStream(out); - - FileChannel readableChannel = fis.getChannel(); - FileChannel writableChannel = fos.getChannel(); - - writableChannel.truncate(0); - writableChannel.transferFrom(readableChannel, 0, readableChannel - .size()); - fis.close(); - fos.close(); - return true; - } catch (IOException ioe) { - throw new AlgorithmExecutionException("IOException during copy", - ioe); - } - } - - final class DataViewer implements Runnable { - public static final String VIEW_DIALOG_TITLE = "View"; - private Shell shell; - private boolean isSaved; - private File outputFile; - private Data data; - private Converter[] converters; - - - DataViewer(Shell parentShell, Data data, Converter[] converters) { - this.shell = parentShell; - this.data = data; - this.converters = converters; - } - - - public void run() { - // Lots of persisters found, return the chooser - ViewDataChooser vdc = new ViewDataChooser( - VIEW_DIALOG_TITLE, shell, data, converters, context, logger); - vdc.open(); - isSaved = vdc.isSaved(); - outputFile = vdc.outputFile; - } - } } \ No newline at end of file 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 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java 2009-10-12 17:37:06 UTC (rev 959) @@ -6,14 +6,12 @@ import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; -import org.osgi.service.component.ComponentContext; -import org.osgi.service.metatype.MetaTypeProvider; -//import org.osgi.service.metatype.MetaTypeService; public class FileViewFactory implements AlgorithmFactory { - - public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { - return new FileView(data, parameters, context); + public Algorithm createAlgorithm(Data[] data, + Dictionary parameters, + CIShellContext ciShellContext) { + return new FileView(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/ViewDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-10-12 17:37:06 UTC (rev 959) @@ -1,51 +1,50 @@ package org.cishell.reference.gui.persistence.view; -import java.io.File; - import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; -import org.cishell.framework.data.DataProperty; -import org.cishell.reference.gui.persistence.FileUtil; import org.cishell.reference.gui.persistence.save.SaveDataChooser; -import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.eclipse.swt.widgets.Shell; import org.osgi.service.log.LogService; -/* - * @author Weixia(Bonnie) Huang (hu...@in...) - * - */ +// TODO: Refactor this class. public class ViewDataChooser extends SaveDataChooser { - boolean isSaved = false; - LogService logger; - Data theData; - File outputFile; + /*private boolean isSaved = false; + private LogService logger; + private Data theData; + private File outputFile;*/ + private Converter selectedConverter = null; - public ViewDataChooser(String title, Shell parent, - Data data, Converter[] converters, CIShellContext context, LogService logger){ - super (data, parent, converters, title, context); + public ViewDataChooser(String title, + Shell parent, + Data data, + Converter[] converters, + CIShellContext ciShellContext, + LogService logger){ + super (data, parent, converters, title, ciShellContext); - this.theData = data; - this.logger = logger; + /*this.theData = data; + this.logger = logger;*/ } - + //TODO: replace this stuff with convertToFile -- specifically, just ahve this return the darn selected format. protected void selectionMade(int selectedIndex) { getShell().setVisible(false); - final Converter converter = converterArray[selectedIndex]; + this.selectedConverter = converterArray[selectedIndex]; + close(true); + /*final Converter selectedConverter = converterArray[selectedIndex]; try { - Data newData = converter.convert(theData); + Data newData = selectedConverter.convert(theData); String label = (String) newData.getMetadata().get(DataProperty.LABEL); String fileName = FileUtil.extractFileName(label); String extension = FileUtil.extractExtension(newData.getFormat()); File tempFile = FileUtil.getTempFile(fileName, extension, logger); try { - isSaved = FileView.copy((File)newData.getData(), tempFile); - } catch (AlgorithmExecutionException e) { - logger.log(LogService.LOG_ERROR, "Error copying view for view:\n " + e.getMessage(), e); + FileUtilities.copyFile((File)newData.getData(), tempFile); + isSaved = true; + } catch (FileCopyingException fileCopyingException) { + logger.log(LogService.LOG_ERROR, "Error copying view for view:\n " + fileCopyingException.getMessage(), fileCopyingException); return; } @@ -54,12 +53,18 @@ } catch (ConversionException e) { logger.log(LogService.LOG_ERROR, "Error: Unable to view data:\n " + e.getMessage(), e); return; - } + }*/ } - public boolean isSaved(){ - return isSaved; + public Converter getSelectedConverter() { + return this.selectedConverter; } - + /*public boolean isSaved(){ + return this.isSaved; + } + + public File getOutputFile() { + return this.outputFile; + }*/ } Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,488 @@ +package org.cishell.reference.gui.persistence.view.core; + +import java.io.File; +import java.io.IOException; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; +import org.cishell.reference.gui.persistence.FileUtil; +import org.cishell.reference.gui.persistence.view.ViewDataChooser; +import org.cishell.reference.gui.persistence.view.core.exceptiontypes.ConvertDataForViewingException; +import org.cishell.reference.gui.persistence.view.core.exceptiontypes.FileViewingException; +import org.cishell.reference.gui.persistence.view.core.exceptiontypes.NoProgramFoundException; +import org.cishell.reference.gui.persistence.view.core.exceptiontypes.UserCanceledDataViewSelectionException; +import org.cishell.service.conversion.ConversionException; +import org.cishell.service.conversion.Converter; +import org.cishell.service.conversion.DataConversionService; +import org.cishell.utilities.FileCopyingException; +import org.cishell.utilities.FileUtilities; +import org.eclipse.swt.program.Program; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.osgi.service.log.LogService; + +public class FileViewer { + public static final String FILE_EXTENSION_MIME_TYPE_PREFIX = "file-ext:"; + public static final String ANY_FILE_EXTENSION_FILTER = "file-ext:*"; + public static final String FILE_EXTENSION_PREFIX = "file-ext:"; + public static final String ANY_MIME_TYPE = "file:"; + public static final String CSV_FILE_EXT = "file-ext:csv"; + public static final String CSV_MIME_TYPE = "file:text/csv"; + public static final String TEMPORARY_CSV_FILE_NAME = "xxx-Session-"; + public static final String CSV_FILE_EXTENSION = "csv"; + public static final String ANY_FILE_FORMAT_PATTERN = + "(file:.*)|(file-ext:.*)"; + + public static void viewDataFile(Data data, + CIShellContext ciShellContext, + DataConversionService conversionManager) + throws ConversionException, FileViewingException { + viewDataFileWithProgram(data, null, ciShellContext, conversionManager); + } + + public static void viewDataFileWithProgram( + Data data, + String customFileExtension, + CIShellContext ciShellContext, + DataConversionService converterManager) + throws FileViewingException { + FileWithExtension fileWithExtension = + convertDataForViewing(data, ciShellContext, converterManager); + viewFileWithExtension(fileWithExtension, customFileExtension); + } + + private static FileWithExtension convertDataForViewing( + Data data, + CIShellContext ciShellContext, + DataConversionService converterManager) + throws FileViewingException { + try { + String dataFormat = data.getFormat(); + + if (isCSVFormat(data)) { + /* + * The data is already a CSV file, so it just needs to + * be copied. + */ + try { + File csvFileForViewing = + FileUtilities.createTemporaryFileCopy( + (File)data.getData(), + TEMPORARY_CSV_FILE_NAME, + CSV_FILE_EXTENSION); + + return new FileWithExtension( + csvFileForViewing, CSV_FILE_EXTENSION); + } catch (FileCopyingException csvFileCopyingException) { + throw new ConvertDataForViewingException( + csvFileCopyingException); + } + } else if (dataIsCSVCompatible(data, converterManager)) { + /* + * The data is either a CSV file already or CSV-convertible. + * This needs to be handled specially so data that can be + * viewed in Excel gets viewed in Excel. + */ + File preparedFileForViewing = prepareFileForViewing( + data, CSV_FILE_EXTENSION, converterManager); + + 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"); + } else if (convertersExist( + data, ANY_FILE_EXTENSION_FILTER, converterManager)) { + /* + * The data is an another type, but it can be converted to a + * text-based file type for viewing in the default + * text-viewing program. + */ + return new FileWithExtension( + convertDataToTextFile( + data, converterManager, ciShellContext), + "txt"); + } else { + String exceptionMessage = + "No converters exist for the data \"" + + 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."; + + throw new FileViewingException( + exceptionMessage, convertDataForViewingException); + } + } + + private static void viewFileWithExtension( + FileWithExtension fileWithExtension, String customFileExtension) + throws FileViewingException { + try { + final Program program = selectProgramForFileExtension( + fileWithExtension.fileExtension, customFileExtension); + + 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."; + + 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)) { + 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)) { + return true; + } else { + return false; + } + } + + private static boolean dataIsFile(Data data, String dataFormat) { + if (data.getData() instanceof File || + dataFormat.startsWith(ANY_MIME_TYPE) || + dataFormat.startsWith(FILE_EXTENSION_PREFIX)) { + return true; + } else { + return false; + } + } + + private static boolean convertersExist( + 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); + + try { + String fileExtensionMimeType = + FILE_EXTENSION_MIME_TYPE_PREFIX + fileExtension; + File convertedFile = convertToFile( + originalData, fileExtensionMimeType, converterManager); + String fileName = FileUtil.extractFileName(dataLabel); + + return FileUtilities.createTemporaryFileCopy( + convertedFile, fileName, fileExtension); + } catch (ConversionException convertingDataToFileException) { + String exceptionMessage = + "A ConversionException occurred when converting the data \"" + + dataLabel + + "\" to " + fileExtension + "."; + + throw new ConvertDataForViewingException( + exceptionMessage, convertingDataToFileException); + } catch (FileCopyingException temporaryFileCopyingException) { + String exceptionMessage = + "A FileCopyingException occurred when converting the data \"" + + dataLabel + + "\" to " + fileExtension + "."; + + throw new ConvertDataForViewingException( + exceptionMessage, temporaryFileCopyingException); + } + } + + private static File prepareTextFileForViewing(Data originalData) + throws ConvertDataForViewingException { + String dataLabel = + (String)originalData.getMetadata().get(DataProperty.LABEL); + String dataFormat = originalData.getFormat(); + String fileName = FileUtil.extractFileName(dataLabel); + String fileExtension = FileUtil.extractExtension(dataFormat); + + try { + File fileToView = FileUtilities. + createTemporaryFileInDefaultTemporaryDirectory( + fileName, fileExtension); + FileUtilities.copyFile((File)originalData.getData(), fileToView); + + return fileToView; + } catch (IOException temporaryFileCreationException) { + String exceptionMessage = + "An IOException occurred when creating the temporary file \"" + + fileName + "." + fileExtension + + "\" for viewing the data \"" + dataLabel + "\"."; + + throw new ConvertDataForViewingException( + exceptionMessage, temporaryFileCreationException); + } catch (FileCopyingException fileCopyingException) { + throw new ConvertDataForViewingException(fileCopyingException); + } + } + + private static File convertDataToTextFile( + Data originalData, + DataConversionService converterManager, + CIShellContext ciShellContext) + throws ConvertDataForViewingException { + final Converter[] converters = converterManager.findConverters( + originalData, ANY_FILE_EXTENSION_FILTER); + + if (converters.length == 1) { + /* + * There is just one converter, so transparently do + * 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."; + + throw new ConvertDataForViewingException( + exceptionMessage, + convertDataToFileAndPrepareForViewingException); + } + } else { + /* + * There are several converters available, so the user will + * need to select how the dataToView is to be converted. + */ + try { + return convertDataBasedOffUserChosenConverter( + originalData, converters, ciShellContext); + } catch (ConversionException conversionException) { + String exceptionMessage = + "A ConversionException occurred when converting the " + + "data \"" + + originalData.getMetadata().get(DataProperty.LABEL) + + "\"."; + + throw new ConvertDataForViewingException( + exceptionMessage, conversionException); + } catch (UserCanceledDataViewSelectionException + userCanceledDataViewSelectionException) { + String exceptionMessage = + "A UserCanceledDataViewSelectionException occurred " + + "when the user did not choose a converter for the " + + "data \"" + + originalData.getMetadata().get(DataProperty.LABEL) + + "\"."; + + throw new ConvertDataForViewingException( + exceptionMessage, userCanceledDataViewSelectionException); + } + } + } + + private static Program selectProgramForFileExtension( + final String fileExtension, final String customFileExtension) + throws NoProgramFoundException { + String chosenFileExtension = null; + + if ((customFileExtension == null) || customFileExtension.equals("")) { + chosenFileExtension = fileExtension; + } else { + chosenFileExtension = customFileExtension; + } + + final Program[] programHolder = new Program[1]; + + Display.getDefault().syncExec(new Runnable() { + public void run() { + programHolder[0] = + Program.findProgram(fileExtension); + } + }); + + Program program = programHolder[0]; + + if (program != null) { + return program; + } else { + String exceptionMessage = + "You do not have a valid viewer for the ." + + chosenFileExtension + + "file installed."; + + throw new NoProgramFoundException(exceptionMessage); + } + } + + private static void executeProgramWithFile(final Program program, + final File file) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + program.execute( + file.getAbsolutePath()); + } + }); + } + + private static File convertToFile(Data data, + String targetFormat, + DataConversionService conversionManager) + throws ConversionException { + if (targetFormat.matches(ANY_FILE_FORMAT_PATTERN)) { + Converter[] converters = + conversionManager.findConverters(data, targetFormat); + + return convertToFile(data, converters[0]); + } else { + String exceptionMessage = + "The target format for conversion (\"" + + targetFormat + + "\") is not valid."; + + throw new ConversionException(exceptionMessage); + } + } + + + private static File convertToFile(Data data, Converter converter) + throws ConversionException { + Data newData = converter.convert(data); + return (File)newData.getData(); + } + + private static File convertDataBasedOffUserChosenConverter( + Data originalData, + Converter[] converters, + CIShellContext ciShellContext) + throws ConversionException, + UserCanceledDataViewSelectionException { + /* + * Open the dataToView viewer, which lets the user choose + * which format he/she wants to see the data item in. + */ + DataViewer dataViewer = new DataViewer( + originalData, converters, ciShellContext); + + if (dataViewer.selectedConverter != null) { + return convertToFile(originalData, dataViewer.selectedConverter); + } else { + String exceptionMessage = + "The user cancelled the selection of a converter for the " + + "data \"" + + originalData.getMetadata().get(DataProperty.LABEL) + + "\"."; + + throw new UserCanceledDataViewSelectionException( + exceptionMessage); + } + } + + private final static class DataViewer implements Runnable { + public static final String VIEW_DIALOG_TITLE = "View"; + private Shell shellWindow; + /*private boolean isSaved; + private File outputFile;*/ + private Converter selectedConverter; + private Data data; + private Converter[] converters; + private CIShellContext ciShellContext; + private LogService logger; + + public DataViewer(Data data, + Converter[] converters, + CIShellContext ciShellContext) { + this(data, + converters, + ciShellContext, + (LogService)ciShellContext.getService( + LogService.class.getName())); + } + + public DataViewer(Data data, + Converter[] converters, + CIShellContext ciShellContext, + LogService logger) { + IWorkbenchWindow[] windows = + PlatformUI.getWorkbench().getWorkbenchWindows(); + this.shellWindow = windows[0].getShell(); + this.data = data; + this.converters = converters; + this.ciShellContext = ciShellContext; + this.logger = logger; + + Display display = PlatformUI.getWorkbench().getDisplay(); + display.syncExec(this); + } + + public void run() { + // Lots of persisters found, return the chooser. + ViewDataChooser viewDataChooser = new ViewDataChooser( + VIEW_DIALOG_TITLE, + this.shellWindow, + this.data, + this.converters, + this.ciShellContext, + this.logger); + viewDataChooser.open(); + /*isSaved = viewDataChooser.isSaved(); + outputFile = viewDataChooser.getOutputFile();*/ + this.selectedConverter = viewDataChooser.getSelectedConverter(); + } + } + + private static class FileWithExtension { + public final File file; + public final String fileExtension; + + public FileWithExtension(File file, String fileExtension) { + this.file = file; + this.fileExtension = fileExtension; + } + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataForViewingException.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataForViewingException.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataForViewingException.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,21 @@ +package org.cishell.reference.gui.persistence.view.core.exceptiontypes; + +public class ConvertDataForViewingException extends Exception { + private static final long serialVersionUID = 1L; + + public ConvertDataForViewingException() { + super(); + } + + public ConvertDataForViewingException(String arg0) { + super(arg0); + } + + public ConvertDataForViewingException(Throwable arg0) { + super(arg0); + } + + public ConvertDataForViewingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataToFileAndPrepareForViewingException.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataToFileAndPrepareForViewingException.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertDataToFileAndPrepareForViewingException.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,22 @@ +package org.cishell.reference.gui.persistence.view.core.exceptiontypes; + +public class ConvertDataToFileAndPrepareForViewingException extends Exception { + private static final long serialVersionUID = 1L; + + public ConvertDataToFileAndPrepareForViewingException() { + super(); + } + + public ConvertDataToFileAndPrepareForViewingException(String arg0) { + super(arg0); + } + + public ConvertDataToFileAndPrepareForViewingException(Throwable arg0) { + super(arg0); + } + + public ConvertDataToFileAndPrepareForViewingException( + String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertInMemoryDataToTextFileException.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertInMemoryDataToTextFileException.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/ConvertInMemoryDataToTextFileException.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,21 @@ +package org.cishell.reference.gui.persistence.view.core.exceptiontypes; + +public class ConvertInMemoryDataToTextFileException extends Exception { + private static final long serialVersionUID = 1L; + + public ConvertInMemoryDataToTextFileException() { + super(); + } + + public ConvertInMemoryDataToTextFileException(String arg0) { + super(arg0); + } + + public ConvertInMemoryDataToTextFileException(Throwable arg0) { + super(arg0); + } + + public ConvertInMemoryDataToTextFileException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/FileViewingException.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/FileViewingException.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/FileViewingException.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,21 @@ +package org.cishell.reference.gui.persistence.view.core.exceptiontypes; + +public class FileViewingException extends Exception { + private static final long serialVersionUID = 1L; + + public FileViewingException() { + super(); + } + + public FileViewingException(String arg0) { + super(arg0); + } + + public FileViewingException(Throwable arg0) { + super(arg0); + } + + public FileViewingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/NoProgramFoundException.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/NoProgramFoundException.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/NoProgramFoundException.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,21 @@ +package org.cishell.reference.gui.persistence.view.core.exceptiontypes; + +public class NoProgramFoundException extends Exception { + private static final long serialVersionUID = 1L; + + public NoProgramFoundException() { + super(); + } + + public NoProgramFoundException(String arg0) { + super(arg0); + } + + public NoProgramFoundException(Throwable arg0) { + super(arg0); + } + + public NoProgramFoundException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/PrepareTextFileForViewingException.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/PrepareTextFileForViewingException.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/PrepareTextFileForViewingException.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,21 @@ +package org.cishell.reference.gui.persistence.view.core.exceptiontypes; + +public class PrepareTextFileForViewingException extends Exception { + private static final long serialVersionUID = 1L; + + public PrepareTextFileForViewingException() { + super(); + } + + public PrepareTextFileForViewingException(String arg0) { + super(arg0); + } + + public PrepareTextFileForViewingException(Throwable arg0) { + super(arg0); + } + + public PrepareTextFileForViewingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/UserCanceledDataViewSelectionException.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/UserCanceledDataViewSelectionException.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/exceptiontypes/UserCanceledDataViewSelectionException.java 2009-10-12 17:37:06 UTC (rev 959) @@ -0,0 +1,21 @@ +package org.cishell.reference.gui.persistence.view.core.exceptiontypes; + +public class UserCanceledDataViewSelectionException extends Exception { + private static final long serialVersionUID = 1L; + + public UserCanceledDataViewSelectionException() { + super(); + } + + public UserCanceledDataViewSelectionException(String arg0) { + super(arg0); + } + + public UserCanceledDataViewSelectionException(Throwable arg0) { + super(arg0); + } + + public UserCanceledDataViewSelectionException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2009-10-12 16:29:06 UTC (rev 958) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2009-10-12 17:37:06 UTC (rev 959) @@ -26,20 +26,22 @@ * @author Felix Terkhorn (ter...@gm...), Weixia Huang (hu...@in...) */ public class FileViewWith implements Algorithm { - Data[] data; - Dictionary parameters; - CIShellContext context; - DataConversionService conversionManager; - static GUIBuilderService guiBuilder; - LogService logger; - Program program; - Program programTwo; - Program programThree; - Program programFour; //TC181 - File tempFile; + public static final String VIEW_WITH_PARAMETER_KEY = "viewWith"; + + private Data[] dataToView; + private Dictionary parameters; + private CIShellContext context; + private DataConversionService conversionManager; + private static GUIBuilderService guiBuilder; + private LogService logger; + private Program textProgram; + private Program wordProgram; + private Program webBrowserProgram; + private Program spreadsheetProgram; + private File temporaryFile; public FileViewWith(Data[] data, Dictionary parameters, CIShellContext context) { - this.data = data; + this.dataToView = data; this.parameters = parameters; this.context = context; @@ -50,150 +52,192 @@ guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); } + public File getTempFile(){ File tempFile; String tempPath = System.getProperty("java.io.tmpdir"); - File tempDir = new File(tempPath+File.separator+"temp"); - if(!tempDir.exists()) + File tempDir = new File(tempPath + File.separator + "temp"); + + if (!tempDir.exists()) { tempDir.mkdir(); - try{ + } + + try { tempFile = File.createTempFile("xxx-Session-", ".txt", tempDir); - }catch (IOException e){ - logger.log(LogService.LOG_ERROR, e.toString(), e); - tempFile = new File (tempPath+File.separator+"temp"+File.separator+"temp.txt"); + } catch (IOException ioException) { + logger.log( + LogService.LOG_ERROR, ioException.toString(), ioException); + + String separator = File.separator; + String temporaryFileName = + tempPath + separator + "temp" + separator + "temp.txt"; + tempFile = new File(temporaryFileName); } + return tempFile; } public Data[] execute() throws AlgorithmExecutionException { - boolean lastSaveSuccessful = false; + // TODO: Refactor this code so it and FileView use the same code. + boolean temporaryFileWasCreated = false; String format; - String viewWith = (String) parameters.get("viewWith"); + String viewWithType = (String)parameters.get(VIEW_WITH_PARAMETER_KEY); Display display; IWorkbenchWindow[] windows; final Shell parentShell; windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - if (windows.length == 0){ + + if (windows.length == 0) { return null; } + parentShell = windows[0].getShell(); display = PlatformUI.getWorkbench().getDisplay(); - tempFile = getTempFile(); + temporaryFile = getTempFile(); - for (int i = 0; i < data.length; i++){ - Object theData = data[i].getData(); - format = data[i].getFormat(); + for (int ii = 0; ii < this.dataToView.length; ii++){ + Data data = this.dataToView[ii]; + Object theData = data.getData(); + format = data.getFormat(); + if (theData instanceof File || format.startsWith("file:text/") || format.startsWith("file-ext:")){ - copy((File)data[i].getData(), tempFile); - lastSaveSuccessful = true; - }else{ - final Converter[] converters = conversionManager.findConverters(data[i], "file-ext:*"); + copy((File)data.getData(), temporaryFile); + temporaryFileWasCreated = true; + } else { + final Converter[] converters = + conversionManager.findConverters(data, "file-ext:*"); - if (converters.length < 1) { - guiBuilder.showError("No Converters", - "No valid converters for data type: " + - data[i].getData().getClass().getName(), - "Please install a plugin that will save the data type to a file"); - } - else if (converters.length == 1){ - //If length=1, use the unique path to save it directly - //and bring the text editor. + if (converters.length == 1) { + /* + * If length is 1, use the unique path to save it directly + * and bring the text editor. + */ + try { - Data newData = converters[0].convert(data[i]); - copy((File)newData.getData(), tempFile); - lastSaveSuccessful = true; - } catch (ConversionException e) { - this.logger.log(LogService.LOG_WARNING, "Warning: Unable to convert to target save format (" + e.getMessage() + "). Will attempt to use other available converters.", e); + Data newData = converters[0].convert(data); + copy((File)newData.getData(), temporaryFile); + temporaryFileWasCreated = true; + } catch (ConversionException conversionException) { + String warningMessage = + "Warning: Unable to convert to target save " + + "format (" + conversionException.getMessage() + + "). Will attempt to use other " + + "available converters."; + this.logger.log(LogService.LOG_WARNING, + warningMessage, + conversionException); } - } - else { + } else if (converters.length > 1) { if (!parentShell.isDisposed()) { try { - DataViewer dataViewer = new DataViewer(parentShell, data[i], converters); - display.syncExec(dataViewer); + DataViewer dataViewer = + new DataViewer(parentShell, data, converters); + display.syncExec(dataViewer); - lastSaveSuccessful = dataViewer.isSaved; - tempFile = dataViewer.theFile; - } catch (Throwable e1) { - throw new AlgorithmExecutionException(e1); + temporaryFileWasCreated = dataViewer.isSaved; + temporaryFile = dataViewer.theFile; + } catch (Throwable thrownObject) { + throw new AlgorithmExecutionException( + thrownObject); } } } + else { + String errorMessage = + "No valid converters for data type: " + + data.getData().getClass().getName(); + String errorDetail = + "Please install a plugin that will save the " + + "data type to a file"; + guiBuilder.showError( + "No Converters", errorMessage, errorDetail); + } } - + //TODO: holy code duplication, batman! Display.getDefault().syncExec(new Runnable() { public void run() { - program = Program.findProgram("txt"); + textProgram = Program.findProgram("txt"); }}); Display.getDefault().syncExec(new Runnable() { public void run() { - programTwo = Program.findProgram("doc"); + wordProgram = Program.findProgram("doc"); }}); Display.getDefault().syncExec(new Runnable() { public void run() { - programThree = Program.findProgram("htm"); + webBrowserProgram = Program.findProgram("htm"); }}); - //TC181 + Display.getDefault().syncExec(new Runnable() { public void run() { - programFour = Program.findProgram("csv"); + spreadsheetProgram = Program.findProgram("csv"); }}); - //TC181 - if (program == null && programTwo == null && programThree == null && programThree == null) { - guiBuilder.showError("No Viewers for TXT, DOC, or HTM", - "No valid viewers for .txt, .doc, or .htm files. " + - "The file is located at: "+tempFile.getAbsolutePath(), - "Unable to open default text viewer. File is located at: "+ - tempFile.getAbsolutePath()); + if ((textProgram == null) && + (wordProgram == null) && + (webBrowserProgram == null) && + (webBrowserProgram == null)) { + String errorTitle = "No Viewers for TXT, DOC, or HTM"; + String errorMessage = + "No valid viewers for .txt, .doc, or .htm files. " + + "The file is located at: " + temporaryFile.getAbsolutePath(); + String errorDetail = + "Unable to open default text viewer. " + + "File is located at: " + + temporaryFile.getAbsolutePath(); + guiBuilder.showError( + errorTitle, errorMessage, errorDetail); } else { - if (lastSaveSuccessful == true) { - if (viewWith.equals("txt")) { + if (temporaryFileWasCreated) { + final String filePath = temporaryFile.getAbsolutePath(); + + //TODO: . . . I already said "holy code duplication batman!", didn't I? + if (viewWithType.equals("txt")) { Display.getDefault().syncExec(new Runnable() { public void run() { - program.execute(tempFile.getAbsolutePath()); - }}); - } else if (viewWith.equals("doc")) { + textProgram.execute(filePath); + } + }); + } else if (viewWithType.equals("doc")) { Display.getDefault().syncExec(new Runnable() { public void run() { - programTwo.execute(tempFile.getAbsolutePath()); - }}); - } el... [truncated message content] |
From: <pat...@us...> - 2009-10-12 16:29:14
|
Revision: 958 http://cishell.svn.sourceforge.net/cishell/?rev=958&view=rev Author: pataphil Date: 2009-10-12 16:29:06 +0000 (Mon, 12 Oct 2009) Log Message: ----------- * Added FileUtilities.createTemporaryFileCopy, which wraps FileUtilities.copyFile. * Made custom exception type FileCopyingException for file copy operations. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java 2009-10-12 16:29:06 UTC (rev 958) @@ -0,0 +1,21 @@ +package org.cishell.utilities; + +public class FileCopyingException extends Exception { + private static final long serialVersionUID = 1L; + + public FileCopyingException() { + super(); + } + + public FileCopyingException(String arg0) { + super(arg0); + } + + public FileCopyingException(Throwable arg0) { + super(arg0); + } + + public FileCopyingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ 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 2009-10-08 21:19:28 UTC (rev 957) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-10-12 16:29:06 UTC (rev 958) @@ -3,10 +3,13 @@ import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.nio.channels.FileChannel; import javax.imageio.ImageIO; @@ -173,6 +176,55 @@ return readTextStringBuffer.toString(); } + public static void copyFile(File sourceFile, File targetFile) + throws FileCopyingException { + try { + FileInputStream inputStream = new FileInputStream(sourceFile); + FileOutputStream outputStream = new FileOutputStream(targetFile); + + FileChannel readableChannel = inputStream.getChannel(); + FileChannel writableChannel = outputStream.getChannel(); + + writableChannel.truncate(0); + writableChannel.transferFrom( + readableChannel, 0, readableChannel.size()); + inputStream.close(); + outputStream.close(); + } catch (IOException ioException) { + String exceptionMessage = + "An error occurred when copying from the file \"" + + sourceFile.getAbsolutePath() + + "\" to the file \"" + + targetFile.getAbsolutePath() + + "\"."; + + throw new FileCopyingException(exceptionMessage, ioException); + } + } + + public static File createTemporaryFileCopy( + File sourceFile, String fileName, String fileExtension) + throws FileCopyingException { + try { + File temporaryTargetFile = + createTemporaryFileInDefaultTemporaryDirectory( + fileName, fileExtension); + + copyFile(sourceFile, temporaryTargetFile); + + return temporaryTargetFile; + } catch (IOException temporaryFileCreationException) { + String exceptionMessage = + "An error occurred when trying to create the temporary file " + + "with file name \"" + fileName + "\" " + + "and file extension \"" + fileExtension + "\" " + + "for copying file \"" + sourceFile.getAbsolutePath() + "\"."; + + throw new FileCopyingException( + exceptionMessage, temporaryFileCreationException); + } + } + private static File ensureDirectoryExists(String directoryPath) { File directory = new File(directoryPath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-08 21:19:36
|
Revision: 957 http://cishell.svn.sourceforge.net/cishell/?rev=957&view=rev Author: pataphil Date: 2009-10-08 21:19:28 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Made slight improvement to StringUtilities.filterEmpetyStrings 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 2009-10-07 21:55:15 UTC (rev 956) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-08 21:19:28 UTC (rev 957) @@ -54,7 +54,7 @@ ArrayList filteredStrings = new ArrayList(); for (int ii = 0; ii < stringsToFilter.length; ii++) { - if (!stringsToFilter[ii].equals("")) { + if (!"".equals(stringsToFilter[ii])) { filteredStrings.add(stringsToFilter[ii]); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-07 21:55:32
|
Revision: 956 http://cishell.svn.sourceforge.net/cishell/?rev=956&view=rev Author: pataphil Date: 2009-10-07 21:55:15 +0000 (Wed, 07 Oct 2009) Log Message: ----------- Added simple filter methods to StringUtilities. *Not reviewed*. They may be redundant, but they're simple enough that it's probably okay they weren't reviewed. 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 2009-10-07 19:50:03 UTC (rev 955) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-07 21:55:15 UTC (rev 956) @@ -1,9 +1,11 @@ package org.cishell.utilities; +import java.util.ArrayList; import java.util.List; public class StringUtilities { - public static String implodeStringArray(String[] stringArray, String separator) { + public static String implodeStringArray(String[] stringArray, + String separator) { final int stringArrayLength = stringArray.length; StringBuffer workingResultString = new StringBuffer(); @@ -33,4 +35,30 @@ return workingResultString.toString(); } + + public static String[] filterStringsByPattern(String[] stringsToFilter, + String pattern) { + ArrayList filteredStrings = new ArrayList(); + + for (int ii = 0; ii < stringsToFilter.length; ii++) { + if (!stringsToFilter[ii].matches(pattern)) { + filteredStrings.add(stringsToFilter[ii]); + } + } + + return (String[])filteredStrings.toArray(new String[0]); + } + + public static String[] filterEmptyStrings(String[] stringsToFilter) { + // TODO: This maybe should use filterStringsByPattern? + ArrayList filteredStrings = new ArrayList(); + + for (int ii = 0; ii < stringsToFilter.length; ii++) { + if (!stringsToFilter[ii].equals("")) { + filteredStrings.add(stringsToFilter[ii]); + } + } + + return (String[])filteredStrings.toArray(new String[0]); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-07 19:50:13
|
Revision: 955 http://cishell.svn.sourceforge.net/cishell/?rev=955&view=rev Author: pataphil Date: 2009-10-07 19:50:03 +0000 (Wed, 07 Oct 2009) Log Message: ----------- Added FileUtilities.readEntireTextFile 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 2009-09-18 17:43:25 UTC (rev 954) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-10-07 19:50:03 UTC (rev 955) @@ -11,10 +11,17 @@ import javax.imageio.ImageIO; public class FileUtilities { - // Return a File pointing to the directory specified in temporaryDirectoryPath, - // creating the directory if it doesn't already exist. - private static File createTemporaryDirectory(String temporaryDirectoryPath) { - return ensureDirectoryExists(temporaryDirectoryPath + File.separator + "temp"); + public static final int READ_TEXT_FILE_BUFFER_SIZE = 1024; + + /* + * Return a File pointing to the directory specified in + * temporaryDirectoryPath, creating the directory if it doesn't + * already exist. + */ + private static File createTemporaryDirectory( + String temporaryDirectoryPath) { + return ensureDirectoryExists( + temporaryDirectoryPath + File.separator + "temp"); } // Attempt to create a temporary file on disk whose name is passed in. @@ -28,9 +35,10 @@ File temporaryFile; try { - temporaryFile = File.createTempFile("NWB-Session-" + temporaryFileName, - "." + temporaryFileExtension, - temporaryDirectory); + temporaryFile = + File.createTempFile("NWB-Session-" + temporaryFileName, + "." + temporaryFileExtension, + temporaryDirectory); } catch (IOException e) { // We couldn't make the temporary file in the temporary directory @@ -143,6 +151,28 @@ return fileIsEmpty; } + /* + * This is basically copied off of: + * http://www.javazoid.com/foj_file.html + */ + public static String readEntireTextFile(File file) + throws IOException { + StringBuffer readTextStringBuffer = new StringBuffer(); + BufferedReader fileReader = new BufferedReader( + new FileReader(file)); + char[] readInCharacters = new char[1]; + int readCharacterCount = fileReader.read(readInCharacters); + + while (readCharacterCount > -1) { + readTextStringBuffer.append(String.valueOf(readInCharacters)); + readCharacterCount = fileReader.read(readInCharacters); + } + + fileReader.close(); + + return readTextStringBuffer.toString(); + } + private static File ensureDirectoryExists(String directoryPath) { File directory = new File(directoryPath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-09-18 17:43:38
|
Revision: 954 http://cishell.svn.sourceforge.net/cishell/?rev=954&view=rev Author: pataphil Date: 2009-09-18 17:43:25 +0000 (Fri, 18 Sep 2009) Log Message: ----------- The GUI log view now prints the welcome text based on a file in the "configuration" directory ("Welcome.properties"). Also cleaned up code a little bit. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/Activator.java trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java Modified: trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/Activator.java 2009-09-16 15:53:12 UTC (rev 953) +++ trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/Activator.java 2009-09-18 17:43:25 UTC (rev 954) @@ -2,10 +2,9 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; - +import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogListener; import org.osgi.service.log.LogReaderService; -import org.osgi.framework.ServiceReference; /** * The activator class controls the plug-in life cycle @@ -23,17 +22,20 @@ super.start(context); Activator.context = context; - LogListener listener = new LogToFile(); - ServiceReference ref = context.getServiceReference(LogReaderService.class.getName()); - LogReaderService reader = (LogReaderService) context.getService(ref); - if (reader != null) { - reader.addLogListener(listener); + LogListener fileLogListener = new LogToFile(); + ServiceReference serviceReference = + context.getServiceReference(LogReaderService.class.getName()); + LogReaderService logReaderService = + (LogReaderService) context.getService(serviceReference); + + if (logReaderService != null) { + logReaderService.addLogListener(fileLogListener); } } - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext bundleContext) throws Exception { plugin = null; - super.stop(context); + super.stop(bundleContext); } public static Activator getDefault() { Modified: trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java 2009-09-16 15:53:12 UTC (rev 953) +++ trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java 2009-09-18 17:43:25 UTC (rev 954) @@ -16,10 +16,14 @@ //standard java import java.io.BufferedWriter; +import java.io.File; import java.io.FileWriter; +import java.io.IOException; +import java.net.URL; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import java.util.Properties; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; @@ -51,12 +55,11 @@ import org.osgi.service.log.LogReaderService; import org.osgi.service.log.LogService; - -/** - * @author Weixia Huang (hu...@in...) - * Bruce Herr (bh...@bh...) - */ -public class LogView extends ViewPart implements LogListener{ +public class LogView extends ViewPart implements LogListener { + public static final String CONFIGURATION_DIRECTORY = "configuration"; + public static final String WELCOME_TEXT_FILE_NAME = "Welcome.properties"; + public static final String GREETING_PROPERTY = "greeting"; + private static LogView defaultView; private static Composite parent; private static StyledText text; @@ -76,19 +79,22 @@ static { Display.getDefault().syncExec(new Runnable(){ public void run(){ - LOG_ERROR_COLOR = Display.getDefault().getSystemColor(SWT.COLOR_RED); - LOG_WARNING_COLOR = new Color(Display.getDefault(), 255, 127, 0); //orange - LOG_INFO_COLOR = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); - LOG_DEBUG_COLOR = new Color(Display.getDefault(), 150, 150, 150); //gray + LOG_ERROR_COLOR = + Display.getDefault().getSystemColor(SWT.COLOR_RED); + // Orange. + LOG_WARNING_COLOR = + new Color(Display.getDefault(), 255, 127, 0); + LOG_INFO_COLOR = + Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + // Gray. + LOG_DEBUG_COLOR = + new Color(Display.getDefault(), 150, 150, 150); URL_COLOR = Display.getDefault().getSystemColor(SWT.COLOR_BLUE); } }); } - - /** - * Constructor - */ + public LogView() { defaultView = this; @@ -103,12 +109,11 @@ currentLevel = LogService.LOG_INFO; } */ - colorMapping = new HashMap(); - colorMapping.put(""+LogService.LOG_DEBUG, LOG_DEBUG_COLOR); - colorMapping.put(""+LogService.LOG_INFO, LOG_INFO_COLOR); - colorMapping.put(""+LogService.LOG_WARNING, LOG_WARNING_COLOR); - colorMapping.put(""+LogService.LOG_ERROR, LOG_ERROR_COLOR); - + this.colorMapping = new HashMap(); + this.colorMapping.put("" + LogService.LOG_DEBUG, LOG_DEBUG_COLOR); + this.colorMapping.put("" + LogService.LOG_INFO, LOG_INFO_COLOR); + this.colorMapping.put("" + LogService.LOG_WARNING, LOG_WARNING_COLOR); + this.colorMapping.put("" + LogService.LOG_ERROR, LOG_ERROR_COLOR); } public static LogView getDefault() { @@ -119,19 +124,18 @@ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { - LogView.parent = parent; - text = new StyledText(parent, + this.text = new StyledText(parent, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.READ_ONLY); - text.setEditable(false); - text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); - text.getCaret().setVisible(false); + this.text.setEditable(false); + this.text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); + this.text.getCaret().setVisible(false); - //handle url - urlListener = new URLClickedListener(); - text.addMouseListener(urlListener); - urlCursorListener = new URLMouseCursorListener(); - text.addMouseMoveListener(urlCursorListener); + // Handle URL. + this.urlListener = new URLClickedListener(); + this.text.addMouseListener(this.urlListener); + this.urlCursorListener = new URLMouseCursorListener(); + this.text.addMouseMoveListener(this.urlCursorListener); //add copy context menu when hover a block of text and right click the mouse Display display = Display.getDefault(); @@ -166,20 +170,57 @@ //Get LogReaderService through BundleContext //Add itself to the LogReaderService as a LogListener BundleContext context = Activator.getContext(); - ServiceReference ref = context.getServiceReference(LogReaderService.class.getName()); - LogReaderService reader = (LogReaderService) context.getService(ref); - if (reader != null) { - reader.addLogListener(this); + ServiceReference logReaderServiceReference = + context.getServiceReference(LogReaderService.class.getName()); + LogReaderService logReaderService = + (LogReaderService) context.getService(logReaderServiceReference); + + if (logReaderService != null) { + logReaderService.addLogListener(this); - Enumeration backLogEntries = reader.getLog(); + Enumeration backLogEntries = logReaderService.getLog(); while (backLogEntries.hasMoreElements()) { LogEntry logEntry = (LogEntry)backLogEntries.nextElement(); this.logged(logEntry); } } - else + else { System.out.println("reader is null"); + } + + ServiceReference logServiceReference = + context.getServiceReference(LogService.class.getName()); + LogService logService = + (LogService)context.getService(logServiceReference); + + if (logService != null) { + try { + String welcomeTextFilePath = CONFIGURATION_DIRECTORY + + File.separator + + WELCOME_TEXT_FILE_NAME; + URL welcomeTextFileURL = new File(welcomeTextFilePath).toURL(); + Properties properties = new Properties(); + properties.load(welcomeTextFileURL.openStream()); + String greetingText = + properties.getProperty(GREETING_PROPERTY, null); + logService.log(LogService.LOG_INFO, greetingText); + } catch (IOException ioException) { + System.err.println("Error reading Welcome properties file: " + + ioException.getMessage()); + } + } + else { + try { + FileWriter fstream = new FileWriter("WelcomeTextError.txt", true); + BufferedWriter out = new BufferedWriter(fstream); + out.write("The Log Service cannot be found.\r\n"); + out.close(); + } catch (Exception exception) { + System.err.println("Error writing to file: " + + exception.getMessage()); + } + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tan...@us...> - 2009-09-16 15:53:29
|
Revision: 953 http://cishell.svn.sourceforge.net/cishell/?rev=953&view=rev Author: tankchintan Date: 2009-09-16 15:53:12 +0000 (Wed, 16 Sep 2009) Log Message: ----------- Deleting. Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.brand.cishell/digital-certificate-files/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |