JAL-2358 ensure mappings removed on close Chimera; pull up method;
[jalview.git] / src / jalview / gui / StructureViewerBase.java
index 91d7130..19291ac 100644 (file)
@@ -26,6 +26,7 @@ import jalview.gui.StructureViewer.ViewerType;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.DataSourceType;
 import jalview.jbgui.GStructureViewer;
+import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 
@@ -39,8 +40,8 @@ import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JInternalFrame;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 
 /**
  * Base class with common functionality for JMol, Chimera or other structure
@@ -352,8 +353,29 @@ public abstract class StructureViewerBase extends GStructureViewer
 
   protected abstract boolean hasPdbId(String pdbId);
 
-  protected abstract List<StructureViewerBase> getViewersFor(
-          AlignmentPanel alp);
+  /**
+   * Returns a list of any structure viewers of the same type. The list is
+   * restricted to those linked to the given alignment panel if it is not null.
+   */
+  protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp){
+
+    List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
+    JInternalFrame[] frames = Desktop.instance.getAllFrames();
+
+    for (JInternalFrame frame : frames)
+    {
+      if (this.getClass().isAssignableFrom(frame.getClass()))
+      {
+        if (alp == null
+                || ((StructureViewerBase) frame).isLinkedWith(alp))
+        {
+          result.add((StructureViewerBase) frame);
+        }
+      }
+    }
+    return result;
+  
+  }
 
   /**
    * Check for any existing views involving this alignment and give user the
@@ -473,8 +495,8 @@ public abstract class StructureViewerBase extends GStructureViewer
           final AlignmentPanel apanel, String pdbId)
   {
     boolean finished = false;
-    String alreadyMapped = apanel.getStructureSelectionManager()
-            .alreadyMappedToFile(pdbId);
+    StructureSelectionManager ssm = apanel.getStructureSelectionManager();
+    String alreadyMapped = ssm.alreadyMappedToFile(pdbId);
 
     if (alreadyMapped != null)
     {