Author: mes
Date: 2011-11-15 12:08:29 -0800 (Tue, 15 Nov 2011)
New Revision: 27470

Modified:
   
core3/api/trunk/core-task-api/src/main/java/org/cytoscape/task/MapNetworkAttrTask.java
   core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
   
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/MergeDataTask.java
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/SessionReaderImpl.java
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/UnrecognizedVisualPropertyManager.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnAdder.java
   
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
   
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
   
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
   
core3/impl/trunk/table-import-impl/src/main/java/org/cytoscape/tableimport/internal/task/MapGeneAssociationTask.java
Log:
made virtual columns only join on the source primary key rather than an 
arbitrary key

Modified: 
core3/api/trunk/core-task-api/src/main/java/org/cytoscape/task/MapNetworkAttrTask.java
===================================================================
--- 
core3/api/trunk/core-task-api/src/main/java/org/cytoscape/task/MapNetworkAttrTask.java
      2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/api/trunk/core-task-api/src/main/java/org/cytoscape/task/MapNetworkAttrTask.java
      2011-11-15 20:08:29 UTC (rev 27470)
@@ -114,7 +114,7 @@
                for (final CyTable targetTable : targetTables) {
                        if (cancelled)
                                return;
-                       targetTable.addVirtualColumns(newGlobalTable, 
sourceTableJoinColumn, mappingKey, false);                        
+                       targetTable.addVirtualColumns(newGlobalTable, 
mappingKey, false);                       
                }
        }
 }

Modified: 
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
===================================================================
--- core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java    
2011-11-15 18:53:49 UTC (rev 27469)
+++ core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java    
2011-11-15 20:08:29 UTC (rev 27470)
@@ -223,35 +223,36 @@
         */
        int getRowCount();
 
-       /** Adds a "virtual" column to the the current table.
-        *  @param virtualColumn  the name of the new virtual column, if this 
name already exists,
-        *                        new column names with -1, -2 and so appended 
to this name on will
-        *                        be tried until a non-existing name will be 
found
-        *  @param sourceColumn   the name of the column in "sourceTable" that 
will be mapped to
-        *                        "virtualColumn"
-        *  @param sourceTable    the table that really contains the column 
that we're adding (all
-        *                        updates and lookups of this new column will 
be redirected to here)
-        *  @param sourceJoinKey  the column in "sourceTable" that will be used 
for the join
-        *  @param targetJoinKey  the column in current table that will be used 
for the join
-        *  @param isImmutable    if true, this column cannot be deleted
-        *  @return the actual name of the new virtual column
-        *  Note: The types of "sourceJoinKey" and "targetJoinKey" have to be 
identical.
+       /** 
+        * Adds a "virtual" column to the the current table.
+        * @param virtualColumn  The name of the new virtual column, if this 
name already exists,
+        *                       new column names with -1, -2 and so appended 
to this name on will
+        *                       be tried until a non-existing name will be 
found.
+        * @param sourceColumn   The name of the column in "sourceTable" that 
will be mapped to
+        *                       "virtualColumn".
+        * @param sourceTable    The table that really contains the column that 
we're adding (all
+        *                       updates and lookups of this new column will be 
redirected to here).
+        *                       The table will be joined on the primary key 
column of this table.
+        * @param targetJoinKey  The column in current table that will be used 
for the join. This
+        *                       column will be joined with the primary key 
column of the source
+        *                       table. These columns must be of the same type!
+        * @param isImmutable    If true, this column cannot be deleted.
+        * @return The actual name of the new virtual column.
         */
        String addVirtualColumn(String virtualColumn, String sourceColumn, 
CyTable sourceTable,
-                               String sourceJoinKey, String targetJoinKey,
-                               boolean isImmutable);
+                               String targetJoinKey, boolean isImmutable);
 
        /** Adds all columns in another table as "virtual" columns to the the 
current table.
-        *  @param sourceTable    the table that really contains the column 
that we're adding (all
-        *                        updates and lookups of this new column will 
be redirected to here)
-        *  @param sourceJoinKey  the column in "sourceTable" that will be used 
for the join
-        *  @param targetJoinKey  the column in current table that will be used 
for the join
-        *  @param isImmutable    if true, these columns cannot be deleted
-        *  Note: The types of "sourceJoinKey" and "targetJoinKey" have to be 
identical.  Also none
-        *        of the column names in "sourceTable" must exist in the 
current table!
+        *  @param sourceTable    The table that really contains the column 
that we're adding (all
+        *                        updates and lookups of this new column will 
be redirected to here).
+        *                        The table will be joined on the primary key 
column of this table.
+        *                        None of the column names in "sourceTable" 
must exist in the current table!
+        *  @param targetJoinKey  The column in current table that will be used 
for the join. This
+        *                        column will be joined with the primary key 
column of the source
+        *                        table. These columns must be of the same type!
+        *  @param isImmutable    If true, these columns cannot be deleted.
         */
