Author: jm
Date: 2011-07-18 09:01:22 -0700 (Mon, 18 Jul 2011)
New Revision: 26199

Added:
   
core3/model-api/trunk/src/main/java/org/cytoscape/model/VirtualColumnInfo.java
   
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnInfoImpl.java
Modified:
   core3/model-api/trunk/src/main/java/org/cytoscape/model/CyColumn.java
   
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
   
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
   
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
   
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
   
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
Log:
Fixes #323: Added API for fetching virtual column definition; Consolidated all 
virtual column API into VirtualColumnInfo

Modified: core3/model-api/trunk/src/main/java/org/cytoscape/model/CyColumn.java
===================================================================
--- core3/model-api/trunk/src/main/java/org/cytoscape/model/CyColumn.java       
2011-07-16 18:21:46 UTC (rev 26198)
+++ core3/model-api/trunk/src/main/java/org/cytoscape/model/CyColumn.java       
2011-07-18 16:01:22 UTC (rev 26199)
@@ -48,9 +48,6 @@
        /** @return the data type of the list elements if the column type is 
List.class otherwise null */
        Class<?> getListElementType(); 
 
-       /** @return true if the column is virtual, otherwise false. */
-       boolean isVirtual();
-
        /** @return true if the column is the primary key, otherwise false. */
        boolean isPrimaryKey();
 
@@ -64,15 +61,15 @@
         */
        CyTable getTable();
 
-       /** Returns the originating table for this column if this column is 
virtual.
-        *  @return the actual table that this column originates at if it is 
virtual, or null if the
-        *          column is not virtual
-        */
-       CyTable getVirtualTable();
-
        /** Returns all the values, some of which may be null, for this given 
column.
         *  @param type  the datatype of this column.  (You can use getType() 
to obtain it.)
         *  @return the values in this column in some arbitrary but consistent 
order
         */
        <T> List<T> getValues(Class<? extends T> type);
+       
+       /**
+        * Returns information about the virtual column definition of this 
column.
+        * This method will return an instance even if the column is not 
virtual.
+        */
+       VirtualColumnInfo getVirtualColumnInfo();
 }
\ No newline at end of file

Added: 
core3/model-api/trunk/src/main/java/org/cytoscape/model/VirtualColumnInfo.java
===================================================================
--- 
core3/model-api/trunk/src/main/java/org/cytoscape/model/VirtualColumnInfo.java  
                            (rev 0)
+++ 
core3/model-api/trunk/src/main/java/org/cytoscape/model/VirtualColumnInfo.java  
    2011-07-18 16:01:22 UTC (rev 26199)
@@ -0,0 +1,31 @@
+package org.cytoscape.model;
+
+public interface VirtualColumnInfo {
+       /**
+        * @return true if the column is virtual, otherwise false.
+        */
+       boolean isVirtual();
+       
+       /**
+        * Returns the name of the column from the source table which contains 
the
+        * values this column provides. 
+        */
+       String getSourceColumn();
+       
+       /**
+        * Returns the name of the column from the source table used for the 
join.
+        */
+       String getSourceJoinKey();
+       
+       /**
+        * Returns the name of the column from the target table used for the 
join.
+        */
+       String getTargetJoinKey();
+       
+       /**
+        * Returns the originating table for this column if this column is 
virtual.
+        * @return the actual table that this column originates at if it is 
virtual, or null if the
+        *         column is not virtual
+        */
+       CyTable getSourceTable();
+}


Property changes on: 
core3/model-api/trunk/src/main/java/org/cytoscape/model/VirtualColumnInfo.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
===================================================================
--- 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
    2011-07-16 18:21:46 UTC (rev 26198)
+++ 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
    2011-07-18 16:01:22 UTC (rev 26199)
@@ -28,18 +28,25 @@
 package org.cytoscape.model;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.awt.Color;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 
-import org.cytoscape.model.CyTable;
+import org.cytoscape.event.DummyCyEventHelper;
 import org.cytoscape.model.CyTable.Mutability;
 import org.cytoscape.model.events.ColumnCreatedEvent;
 import org.cytoscape.model.events.ColumnDeletedEvent;
 import org.cytoscape.model.events.RowSetRecord;
