Author: rozagh
Date: 2012-05-11 15:46:49 -0700 (Fri, 11 May 2012)
New Revision: 29249
Modified:
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/events/RowsSetEvent.java
core3/api/trunk/swing-application-api/src/main/java/org/cytoscape/application/swing/AbstractViewUpdater.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
Log:
fixes #697 some convenience methods are added to the RowsSetEvent enabling the
check for if a specific column value has been changed and also getting the
records for a specific column. Making RowSetRecord specific for a column needs
highly complicated refactoring which can be done later.
Modified:
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/events/RowsSetEvent.java
===================================================================
---
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/events/RowsSetEvent.java
2012-05-11 22:17:12 UTC (rev 29248)
+++
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/events/RowsSetEvent.java
2012-05-11 22:46:49 UTC (rev 29249)
@@ -1,6 +1,10 @@
package org.cytoscape.model.events;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
import org.cytoscape.event.AbstractCyPayloadEvent;
import org.cytoscape.model.CyTable;
@@ -11,6 +15,8 @@
*/
public final class RowsSetEvent extends AbstractCyPayloadEvent<CyTable,
RowSetRecord> {
+ private Map<String, Collection<RowSetRecord>> columnNameToRecordMap;
+
/**
* Constructs Event.
* @param source the table in which the rows have been set.
@@ -19,4 +25,46 @@
public RowsSetEvent(CyTable source, Collection<RowSetRecord> rows) {
super(source, RowsSetListener.class, rows);
}
+
+ /**
+ * Returns true if any of the changed records' column name is colName
+ * @param colName Name of the column.
+ * @return
+ */
+ public boolean containsColumn(String colName) {
+ return getMap().containsKey(colName);
+ }
+
+ /**
+ * Returns all of the {@link RowSetRecord}s whose specified column value
is set.
+ * @param colName Name of the column.
+ * @return
+ */
+ public Collection<RowSetRecord> getColumnRecords(String colName) {
+ Collection<RowSetRecord> col = getMap().get(colName);
+ if ( col == null )
+ return Collections.emptyList();
+ else
+ return col;
+ }
+
+
+ /**
+ * Creates a map based on the columns of the {@link RowSetRecord}s in the
event payload.
+ * This map is not created in the initialization to prevent performance
penalties.
+ * @return
+ */
+ private synchronized Map<String, Collection<RowSetRecord>> getMap() {
+ if ( columnNameToRecordMap == null ) {
+ columnNameToRecordMap = new HashMap<String,
Collection<RowSetRecord>>();
+ for(RowSetRecord record: this.getPayloadCollection()){
+ String columnName = record.getColumn();
+ if (!columnNameToRecordMap.containsKey(columnName))
+ columnNameToRecordMap.put(columnName, new
ArrayList<RowSetRecord>());
+
+ columnNameToRecordMap.get(columnName).add(record);
+ }
+ }
+ return columnNameToRecordMap;
+ }
}
Modified:
core3/api/trunk/swing-application-api/src/main/java/org/cytoscape/application/swing/AbstractViewUpdater.java
===================================================================
---
core3/api/trunk/swing-application-api/src/main/java/org/cytoscape/application/swing/AbstractViewUpdater.java
2012-05-11 22:17:12 UTC (rev 29248)
+++
core3/api/trunk/swing-application-api/src/main/java/org/cytoscape/application/swing/AbstractViewUpdater.java
2012-05-11 22:46:49 UTC (rev 29249)
@@ -76,10 +76,7 @@
*/
@SuppressWarnings("unchecked")
public void handleEvent(RowsSetEvent e) {
- for (RowSetRecord record : e.getPayloadCollection()) {
- if (columnName != record.getColumn())
- continue;
-
+ for (RowSetRecord record : e.getColumnRecords(columnName)) {
View<?> v = rowViewMap.get(record.getRow());
if (v != null)
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
2012-05-11 22:17:12 UTC (rev 29248)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
2012-05-11 22:46:49 UTC (rev 29249)
@@ -2,14 +2,12 @@
import java.util.List;
-import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
import org.cytoscape.model.events.RowSetRecord;
import org.cytoscape.model.events.RowsSetEvent;
import org.cytoscape.model.events.RowsSetListener;
-import org.cytoscape.model.subnetwork.CyRootNetwork;
public class ColumnSetListener implements RowsSetListener {
@@ -29,10 +27,8 @@
final List<CyTable> sharedList = tables.get(local);
for ( CyTable shared : sharedList ) {
- for ( RowSetRecord record : e.getPayloadCollection() ) {
+ for ( RowSetRecord record :
e.getColumnRecords(columnName) ) {
// assume payload collection is for same column
- if ( !record.getColumn().equals(columnName))
- continue;
final CyRow r =
shared.getRow(record.getRow().get( CyIdentifiable.SUID, Long.class ));
if( r != null ) {
final Object name = record.getValue();
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
2012-05-11 22:17:12 UTC (rev 29248)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
2012-05-11 22:46:49 UTC (rev 29249)
@@ -1,16 +1,6 @@
package org.cytoscape.model.internal;
-import java.util.List;
-
-
import org.cytoscape.model.CyEdge;
-import org.cytoscape.model.CyIdentifiable;
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyRow;
-import org.cytoscape.model.CyTable;
-import org.cytoscape.model.events.RowSetRecord;
-import org.cytoscape.model.events.RowsSetEvent;
-import org.cytoscape.model.events.RowsSetListener;
import org.cytoscape.model.subnetwork.CyRootNetwork;
public class InteractionSetListener extends ColumnSetListener {
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
2012-05-11 22:17:12 UTC (rev 29248)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
2012-05-11 22:46:49 UTC (rev 29249)
@@ -30,17 +30,8 @@
import org.cytoscape.model.subnetwork.CyRootNetwork;
-import org.cytoscape.model.CyTable;
import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyIdentifiable;
-import org.cytoscape.model.CyRow;
-import org.cytoscape.model.events.RowsSetListener;
-import org.cytoscape.model.events.RowsSetEvent;
-import org.cytoscape.model.events.RowSetRecord;
-import java.util.List;
-import java.util.ArrayList;
-
/**
* Any time that the CyNetwork.NAME column is set
* in a local table, update the shared table with the
@@ -51,7 +42,6 @@
NameSetListener() {
super(CyNetwork.NAME, CyRootNetwork.SHARED_NAME);
}
-
}
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
2012-05-11 22:17:12 UTC (rev 29248)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
2012-05-11 22:46:49 UTC (rev 29249)
@@ -1,14 +1,8 @@
package org.cytoscape.model.internal;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.WeakHashMap;
-import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
import org.cytoscape.model.events.NetworkAddedEvent;
import org.cytoscape.model.events.NetworkAddedListener;
@@ -20,7 +14,7 @@
/**
* NetworkNameSetListener implements NetworkAddedListener and RowsSetListener.
* The tables are renamed based on the network name. When a network is created
- * for the first time first root network is consructed which creates the base
network
+ * for the first time first root network is constructed which creates the base
network
* immediately. Since when networks are created the rowssetevent is not fired,
the
* networkaddedlistener is implemented which sets the name of the table at
first.
* If the networkaddedevent is for the base network, it sets the root network
name
@@ -48,7 +42,7 @@
updateRootNetworkTableNames(e.getPayloadCollection());
}
else{
- updateSubNetworkTableNames(e.getPayloadCollection(),
sourceTable);
+
updateSubNetworkTableNames(e.getColumnRecords(CyNetwork.NAME), sourceTable);
}
@@ -60,9 +54,6 @@
if (sourceTable.equals(net.getDefaultNetworkTable())){
for ( RowSetRecord record :payloadCollection) {
// assume payload collection is for
same column
- if (
!record.getColumn().equals(CyNetwork.NAME))
- break;
-
final Object name = record.getValue();
setTablesName(name.toString() + "
default ", net.getDefaultEdgeTable(), net.getDefaultNodeTable(),
net.getDefaultNetworkTable());
@@ -78,15 +69,11 @@
for ( RowSetRecord record : payloadCollection ) {
// assume payload collection is for same column
- if ( !record.getColumn().equals(CyNetwork.NAME))
- break;
-
final Object name = record.getValue();
setTablesName(name.toString() + " root shared ",
rootNetwork.getSharedEdgeTable(), rootNetwork.getSharedNodeTable(),
rootNetwork.getSharedNetworkTable());
setTablesName(name.toString() + " root default ",
rootNetwork.getDefaultEdgeTable(), rootNetwork.getDefaultNodeTable(),
rootNetwork.getDefaultNetworkTable());
return;
-
}
}
Modified:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
2012-05-11 22:17:12 UTC (rev 29248)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
2012-05-11 22:46:49 UTC (rev 29249)
@@ -555,7 +555,7 @@
@Override
public void handleEvent(final RowsSetEvent e) {
- final Collection<RowSetRecord> records =
e.getPayloadCollection();
+ final Collection<RowSetRecord> records =
e.getColumnRecords(CyNetwork.NAME);
final CyTable source = e.getSource();
SwingUtilities.invokeLater(new Runnable() {
@Override
@@ -568,8 +568,6 @@
private final void updateNetworkNameColumn(final
Collection<RowSetRecord> records, final CyTable source) {
for (final RowSetRecord record : records) {
// assume payload collection is for same column
- if (!record.getColumn().equals(CyNetwork.NAME))
- break;
for (JInternalFrame targetIF : iFrameMap.keySet()) {
if
(iFrameMap.get(targetIF).getModel().getDefaultNetworkTable().equals(source)) {
targetIF.setTitle(record.getRow().get(CyNetwork.NAME, String.class));
--
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.