Author: rozagh
Date: 2012-05-11 12:17:44 -0700 (Fri, 11 May 2012)
New Revision: 29232
Added:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributes.java
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/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
Log:
Implemented a class for updating an added network if a table exists which needs
to be mapped to all of the network related tables.
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-05-11 18:36:34 UTC (rev 29231)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/CyActivator.java
2012-05-11 19:17:44 UTC (rev 29232)
@@ -37,6 +37,7 @@
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.events.NetworkAddedListener;
import org.cytoscape.model.subnetwork.CyRootNetworkManager;
import org.cytoscape.property.CyProperty;
import org.cytoscape.service.util.AbstractCyActivator;
@@ -130,6 +131,7 @@
import
org.cytoscape.task.internal.table.MapTableToNetworkTablesTaskFactoryImpl;
import org.cytoscape.task.internal.table.MapGlobalToLocalTableTaskFactoryImpl;
import org.cytoscape.task.internal.table.RenameColumnTaskFactoryImpl;
+import org.cytoscape.task.internal.table.UpdateAddedNetworkAttributes;
import org.cytoscape.task.internal.title.EditNetworkTitleTaskFactoryImpl;
import org.cytoscape.task.internal.vizmap.ApplyVisualStyleTaskFactoryimpl;
import org.cytoscape.task.internal.zoom.FitContentTaskFactory;
@@ -979,5 +981,9 @@
ExportTableTaskFactoryImpl exportTableTaskFactory = new
ExportTableTaskFactoryImpl(cyTableWriterManagerRef,tunableSetterServiceRef);
Properties exportTableTaskFactoryProps = new Properties();
registerService(bc,exportTableTaskFactory,ExportTableTaskFactory.class,exportTableTaskFactoryProps);
+
+ UpdateAddedNetworkAttributes updateAddedNetworkAttributes = new
UpdateAddedNetworkAttributes(mapGlobal, synchronousTaskManagerServiceRef);
+ registerService(bc, updateAddedNetworkAttributes,
NetworkAddedListener.class, new Properties());
+
}
}
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-05-11 18:36:34 UTC (rev 29231)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTask.java
2012-05-11 19:17:44 UTC (rev 29232)
@@ -3,10 +3,14 @@
import java.util.ArrayList;
import java.util.List;
+import org.cytoscape.event.CyEventHelper;
import org.cytoscape.io.read.CyTableReader;
import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyTable;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.ProvidesTitle;
@@ -16,17 +20,22 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public final class MapTableToNetworkTablesTask extends AbstractTask {
private static enum TableType {
- NODE_ATTR("Node Attributes"), EDGE_ATTR("Edge Attributes"),
NETWORK_ATTR("Network Attributes"), GLOBAL("Tables");
+ NODE_ATTR("Node Attributes", CyNode.class), EDGE_ATTR("Edge
Attributes", CyEdge.class), NETWORK_ATTR("Network Attributes",
CyNetwork.class), GLOBAL("Tables", CyTable.class);
private final String name;
-
- private TableType(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;
}
@@ -40,6 +49,7 @@
private final CyTableReader reader;
private final boolean byReader;
+
@Tunable(description = "Import Data To:")
public ListSingleSelection<TableType> dataTypeOptions;
@@ -48,8 +58,7 @@
return "Import Data";
}
- public MapTableToNetworkTablesTask(final CyNetworkManager
networkManager, final CyTableReader reader)
- {
+ public MapTableToNetworkTablesTask(final CyNetworkManager
networkManager, final CyTableReader reader){
this.reader = reader;
globalTable = null;
this.byReader = true;
@@ -62,18 +71,16 @@
this.globalTable = globalTable;
this.byReader = false;
this.reader = null;
-
initTunable();
}
private void initTunable(){
final List<TableType> options = new ArrayList<TableType>();
- if (networkManager.getNetworkSet().size() > 0 ) {
- for(TableType type: TableType.values())
- options.add(type);
- } else
- options.add(TableType.GLOBAL);
+ for(TableType type: TableType.values())
+ options.add(type);
+ options.add(TableType.GLOBAL);
+
dataTypeOptions = new ListSingleSelection<TableType>(options);
dataTypeOptions.setSelectedValue(TableType.NODE_ATTR);
}
@@ -83,10 +90,11 @@
TableType tableType = dataTypeOptions.getSelectedValue();
if (tableType != tableType.GLOBAL ){ //The table has already
been added to the global tables
-
+ boolean isEverMapped = false;
for (CyNetwork network: networkManager.getNetworkSet()){
CyTable targetTable = getTable(network,
tableType);
if (targetTable != null){
+ isEverMapped = true;
if(byReader){
if (reader.getTables() != null
&& reader.getTables().length >0){
for(CyTable sourceTable
: reader.getTables())
@@ -95,8 +103,16 @@
}else{
mapTable(targetTable,
globalTable);
}
+
}
}
+ //add each mapped table to the list for mapping to
networks going to be added later
+ if(byReader){
+ if (reader.getTables() != null &&
reader.getTables().length >0)
+ for(CyTable sourceTable :
reader.getTables())
+
UpdateAddedNetworkAttributes.addMappingToList(sourceTable, tableType.getType());
+ }else
+
UpdateAddedNetworkAttributes.addMappingToList(globalTable, tableType.getType());
}
}
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-05-11 18:36:34 UTC (rev 29231)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/MapTableToNetworkTablesTaskFactoryImpl.java
2012-05-11 19:17:44 UTC (rev 29232)
@@ -3,6 +3,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.cytoscape.event.CyEventHelper;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.CyTable;
import org.cytoscape.task.AbstractTableTaskFactory;
Added:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributes.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributes.java
(rev 0)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/table/UpdateAddedNetworkAttributes.java
2012-05-11 19:17:44 UTC (rev 29232)
@@ -0,0 +1,69 @@
+package org.cytoscape.task.internal.table;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.cytoscape.model.events.NetworkAddedEvent;
+import org.cytoscape.model.events.NetworkAddedListener;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.task.edit.MapGlobalToLocalTableTaskFactory;
+import org.cytoscape.work.SynchronousTaskManager;
+
+/**
+ * This class is for updating the tables for a newly added network
+ * and map the global tables that are required to to the specified
+ * tables. The core-task-impl package may not be the best place for
+ * this class. In case this class needs to be moved to another package
+ * an event needs to be added which is fired when an imported table
+ * is mapped to all network related tables.
+ * @author rozagh
+ *
+ */
+
+public class UpdateAddedNetworkAttributes implements NetworkAddedListener{
+
+ private static Map<CyTable, List< Class<? extends CyIdentifiable>>>
tableMappings;
+ private final MapGlobalToLocalTableTaskFactory mappingTF;
+ private final SynchronousTaskManager<?> syncTaskManager;
+
+ public UpdateAddedNetworkAttributes(MapGlobalToLocalTableTaskFactory
mappingTF, final SynchronousTaskManager<?> syncTaskManager){
+ tableMappings = new HashMap<CyTable, List<Class<? extends
CyIdentifiable>>>();
+ this.mappingTF = mappingTF;
+ this.syncTaskManager = syncTaskManager;
+ }
+
+ @Override
+ public void handleEvent(NetworkAddedEvent e) {
+ for (CyTable mappedTable: tableMappings.keySet()){
+ for( Class<? extends CyIdentifiable> tableType:
tableMappings.get(mappedTable)){
+
syncTaskManager.execute(mappingTF.createTaskIterator(mappedTable,
getTable(e.getNetwork(),tableType)));
+ }
+ }
+
+ }
+
+ final static void addMappingToList(CyTable importedTable, Class<?
extends CyIdentifiable> mappedTableType){
+ //When an imported table is mapped add it to the list with the
type of table it has been mapped to.
+ if (!tableMappings.containsKey(importedTable))
+ tableMappings.put(importedTable, new ArrayList< Class<?
extends CyIdentifiable>>());
+
+ tableMappings.get(importedTable).add(mappedTableType);
+ }
+
+ private CyTable getTable(CyNetwork network, Class<? extends
CyIdentifiable> tableType){
+ if (tableType == CyNode.class)
+ return network.getDefaultNodeTable();
+ if (tableType == CyEdge.class)
+ return network.getDefaultEdgeTable();
+ if (tableType == CyNetwork.class)
+ return network.getDefaultNetworkTable();
+ return null;
+ }
+
+}
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-05-11 18:36:34 UTC (rev 29231)
+++
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesFileTaskFactoryImplTest.java
2012-05-11 19:17:44 UTC (rev 29232)
@@ -6,6 +6,7 @@
import java.io.File;
+import org.cytoscape.event.CyEventHelper;
import org.cytoscape.io.read.CyTableReaderManager;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.CyTableManager;
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-05-11 18:36:34 UTC (rev 29231)
+++
core3/impl/trunk/core-task-impl/src/test/java/org/cytoscape/task/internal/loaddatatable/LoadAttributesURLTaskFactoryImplTest.java
2012-05-11 19:17:44 UTC (rev 29232)
@@ -5,6 +5,7 @@
import java.net.URL;
+import org.cytoscape.event.CyEventHelper;
import org.cytoscape.io.read.CyTableReaderManager;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.CyTableManager;
@@ -34,6 +35,7 @@
@Mock
CyTableManager tabMgr;
+
@Before
public void initMocks() {
MockitoAnnotations.initMocks(this);
--
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.