-import org.cytoscape.model.events.RowsCreatedEvent;
-import org.cytoscape.event.DummyCyEventHelper;
-
-import static org.junit.Assert.*;
 import org.junit.Test;
 
 
@@ -681,9 +688,9 @@
                table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
                table.addVirtualColumn("b1", "b", table2, "x2", "x", true);
-               assertTrue(table.getColumn("b1").isVirtual());
-               assertFalse(table.getColumn("x").isVirtual());
-               assertFalse(table2.getColumn("b").isVirtual());
+               
assertTrue(table.getColumn("b1").getVirtualColumnInfo().isVirtual());
+               
assertFalse(table.getColumn("x").getVirtualColumnInfo().isVirtual());
+               
assertFalse(table2.getColumn("b").getVirtualColumnInfo().isVirtual());
        }
 
        @Test
@@ -712,12 +719,12 @@
        public void testCyColumnGetVirtualTable() {
                table.createColumn("x", Long.class, false);
                CyColumn column = table.getColumn("x");
-               assertNull(column.getVirtualTable());
+               assertNull(column.getVirtualColumnInfo().getSourceTable());
                table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
                table.addVirtualColumn("b1", "b", table2, "x2", "x", true);
                CyColumn column2 = table.getColumn("b1");
-               assertEquals(table2, column2.getVirtualTable());
+               assertEquals(table2, 
column2.getVirtualColumnInfo().getSourceTable());
        }
 
        @Test

Modified: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
    2011-07-16 18:21:46 UTC (rev 26198)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyColumnImpl.java
    2011-07-18 16:01:22 UTC (rev 26199)
@@ -32,6 +32,7 @@
 
 import org.cytoscape.model.CyColumn;
 import org.cytoscape.model.CyTable;
+import org.cytoscape.model.VirtualColumnInfo;
 
 
 /** This class describes a column in a CyTable. */
@@ -40,21 +41,19 @@
        private String columnName;
        private final Class<?> columnType;
        private final Class<?> listElementType;
-       private final boolean isVirtual;
-       private final CyTable virtTable;
+       private final VirtualColumnInfo virtualInfo;
        private final boolean isPrimaryKey;
        private final boolean isImmutable;
 
        CyColumnImpl(final CyTableImpl table, final String columnName, final 
Class<?> columnType,
-                    final Class<?> listElementType, final boolean isVirtual, 
final CyTable virtTable,
+                    final Class<?> listElementType, final VirtualColumnInfo 
virtualInfo,
                     final boolean isPrimaryKey, final boolean isImmutable)
        {
                this.table           = table;
                this.columnName      = columnName;
                this.columnType      = columnType;
                this.listElementType = listElementType;
-               this.isVirtual       = isVirtual;
-               this.virtTable       = virtTable;
+               this.virtualInfo     = virtualInfo;
                this.isPrimaryKey    = isPrimaryKey;
                this.isImmutable     = isImmutable;
        }
@@ -62,9 +61,6 @@
        @Override
        public CyTable getTable() { return table; }
 
-       @Override
-       public CyTable getVirtualTable() { return virtTable; }
-
        /** @return the name of the column. */
        @Override
        public String getName() { return columnName; }
@@ -90,10 +86,6 @@
        @Override
        public Class<?> getListElementType() { return listElementType; }
 
-       /** @return true if the column is virtual, otherwise false. */
-       @Override
-       public boolean isVirtual() { return isVirtual; }
-
        /** @return true if the column is the primary key, otherwise false. */
        @Override
        public boolean isPrimaryKey() { return isPrimaryKey; }
@@ -111,4 +103,9 @@
                                                           + " got " + 
type.getName() + "!");
                return table.getColumnValues(columnName, type);
        }
+       
+       @Override
+       public VirtualColumnInfo getVirtualColumnInfo() {
+               return virtualInfo;
+       }
 }

Modified: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
     2011-07-16 18:21:46 UTC (rev 26198)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
     2011-07-18 16:01:22 UTC (rev 26199)
@@ -30,7 +30,6 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -39,20 +38,18 @@
 
 import org.cytoscape.equations.Equation;
 import org.cytoscape.equations.Interpreter;
