Skip to content

Commit

Permalink
fix currentnetwork selection
Browse files Browse the repository at this point in the history
  • Loading branch information
yihangx committed Mar 28, 2024
1 parent 506889d commit 61f6bab
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<artifactId>enrichment</artifactId>

<name>EnrichmentTable</name>
<version>2.0.6</version>
<version>2.0.7</version>


<!--
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/nrnb/gsoc/enrichment/CyActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ public void start(BundleContext context) throws Exception {

if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);
cytoPanel.setSelectedIndex(
cytoPanel.indexOfComponent("org.cytoscape.NodeTables"));
TaskFactory myFactory = new EnrichmentTaskFactory(registrar,enrichmentPanel); // Implementation
registerService(context, myFactory,
TaskFactory.class, // Interface
properties); // Service properties
cytoPanel.setSelectedIndex(cytoPanel.indexOfComponent("org.cytoscape.NodeTables"));
TaskFactory myFactory = new EnrichmentTaskFactory(registrar,enrichmentPanel); // Implementation
registerService(context, myFactory,
TaskFactory.class, // Interface
properties); // Service properties

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.cytoscape.session.events.SessionLoadedListener;
import org.cytoscape.util.swing.TextIcon;
import org.cytoscape.work.TaskFactory;
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.TaskManager;
import org.nrnb.gsoc.enrichment.tasks.EnrichmentTask;
import org.nrnb.gsoc.enrichment.tasks.EnrichmentTaskFactory;
import org.nrnb.gsoc.enrichment.ui.EnrichmentCytoPanel;
import org.nrnb.gsoc.enrichment.utils.IconUtil;
Expand All @@ -42,34 +45,39 @@ public ShowAppTableAction(CyServiceRegistrar serviceRegistrar) {
var iconFont = IconUtil.getIconFont(30.0f);
var icon = new TextIcon(APP_ICON_LAYERS, iconFont, APP_ICON_COLORS, 32, 32, 1);

putValue(SHORT_DESCRIPTION, "Show Enrichment Table"); // Tooltip's short description
putValue(SHORT_DESCRIPTION, "Perform Gene Enrichment");
putValue(LARGE_ICON_KEY, icon);
}

@Override
public void actionPerformed(ActionEvent e) {
CySwingApplication swingApplication = serviceRegistrar.getService(CySwingApplication.class);
CytoPanel cytoPanel = swingApplication.getCytoPanel(CytoPanelName.SOUTH);
if (enrichmentPanel == null){
enrichmentPanel = new EnrichmentCytoPanel(serviceRegistrar,false,null);
serviceRegistrar.registerService(enrichmentPanel, CytoPanelComponent.class,new Properties());
serviceRegistrar.registerService(enrichmentPanel, SelectedNodesAndEdgesListener.class, new Properties());
serviceRegistrar.registerService(enrichmentPanel, NetworkAboutToBeDestroyedListener.class, new Properties());
serviceRegistrar.registerService(enrichmentPanel, SessionLoadedListener.class, new Properties());
serviceRegistrar.registerService(enrichmentPanel, SetCurrentNetworkListener.class, new Properties());
//registrar.registerService(enrichmentPanel, SetCurrentNetworkListener.class, new Properties());
//registrar.registerService(enrichmentPanel, NetworkAddedListener.class, new Properties());
if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);
cytoPanel.setSelectedIndex(
cytoPanel.indexOfComponent("org.nrnb.gsoc.enrichment"));

TaskManager<?, ?> tm = serviceRegistrar.getService(TaskManager.class);
if (enrichmentPanel == null) {
enrichmentPanel = new EnrichmentCytoPanel(serviceRegistrar, false, null);
serviceRegistrar.registerService(enrichmentPanel, CytoPanelComponent.class, new Properties());
serviceRegistrar.registerService(enrichmentPanel, SelectedNodesAndEdgesListener.class, new Properties());
serviceRegistrar.registerService(enrichmentPanel, NetworkAboutToBeDestroyedListener.class, new Properties());
serviceRegistrar.registerService(enrichmentPanel, SessionLoadedListener.class, new Properties());
serviceRegistrar.registerService(enrichmentPanel, SetCurrentNetworkListener.class, new Properties());
if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);
cytoPanel.setSelectedIndex(cytoPanel.indexOfComponent("org.nrnb.gsoc.enrichment"));
} else {
if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);
cytoPanel.setSelectedIndex(cytoPanel.indexOfComponent("org.nrnb.gsoc.enrichment"));
}

