Author: rozagh
Date: 2012-08-29 16:23:32 -0700 (Wed, 29 Aug 2012)
New Revision: 30291

Modified:
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/CyActivator.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/AbstractNetworkFromSelectionTask.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/AbstractLoadAttributesTask.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/CombineReaderAndMappingTask.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTask.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImpl.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTask.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImpl.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTask.java
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTaskFactoryImpl.java
   
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImplTest.java
   
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImplTest.java
   
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MapTableToNetworkTableTaskTest.java
   
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MappingIntegrationTest.java
   
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributeTaskTest.java
Log:
fixes #1402 mapping the virtual columns to local tables of subnetworks for 
selected only condition and to default attrs of root network for map to all 
condition.

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/CyActivator.java
  2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/CyActivator.java
  2012-08-29 23:23:32 UTC (rev 30291)
@@ -221,8 +221,8 @@
                CyTableWriterManager cyTableWriterManagerRef = 
getService(bc,CyTableWriterManager.class);
                SynchronousTaskManager<?> synchronousTaskManagerServiceRef = 
getService(bc,SynchronousTaskManager.class);
                TunableSetter tunableSetterServiceRef = 
getService(bc,TunableSetter.class);
+               CyRootNetworkManager rootNetworkManagerServiceRef  = 
getService(bc, CyRootNetworkManager.class);
                
-               
                CyGroupManager cyGroupManager = getService(bc, 
CyGroupManager.class);
                CyGroupFactory cyGroupFactory = getService(bc, 
CyGroupFactory.class);
                
@@ -300,8 +300,8 @@
                registerService(bc, updateAddedNetworkAttributes, 
SessionLoadedListener.class, new Properties());
                
 
-               LoadAttributesFileTaskFactoryImpl loadAttrsFileTaskFactory = 
new LoadAttributesFileTaskFactoryImpl(cyDataTableReaderManagerServiceRef, 
tunableSetterServiceRef,cyNetworkManagerServiceRef, cyTableManagerServiceRef, 
updateAddedNetworkAttributes);
-               LoadAttributesURLTaskFactoryImpl loadAttrsURLTaskFactory = new 
LoadAttributesURLTaskFactoryImpl(cyDataTableReaderManagerServiceRef, 
tunableSetterServiceRef, cyNetworkManagerServiceRef, cyTableManagerServiceRef, 
updateAddedNetworkAttributes);
+               LoadAttributesFileTaskFactoryImpl loadAttrsFileTaskFactory = 
new LoadAttributesFileTaskFactoryImpl(cyDataTableReaderManagerServiceRef, 
tunableSetterServiceRef,cyNetworkManagerServiceRef, cyTableManagerServiceRef, 
updateAddedNetworkAttributes,rootNetworkManagerServiceRef );
+               LoadAttributesURLTaskFactoryImpl loadAttrsURLTaskFactory = new 
LoadAttributesURLTaskFactoryImpl(cyDataTableReaderManagerServiceRef, 
tunableSetterServiceRef, cyNetworkManagerServiceRef, cyTableManagerServiceRef, 
updateAddedNetworkAttributes, rootNetworkManagerServiceRef);
                
                // Apply Visual Style Task
                ApplyVisualStyleTaskFactoryimpl applyVisualStyleTaskFactory = 
new ApplyVisualStyleTaskFactoryimpl(visualMappingManagerServiceRef);
@@ -1067,7 +1067,7 @@
 
                // TODO: remove from group...
 
-               MapTableToNetworkTablesTaskFactoryImpl mapNetworkToTables = new 
MapTableToNetworkTablesTaskFactoryImpl(cyNetworkManagerServiceRef, 
tunableSetterServiceRef, updateAddedNetworkAttributes);
+               MapTableToNetworkTablesTaskFactoryImpl mapNetworkToTables = new 
MapTableToNetworkTablesTaskFactoryImpl(cyNetworkManagerServiceRef, 
tunableSetterServiceRef, updateAddedNetworkAttributes, 
rootNetworkManagerServiceRef);
                Properties mapNetworkToTablesProps = new Properties();
                registerService(bc, mapNetworkToTables, 
MapTableToNetworkTablesTaskFactory.class, mapNetworkToTablesProps);
                

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/AbstractNetworkFromSelectionTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/AbstractNetworkFromSelectionTask.java
    2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/AbstractNetworkFromSelectionTask.java
    2012-08-29 23:23:32 UTC (rev 30291)
@@ -115,11 +115,12 @@
 
                // create subnetwork and add selected nodes and appropriate 
edges
                final CySubNetwork newNet = 