-
 import org.cytoscape.event.CyEventHelper;
-
 import org.cytoscape.model.CyColumn;
-import org.cytoscape.model.CyTable;
 import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
 import org.cytoscape.model.SUIDFactory;
+import org.cytoscape.model.VirtualColumnInfo;
 import org.cytoscape.model.events.ColumnCreatedEvent;
 import org.cytoscape.model.events.ColumnDeletedEvent;
 import org.cytoscape.model.events.ColumnNameChangedEvent;
 import org.cytoscape.model.events.RowSetRecord;
 import org.cytoscape.model.events.RowsCreatedEvent;
 import org.cytoscape.model.events.RowsSetEvent;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -113,12 +110,12 @@
                rows = new HashMap<Object, CyRow>();
                types = new HashMap<String, CyColumn>();
 
+               VirtualColumnInfo virtualInfo = new 
VirtualColumnInfoImpl(false, null, null, null, null);
                // Create the primary key column.  Do this explicitly
                // so that we don't fire an event.
                types.put(primaryKey, new CyColumnImpl(this, primaryKey, 
primaryKeyType,
                                                       /* listElementType = */ 
null,
-                                                      /* isVirtual = */ false,
-                                                      /* virtTable = */ null,
+                                                      virtualInfo,
                                                       /* isPrimaryKey = */ 
true,
                                                       /* isImmutable = */ 
true));
                attributes.put(primaryKey, new HashMap<Object, Object>());
@@ -255,7 +252,7 @@
                                        final CyColumn cyColumn = 
types.get(columnName);
                                        virtualColumnMap.remove(columnName);
                                        types.remove(columnName);
-                                       
--((CyTableImpl)cyColumn.getVirtualTable()).virtualColumnReferenceCount;
+                                       
--((CyTableImpl)cyColumn.getVirtualColumnInfo().getSourceTable()).virtualColumnReferenceCount;
                                } else {
                                        attributes.remove(columnName);
                                        reverse.remove(columnName);
@@ -291,10 +288,10 @@
 
                        checkClass(type);
 
+                       VirtualColumnInfo virtualInfo = new 
VirtualColumnInfoImpl(false, null, null, null, null);
                        types.put(columnName, new CyColumnImpl(this, 
columnName, type,
                                                               /* 
listElementType = */ null,
-                                                              /* isVirtual = 
*/ false,
-                                                              /* virtTable = 
*/ null,
+                                                              virtualInfo ,
                                                               /* isPrimaryKey 
= */ false,
                                                               isImmutable));
                        attributes.put(columnName, new HashMap<Object, 
Object>());
@@ -322,10 +319,10 @@
 
                        checkClass(listElementType);
 
+                       VirtualColumnInfo virtualInfo = new 
VirtualColumnInfoImpl(false, null, null, null, null);
                        types.put(columnName, new CyColumnImpl(this, 
columnName, List.class,
                                                               listElementType,
-                                                              /* isVirtual = 
*/ false,
-                                                              /* virtTable = 
*/ null,
+                                                              virtualInfo,
                                                               /* isPrimaryKey 
= */ false,
                                                               isImmutable));
                        attributes.put(columnName, new HashMap<Object, 
Object>());
@@ -792,11 +789,11 @@
                                throw new 
IllegalArgumentException("\"sourceJoinKey\" has a different type from 
\"targetJoinKey\"!");
 
                        
++((CyTableImpl)sourceTable).virtualColumnReferenceCount;
+                       VirtualColumnInfo virtualInfo = new 
VirtualColumnInfoImpl(true, sourceTable, sourceColumnName, sourceJoinKeyName, 
targetJoinKeyName);
                        final CyColumn targetColumn =
                                new CyColumnImpl(this, virtualColumnName, 
sourceColumn.getType(),
                                                 
sourceColumn.getListElementType(),
-                                                /* isVirtual = */ true,
-                                                /* virtTable = */ sourceTable,
+                                                virtualInfo,
                                                 /* isPrimaryKey = */ false,
                                                 isImmutable);
                        types.put(targetName, targetColumn);
@@ -833,7 +830,7 @@
                for (final String columnName : virtualColumnMap.keySet()) {
                        final CyColumn column = types.get(columnName);
                        types.remove(columnName);
-                       
--((CyTableImpl)column.getVirtualTable()).virtualColumnReferenceCount;
+                       
--((CyTableImpl)column.getVirtualColumnInfo().getSourceTable()).virtualColumnReferenceCount;
                }
                virtualColumnMap.clear();
        }