try {
tm.execute(new TaskIterator(new EnrichmentTask(serviceRegistrar, enrichmentPanel)));
} catch (Exception ex) {
System.err.println("Error executing EnrichmentTask: " + ex.getMessage());
}

if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);
cytoPanel.setSelectedIndex(
cytoPanel.indexOfComponent("org.nrnb.gsoc.enrichment"));

}
cytoPanel.setSelectedIndex(cytoPanel.indexOfComponent("org.nrnb.gsoc.enrichment"));
}
}
43 changes: 36 additions & 7 deletions src/main/java/org/nrnb/gsoc/enrichment/ui/EnrichmentCytoPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class EnrichmentCytoPanel extends JPanel
CyTable filteredEnrichmentTable = null;
boolean clearSelection = false;
JPopupMenu popupMenu;
private boolean registered = false;

private String[] columnToolTips = {
"the full name of the datasource for the term",
Expand Down Expand Up @@ -148,6 +149,7 @@ public EnrichmentCytoPanel(CyServiceRegistrar registrar, boolean noSignificant,
enrichmentTables = new HashMap<String, JTable>();
this.noSignificant = noSignificant;
initPanel(this.noSignificant);
registered = true;
}

public void setEnrichmentTable(CyTable enrichmentTable){
Expand Down Expand Up @@ -874,13 +876,19 @@ private void clearNetworkSelection(CyNetwork network) {
clearSelection = false;
}

public void handleEvent(SetCurrentNetworkEvent event) {
CyNetwork network = event.getNetwork();
if (network != null) {
initPanel(network, false);
return;
}
}
public void handleEvent(SetCurrentNetworkEvent event) {
CyNetwork network = event.getNetwork();
if (ModelUtils.ifHaveEnrichmentNS(network)) {
if (!registered) {
showCytoPanel();
} else {
initPanel(network, false);
}
} else {
hideCytoPanel();
}

}

@Override
public void handleEvent(SelectedNodesAndEdgesEvent event) {
Expand Down Expand Up @@ -942,6 +950,7 @@ public void handleEvent(NetworkAboutToBeDestroyedEvent e) {
cytoPanel.indexOfComponent("org.cytoscape.NodeTables"));
}


public void handleEvent(SessionLoadedEvent arg0) {
CySwingApplication swingApplication = registrar.getService(CySwingApplication.class);
CytoPanel cytoPanel = swingApplication.getCytoPanel(CytoPanelName.SOUTH);
Expand Down Expand Up @@ -983,6 +992,26 @@ public void drawCharts() {
public boolean getIsChartEnabled() {
return isChartEnabled;
}
public void showCytoPanel() {
CySwingApplication swingApplication = registrar.getService(CySwingApplication.class);
CytoPanel cytoPanel = swingApplication.getCytoPanel(CytoPanelName.SOUTH);
if (!registered && cytoPanel.indexOfComponent("org.nrnb.gsoc.enrichment") < 0) {
// System.out.println("panel: register enrichment panel");
registrar.registerService(this, CytoPanelComponent.class, new Properties());
registered = true;
}
if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);

initPanel(false);
cytoPanel
.setSelectedIndex(cytoPanel.indexOfComponent("edu.ucsf.rbvi.stringApp.Enrichment"));
}

public void hideCytoPanel() {
registrar.unregisterService(this, CytoPanelComponent.class);
registered = false;
}

private boolean isEnrichmentMapInstalled() {
return availableCommands.getNamespaces().contains("enrichmentmap");
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/nrnb/gsoc/enrichment/utils/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.nrnb.gsoc.enrichment.model.EnrichmentTerm.TermSource;

import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

import java.io.IOException;
Expand Down Expand Up @@ -831,4 +830,13 @@ public static class ConfigPropsReader extends AbstractConfigDirPropsReader {
}
}

// This method will tell us if we have the new side panel functionality (i.e. namespaces)
public static boolean ifHaveEnrichmentNS(CyNetwork network) {
if (network == null) return false;
Collection<CyColumn> columns = network.getDefaultNetworkTable().getColumns(ENRICHMENT_NAMESPACE);
if (columns != null && columns.size() > 0)
return true;
return false;
}

}

0 comments on commit 61f6bab

Please sign in to comment.