import jalview.analysis.AlignSeq;
import jalview.api.StructureSelectionManagerProvider;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.commands.CommandI;
import jalview.commands.EditCommand;
import jalview.commands.OrderCommand;
import mc_view.PDBChain;
import mc_view.PDBfile;
-public class StructureSelectionManager
+public class StructureSelectionManager implements ApplicationSingletonI
{
-
- public StructureSelectionManager()
- {
- }
-
public final static String NEWLINE = System.lineSeparator();
- // BH unnecessary; IdentityHashMap can handle this
- // private static StructureSelectionManager nullProvider;
-
private List<StructureMapping> mappings = new ArrayList<>();
private boolean processSecondaryStructure = false;
private List<SelectionListener> sel_listeners = new ArrayList<>();
+ /*
+ * instances of this class scoped by some context class
+ */
+ private IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> structureSelections;
+
+ /**
+ * Answers an instance of this class for the current application (Java or JS
+ * 'applet') scope
+ *
+ * @return
+ */
+ private static StructureSelectionManager getInstance()
+ {
+ return (StructureSelectionManager) ApplicationSingletonProvider
+ .getInstance(StructureSelectionManager.class);
+ }
+
+ /**
+ * Answers an instance of this class for the current application (Java or JS
+ * 'applet') scope, and scoped to the specified context
+ *
+ * @param context
+ * @return
+ */
+ public static StructureSelectionManager getStructureSelectionManager(
+ StructureSelectionManagerProvider context)
+ {
+ return getInstance().getInstanceForContext(context);
+ }
+
+ /**
+ * Answers an instance of this class scoped to the given context. The instance
+ * is created on the first request for the context, thereafter the same
+ * instance is returned.
+ *
+ * @param context
+ * @return
+ */
+ StructureSelectionManager getInstanceForContext(
+ StructureSelectionManagerProvider context)
+ {
+ StructureSelectionManager instance = structureSelections.get(context);
+ if (instance == null)
+ {
+ instance = new StructureSelectionManager();
+ structureSelections.put(context, instance);
+ }
+ return instance;
+ }
+
+ /**
+ * Removes the instance associated with this provider
+ *
+ * @param provider
+ */
+
+ public static void release(StructureSelectionManagerProvider provider)
+ {
+ getInstance().structureSelections.remove(provider);
+ }
+
+ /**
+ * Private constructor as all 'singleton' instances are managed here or by
+ * ApplicationSingletonProvider
+ */
+ private StructureSelectionManager()
+ {
+ structureSelections = new IdentityHashMap<>();
+ }
+
/**
* @return true if will try to use external services for processing secondary
* structure
* Import structure data and register a structure mapping for broadcasting
* colouring, mouseovers and selection events (convenience wrapper).
*
+ * This is the standard entry point.
+ *
* @param sequence
* - one or more sequences to be mapped to pdbFile
* @param targetChains
* broadcasting colouring, mouseovers and selection events (convenience
* wrapper).
*
+ *
+ *
* @param forStructureView
- * when true, record the mapping for use in mouseOvers
+ * when true (testng only), record the mapping for use in mouseOvers
+ * (testng only)
* @param sequence
* - one or more sequences to be mapped to pdbFile
* @param targetChains
* mapping operation
* @return null or the structure data parsed as a pdb file
*/
- synchronized public StructureFile computeMapping(
+ synchronized private StructureFile computeMapping(
boolean forStructureView, SequenceI[] sequenceArray,
String[] targetChainIds, String pdbFile, DataSourceType sourceType,
IProgressIndicator progress)
{
ds = ds.getDatasetSequence();
}
- ;
if (ds.getAnnotation() != null)
{
for (AlignmentAnnotation ala : ds.getAnnotation())
}
/**
- * Resets this object to its initial state by removing all registered
- * listeners, codon mappings, PDB file mappings
+ * Reset this object to its initial state by removing all registered
+ * listeners, codon mappings, PDB file mappings.
+ *
+ * Called only by Desktop and testng.
+ *
*/
public void resetAll()
{
- if (mappings != null)
- {
- mappings.clear();
- }
- if (seqmappings != null)
- {
- seqmappings.clear();
- }
- if (sel_listeners != null)
- {
- sel_listeners.clear();
- }
- if (listeners != null)
- {
- listeners.clear();
- }
- if (commandListeners != null)
- {
- commandListeners.clear();
- }
- if (view_listeners != null)
- {
- view_listeners.clear();
- }
- if (pdbFileNameId != null)
- {
- pdbFileNameId.clear();
- }
- if (pdbIdFileName != null)
- {
- pdbIdFileName.clear();
- }
+ mappings.clear();
+ seqmappings.clear();
+ sel_listeners.clear();
+ listeners.clear();
+ commandListeners.clear();
+ view_listeners.clear();
+ pdbFileNameId.clear();
+ pdbIdFileName.clear();
}
public void addSelectionListener(SelectionListener selecter)
{
slis.viewPosition(startRes, endRes, startSeq, endSeq, source);
}
- ;
}
}
}
return seqmappings;
}
- public static StructureSelectionManager getStructureSelectionManager(
- StructureSelectionManagerProvider context)
- {
- IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
- .getInstance().structureSelections;
-
- if (map == null)
- {
- map = Instance
- .getInstance().structureSelections = new IdentityHashMap<>();
- }
- StructureSelectionManager instance = map.get(context);
- if (instance == null)
- {
- // BH: actually, not possible except for coding error; this is an attempt
- // to discover that.
- if (context == null && !map.isEmpty())
- {
- throw new Error(MessageManager.getString(
- "error.implementation_error_structure_selection_manager_null"),
- new NullPointerException(MessageManager
- .getString("exception.ssm_context_is_null")));
- }
- map.put(context,
- instance = new StructureSelectionManager());
- }
- return instance;
- }
-
- /**
- * release all references associated with this manager provider
- *
- * @param provider
- */
-
- public static void release(StructureSelectionManagerProvider provider)
- {
- IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
- .getInstance().structureSelections;
- if (map != null)
- {
- map.remove(provider);
- }
- }
-
}