Added: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnInfoImpl.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnInfoImpl.java
                           (rev 0)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnInfoImpl.java
   2011-07-18 16:01:22 UTC (rev 26199)
@@ -0,0 +1,47 @@
+package org.cytoscape.model.internal;
+
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.VirtualColumnInfo;
+
+public class VirtualColumnInfoImpl implements VirtualColumnInfo {
+
+       private final boolean isVirtual;
+       private final CyTable sourceTable;
+       private final String sourceColumn;
+       private final String sourceJoinKey;
+       private final String targetJoinKey;
+
+       public VirtualColumnInfoImpl(boolean isVirtual, CyTable sourceTable, 
String sourceColumn, String sourceJoinKey, String targetJoinKey) {
+               this.isVirtual = isVirtual;
+               this.sourceTable = sourceTable;
+               this.sourceColumn = sourceColumn;
+               this.sourceJoinKey = sourceJoinKey;
+               this.targetJoinKey = targetJoinKey;
+       }
+       
+       @Override
+       public boolean isVirtual() {
+               return isVirtual;
+       }
+
+       @Override
+       public String getSourceColumn() {
+               return sourceColumn;
+       }
+
+       @Override
+       public String getSourceJoinKey() {
+               return sourceJoinKey;
+       }
+
+       @Override
+       public String getTargetJoinKey() {
+               return targetJoinKey;
+       }
+
+       @Override
+       public CyTable getSourceTable() {
+               return sourceTable;
+       }
+
+}


Property changes on: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/VirtualColumnInfoImpl.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: 
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
       2011-07-16 18:21:46 UTC (rev 26198)
+++ 
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableManagerTest.java
       2011-07-18 16:01:22 UTC (rev 26199)
@@ -28,22 +28,17 @@
 package org.cytoscape.model;
 
 
-import java.util.Map;
-
-
-import org.cytoscape.model.CyTable.SavePolicy;
-import org.cytoscape.model.internal.CyTableManagerImpl;
-import org.cytoscape.model.internal.CyTableFactoryImpl;
-import org.cytoscape.model.internal.CyTableImpl;
-import org.cytoscape.model.internal.ArrayGraph;
 import org.cytoscape.equations.Interpreter;
 import org.cytoscape.equations.internal.interpreter.InterpreterImpl;
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.event.DummyCyEventHelper;
+import org.cytoscape.model.CyTable.SavePolicy;
+import org.cytoscape.model.internal.ArrayGraph;
+import org.cytoscape.model.internal.CyTableFactoryImpl;
+import org.cytoscape.model.internal.CyTableImpl;
+import org.cytoscape.model.internal.CyTableManagerImpl;
 
-import org.junit.Test;
 
-
 public class CyTableManagerTest extends AbstractCyTableManagerTest {
        CyTableManagerImpl mgrImpl;
 
@@ -83,7 +78,7 @@
 
                table.createColumn("x", Long.class, false);
                CyColumn column = table.getColumn("x");
-               assertNull(column.getVirtualTable());
+               assertNull(column.getVirtualColumnInfo().getSourceTable());
                table2.createColumn("x2", Long.class, false);
                table2.createListColumn("b", Boolean.class, false);
                table.addVirtualColumn("b1", "b", table2, "x2", "x", true);

Modified: 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
===================================================================
--- 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
      2011-07-16 18:21:46 UTC (rev 26198)
+++ 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/MyTableHeaderRenderer.java
      2011-07-18 16:01:22 UTC (rev 26199)
@@ -76,7 +76,7 @@
                CyColumn col = 
model.getAttributes().getColumn(value.toString());
                
                String toolTip = col.getType().getName();
-               if(col.isVirtual()){
+               if(col.getVirtualColumnInfo().isVirtual()){
                        this.setForeground(defaultForeground);
                        this.setBackground(Color.lightGray);
                        this.setOpaque(true);

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