|
2 | 2 |
|
3 | 3 | import java.util.Collections;
|
4 | 4 | import java.util.HashMap;
|
| 5 | +import java.util.List; |
5 | 6 | import java.util.SortedMap;
|
6 | 7 | import java.util.TreeMap;
|
7 | 8 |
|
| 9 | +import javax.swing.ListSelectionModel; |
| 10 | +import javax.swing.table.TableModel; |
| 11 | + |
8 | 12 | import org.baderlab.csplugins.enrichmentmap.actions.EnrichmentMapActionListener;
|
9 | 13 | import org.baderlab.csplugins.enrichmentmap.autoannotate.action.DisplayOptionsPanelAction;
|
| 14 | +import org.baderlab.csplugins.enrichmentmap.autoannotate.model.AnnotationSet; |
| 15 | +import org.baderlab.csplugins.enrichmentmap.autoannotate.model.Cluster; |
10 | 16 | import org.baderlab.csplugins.enrichmentmap.autoannotate.view.AutoAnnotationPanel;
|
11 | 17 | import org.baderlab.csplugins.enrichmentmap.autoannotate.view.DisplayOptionsPanel;
|
12 | 18 | import org.baderlab.csplugins.enrichmentmap.view.HeatMapPanel;
|
|
21 | 27 | import org.cytoscape.group.CyGroupFactory;
|
22 | 28 | import org.cytoscape.group.CyGroupManager;
|
23 | 29 | import org.cytoscape.model.CyNetwork;
|
| 30 | +import org.cytoscape.model.CyNode; |
24 | 31 | import org.cytoscape.model.CyTableManager;
|
| 32 | +import org.cytoscape.model.CyTableUtil; |
25 | 33 | import org.cytoscape.model.events.ColumnCreatedEvent;
|
26 | 34 | import org.cytoscape.model.events.ColumnCreatedListener;
|
27 | 35 | import org.cytoscape.model.events.ColumnDeletedEvent;
|
|
50 | 58 | public class AutoAnnotationManager implements
|
51 | 59 | SetSelectedNetworkViewsListener, ColumnCreatedListener,
|
52 | 60 | ColumnDeletedListener, ColumnNameChangedListener,
|
53 |
| - NetworkViewAboutToBeDestroyedListener { |
| 61 | + NetworkViewAboutToBeDestroyedListener, RowsSetListener { |
54 | 62 |
|
55 | 63 | // instance variable used to get the manager from other parts of the program
|
56 | 64 | private static AutoAnnotationManager instance = null;
|
@@ -180,6 +188,101 @@ public void handleEvent(NetworkViewAboutToBeDestroyedEvent e) {
|
180 | 188 | }
|
181 | 189 | }
|
182 | 190 |
|
| 191 | + @Override |
| 192 | + public void handleEvent(RowsSetEvent e) { |
| 193 | + if (annotationPanel != null && e.getColumnRecords(CyNetwork.SELECTED).size() > 0) { |
| 194 | + |
| 195 | + //get the current network |
| 196 | + CyNetwork network = this.applicationManager.getCurrentNetwork(); |
| 197 | + CyNetworkView view = this.applicationManager.getCurrentNetworkView(); |
| 198 | + List<CyNode> selectedNodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true); |
| 199 | + |
| 200 | + //if the network has been autoannotated we need to make sure the clusters have been selected |
| 201 | + //also only handle the node selection events (not edges) |
| 202 | + //TODO:need a cleaner way to find out if the currentView has an annotation |
| 203 | + if(AutoAnnotationManager.getInstance().getAnnotationPanel()!=null && !AutoAnnotationManager.getInstance().isClusterTableUpdating() |
| 204 | + && e.getSource() == network.getDefaultNodeTable()) { |
| 205 | + |
| 206 | + //go through all the clusters for this network to see if any of the cluster have all of their nodes selected |
| 207 | + HashMap<CyNetworkView, AutoAnnotationParameters> annotations = AutoAnnotationManager.getInstance().getNetworkViewToAutoAnnotationParameters(); |
| 208 | + if(annotations.containsKey(view)){ |
| 209 | + AnnotationSet currentAnnotation = annotations.get(view).getSelectedAnnotationSet(); |
| 210 | + TableModel clusterTableModel = currentAnnotation.getClusterTable().getModel(); |
| 211 | + ListSelectionModel clusterListSelectionModel = currentAnnotation.getClusterTable().getSelectionModel(); |
| 212 | + System.out.println("HERE"); |
| 213 | + //if there are clusters to add or to remove only do it once we have gone through all the clusters - to avoid race conditions. |
| 214 | + clusterListSelectionModel.setValueIsAdjusting(true); |
| 215 | + |
| 216 | + TreeMap<Integer, Cluster> clusters = currentAnnotation.getClusterMap(); |
| 217 | + //go through each cluster - figure out which ones need to be selected and |
| 218 | + //which ones need to deselected |
| 219 | + //If any nodes in a cluster are no longer selected then deselect cluster |
| 220 | + //If all nodes in a cluster are selected then select cluster (in table and annotation) |
| 221 | + for(Cluster cluster:clusters.values()){ |
| 222 | + |
| 223 | + boolean select = true; |
| 224 | + boolean unselectCluster = false; |
| 225 | + for (CyNode node : cluster.getNodes()) { |
| 226 | + //if any of the nodes that belong to this cluster are not in the selected set |
| 227 | + //And the cluster is current marked as selected |
| 228 | + //then unselect the cluster |
| 229 | + if (!selectedNodes.contains(node) && cluster.isSelected()) { |
| 230 | + unselectCluster = true; |
| 231 | + break; |
| 232 | + } |
| 233 | + //if any of the nodes that belong to this cluster are not in the selected set |
| 234 | + //then do not select this cluster. |
| 235 | + if (!selectedNodes.contains(node)) { |
| 236 | + select = false; |
| 237 | + break; |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + //one last check, if the cluster is already selected and all its nodes are |
| 242 | + //already selected then this is not a new selection event |
| 243 | + if(select == true && cluster.isSelected()) |
| 244 | + select = false; |
| 245 | + |
| 246 | + //Cluster has been selected |
| 247 | + //if all nodes in a cluster are selected |
| 248 | + //update the cluster table |
| 249 | + if (select) { |
| 250 | + //set flag to tell listener that it shouldn't reselect the nodes as the user manually selected them. |
| 251 | + currentAnnotation.setManualSelection(true); |
| 252 | + for (int rowIndex = 0; rowIndex < clusterTableModel.getRowCount(); rowIndex++) { |
| 253 | + if (cluster.equals(clusterTableModel.getValueAt(rowIndex, 0))) { |
| 254 | + clusterListSelectionModel.addSelectionInterval(rowIndex, rowIndex); |
| 255 | + //AutoAnnotationManager.getInstance().flushPayloadEvents(); |
| 256 | + break; |
| 257 | + } |
| 258 | + } |
| 259 | + } |
| 260 | + |
| 261 | + //Cluster has been unselected |
| 262 | + //update the cluster table |
| 263 | + if(unselectCluster){ |
| 264 | + //set flag to tell listener that it shouldn't reselect the nodes as the user manually selected them. |
| 265 | + currentAnnotation.setManualSelection(true); |
| 266 | + for (int rowIndex = 0; rowIndex < clusterTableModel.getRowCount(); rowIndex++) { |
| 267 | + if (cluster.equals(clusterTableModel.getValueAt(rowIndex, 0))) { |
| 268 | + clusterListSelectionModel.removeSelectionInterval(rowIndex, rowIndex); |
| 269 | + //AutoAnnotationManager.getInstance().flushPayloadEvents(); |
| 270 | + break; |
| 271 | + }//end of if |
| 272 | + }//end of for |
| 273 | + |
| 274 | + }//end of if unselectedcluster |
| 275 | + |
| 276 | + }//end of For going through all clusters |
| 277 | + |
| 278 | + //if there are clusters to add or to remove only do it once we have gone through all the clusters - to avoid race conditions. |
| 279 | + clusterListSelectionModel.setValueIsAdjusting(false); |
| 280 | + |
| 281 | + } |
| 282 | + } |
| 283 | + } |
| 284 | + } |
| 285 | + |
183 | 286 | public HashMap<CyNetworkView, AutoAnnotationParameters> getNetworkViewToAutoAnnotationParameters() {
|
184 | 287 | return networkViewToAutoAnnotationParameters;
|
185 | 288 | }
|
@@ -277,10 +380,6 @@ public CytoPanel getSouthPanel() {
|
277 | 380 | return application.getCytoPanel(CytoPanelName.SOUTH);
|
278 | 381 | }
|
279 | 382 |
|
280 |
| - public boolean isHeatMapUpdating() { |
281 |
| - return EMActionListener.isHeatMapUpdating(); |
282 |
| - } |
283 |
| - |
284 | 383 | public void flushPayloadEvents() {
|
285 | 384 | eventHelper.flushPayloadEvents();
|
286 | 385 | }
|
|
0 commit comments