-       void addVirtualColumns(CyTable sourceTable, String sourceJoinKey, 
String targetJoinKey,
-                              boolean isImmutable);
+       void addVirtualColumns(CyTable sourceTable, String targetJoinKey, 
boolean isImmutable);
        
        /**
         * Returns how (or if) this CyTable should be saved.

Modified: 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
===================================================================
--- 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
        2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
        2011-11-15 20:08:29 UTC (rev 27470)
@@ -541,26 +541,21 @@
        @Test
        public void testVirtualColumn() {
                table.createColumn("x", Long.class, false);
-               table2.createColumn("x2", Long.class, false);
                table2.createColumn("s", String.class, false);
-               assertEquals(table.addVirtualColumn("s1", "s", table2, "x2", 
"x", false), "s1");
+               assertEquals(table.addVirtualColumn("s1", "s", table2, "x", 
false), "s1");
                assertEquals("Virtual column type should have been String!",
                             String.class, table.getColumn("s1").getType());
-               assertEquals(table.addVirtualColumn("s1", "s", table2, "x2", 
"x", false), "s1-1");
+               assertEquals(table.addVirtualColumn("s1", "s", table2, "x", 
false), "s1-1");
                assertEquals("Virtual column type should have been String!",
                             String.class, table.getColumn("s1-1").getType());
        }
 
        @Test
        public void testVirtualColumnIsSet() {
-               table.createColumn("x", Integer.class, false);
                CyRow row1 = table.getRow(1L);
-               row1.set("x", 33);
-               table2.createColumn("x2", Integer.class, false);
                CyRow row2 =  table2.getRow(1L);
-               row2.set("x2", 33);
                table2.createColumn("s", String.class, false);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", true);
+               table.addVirtualColumn("s1", "s", table2, 
table.getPrimaryKey().getName(), true);
                assertFalse(row1.isSet("s1"));
                row2.set("s", "abc");
                assertTrue(row1.isSet("s1"));
@@ -568,14 +563,10 @@
 
        @Test
        public void testVirtualColumnGet() {
-               table.createColumn("x", Integer.class, false);
                CyRow row1 = table.getRow(1L);
-               row1.set("x", 33);
-               table2.createColumn("x2", Integer.class, false);
                CyRow row2 =  table2.getRow(1L);
-               row2.set("x2", 33);
                table2.createColumn("s", String.class, false);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", false);
+               table.addVirtualColumn("s1", "s", table2, 
table.getPrimaryKey().getName(), false);
                assertFalse(row1.isSet("s1"));
                row2.set("s", "abc");
                assertEquals(row1.get("s1", String.class), "abc");
@@ -583,14 +574,10 @@
 
        @Test
        public void testVirtualColumnSetWithAReplacementValue() {
-               table.createColumn("x", Integer.class, false);
                CyRow row1 = table.getRow(1L);
-               row1.set("x", 33);
-               table2.createColumn("x2", Integer.class, false);
                CyRow row2 =  table2.getRow(1L);
-               row2.set("x2", 33);
                table2.createColumn("s", String.class, false);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", true);
+               table.addVirtualColumn("s1", "s", table2, 
table.getPrimaryKey().getName(), true);
                assertFalse(row1.isSet("s1"));
                row2.set("s", "abc");
                assertEquals(row1.get("s1", String.class), "abc");
@@ -600,14 +587,10 @@
 
        @Test
        public void testVirtualColumnUnset() {
-               table.createColumn("x", Integer.class, false);
                CyRow row1 = table.getRow(1L);
-               row1.set("x", 33);
-               table2.createColumn("x2", Integer.class, false);
                CyRow row2 =  table2.getRow(1L);
-               row2.set("x2", 33);
                table2.createColumn("s", String.class, false);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", false);
+               table.addVirtualColumn("s1", "s", table2, 
table.getPrimaryKey().getName(), false);
                row2.set("s", "abc");
                assertTrue(row1.isSet("s1"));
                row1.set("s1", null);
@@ -619,11 +602,9 @@
                table.createColumn("x", Integer.class, false);
                CyRow row1 = table.getRow(1L);
                row1.set("x", 33);
-               table2.createColumn("x2", Integer.class, false);
                CyRow row2 =  table2.getRow(1L);
-               row2.set("x2", 33);
                table2.createColumn("s", String.class, false);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", true);
+               table.addVirtualColumn("s1", "s", table2, 
table.getPrimaryKey().getName(), true);
                assertFalse(row1.isSet("s1"));
                row2.set("s", "abc");
                Collection<CyRow> matchingRows = table.getMatchingRows("s1", 
"abc");
@@ -636,9 +617,8 @@
        @Test
        public void testVirtualColumnDelete() {
                table.createColumn("x", Long.class, false);
-               table2.createColumn("x2", Long.class, false);
                table2.createColumn("s", String.class, false);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", false);
+               table.addVirtualColumn("s1", "s", table2, "x", false);
                assertNotNull(table.getColumn("s1"));
                table.deleteColumn("s1");
                assertNull(table.getColumn("s1"));
@@ -646,14 +626,10 @@
 
        @Test
        public void testVirtualColumnColumnSize() {
-               table.createColumn("x", Integer.class, false);
                CyRow row1 = table.getRow(1L);
-               row1.set("x", 33);
-               table2.createColumn("x2", Integer.class, false);
                CyRow row2 =  table2.getRow(1L);
-               row2.set("x2", 33);
                table2.createColumn("s", String.class, false);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", true);
+               table.addVirtualColumn("s1", "s", table2, 
table.getPrimaryKey().getName(), true);
                assertFalse(row1.isSet("s1"));
                row2.set("s", "abc");
                List<String> columnValues = 
table.getColumn("s1").getValues(String.class);
@@ -664,9 +640,8 @@
        @Test
        public void testVirtualColumnGetColumnValues() {
                table.createColumn("x", Long.class, false);
-               table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
-               table.addVirtualColumn("b1", "b", table2, "x2", "x", false);
+               table.addVirtualColumn("b1", "b", table2, "x", false);
                assertEquals("Virtual column list element type should have been 
Boolean!",
                             Boolean.class, 
table.getColumn("b1").getListElementType());
        }
@@ -674,9 +649,8 @@
        @Test
        public void testIsVirtual() {
                table.createColumn("x", Long.class, false);
-               table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
-               table.addVirtualColumn("b1", "b", table2, "x2", "x", true);
+               table.addVirtualColumn("b1", "b", table2, "x", true);
                
assertTrue(table.getColumn("b1").getVirtualColumnInfo().isVirtual());
                
assertFalse(table.getColumn("x").getVirtualColumnInfo().isVirtual());
                
assertFalse(table2.getColumn("b").getVirtualColumnInfo().isVirtual());
@@ -709,9 +683,8 @@
                table.createColumn("x", Long.class, false);
                CyColumn column = table.getColumn("x");
                assertNull(column.getVirtualColumnInfo().getSourceTable());
-               table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
-               table.addVirtualColumn("b1", "b", table2, "x2", "x", true);
+               table.addVirtualColumn("b1", "b", table2, "x", true);
                CyColumn column2 = table.getColumn("b1");
                assertEquals(table2, 
column2.getVirtualColumnInfo().getSourceTable());
        }
@@ -719,10 +692,9 @@
        @Test
        public void testTableMutability() {
                table.createColumn("x", Long.class, false);
-               table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
                assertEquals(Mutability.MUTABLE, table2.getMutability());
-               table.addVirtualColumn("b1", "b", table2, "x2", "x", true);
+               table.addVirtualColumn("b1", "b", table2, "x", true);
                
assertEquals(Mutability.IMMUTABLE_DUE_TO_VIRT_COLUMN_REFERENCES, 
table2.getMutability());
        }
 
@@ -927,4 +899,80 @@
        public void testGetAttrBeforeColumnExists() {
                assertNull(attrs.get("nonexistentColumnX",Integer.class));
        }
+
+       @Test
+       public void testVirtualColumns() {
+               table2.createColumn("s", String.class, false);
+               table2.createColumn("t", Integer.class, false);
+               table2.createColumn("u", Long.class, false);
+               table2.createColumn("v", Boolean.class, false);
+               table2.createColumn("w", Double.class, false);
+               table2.createListColumn("x", String.class, false);
+               table.addVirtualColumns( table2, 
table.getPrimaryKey().getName(), false);
+
+               CyColumn scol = table.getColumn("s");
+               assertNotNull(scol);
+               assertEquals(String.class,scol.getType());
+
+               CyColumn tcol = table.getColumn("t");
+               assertNotNull(tcol);
+               assertEquals(Integer.class,tcol.getType());
+
+               CyColumn ucol = table.getColumn("u");
+               assertNotNull(ucol);
+               assertEquals(Long.class,ucol.getType());
+
+               CyColumn vcol = table.getColumn("v");
+               assertNotNull(vcol);
+               assertEquals(Boolean.class,vcol.getType());
+
+               CyColumn wcol = table.getColumn("w");
+               assertNotNull(wcol);
+               assertEquals(Double.class,wcol.getType());
+
+               CyColumn xcol = table.getColumn("x");
+               assertNotNull(xcol);
+               assertEquals(List.class,xcol.getType());
+               assertEquals(String.class,xcol.getListElementType());
+       }
+
+       @Test
+       public void testVirtualColumnWithDupe() {
+               table2.createColumn("s", String.class, false);
+               table.createColumn("s", String.class, false);
+               table.addVirtualColumns( table2, 
table.getPrimaryKey().getName(), false);
+
+               CyColumn scol = table.getColumn("s");
+               assertFalse( scol.getVirtualColumnInfo().isVirtual() );
+
+               CyColumn s1col = table.getColumn("s-1");
+               assertTrue( s1col.getVirtualColumnInfo().isVirtual() );
+       }
+
+       @Test
+       public void testVirtualColumnsNoPrimaryKey() {
+               table2.createColumn("s", String.class, false);
+               table.addVirtualColumns( table2, 
table.getPrimaryKey().getName(), false);
+
+               CyColumn scol = table.getColumn("s");
+               assertNotNull(scol);
+
+               // If the tables have the same name for the primary key column, 
then verify that
+               // we don't get new column with the expected new column name 
for source table
+               // primary key.  Also make sure that the existing column for 
the primary key
+               // is not virtual.
+               if ( table.getPrimaryKey().getName().equals( 
table2.getPrimaryKey().getName() ) ) {
+                       String expectedNewName = 
table2.getPrimaryKey().getName() + "-1";
+                       CyColumn npkcol = table.getColumn( expectedNewName );
+                       assertNull(npkcol);
+                       CyColumn pkcol = table.getColumn( 
table.getPrimaryKey().getName() );
+                       assertFalse( pkcol.getVirtualColumnInfo().isVirtual() );
+               
+               // Otherwise, just make sure that the primary key column of the 
source table
+               // isn't added.
+               } else {
+                       CyColumn npkcol = table.getColumn( 
table2.getPrimaryKey().getName() );
+                       assertNull(npkcol);
+               }
+       }
 }

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/MergeDataTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/MergeDataTask.java
     2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/MergeDataTask.java
     2011-11-15 20:08:29 UTC (rev 27470)
@@ -37,9 +37,9 @@
                taskMonitor.setProgress(0.2);
                // "Copy" Name column to ID type name.
                final CyColumn pKey = table.getPrimaryKey();
-               table.addVirtualColumn(columnName, pKey.getName(), table, 
pKey.getName(), pKey.getName(), false);
+               table.addVirtualColumn(columnName, pKey.getName(), table, 
pKey.getName(), false);
                taskMonitor.setProgress(0.5);
-               nodeTable.addVirtualColumn(columnName, pKey.getName(), table, 
pKey.getName(), pKey.getName(), false);
+               nodeTable.addVirtualColumn(columnName, pKey.getName(), table, 
pKey.getName(), false);
                                
                taskMonitor.setStatusMessage("Finished!");
                taskMonitor.setProgress(1.0);

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/SessionReaderImpl.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/SessionReaderImpl.java
   2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/SessionReaderImpl.java
   2011-11-15 20:08:29 UTC (rev 27470)
@@ -287,7 +287,6 @@
                        targetTable.addVirtualColumn(columnData.getName(),
                                                                                
 columnData.getSourceColumn(),
                                                                                
 sourceTable,
-                                                                               
 columnData.getSourceJoinKey(),
                                                                                
 columnData.getTargetJoinKey(),
                                                                                
 columnData.isImmutable());
                }

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/UnrecognizedVisualPropertyManager.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/UnrecognizedVisualPropertyManager.java
   2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/UnrecognizedVisualPropertyManager.java
   2011-11-15 20:08:29 UTC (rev 27470)
@@ -178,7 +178,7 @@
                vpTbl.createColumn("att_id", Long.class, false);
                vpTbl.createColumn("att_value", String.class, false);
                vpTbl.createColumn("target_id", Long.class, false);
-               vpTbl.addVirtualColumn("att_name_vc", "att_name", rendererTbl, 
RENDERER_TABLE_PK, "att_id", false);
+               vpTbl.addVirtualColumn("att_name_vc", "att_name", rendererTbl, 
"att_id", false);
 
                // add tables to the internal maps
                rendererTablesMap.put(netViewId, rendererTbl);

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
 2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
 2011-11-15 20:08:29 UTC (rev 27470)
@@ -195,7 +195,7 @@
 
        private void linkDefaultTables(CyTable srcTable, CyTable tgtTable) {
                // Add all columns from source table as virtual columns in 
target table.
-               
tgtTable.addVirtualColumns(srcTable,Identifiable.SUID,Identifiable.SUID,true);
+               tgtTable.addVirtualColumns(srcTable,Identifiable.SUID,true);
 
                // Now add a listener for column created events to add
                // virtual columns to any subsequent source columns added.

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
        2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
        2011-11-15 20:08:29 UTC (rev 27470)
@@ -715,24 +715,40 @@
                        logger.debug("risky use of get() instead of getList() 
for retrieving list");
                lastInternalError = null;
 
+               final Object value = getValue(key,columnName,type);
+
+               if ( value == null )
+                       return getDefaultValue(columnName,defaultValue);
+               else
+                       return type.cast(value);
+       }
+
+       Object getValue(Object key, String columnName) {
+               return getValue(key,columnName,null);
+       }
+
+       private Object getValue(Object key, String columnName, Class<?> type) {
                final VirtualColumn virtColumn = 
virtualColumnMap.get(columnName);
                if (virtColumn != null)
-                       return (T)virtColumn.getValue(key);
+                       return virtColumn.getValue(key);
 
                final Object vl = getValueOrEquation(key, columnName);
                if (vl == null)
-                       return getDefaultValue(columnName,defaultValue);
+                       return null;
 
                if (vl instanceof Equation) {
                        final StringBuilder errorMsg = new StringBuilder();
-                       final Object result =
+                       final Object value =
                                EqnSupport.evalEquation((Equation)vl, key, 
interpreter,
                                                        
currentlyActiveAttributes, columnName,
                                                        errorMsg, this);
                        lastInternalError = errorMsg.toString();
-                       return result == null ? 
getDefaultValue(columnName,defaultValue) : 
(T)EqnSupport.convertEqnResultToColumnType(type, result);
+                       if ( type == null )
+                               return value;
+                       else
+                               return 
EqnSupport.convertEqnResultToColumnType(type, value);
                } else
-                       return type.cast(vl);
+                       return vl;
        }
 
        private <T> T getDefaultValue(final String columnName, final T 
defaultValue) {
@@ -747,27 +763,7 @@
                }
        }
 
-       Object getValue(Object key, String columnName) {
-               final VirtualColumn virtColumn = 
virtualColumnMap.get(columnName);
-               if (virtColumn != null)
-                       return virtColumn.getValue(key);
 
-               final Object vl = getValueOrEquation(key, columnName);
-               if (vl == null)
-                       return null;
-
-               if (vl instanceof Equation) {
-                       final StringBuilder errorMsg = new StringBuilder();
-                       final Object value =
-                               EqnSupport.evalEquation((Equation)vl, key, 
interpreter,
-                                                       
currentlyActiveAttributes, columnName,
-                                                       errorMsg, this);
-                       lastInternalError = errorMsg.toString();
-                       return value;
-               } else
-                       return vl;
-       }
-
        synchronized private <T> List<T> getListX(final Object key, final 
String columnName,
                                                           final Class<? 
extends T> listElementType, final List<T> defaultValue)
        {
@@ -845,8 +841,7 @@
 
        @Override
        public final String addVirtualColumn(final String virtualColumnName, 
final String sourceColumnName,
-                                            final CyTable sourceTable, final 
String sourceJoinKeyName,
-                                            final String targetJoinKeyName, 
final boolean isImmutable)
+                                            final CyTable sourceTable, final 
String targetJoinKeyName, final boolean isImmutable)
        {
                if (virtualColumnName == null)
                        throw new NullPointerException("\"virtualColumn\" 
argument must never be null!");
@@ -857,8 +852,6 @@
                                throw new 
NullPointerException("\"sourceColumn\" argument must never be null!");
                        if (sourceTable == null)
                                throw new NullPointerException("\"sourceTable\" 
argument must never be null!");
-                       if (sourceJoinKeyName == null)
-                               throw new 
NullPointerException("\"sourceJoinKey\" argument must never be null!");
                        if (targetJoinKeyName == null)
                                throw new 
NullPointerException("\"targetJoinKey\" argument must never be null!");
 
@@ -866,19 +859,16 @@
                        if (sourceColumn == null)
                                throw new 
IllegalArgumentException("\"sourceColumn\" is not a column in 
\"sourceColumn\"!");
 
-                       final CyColumn sourceJoinKeyType = 
sourceTable.getColumn(sourceJoinKeyName);
-                       if (sourceJoinKeyType == null)
-                               throw new 
IllegalArgumentException("\"sourceJoinKey\" is not a known column in 
\"sourceTable\"!");
-
                        final CyColumn targetJoinKeyType = 
this.getColumn(targetJoinKeyName);
                        if (targetJoinKeyType == null)
                                throw new 
IllegalArgumentException("\"targetJoinKey\" is not a known column in this 
table!");
 
+                       final CyColumn sourceJoinKeyType = 
sourceTable.getPrimaryKey();
                        if (sourceJoinKeyType.getType() != 
targetJoinKeyType.getType())
                                throw new 
IllegalArgumentException("\"sourceJoinKey\" has a different type from 
\"targetJoinKey\"!");
 
                        
++((CyTableImpl)sourceTable).virtualColumnReferenceCount;
-                       VirtualColumnInfo virtualInfo = new 
VirtualColumnInfoImpl(true, sourceTable, sourceColumnName, sourceJoinKeyName, 
targetJoinKeyName, isImmutable);
+                       VirtualColumnInfo virtualInfo = new 
VirtualColumnInfoImpl(true, sourceTable, sourceColumnName, 
sourceTable.getPrimaryKey().getName(), targetJoinKeyName, isImmutable);
                        final CyColumn targetColumn =
                                new CyColumnImpl(this, virtualColumnName, 
sourceColumn.getType(),
                                                 
sourceColumn.getListElementType(),
@@ -889,7 +879,7 @@
                        types.put(targetName, targetColumn);
                        virtualColumnMap.put(targetName,
                                             new VirtualColumn(sourceTable, 
sourceColumnName, this,
-                                                              
sourceJoinKeyName, targetJoinKeyName));
+                                                              
sourceTable.getPrimaryKey().getName(), targetJoinKeyName));
                }
 
                eventHelper.fireEvent(new ColumnCreatedEvent(this, targetName));
@@ -927,39 +917,33 @@
 
        @Override
        synchronized public final void addVirtualColumns(final CyTable 
sourceTable,
-                                                        final String 
sourceJoinKeyName,
                                                         final String 
targetJoinKeyName,
                                                         final boolean 
isImmutable)
        {
                if (sourceTable == null)
                        throw new NullPointerException("\"sourceTable\" 
argument must never be null!");
-               if (sourceJoinKeyName == null)
-                       throw new NullPointerException("\"sourceJoinKeyName\" 
argument must never be null!");
                if (targetJoinKeyName == null)
                        throw new NullPointerException("\"targetJoinKeyName\" 
argument must never be null!");
 
-               final CyColumn sourceJoinKey = 
sourceTable.getColumn(sourceJoinKeyName);
-               if (sourceJoinKey == null)
-                       throw new IllegalArgumentException("\"sourceJoinKey\" 
is not a known column in \"sourceTable\"!");
-
                final CyColumn targetJoinKey = 
this.getColumn(targetJoinKeyName);
                if (targetJoinKey == null)
                        throw new IllegalArgumentException("\"" + 
targetJoinKeyName
                                                           + "\" is not a known 
column in this table!");
 
+               final CyColumn sourceJoinKey = sourceTable.getPrimaryKey();
                if (sourceJoinKey.getType() != targetJoinKey.getType())
-                       throw new IllegalArgumentException("\"" + 
sourceJoinKeyName
+                       throw new IllegalArgumentException("\"" + 
sourceJoinKey.getName()
                                                           + "\" has a 
different type from \""
                                                           + targetJoinKeyName 
+ "\"!");
 
                final Collection<CyColumn> columns = sourceTable.getColumns();
                for (final CyColumn column : columns) {
                        final String columnName = column.getName();
-                       if (columnName.equals(sourceJoinKeyName))
+                       // skip the primary key
+                       if (columnName.equals(sourceJoinKey.getName()))
                                continue;
 
-                       addVirtualColumn(columnName, columnName, sourceTable, 
sourceJoinKeyName,
-                                        targetJoinKeyName, isImmutable);
+                       addVirtualColumn(columnName, columnName, sourceTable, 
targetJoinKeyName, isImmutable);
                }
        }
 

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
      2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
      2011-11-15 20:08:29 UTC (rev 27470)
@@ -97,10 +97,11 @@
        }
 
        private CyRow getSourceRow(final Object targetKey) {
-               final Object joinKey =
-                       targetTable.getValue(targetKey, 
targetJoinColumn.getName());
+               final Object joinKey = targetTable.getValue(targetKey, 
targetJoinColumn.getName());
                if (joinKey == null)
                        return null;
+               return sourceTable.getRow(joinKey);
+               /*
                final Collection<CyRow> sourceRows =
                        sourceTable.getMatchingRows(sourceJoinColumn.getName(),
                                                    joinKey);
@@ -108,6 +109,7 @@
                        return null;
 
                return sourceRows.iterator().next();
+               */
        }
 
        Collection<CyRow> getMatchingRows(final Object value) {

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnAdder.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnAdder.java
 2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnAdder.java
 2011-11-15 20:08:29 UTC (rev 27470)
@@ -62,7 +62,7 @@
                if ( tgt.getColumn(srcName) != null )
                        return;
                CyColumn srcCol = src.getColumn(srcName);
-               tgt.addVirtualColumn(srcName,srcName,src,Identifiable.SUID, 
Identifiable.SUID,srcCol.isImmutable());
+               
tgt.addVirtualColumn(srcName,srcName,src,Identifiable.SUID,srcCol.isImmutable());
        }
 }
 

