Author: kono
Date: 2012-06-05 16:21:58 -0700 (Tue, 05 Jun 2012)
New Revision: 29472
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
Log:
refs #1029 Passthrough mapping value handlers had been modified to be a bit
more robust.
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
2012-06-05 23:11:16 UTC (rev 29471)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
2012-06-05 23:21:58 UTC (rev 29472)
@@ -142,14 +142,14 @@
* the type-parameter of the View
*/
private void doMap(final CyRow row, final View<? extends
CyIdentifiable> view) {
- if (row.isSet(attrName)) {
+ if (row.isSet(columnName)) {
// skip Views where source attribute is not defined;
// ViewColumn will automatically substitute the per-VS
or global
// default, as appropriate
// In all cases, attribute value should be a number for
continuous
// mapping.
- final K attrValue = row.get(attrName, attrType);
+ final K attrValue = row.get(columnName, columnType);
final V value = getRangeValue(attrValue);
view.setVisualProperty(vp, value);
}
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
2012-06-05 23:11:16 UTC (rev 29471)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
2012-06-05 23:21:58 UTC (rev 29472)
@@ -77,20 +77,20 @@
if (row != null && view != null) {
V value = null;
- if (attrName.equals(CyIdentifiable.SUID)) {
+ if (columnName.equals(CyIdentifiable.SUID)) {
// Special case: SUID
Object key =
Long.valueOf(view.getModel().getSUID());
if (key != null)
value = attribute2visualMap.get(key);
- } else if (row.isSet(attrName)) {
+ } else if (row.isSet(columnName)) {
// skip Views where source attribute is not
defined;
// ViewColumn will automatically substitute the
per-VS or global default, as appropriate
- final CyColumn column =
row.getTable().getColumn(attrName);
+ final CyColumn column =
row.getTable().getColumn(columnName);
final Class<?> attrClass = column.getType();
if (attrClass.isAssignableFrom(List.class)) {
- List<?> list = row.getList(attrName,
column.getListElementType());
+ List<?> list = row.getList(columnName,
column.getListElementType());
if (list != null) {
for (Object item : list) {
@@ -103,7 +103,7 @@
}
}
} else {
- Object key = row.get(attrName,
attrType);
+ Object key = row.get(columnName,
columnType);
if (key != null)
value =
attribute2visualMap.get(key);
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
2012-06-05 23:11:16 UTC (rev 29471)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
2012-06-05 23:21:58 UTC (rev 29472)
@@ -48,9 +48,9 @@
* dataType is the type of the _attribute_ !! currently we force that
to be
* the same as the VisualProperty; FIXME: allow different once? but how
to coerce?
*/
- public PassthroughMappingImpl(final String attrName, final Class<K>
attrType, final CyTable table,
+ public PassthroughMappingImpl(final String columnName, final Class<K>
columnType, final CyTable table,
final VisualProperty<V> vp) {
- super(attrName, attrType, table, vp);
+ super(columnName, columnType, table, vp);
}
@Override
@@ -65,20 +65,18 @@
V value = null;
- if (attrName.equals(CyIdentifiable.SUID)) {
- // Special case: SUID
- value = (V) view.getModel().getSUID();
- } else if (row.isSet(attrName)) {
- // skip Views where source attribute is not defined;
- // ViewColumn will automatically substitute the per-VS
or
- // global default, as appropriate
- final CyColumn column =
row.getTable().getColumn(attrName);
- final Class<?> attrClass = column.getType();
- K tempValue = null;
+ if (columnName.equals(CyIdentifiable.SUID)) {
+ // Special case: SUID. Value is type Long. This
always exists.
+ value = (V) view.getModel().getSUID().toString();
+ } else if (row.isSet(columnName)) {
+ final CyColumn column =
row.getTable().getColumn(columnName);
+ final Class<?> columnClass = column.getType();
- if (attrClass.isAssignableFrom(List.class)) {
- List<?> list = row.getList(attrName,
column.getListElementType());
- StringBuffer sb = new StringBuffer();
+ Object tempValue = null;
+ if (columnClass.isAssignableFrom(List.class)) {
+ // Special handler for List column. String is
only supported one.
+ final List<?> list = row.getList(columnName,
column.getListElementType());
+ final StringBuffer sb = new StringBuffer();
if (list != null && !list.isEmpty()) {
for (Object item : list)
@@ -87,24 +85,24 @@
sb.deleteCharAt(sb.length() - 1);
}
- tempValue = (K) sb.toString();
+ tempValue = sb.toString();
} else {
- tempValue = row.get(attrName, (Class<? extends
K>) attrClass);
+ // Regular column.
+ tempValue = row.get(columnName, columnType);
}
- value = convertToValue(tempValue);
+ try {
+ value = vp.getRange().getType().cast(tempValue);
+ } catch(ClassCastException ex) {
+ // Invalid. Try if it's a String
+ if(vp.getRange().getType() == String.class)
+ value=(V) tempValue.toString();
+ else
+ value = null;
+ }
}
if (value != null)
view.setVisualProperty(vp, value);
}
-
- // TODO: make this converter pluggable
- private V convertToValue(final K key) {
- try {
- return (V) key;
- } catch (Exception e) {
- return null;
- }
- }
}
--
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.