Author: mes
Date: 2012-06-15 17:24:53 -0700 (Fri, 15 Jun 2012)
New Revision: 29591
Modified:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/util/ListSingleSelection.java
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/util/ListSingleSelectionTest.java
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/AbstractCyWriter.java
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
Log:
Made list single selection a bit more flexibile to better work with commands
and tweaked some writer code to handle a broader range of input
Modified:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/util/ListSingleSelection.java
===================================================================
---
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/util/ListSingleSelection.java
2012-06-16 00:22:45 UTC (rev 29590)
+++
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/util/ListSingleSelection.java
2012-06-16 00:24:53 UTC (rev 29591)
@@ -38,6 +38,8 @@
import java.util.Arrays;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -47,6 +49,8 @@
* @CyAPI.Final.Class
*/
public final class ListSingleSelection<T> extends ListSelection<T> {
+
+ private static final Logger logger =
LoggerFactory.getLogger(ListSingleSelection.class);
/**
* The item that will be selected.
@@ -107,7 +111,8 @@
*/
public void setSelectedValue(T val) {
if (!values.contains(val))
- throw new IllegalArgumentException("value not contained
in list of possible values\n possible items = "+this.getPossibleValues());
+ logger.warn("value not contained in list of possible
values possible items = "+
+
Arrays.toString(getPossibleValues().toArray()));
selected = val;
}
Modified:
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/util/ListSingleSelectionTest.java
===================================================================
---
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/util/ListSingleSelectionTest.java
2012-06-16 00:22:45 UTC (rev 29590)
+++
core3/api/trunk/work-api/src/test/java/org/cytoscape/work/util/ListSingleSelectionTest.java
2012-06-16 00:24:53 UTC (rev 29591)
@@ -37,7 +37,7 @@
public class ListSingleSelectionTest {
private ListSingleSelection<String> lss;
-
+
@Before
public void init() {
lss = new ListSingleSelection<String>("carrots", "cabbages",
"brocolli", "cucumbers");
@@ -49,9 +49,10 @@
assertEquals("Selected value not as expected!", "cabbages",
lss.getSelectedValue());
}
- @Test(expected=IllegalArgumentException.class)
- public final void testSetSelectedValueWithInvalidSelection() throws
Exception {
+ @Test
+ public final void testSetSelectedValueWithRiskySelection() throws
Exception {
lss.setSelectedValue("oranges");
+ assertEquals("Selected value not as expected!", "oranges",
lss.getSelectedValue());
}
@Test(expected=NullPointerException.class)
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/AbstractCyWriter.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/AbstractCyWriter.java
2012-06-16 00:22:45 UTC (rev 29590)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/AbstractCyWriter.java
2012-06-16 00:24:53 UTC (rev 29591)
@@ -15,6 +15,7 @@
import java.util.Map;
import java.util.TreeMap;
import java.util.ArrayList;
+import java.util.Collection;
/**
@@ -59,9 +60,13 @@
* @return a file format description from {@link CyFileFilter}.
*/
abstract protected String getExportFileFormat();
- /** A Map that maps description strings to {@link CyFileFilter}s*/
- protected final Map<String,CyFileFilter> descriptionFilterMap;
+ /** A Map that maps file filter description strings to {@link
CyFileFilter}s*/
+ private final Map<String,CyFileFilter> descriptionFilterMap;
+
+ /** A Map that maps file filter extension strings to {@link
CyFileFilter}s*/
+ private final Map<String,CyFileFilter> extensionFilterMap;
+
/**
* The CyWriterManager specified in the constructor.
*/
@@ -78,8 +83,13 @@
this.writerManager = writerManager;
descriptionFilterMap = new TreeMap<String,CyFileFilter>();
- for (CyFileFilter f : writerManager.getAvailableWriterFilters())
+ extensionFilterMap = new TreeMap<String,CyFileFilter>();
+ for (CyFileFilter f :
writerManager.getAvailableWriterFilters()) {
descriptionFilterMap.put(f.getDescription(), f);
+ for ( String ext : f.getExtensions() ) {
+ extensionFilterMap.put(ext.toLowerCase(),f);
+ }
+ }
}
/**
@@ -95,7 +105,7 @@
if (desc == null)
throw new NullPointerException("No file type has been
specified!");
- final CyFileFilter filter = descriptionFilterMap.get(desc);
+ final CyFileFilter filter = getFileFilter(desc);
if (filter == null)
throw new NullPointerException("No file filter found
for specified file type!");
@@ -107,12 +117,42 @@
}
/**
- * Should return a {@link org.cytoscape.io.write.CyWriter} object for
writing the specified file of the specified type.
+ * Should return a {@link org.cytoscape.io.write.CyWriter} object for
writing
+ * the specified file of the specified type.
* @param filter The specific type of file to be written.
* @param out The file that will be written.
- * @return a {@link org.cytoscape.io.write.CyWriter} object for writing
the specified file of the specified type.
+ * @return a {@link org.cytoscape.io.write.CyWriter} object for writing
the specified file
+ * of the specified type.
* @throws Exception
*/
protected abstract CyWriter getWriter(CyFileFilter filter, File out)
throws Exception;
+ /**
+ * Returns a collection of human readable descriptions of all of the
file filters
+ * available for this writer.
+ * @return a collection of human readable descriptions of all of the
file filters
+ * available for this writer.
+ */
+ protected final Collection<String> getFileFilterDescriptions() {
+ return descriptionFilterMap.keySet();
+ }
+
+ /**
+ * Returns a CyFileFilter that matches the specifed description where
the description
+ * is either the human readable text returned from
#getFileFilterDescriptions or a
+ * valid extension for the CyFileFilter. Duplicate file extensions
(e.g. xml) will
+ * return an arbitrary filter.
+ * @param description A human readable description or file extension
string.
+ * @returns a CyFileFilter matching the description or extension.
+ */
+ protected final CyFileFilter getFileFilter(String description) {
+ if (description == null)
+ return null;
+
+ CyFileFilter f = descriptionFilterMap.get(description);
+ if ( f != null )
+ return f;
+ else
+ return
extensionFilterMap.get(description.toLowerCase());
+ }
}
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
2012-06-16 00:22:45 UTC (rev 29590)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
2012-06-16 00:24:53 UTC (rev 29591)
@@ -42,7 +42,7 @@
*/
public TunableAbstractCyWriter(T writerManager) {
super(writerManager);
- options = new ListSingleSelection<String>(new
ArrayList<String>(descriptionFilterMap.keySet()));
+ options = new ListSingleSelection<String>(new
ArrayList<String>(getFileFilterDescriptions()));
}
@Override
@@ -87,7 +87,7 @@
if (exportFileFormat == null)
return true;
- final CyFileFilter filter =
descriptionFilterMap.get(exportFileFormat);
+ final CyFileFilter filter = getFileFilter(exportFileFormat);
if (filter == null)
return true;
@@ -106,7 +106,7 @@
}
protected final File addOrReplaceExtension(final File file) {
- final CyFileFilter filter =
descriptionFilterMap.get(getExportFileFormat());
+ final CyFileFilter filter =
getFileFilter(getExportFileFormat());
if (filter == null)
return file;
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.