rootNetworkManager.getRootNetwork(parentNetwork).addSubNetwork();
+               
+               //We need to cpy the columns to local tables, since copying 
them to default table will duplicate the virtual columns.
+               addColumns(parentNetwork.getTable(CyNode.class, 
CyNetwork.LOCAL_ATTRS), newNet.getTable(CyNode.class, CyNetwork.LOCAL_ATTRS));
+               addColumns(parentNetwork.getTable(CyEdge.class, 
CyNetwork.LOCAL_ATTRS), newNet.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS) );
+               addColumns(parentNetwork.getTable(CyNetwork.class, 
CyNetwork.LOCAL_ATTRS), newNet.getTable(CyNetwork.class, 
CyNetwork.LOCAL_ATTRS));
 
-               addColumns(parentNetwork.getDefaultNodeTable(), 
newNet.getDefaultNodeTable() );
-               addColumns(parentNetwork.getDefaultEdgeTable(), 
newNet.getDefaultEdgeTable() );
-               addColumns(parentNetwork.getDefaultNetworkTable(), 
newNet.getDefaultNetworkTable());
-
                tm.setProgress(0.3);
                
                for (final CyNode node : selectedNodes){
@@ -174,13 +175,13 @@
                VirtualColumnInfo colInfo = col.getVirtualColumnInfo();
                CyColumn checkCol= subTable.getColumn(col.getName());
                if(checkCol == null)
-                       subTable.addVirtualColumn(col.getName(), 
colInfo.getSourceColumn(), colInfo.getSourceTable(), 
colInfo.getTargetJoinKey(), true);
+                       subTable.addVirtualColumn(col.getName(), 
colInfo.getSourceColumn(), colInfo.getSourceTable(), 
colInfo.getTargetJoinKey(), col.isImmutable());
 
                else
                        if(!checkCol.getVirtualColumnInfo().isVirtual() ||
                                        
!checkCol.getVirtualColumnInfo().getSourceTable().equals(colInfo.getSourceTable())
 ||
                                        
!checkCol.getVirtualColumnInfo().getSourceColumn().equals(colInfo.getSourceColumn()))
-                               subTable.addVirtualColumn(col.getName(), 
colInfo.getSourceColumn(), colInfo.getSourceTable(), 
colInfo.getTargetJoinKey(), true);
+                               subTable.addVirtualColumn(col.getName(), 
colInfo.getSourceColumn(), colInfo.getSourceTable(), 
colInfo.getTargetJoinKey(), col.isImmutable());
        }
 
        private void copyColumn(CyColumn col, CyTable subTable) {

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/AbstractLoadAttributesTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/AbstractLoadAttributesTask.java
     2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/AbstractLoadAttributesTask.java
     2012-08-29 23:23:32 UTC (rev 30291)
@@ -7,6 +7,7 @@
 import org.cytoscape.io.read.CyTableReaderManager;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.MapTableToNetworkTablesTask;
 import 
org.cytoscape.task.internal.table.MapTableToNetworkTablesTaskFactoryImpl;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
@@ -22,13 +23,15 @@
        private final CyNetworkManager netMgr;
        private final CyTableManager tableMgr;
        private final UpdateAddedNetworkAttributes updateAddedNetworkAttributes;
-
+       private final CyRootNetworkManager rootNetMgr;
+       
        public AbstractLoadAttributesTask(final CyTableReaderManager mgr, final 
CyNetworkManager netMgr, final CyTableManager tabelMgr, 
-                       final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes) {
+                       final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes,  final CyRootNetworkManager rootNetMgr) {
                this.mgr = mgr;
                this.netMgr = netMgr;
                this.tableMgr = tabelMgr;
                this.updateAddedNetworkAttributes = 
updateAddedNetworkAttributes;
+               this.rootNetMgr = rootNetMgr;
        }
 
        void loadTable(final String name, final URI uri, final TaskMonitor 
taskMonitor) throws Exception {
@@ -42,7 +45,7 @@
 
                taskMonitor.setStatusMessage("Importing Data Table...");
                
-               insertTasksAfterCurrentTask(new CombineReaderAndMappingTask( 
reader, netMgr, updateAddedNetworkAttributes) , new 
AddImportedTableTask(tableMgr, reader));
+               insertTasksAfterCurrentTask(new CombineReaderAndMappingTask( 
reader, netMgr, updateAddedNetworkAttributes, rootNetMgr) , new 
AddImportedTableTask(tableMgr, reader));
                
        }
 }

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/CombineReaderAndMappingTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/CombineReaderAndMappingTask.java
    2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/CombineReaderAndMappingTask.java
    2012-08-29 23:23:32 UTC (rev 30291)
