package jalview.gui;
+import java.awt.event.ItemEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.concurrent.Executors;
+
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.SwingUtilities;
+import javax.swing.table.AbstractTableModel;
+
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
import jalview.bin.Jalview;
-import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.fts.api.FTSData;
import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
import jalview.ws.DBRefFetcher;
+import jalview.ws.seqfetcher.DbSourceProxy;
import jalview.ws.sifts.SiftsSettings;
-import java.awt.event.ItemEvent;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-import java.util.Vector;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JLabel;
-import javax.swing.JTable;
-import javax.swing.SwingUtilities;
-import javax.swing.table.AbstractTableModel;
-
/**
* Provides the behaviors for the Structure chooser Panel
*
chk_superpose.setSelected(Cache.getDefault(AUTOSUPERIMPOSE, true));
- // ensure a filter option is in force for search
- populateFilterComboBox(true, cachedPDBExists);
- // todo change to futures I guess
-
final Runnable discoverPDBStructures = new Runnable()
{
@Override
public void run()
{
+ // check which FTS engine to use
+ data = StructureChooserQuerySource
+ .getQuerySourceFor(selectedSequences);
+
+ // ensure a filter option is in force for search
+ populateFilterComboBox(true, cachedPDBExists);
+
// looks for any existing structures already loaded
// for the sequences (the cached ones)
// then queries the StructureChooserQuerySource to
long progressId = System.currentTimeMillis();
int y = seqsWithoutSourceDBRef.size();
+
setProgressBar(MessageManager.formatMessage(
"status.fetching_dbrefs_for_sequences_without_valid_refs",
y), progressId);
SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
.toArray(new SequenceI[y]);
- DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
+
+ DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef,
+ progressBar, new DbSourceProxy[]
+ { new jalview.ws.dbsources.Uniprot() },
+ null, false);
+
dbRefFetcher.fetchDBRefs(true);
setProgressBar("Fetch complete.", progressId); // todo i18n
- SwingUtilities.invokeLater(discoverPDBStructures);
+ Executors.defaultThreadFactory().newThread(discoverPDBStructures).start();
}
};
.checkUniprotRefs(seq.getDBRefs());
if (dbRef < 0)
{
- seqsWithoutSourceDBRef.add(seq);
+ if (seq.getAllPDBEntries()==null && seq.getAllPDBEntries().size()==0)
+ {
+ seqsWithoutSourceDBRef.add(seq);
+ }
}
}
}
// retrieve database refs for protein sequences
if (!seqsWithoutSourceDBRef.isEmpty())
{
+ // need cancel and no to result in the discoverPDB action - mocked is 'cancel'
JvOptionPane.newOptionDialog(Desktop.getDesktop())
- .setResponseHandler(0, discoverCanonicalDBrefs)
- .setResponseHandler(1, discoverPDBStructures)
- .showDialog(MessageManager.formatMessage("label.fetch_references_for",seqsWithoutSourceDBRef.size()), MessageManager.getString(
+ .setResponseHandler(JvOptionPane.OK_OPTION, discoverCanonicalDBrefs)
+ .setResponseHandler(JvOptionPane.CANCEL_OPTION, discoverPDBStructures)
+ .setResponseHandler(JvOptionPane.NO_OPTION, discoverPDBStructures)
+ .showDialog(MessageManager.formatMessage("label.fetch_references_for",
+ seqsWithoutSourceDBRef.size()), MessageManager.getString(
"label.fetch_uniprot_references"),
JvOptionPane.YES_NO_OPTION,
JvOptionPane.PLAIN_MESSAGE, null, new Object[]
data.setDocFieldPrefs(newPrefs);
}
+
+ /**
+ *
+ * @return true when all initialisation threads have finished and dialog is visible
+ */
+ public boolean isDialogVisible()
+ {
+ return mainFrame != null && data != null && cmb_filterOption != null
+ && mainFrame.isVisible()
+ && cmb_filterOption.getSelectedItem() != null;
+ }
}
SequenceI[] selectedSeqs = new SequenceI[] { seq };
StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
+ ThreadwaitFor(200, sc);
// if structures are not discovered then don't
// populate filter options
PDBFTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
SequenceI[] selectedSeqs = new SequenceI[] { seq };
StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
+ // not mocked, wait for 2s
+ ThreadwaitFor(2000, sc);
+
sc.fetchStructuresMetaData();
Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
"discoveredStructuresSet");
PDBFTSRestClientTest.setMock();
SequenceI[] selectedSeqs = new SequenceI[] { upSeq };
StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
+ ThreadwaitFor(500, sc);
+
sc.fetchStructuresMetaData();
Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
"discoveredStructuresSet");
assertTrue(ss.size() > 0);
}
+ private void ThreadwaitFor(int i, StructureChooser sc)
+ {
+ long timeout = i+System.currentTimeMillis();
+ while (!sc.isDialogVisible() && timeout > System.currentTimeMillis())
+ {
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException x)
+ {
+
+ }
+ }
+
+ }
+
+
@Test(groups = { "Functional" })
public void sanitizeSeqNameTest()
{