Modified: 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
  2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
  2011-11-15 20:08:29 UTC (rev 27470)
@@ -98,9 +98,8 @@
                table.createColumn("x", Long.class, false);
                CyColumn column = table.getColumn("x");
                assertNull(column.getVirtualColumnInfo().getSourceTable());
-               table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
-               table.addVirtualColumn("b1", "b", table2, "x2", "x", true);
+               table.addVirtualColumn("b1", "b", table2, "x", true);
 
                mgrImpl.addTable(table2);
                boolean caughtException = false;

Modified: 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
 2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/model-impl/impl/src/test/java/org/cytoscape/model/CyTableTest.java
 2011-11-15 20:08:29 UTC (rev 27470)
@@ -201,15 +201,11 @@
 
        @Test
        public void testVirtualColumnWithAnEquationReference() {
-               table.createColumn("x", Integer.class, false);
                table.createColumn("ss", String.class, false);
                CyRow row1 = table.getRow(1L);
-               row1.set("x", 33);
-               table2.createColumn("x2", Integer.class, false);
                CyRow row2 =  table2.getRow(1L);
-               row2.set("x2", 33);
                table2.createColumn("s", String.class, true);
-               table.addVirtualColumn("s1", "s", table2, "x2", "x", true);
+               table.addVirtualColumn("s1", "s", table2, 
table.getPrimaryKey().getName(), true);
                row2.set("s", "abc");
 
                final Map<String, Class<?>> varnameToTypeMap = new 
HashMap<String, Class<?>>();

Modified: 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
===================================================================
--- 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
     2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
     2011-11-15 20:08:29 UTC (rev 27470)
@@ -317,7 +317,6 @@
         *                        "virtualColumn"
         *  @param sourceTable    the table that really contains the column 
that we're adding (all
         *                        updates and lookups of this new column will 
be redirected to here)
-        *  @param sourceJoinKey  the column in "sourceTable" that will be used 
for the join
         *  @param targetJoinKey  the column in current table that will be used 