@@ -3,6 +3,7 @@
 import org.cytoscape.io.read.CyTableReader;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTable;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.MapTableToNetworkTablesTask;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
 import org.cytoscape.work.AbstractTask;
@@ -27,9 +28,9 @@
        public CyTableReader readerTask;
 
        
-       public CombineReaderAndMappingTask(CyTableReader readerTask , 
CyNetworkManager networkManager, final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes){
+       public CombineReaderAndMappingTask(CyTableReader readerTask , 
CyNetworkManager networkManager, final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes, final CyRootNetworkManager rootNetMgr){
                this.readerTask = readerTask;
-               this.mappingTask = new 
MapTableToNetworkTablesTask(networkManager, readerTask, 
updateAddedNetworkAttributes);
+               this.mappingTask = new 
MapTableToNetworkTablesTask(networkManager, readerTask, 
updateAddedNetworkAttributes, rootNetMgr);
        }
 
        @Override

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTask.java
 2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTask.java
 2012-08-29 23:23:32 UTC (rev 30291)
@@ -6,6 +6,7 @@
 import org.cytoscape.io.read.CyTableReaderManager;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
 import org.cytoscape.work.TaskMonitor;
 import org.cytoscape.work.Tunable;
@@ -15,8 +16,9 @@
        @Tunable(description="Attribute Table file", 
params="fileCategory=table;input=true")
        public File file;
 
-       public LoadAttributesFileTask(final CyTableReaderManager mgr,  final 
CyNetworkManager netMgr, final CyTableManager tabelMgr, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes) {
-               super(mgr, netMgr, tabelMgr, updateAddedNetworkAttributes);
+       public LoadAttributesFileTask(final CyTableReaderManager mgr,  final 
CyNetworkManager netMgr, final CyTableManager tabelMgr, 
+                       final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes, final CyRootNetworkManager rootNetMgr) {
+               super(mgr, netMgr, tabelMgr, updateAddedNetworkAttributes, 
rootNetMgr);
        }
 
        /**

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImpl.java
      2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImpl.java
      2012-08-29 23:23:32 UTC (rev 30291)
@@ -8,6 +8,7 @@
 import org.cytoscape.io.read.CyTableReaderManager;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
 import org.cytoscape.task.read.LoadTableFileTaskFactory;
 import org.cytoscape.work.AbstractTaskFactory;
@@ -22,18 +23,20 @@
        private final CyNetworkManager netMgr;
        private final CyTableManager tableMgr;
        private final UpdateAddedNetworkAttributes updateAddedNetworkAttributes;
+       private final CyRootNetworkManager rootNetMgr;
        
        public LoadAttributesFileTaskFactoryImpl(CyTableReaderManager mgr, 
TunableSetter tunableSetter,  final CyNetworkManager netMgr, 
-                       final CyTableManager tabelMgr, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes) {
+                       final CyTableManager tabelMgr, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes, final 
CyRootNetworkManager rootNetMgr) {
                this.mgr = mgr;
                this.tunableSetter = tunableSetter;
                this.netMgr = netMgr;
                this.tableMgr = tabelMgr;
                this.updateAddedNetworkAttributes = 
updateAddedNetworkAttributes;
+               this.rootNetMgr = rootNetMgr;
        }
 
        public TaskIterator createTaskIterator() {
-               return new TaskIterator(2, new LoadAttributesFileTask(mgr, 
netMgr, tableMgr, updateAddedNetworkAttributes));
+               return new TaskIterator(2, new LoadAttributesFileTask(mgr, 
netMgr, tableMgr, updateAddedNetworkAttributes, rootNetMgr));
        }
 
        @Override

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTask.java
  2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTask.java
  2012-08-29 23:23:32 UTC (rev 30291)
@@ -6,6 +6,7 @@
 import org.cytoscape.io.read.CyTableReaderManager;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
 import org.cytoscape.work.TaskMonitor;
 import org.cytoscape.work.Tunable;
@@ -16,8 +17,9 @@
        @Tunable(description="Attribute Table URL", 
params="fileCategory=table;input=true")
        public URL url;
 
-       public LoadAttributesURLTask(final CyTableReaderManager mgr,  final 
CyNetworkManager netMgr, final CyTableManager tableMgr, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes) {
-               super(mgr, netMgr, tableMgr, updateAddedNetworkAttributes);
+       public LoadAttributesURLTask(final CyTableReaderManager mgr,  final 
CyNetworkManager netMgr, final CyTableManager tableMgr, 
+                       final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes, final CyRootNetworkManager rootNetMgr) {
+               super(mgr, netMgr, tableMgr, updateAddedNetworkAttributes, 
rootNetMgr);
        }
 
        /**

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImpl.java
       2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImpl.java
       2012-08-29 23:23:32 UTC (rev 30291)
@@ -8,6 +8,7 @@
 import org.cytoscape.io.read.CyTableReaderManager;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
 import org.cytoscape.task.read.LoadTableFileTaskFactory;
 import org.cytoscape.task.read.LoadTableURLTaskFactory;
@@ -24,17 +25,20 @@
        private  final CyNetworkManager netMgr;
        private final CyTableManager tableMgr;
        private final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes; 
+       private final CyRootNetworkManager rootNetMgr;
+       
        public LoadAttributesURLTaskFactoryImpl(CyTableReaderManager mgr, 
TunableSetter tunableSetter,  final CyNetworkManager netMgr,
-                       final CyTableManager tabelMgr, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes) {
+                       final CyTableManager tabelMgr, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes, final 
CyRootNetworkManager rootNetMgr) {
                this.mgr = mgr;
                this.tunableSetter = tunableSetter;
                this.netMgr = netMgr;
                this.tableMgr = tabelMgr;
                this.updateAddedNetworkAttributes = 
updateAddedNetworkAttributes;
+               this.rootNetMgr = rootNetMgr;
        }
 
        public TaskIterator createTaskIterator() {
-               return new TaskIterator(2, new LoadAttributesURLTask(mgr, 
netMgr, tableMgr, updateAddedNetworkAttributes));
+               return new TaskIterator(2, new LoadAttributesURLTask(mgr, 
netMgr, tableMgr, updateAddedNetworkAttributes, rootNetMgr));
        }
 
        @Override

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTask.java
    2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTask.java
    2012-08-29 23:23:32 UTC (rev 30291)
@@ -13,6 +13,8 @@
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyTable;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.work.AbstractTask;
 import org.cytoscape.work.ProvidesTitle;
 import org.cytoscape.work.TaskMonitor;
@@ -23,45 +25,46 @@
 import org.slf4j.LoggerFactory;
 
 public final class MapTableToNetworkTablesTask extends AbstractTask {
-       
+
        enum TableType {
                NODE_ATTR("Node Attributes", CyNode.class), EDGE_ATTR("Edge 
Attributes", CyEdge.class), NETWORK_ATTR("Network Attributes", 
CyNetwork.class), GLOBAL("Unassigned Tables", CyTable.class);
 
                private final String name;
                private final  Class<? extends CyIdentifiable> type;
-               
+
                private TableType(final String name, Class<? extends 
CyIdentifiable> type) {
                        this.name = name;
                        this.type = type;
                }
-               
+
                public Class<? extends CyIdentifiable> getType(){
                        return this.type;
                }
-               
+
                @Override 
                public String toString() {
                        return name;
                }
        };
-       
+
        private static Logger logger = 
LoggerFactory.getLogger(MapTableToNetworkTablesTask.class);
        private static String NO_NETWORKS = "No Networks Found";
        private final CyNetworkManager networkManager;
+       private final CyRootNetworkManager rootNetworkManager;
        private final CyTable globalTable;
        private final  CyTableReader reader;
        private final boolean byReader;
        private Map<String, CyNetwork> name2NetworkMap;
        private final UpdateAddedNetworkAttributes updateAddedNetworkAttributes;
-       
-       
+
+
        @Tunable(description = "Import Data To:")
        public ListSingleSelection<TableType> dataTypeOptions;
-       
+
        //******* we couldnt use the enum to check the dependency. So, update 
this line if you change the GLOBAL enum string 
        @Tunable(description = "Apply to Selected Networks 
Only",groups="Network Options", dependsOn="dataTypeOptions!=Unassigned Tables", 
params="displayState=collapsed")
        public boolean selectedNetworksOnly = false;
-       
+
        @Tunable(description = "Network List",groups="Network 
Options",dependsOn="selectedNetworksOnly=true", params="displayState=collapsed")
        public ListMultipleSelection<String> networkList;
 
@@ -71,36 +74,39 @@
                return "Import Data ";
        }
 
-       
-       public MapTableToNetworkTablesTask(final CyNetworkManager 
networkManager, final CyTableReader reader, final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes){
+
+       public MapTableToNetworkTablesTask(final CyNetworkManager 
networkManager, final CyTableReader reader, final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes, final CyRootNetworkManager rootNetworkManager ){
                this.reader = reader;
                globalTable = null;
                this.byReader = true;
                this.networkManager = networkManager;
                this.name2NetworkMap = new HashMap<String, CyNetwork>();
                this.updateAddedNetworkAttributes = 
updateAddedNetworkAttributes;
-               
+               this.rootNetworkManager = rootNetworkManager;
+
                initTunable(networkManager);
-               
+
        }
-       
-       public MapTableToNetworkTablesTask(final CyNetworkManager 
networkManager, final CyTable globalTable, final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes){
+
+       public MapTableToNetworkTablesTask(final CyNetworkManager 
networkManager, final CyTable globalTable, final UpdateAddedNetworkAttributes 
updateAddedNetworkAttributes, final CyRootNetworkManager rootNetworkManager){
                this.networkManager = networkManager;
                this.globalTable = globalTable;
                this.byReader = false;
                this.reader = null;
                this.name2NetworkMap = new HashMap<String, CyNetwork>();
                this.updateAddedNetworkAttributes = 
updateAddedNetworkAttributes;
+               this.rootNetworkManager = rootNetworkManager;
+
                initTunable(networkManager);
        }
-       
+
        private void initTunable(CyNetworkManager networkManage){
                final List<TableType> options = new ArrayList<TableType>();
                for(TableType type: TableType.values())
                        options.add(type);
                dataTypeOptions = new ListSingleSelection<TableType>(options);
                dataTypeOptions.setSelectedValue(TableType.NODE_ATTR);
-               
+
                for(CyNetwork net: networkManage.getNetworkSet()){
                        String netName = net.getRow(net).get(CyNetwork.NAME, 
String.class);
                        name2NetworkMap.put(netName, net);
@@ -111,35 +117,23 @@
                        networkList = new 
ListMultipleSelection<String>(NO_NETWORKS);
                else
                        networkList = new ListMultipleSelection<String>(names);
-                       
+
        }
-       
-       
+
+
        public void run(TaskMonitor taskMonitor) throws Exception {     
                TableType tableType = dataTypeOptions.getSelectedValue();
-               if (tableType != TableType.GLOBAL ){
-                       List<CyNetwork> networks = new ArrayList<CyNetwork>();
+               if (tableType == TableType.GLOBAL )
+                       return;
 
-                       if (!selectedNetworksOnly)
-                               networks.addAll(networkManager.getNetworkSet());
-                       else{
-                               
if(!networkList.getSelectedValues().get(0).equals(NO_NETWORKS))
-                                       for(String netName: 
networkList.getSelectedValues())
-                                               
networks.add(name2NetworkMap.get(netName));
+               List<CyNetwork> networks = new ArrayList<CyNetwork>();
 
-                       }
-                       for (CyNetwork network: networks){
-                               CyTable targetTable = getTable(network, 
tableType);
-                               if (targetTable != null){
-                                       if(byReader){
-                                               if (reader.getTables() != null 
&& reader.getTables().length >0){
-                                                       for(CyTable sourceTable 
: reader.getTables())
-                                                               
mapTable(targetTable, sourceTable);
-                                               }
-                                       }else
-                                               mapTable(targetTable, 
globalTable);
-                               }
-                       }
+               if (!selectedNetworksOnly)
+                       mapTableToDefaultAttrs (tableType);
+               else
+                       mapTableToLocalAttrs (tableType);
+
+               
                        if(!selectedNetworksOnly){ //if table should be mapped 
to all of the tables
                                //add each mapped table to the list for mapping 
to networks going to be added later
                                if(byReader){
@@ -148,23 +142,67 @@
                                                        
updateAddedNetworkAttributes.addMappingToList(sourceTable, tableType.getType());
                                }else
                                        
updateAddedNetworkAttributes.addMappingToList(globalTable, tableType.getType());
+
                        }
+                
+       }
+
+
+
+       private void mapTableToLocalAttrs(TableType tableType) {
+               List<CyNetwork> networks = new ArrayList<CyNetwork>();
+
+               if(!networkList.getSelectedValues().get(0).equals(NO_NETWORKS))
+                       for(String netName: networkList.getSelectedValues())
+                               networks.add(name2NetworkMap.get(netName));
+
+               for (CyNetwork network: networks){
+                       CyTable targetTable = getTable(network, tableType, 
CyNetwork.LOCAL_ATTRS);
+                       if (targetTable != null)
+                               applyMapping(targetTable);
                }
+
        }
 
 
+       private void mapTableToDefaultAttrs(TableType tableType) {
+               List<CyRootNetwork> rootNetworkList = new 
ArrayList<CyRootNetwork>();
+               for (CyNetwork net : networkManager.getNetworkSet())
+                       if (! 
rootNetworkList.contains(rootNetworkManager.getRootNetwork(net)))
+                               rootNetworkList.add( 
rootNetworkManager.getRootNetwork(net));
 
-       private CyTable getTable(CyNetwork network, TableType tableType){
+               for (CyRootNetwork root: rootNetworkList ){
+                       CyTable targetTable = getTable(root, tableType, 
CyNetwork.DEFAULT_ATTRS);
+                       if (targetTable != null){
+                               applyMapping(targetTable);
+                       }
+               }
+       }
+
+
+       private CyTable getTable(CyNetwork network, TableType tableType, String 
namespace){
                if (tableType == TableType.NODE_ATTR)
-                       return network.getDefaultNodeTable();
+                       return network.getTable(CyNode.class, namespace);
                if (tableType == TableType.EDGE_ATTR)
-                       return network.getDefaultEdgeTable();
+                       return network.getTable(CyEdge.class, namespace);
                if (tableType == TableType.NETWORK_ATTR)
-                       return network.getDefaultNetworkTable();
+                       return network.getTable(CyNetwork.class, namespace);
+
                logger.warn("The selected table type is not valie. \nTable 
needs to be one of these types: " +TableType.NODE_ATTR +", " + 
TableType.EDGE_ATTR  + ", "+ TableType.NETWORK_ATTR +" or "+TableType.GLOBAL 
+".");
                return null;
        }
-       
+
+
+       private void applyMapping(CyTable targetTable){
+               if(byReader){
+                       if (reader.getTables() != null && 
reader.getTables().length >0){
+                               for(CyTable sourceTable : reader.getTables())
+                                       mapTable(targetTable, sourceTable);
+                       }
+               }else
+                       mapTable(targetTable, globalTable);
+       }
+
        private void mapTable(final CyTable localTable, final CyTable 
globalTable) {
                if (globalTable.getPrimaryKey().getType() != String.class)
                        throw new IllegalStateException("Local table's primary 
key should be type String.");

Modified: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTaskFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTaskFactoryImpl.java
 2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTaskFactoryImpl.java
 2012-08-29 23:23:32 UTC (rev 30291)
@@ -9,6 +9,7 @@
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTable;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.AbstractTableTaskFactory;
 import org.cytoscape.task.edit.MapTableToNetworkTablesTaskFactory;
 import org.cytoscape.task.internal.table.MapTableToNetworkTablesTask.TableType;
@@ -23,17 +24,19 @@
        private final CyNetworkManager networkManager;
        private final TunableSetter tunableSetter; 
        private final UpdateAddedNetworkAttributes updateAddedNetworkAttributes;
+       private final CyRootNetworkManager rootNetMgr;
        
-       public MapTableToNetworkTablesTaskFactoryImpl( final CyNetworkManager 
networkManager, final TunableSetter tunableSetter, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes ){
+       public MapTableToNetworkTablesTaskFactoryImpl( final CyNetworkManager 
networkManager, final TunableSetter tunableSetter, final 
UpdateAddedNetworkAttributes updateAddedNetworkAttributes, final 
CyRootNetworkManager rootNetMgr ){
        
                this.networkManager = networkManager;
                this.tunableSetter = tunableSetter;
                this.updateAddedNetworkAttributes = 
updateAddedNetworkAttributes;
+               this.rootNetMgr = rootNetMgr;
        }
 
        @Override
        public TaskIterator createTaskIterator(CyTable globalTable) {
-               return new TaskIterator(new 
MapTableToNetworkTablesTask(networkManager, globalTable, 
updateAddedNetworkAttributes));
+               return new TaskIterator(new 
MapTableToNetworkTablesTask(networkManager, globalTable, 
updateAddedNetworkAttributes, rootNetMgr));
        }
 
        @Override

Modified: 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImplTest.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImplTest.java
  2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImplTest.java
  2012-08-29 23:23:32 UTC (rev 30291)
@@ -10,6 +10,7 @@
 import org.cytoscape.io.read.CyTableReaderManager;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
 import org.cytoscape.work.Task;
 import org.cytoscape.work.TaskIterator;
@@ -38,6 +39,9 @@
        @Mock 
        UpdateAddedNetworkAttributes updateAddedNetworkAttributes;
 
+       @Mock
+       CyRootNetworkManager rootNetMgr;
+       
        @Before
        public void initMocks() {
                MockitoAnnotations.initMocks(this);
@@ -47,7 +51,7 @@
        @Test(expected = NullPointerException.class)
        public void testLoadAttributesFileTaskFactory() throws Exception {
 
-               final LoadAttributesFileTaskFactoryImpl factory = new 
LoadAttributesFileTaskFactoryImpl(rmgr, ts, netMgr, tabMgr, 
updateAddedNetworkAttributes);
+               final LoadAttributesFileTaskFactoryImpl factory = new 
LoadAttributesFileTaskFactoryImpl(rmgr, ts, netMgr, tabMgr, 
updateAddedNetworkAttributes, rootNetMgr);
                TaskIterator ti = factory.createTaskIterator();
                assertNotNull(ti);
 

Modified: 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImplTest.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImplTest.java
   2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImplTest.java
   2012-08-29 23:23:32 UTC (rev 30291)
@@ -9,6 +9,7 @@
 import org.cytoscape.io.read.CyTableReaderManager;
 import org.cytoscape.model.CyNetworkManager;
 import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
 import org.cytoscape.work.Task;
 import org.cytoscape.work.TaskIterator;
@@ -39,6 +40,9 @@
        @Mock 
        UpdateAddedNetworkAttributes updateAddedNetworkAttributes;
 
+       @Mock
+       CyRootNetworkManager rootNetMgr;
+       
        @Before
        public void initMocks() {
                MockitoAnnotations.initMocks(this);
@@ -48,7 +52,7 @@
        @Test(expected = NullPointerException.class)
        public void testLoadAttributesURLTaskFactory() throws Exception {
 
-               final LoadAttributesURLTaskFactoryImpl factory = new 
LoadAttributesURLTaskFactoryImpl(rmgr, ts, netMgr, tabMgr, 
updateAddedNetworkAttributes);
+               final LoadAttributesURLTaskFactoryImpl factory = new 
LoadAttributesURLTaskFactoryImpl(rmgr, ts, netMgr, tabMgr, 
updateAddedNetworkAttributes, rootNetMgr);
                
                final TaskIterator ti = factory.createTaskIterator();
                assertNotNull(ti);

Modified: 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MapTableToNetworkTableTaskTest.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MapTableToNetworkTableTaskTest.java
 2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MapTableToNetworkTableTaskTest.java
 2012-08-29 23:23:32 UTC (rev 30291)
@@ -16,11 +16,11 @@
 import org.cytoscape.model.NetworkTestSupport;
 import org.cytoscape.model.SavePolicy;
 import org.cytoscape.model.internal.CyNetworkManagerImpl;
+import org.cytoscape.model.internal.CyRootNetworkManagerImpl;
 import org.cytoscape.model.internal.CyTableImpl;
 import org.cytoscape.work.Task;
 import org.cytoscape.work.TaskIterator;
 import org.cytoscape.work.TaskMonitor;
-import org.cytoscape.work.TunableHandlerFactory;
 import org.junit.Test;
 
 import static org.mockito.Mockito.mock;
@@ -48,6 +48,8 @@
 
        private static CyEventHelper eventHelper = new DummyCyEventHelper();
        private static CyNetworkManagerImpl netMgr = new 
CyNetworkManagerImpl(eventHelper);     
+       private static CyRootNetworkManagerImpl rootNetMgr = new 
CyRootNetworkManagerImpl();
+       
        private static SyncTunableMutator stm = new SyncTunableMutator();
        private static SyncTunableHandlerFactory syncTunableHandlerFactory = 
new SyncTunableHandlerFactory();
        private static TunableSetterImpl ts =new TunableSetterImpl(new 
SyncTunableMutatorFactory(syncTunableHandlerFactory),  new 
TunableRecorderManager());
@@ -88,7 +90,7 @@
        
        public static void mapping(CyTable table, CyNetwork net, boolean 
selectedOnly) throws Exception{
                UpdateAddedNetworkAttributes up = new 
UpdateAddedNetworkAttributes(new 
MapGlobalToLocalTableTaskFactoryImpl(mock(CyTableManager.class), netMgr, ts), 
new SyncTaskManager(stm));
-               MapTableToNetworkTablesTaskFactoryImpl mappingTF = new 
MapTableToNetworkTablesTaskFactoryImpl(netMgr, ts, up);
+               MapTableToNetworkTablesTaskFactoryImpl mappingTF = new 
MapTableToNetworkTablesTaskFactoryImpl(netMgr, ts, up , rootNetMgr);
                List<CyNetwork> nets = new ArrayList<CyNetwork>();
                nets.add(net);
                

Modified: 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MappingIntegrationTest.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MappingIntegrationTest.java
 2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/MappingIntegrationTest.java
 2012-08-29 23:23:32 UTC (rev 30291)
@@ -26,9 +26,11 @@
 import org.cytoscape.model.events.NetworkAddedEvent;
 import org.cytoscape.model.internal.CyNetworkManagerImpl;
 import org.cytoscape.model.internal.CyNetworkTableManagerImpl;
+import org.cytoscape.model.internal.CyRootNetworkManagerImpl;
 import org.cytoscape.model.internal.CySubNetworkImpl;
 import org.cytoscape.model.internal.CyTableImpl;
 import org.cytoscape.model.internal.CyTableManagerImpl;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.session.CyNetworkNaming;
 import org.cytoscape.task.internal.creation.NewNetworkSelectedNodesOnlyTask;
 import org.cytoscape.view.model.CyNetworkViewManager;
@@ -56,6 +58,8 @@
 
        private CyEventHelper eventHelper = new DummyCyEventHelper();
        private CyNetworkManagerImpl netMgr = new 
CyNetworkManagerImpl(eventHelper);    
+       private final CyRootNetworkManagerImpl rootNetMgr = new 
CyRootNetworkManagerImpl();
+       
        private SyncTunableMutator stm = new SyncTunableMutator();
        SyncTunableHandlerFactory syncTunableHandlerFactory = new 
SyncTunableHandlerFactory();
 
@@ -142,6 +146,7 @@
                
                ((CySubNetworkImpl) subnet1).handleEvent(new 
NetworkAddedEvent(netMgr, subnet1));
                
+               
                assertEquals(2, subnet1.getNodeList().size());
                
                
assertNotNull(subnet1.getDefaultNodeTable().getColumn(table1sCol));
@@ -163,8 +168,8 @@
                //check the mapping by task
                assertNotNull(net1.getDefaultNodeTable().getColumn(table2sCol));
                assertEquals(table2sRow1, 
net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table2sCol, 
String.class) );
-               // TODO!!!
-               
//assertNull(subnet1.getDefaultNodeTable().getColumn(table2sCol)); //subnet1 
should not be mapped 
+               
+               
assertNull(subnet1.getDefaultNodeTable().getColumn(table2sCol)); //subnet1 
should not be mapped 
 
                //creating another subnetwork (subnet2) to check that bot 
virtual columns will be added
                
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, 
true);
@@ -201,7 +206,7 @@
        
        public void mapping(CyTable table, CyNetwork net, boolean selectedOnly) 
throws Exception{
                
-               MapTableToNetworkTablesTaskFactoryImpl mappingTF = new 
MapTableToNetworkTablesTaskFactoryImpl(netMgr, ts, up);
+               MapTableToNetworkTablesTaskFactoryImpl mappingTF = new 
MapTableToNetworkTablesTaskFactoryImpl(netMgr, ts, up, rootNetMgr);
                List<CyNetwork> nets = new ArrayList<CyNetwork>();
                nets.add(net);
                

Modified: 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributeTaskTest.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributeTaskTest.java
    2012-08-29 21:54:33 UTC (rev 30290)
+++ 
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributeTaskTest.java
    2012-08-29 23:23:32 UTC (rev 30291)
@@ -22,6 +22,7 @@
 import org.cytoscape.model.events.NetworkAddedEvent;
 import org.cytoscape.model.internal.CyNetworkManagerImpl;
 import org.cytoscape.model.internal.CyNetworkTableManagerImpl;
+import org.cytoscape.model.internal.CyRootNetworkManagerImpl;
 import org.cytoscape.model.internal.CySubNetworkImpl;
 import org.cytoscape.model.internal.CyTableImpl;
 import org.cytoscape.model.internal.CyTableManagerImpl;
@@ -47,7 +48,9 @@
 
 
        private CyEventHelper eventHelper = new DummyCyEventHelper();
-       private CyNetworkManagerImpl netMgr = new 
CyNetworkManagerImpl(eventHelper);    
+       private CyNetworkManagerImpl netMgr = new 
CyNetworkManagerImpl(eventHelper);
+       private CyRootNetworkManagerImpl rootNetMgr = new 
CyRootNetworkManagerImpl();
+       
        private SyncTunableMutator stm = new SyncTunableMutator();
        SyncTunableHandlerFactory syncTunableHandlerFactory = new 
SyncTunableHandlerFactory();
        private TunableSetterImpl ts = new TunableSetterImpl(new 
SyncTunableMutatorFactory(syncTunableHandlerFactory),  new 
TunableRecorderManager());
@@ -172,7 +175,7 @@
        
        public void mapping(CyTable table, CyNetwork net, boolean selectedOnly 
) throws Exception{
                
-               MapTableToNetworkTablesTaskFactoryImpl mappingTF = new 
MapTableToNetworkTablesTaskFactoryImpl(netMgr, ts, up);
+               MapTableToNetworkTablesTaskFactoryImpl mappingTF = new 
MapTableToNetworkTablesTaskFactoryImpl(netMgr, ts, up, rootNetMgr);
                List<CyNetwork> nets = new ArrayList<CyNetwork>();
                nets.add(net);
                

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