Author: abeld
Date: 2009-03-12 03:20:12 -0700 (Thu, 12 Mar 2009)
New Revision: 16217
Removed:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/PassthroughMappingCalculator.java
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/pom.xml
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/CyMain.java
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-api-columns/src/main/java/org/cytoscape/view/model/ViewColumn.java
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
Log:
refactored-viewmodel: implement ViewColumn.setValues() bulk method, and use
that from MappingCalculators in default-mappings.
also, remove PassthroughMappingCalculator.java from column-oriented
integration-testing bundle, and make that bundle use default-mappings
instead.
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/pom.xml
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/pom.xml
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/pom.xml
2009-03-12 10:20:12 UTC (rev 16217)
@@ -172,6 +172,11 @@
<version>1.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>default-mappings</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.cytoscape</groupId>
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/CyMain.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/CyMain.java
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/CyMain.java
2009-03-12 10:20:12 UTC (rev 16217)
@@ -48,6 +48,7 @@
import org.cytoscape.view.model.*;
import org.cytoscape.vizmap.*;
+import org.cytoscape.vizmap.mappings.PassthroughMappingCalculator;
/**
Deleted:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/PassthroughMappingCalculator.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/PassthroughMappingCalculator.java
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/column-oriented-integration_test/src/main/java/cytoscape/PassthroughMappingCalculator.java
2009-03-12 10:20:12 UTC (rev 16217)
@@ -1,144 +0,0 @@
-
-/*
- Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
-
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-
-package cytoscape;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.cytoscape.model.*;
-
-import org.cytoscape.view.model.*;
-
-import org.cytoscape.vizmap.*;
-
-
-/**
- */
-public class PassthroughMappingCalculator implements MappingCalculator {
- private String attributeName;
- private VisualProperty<?> vp;
-
- /**
- * 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 <T> PassthroughMappingCalculator(final String attributeName,
final VisualProperty<T> vp) {
- this.attributeName = attributeName;
- this.vp = vp;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param attributeName DOCUMENT ME!
- */
- public void setMappingAttributeName(final String attributeName) {
- this.attributeName = attributeName;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public String getMappingAttributeName() {
- return attributeName;
- }
-
- /**
- * The visual property the attribute gets mapped to.
- *
- * @param vp DOCUMENT ME!
- */
- public void setVisualProperty(final VisualProperty<?> vp) {
- this.vp = vp;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public VisualProperty<?> getVisualProperty() {
- return vp;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param v DOCUMENT ME!
- */
- public <T, V extends GraphObject> void apply(ViewColumn<T> column,
List<? extends View<V>> views){
- if (views.size() < 1)
- return; // empty list, nothing to do
- CyRow row = views.get(0).getSource().attrs();
- Class<?> attrType =
row.getDataTable().getColumnTypeMap().get(attributeName);
- // since attributes can only store certain types of Objects, it
is enough to test for these:
- Class<?> vpType = vp.getType();
- // FIXME: also check that column's vp is internally-stored vp!
- if (vpType.isAssignableFrom(attrType)){
- // can simply copy object without any conversion
- for (View<V> v: views){
- row = v.getSource().attrs();
- if (row.contains(attributeName, attrType) ){
- // skip Views where source attribute is
not defined; ViewColumn will automatically substitute the per-VS or global
default, as appropriate
- final T value = (T)
row.get(attributeName, attrType);
- column.setValue(v, value);
- } else { // remove value so that default value
will be used:
- column.clearValue(v);
- }
- }
- } else if (String.class.isAssignableFrom(vpType)){
- // can convert any object to string, so no need to
check attribute type
- // also, since we have to convert the Object here,
can't use checkAndDoCopy()
- ViewColumn<String> c = (ViewColumn<String>) column; //
have to cast here, even though previous check ensures that T is
java.util.String
- for (View<V> v: views){
- row = v.getSource().attrs();
- if (row.contains(attributeName, attrType) ){
- // skip Views where source attribute is
not defined; ViewColumn will automatically substitute the per-VS or global
default, as appropriate
- final Object value = (Object)
row.get(attributeName, attrType);
- c.setValue(v, value.toString());
- } else { // remove value so that default value
will be used:
- c.clearValue(v);
- }
- }
- } else {
- throw new IllegalArgumentException("Mapping
"+toString()+" can't map from attribute type "+attrType+" to VisualProperty
"+vp+" of type "+vp.getType());
- }
- }
-}
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
2009-03-12 10:20:12 UTC (rev 16217)
@@ -56,7 +56,9 @@
import java.awt.Color;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* Implements an interpolation table mapping data to values of a particular
@@ -174,6 +176,10 @@
* @param <V> the type-parameter of the View
*/
private <T,K extends Number, V extends GraphObject> void doMap(final
List<? extends View<V>> views, ViewColumn<T> column, Class<K> attrType){
+ // aggregate changes to be made in these:
+ Map<View<V>, T> valuesToSet = new HashMap<View<V>, T>();
+ List<View<V>> valuesToClear = new ArrayList<View<V>>();
+
for (View<V> v: views){
CyRow row = v.getSource().attrs();
if (row.contains(attrName, attrType) ){
@@ -182,11 +188,12 @@
final K attrValue = (K)
v.getSource().attrs().get(attrName, attrType);
final T value = (T) getRangeValue(attrValue);
// FIXME: make getRangeValue type-parametric, so this shouldn't be needed (??)
- column.setValue(v, value);
+ valuesToSet.put(v, value);
} else { // remove value so that default value will be
used:
- column.clearValue(v);
+ valuesToClear.add(v);
}
- }
+ }
+ column.setValues(valuesToSet, valuesToClear);
}
private Object getRangeValue(Number domainValue) {
ContinuousMappingPoint firstPoint = points.get(0);
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
2009-03-12 10:20:12 UTC (rev 16217)
@@ -49,6 +49,8 @@
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.vizmap.MappingCalculator;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
@@ -134,6 +136,10 @@
* @param <V> the type-parameter of the View
*/
private <T,K, V extends GraphObject> void doMap(final List<? extends
View<V>> views, ViewColumn<T> column, Class<K> attrType){
+ // aggregate changes to be made in these:
+ Map<View<V>, T> valuesToSet = new HashMap<View<V>, T>();
+ List<View<V>> valuesToClear = new ArrayList<View<V>>();
+
for (View<V> v: views){
CyRow row = v.getSource().attrs();
if (row.contains(attrName, attrType) ){
@@ -143,14 +149,15 @@
final K key = (K)
v.getSource().attrs().get(attrName, attrType);
if (treeMap.containsKey(key)){
final T value = (T) treeMap.get(key);
- column.setValue(v, value);
+ valuesToSet.put(v, value);
} else { // remove value so that default value
will be used:
- column.clearValue(v);
+ valuesToClear.add(v);
}
} else { // remove value so that default value will be
used:
- column.clearValue(v);
+ valuesToClear.add(v);
}
- }
+ }
+ column.setValues(valuesToSet, valuesToClear);
}
/**
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
2009-03-12 10:20:12 UTC (rev 16217)
@@ -42,7 +42,10 @@
import org.cytoscape.vizmap.*;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
*/
@@ -109,32 +112,41 @@
// since attributes can only store certain types of Objects, it
is enough to test for these:
Class<?> vpType = vp.getType();
// FIXME: also check that column's vp is internally-stored vp!
- if (vpType.isAssignableFrom(attrType)){
- // can simply copy object without any conversion
+ if (vpType.isAssignableFrom(attrType)){ // can simply copy
object without any conversion
+ // aggregate changes to be made in these:
+ Map<View<V>, T> valuesToSet = new HashMap<View<V>, T>();
+ List<View<V>> valuesToClear = new ArrayList<View<V>>();
for (View<V> v: views){
row = v.getSource().attrs();
if (row.contains(attributeName, attrType) ){
// skip Views where source attribute is
not defined; ViewColumn will automatically substitute the per-VS or global
default, as appropriate
final T value = (T)
row.get(attributeName, attrType);
- column.setValue(v, value);
+ valuesToSet.put(v, value);
} else { // remove value so that default value
will be used:
- column.clearValue(v);
+ valuesToClear.add(v);
}
}
+ column.setValues(valuesToSet, valuesToClear);
} else if (String.class.isAssignableFrom(vpType)){
// can convert any object to string, so no need to
check attribute type
// also, since we have to convert the Object here,
can't use checkAndDoCopy()
ViewColumn<String> c = (ViewColumn<String>) column; //
have to cast here, even though previous check ensures that T is
java.util.String
+
+ // aggregate changes to be made in these:
+ Map<View<V>, String> valuesToSet = new HashMap<View<V>,
String>();
+ List<View<V>> valuesToClear = new ArrayList<View<V>>();
+
for (View<V> v: views){
row = v.getSource().attrs();
if (row.contains(attributeName, attrType) ){
// skip Views where source attribute is
not defined; ViewColumn will automatically substitute the per-VS or global
default, as appropriate
final Object value = (Object)
row.get(attributeName, attrType);
- c.setValue(v, value.toString());
+ valuesToSet.put(v, value.toString());
} else { // remove value so that default value
will be used:
- c.clearValue(v);
+ valuesToClear.add(v);
}
}
+ c.setValues(valuesToSet, valuesToClear);
} else {
throw new IllegalArgumentException("Mapping
"+toString()+" can't map from attribute type "+attrType+" to VisualProperty
"+vp+" of type "+vp.getType());
}
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-api-columns/src/main/java/org/cytoscape/view/model/ViewColumn.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-api-columns/src/main/java/org/cytoscape/view/model/ViewColumn.java
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-api-columns/src/main/java/org/cytoscape/view/model/ViewColumn.java
2009-03-12 10:20:12 UTC (rev 16217)
@@ -1,5 +1,8 @@
package org.cytoscape.view.model;
+import java.util.List;
+import java.util.Map;
+
import org.cytoscape.view.model.View;
/**
@@ -16,9 +19,20 @@
*/
T getValue(View<?> view);
+ /**
+ *
+ * Sets the computed value for the given view. Note that using this
method
+ * for setting many values will be horribly inefficient. Use setValues()
+ * instead.
+ */
void setValue(View<?> view, T value);
/**
+ * Bulk method for setting many values at once. This fires only a
single event and is thus much more efficient.
+ */
+ public void setValues(Map<View<?>, T> values, List<View<?>> toClear);
+
+ /**
* Remove the value stored for the given view.
*
* This is needed to allow reverting the value for a given view to "the
default value, whatever that is".
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
2009-03-12 09:34:46 UTC (rev 16216)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
2009-03-12 10:20:12 UTC (rev 16217)
@@ -1,6 +1,8 @@
package org.cytoscape.view.model.internal;
import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.cytoscape.view.model.View;
import org.cytoscape.view.model.ViewColumn;
@@ -62,14 +64,46 @@
}
}
+ /**
+ *
+ * Sets the computed value for the given view. Note that using this
method
+ * for setting many values will be horribly inefficient. Use setValues()
+ * instead.
+ */
public void setValue(View<?> view, T value) {
+ internal_setValue(view, value);
+ // FIXME: fire event!
+ }
+
+ /**
+ * Bulk method for setting many values at once. This fires only a
single event and is thus much more efficient.
+ */
+ public void setValues(Map<View<?>, T> values, List<View<?>> toClear) {
+ for (Map.Entry<View<?>, T> entry : values.entrySet()){
+ internal_setValue(entry.getKey(), entry.getValue());
+ }
+ for (View<?>v: toClear){
+ internal_clearValue(v);
+ }
+ // FIXME: fire event!
+ }
+
+ /** An internal method, to avoid duplicating this code in setValue()
and setValues(). This method does not fire events!
+ * (I hope the compiler optimizes this away...)
+ */
+ private void internal_setValue(View<?> view, T value){
if (view == null)
throw new NullPointerException(VIEW_IS_NULL);
values.put(view, value);
}
-
+
public void clearValue(View<?> view) {
+ internal_clearValue(view);
+ // FIXME: fire event!
+ }
+
+ private void internal_clearValue(View<?> view) {
if (view == null)
throw new NullPointerException(VIEW_IS_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
-~----------~----~----~----~------~----~------~--~---