for the join
         *  @param isImmutable    if true, this column cannot be deleted
         *  @return the actual name of the new virtual column
@@ -325,8 +324,7 @@
         */
        @Override
        public String addVirtualColumn(String virtualColumn, String 
sourceColumn,
-                                      CyTable sourceTable, String 
sourceJoinKey,
-                                      String targetJoinKey, boolean 
isImmutable)
+                                      CyTable sourceTable, String 
targetJoinKey, boolean isImmutable)
        {
                throw new UnsupportedOperationException("addVirtualColumn() 
method not supported!");
        }
@@ -334,17 +332,15 @@
        /** Adds all columns in another table as "virtual" columns to the the 
current table.
         *  @param sourceTable    the table that really contains the column 
that we're adding (all
         *                        updates and lookups of this new column will 
be redirected to here)
-        *  @param sourceJoinKey  the column in "sourceTable" that will be used 
for the join
         *  @param targetJoinKey  the column in current table that will be used 
for the join
         *  @param isImmutable    if true, these columns cannot be deleted
         *  Note: The types of "sourceJoinKey" and "targetJoinKey" have to be 
identical.  Also none
         *        of the column names in "sourceTable" must exist in the 
current table!
         */
        @Override
-       public void addVirtualColumns(CyTable sourceTable, String sourceJoinKey,
-                                     String targetJoinKey, boolean isImmutable)
+       public void addVirtualColumns(CyTable sourceTable, String 
targetJoinKey, boolean isImmutable)
        {
-               throw new UnsupportedOperationException("addVirtualColumn() 
method not supported!");
+               throw new UnsupportedOperationException("addVirtualColumns() 
method not supported!");
        }
        
        /**

Modified: 
core3/impl/trunk/table-import-impl/src/main/java/org/cytoscape/tableimport/internal/task/MapGeneAssociationTask.java
===================================================================
--- 
core3/impl/trunk/table-import-impl/src/main/java/org/cytoscape/tableimport/internal/task/MapGeneAssociationTask.java
        2011-11-15 18:53:49 UTC (rev 27469)
+++ 
core3/impl/trunk/table-import-impl/src/main/java/org/cytoscape/tableimport/internal/task/MapGeneAssociationTask.java
        2011-11-15 20:08:29 UTC (rev 27470)
@@ -87,6 +87,6 @@
                        taskMonitor.setProgress(progress);
                }
                
-               nodeTable.addVirtualColumns(globalTable, colName, 
CyTableEntry.NAME, false);
+               nodeTable.addVirtualColumns(globalTable, CyTableEntry.NAME, 
false);
        }
 }

-- 
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.

Reply via email to