import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import jalview.api.FeatureSettingsModelI;
import jalview.bin.Cache;
+import jalview.bin.Console;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.SequenceI;
* @param guiIndic
* @param selectedDb
* @param queryString
+ * @param interactive
*/
public SequenceFetcher(IProgressIndicator guiIndic,
final String selectedDb, final String queryString)
{
+ this(guiIndic, selectedDb, queryString, true);
+ }
+
+ public SequenceFetcher(IProgressIndicator guiIndic,
+ final String selectedDb, final String queryString,
+ boolean interactive)
+ {
this.progressIndicator = guiIndic;
getSequenceFetcherSingleton();
this.guiWindow = progressIndicator;
alignFrame = (AlignFrame) progressIndicator;
}
- jbInit(selectedDb);
+ jbInit(selectedDb, interactive);
textArea.setText(queryString);
frame = new JInternalFrame();
.getString("label.additional_sequence_fetcher"));
}
- private void jbInit(String selectedDb)
+ private void jbInit(String selectedDb, boolean interactive)
{
this.setLayout(new BorderLayout());
jScrollPane1.getViewport().add(textArea);
idsPanel.add(jScrollPane1, BorderLayout.CENTER);
+ // En/disable or show/hide interactive elements
+ database.setEnabled(interactive);
+ exampleAccession.setVisible(interactive);
+ replacePunctuation.setVisible(interactive);
+ okBtn.setVisible(interactive);
+ exampleBtn.setVisible(interactive);
+ closeBtn.setVisible(interactive);
+ backBtn.setVisible(interactive);
+ jLabel1.setVisible(interactive);
+ clear.setVisible(interactive);
+ textArea.setEnabled(interactive);
+
this.add(actionPanel, BorderLayout.SOUTH);
this.add(idsPanel, BorderLayout.CENTER);
this.add(databasePanel, BorderLayout.NORTH);
*
* @param e
*/
- protected void close_actionPerformed(ActionEvent e)
+ public void close_actionPerformed(ActionEvent e)
{
try
{
*/
public void ok_actionPerformed()
{
+ ok_actionPerformed(false, null);
+ }
+
+ public CompletableFuture<Void> ok_actionPerformed(boolean returnFuture,
+ String id)
+ {
/*
* tidy inputs and check there is something to search for
*/
showErrorMessage(
"Please enter a (semi-colon separated list of) database id(s)");
resetDialog();
- return;
+ return null;
}
if (database.getSelectedIndex() == 0)
{
// todo i18n
showErrorMessage("Please choose a database");
resetDialog();
- return;
+ return null;
}
exampleBtn.setEnabled(false);
closeBtn.setEnabled(false);
backBtn.setEnabled(false);
- Thread worker = new Thread(this);
- worker.start();
+ CompletableFuture<Void> worker = CompletableFuture
+ .runAsync(() -> runAndCacheAlignFrame(returnFuture, id));
+
+ return returnFuture ? worker : null;
+ }
+
+ private void runAndCacheAlignFrame(boolean cacheAlignFrame, String id)
+ {
+ AlignFrame af = this.run(cacheAlignFrame);
+ if (cacheAlignFrame && id != null && af != null)
+ af.cacheAlignFrameFromRestId(id);
}
private void resetDialog()
@Override
public void run()
{
+ run(false);
+ }
+
+ public AlignFrame run(boolean returnAlignFrame)
+ {
boolean addToLast = false;
List<String> aresultq = new ArrayList<>();
List<String> presultTitle = new ArrayList<>();
: MessageManager.getString("status.processing"),
Thread.currentThread().hashCode());
// process results
+ AlignFrame af = null;
while (presult.size() > 0)
{
- parseResult(presult.remove(0), presultTitle.remove(0), null,
+ af = parseResult(presult.remove(0), presultTitle.remove(0), null,
preferredFeatureColours);
}
// only remove visual delay after we finished parsing.
showErrorMessage(sb.toString());
}
resetDialog();
+ return returnAlignFrame ? af : null;
}
/**
}
} catch (Exception e)
{
- Cache.info("Error retrieving " + accession + " from "
+ Console.info("Error retrieving " + accession + " from "
+ proxy.getDbName(), e);
}
return success;
* @param preferredFeatureColours
* @return the alignment
*/
- public AlignmentI parseResult(AlignmentI al, String title,
+ public AlignFrame parseResult(AlignmentI al, String title,
FileFormatI currentFileFormat,
FeatureSettingsModelI preferredFeatureColours)
{
+ AlignFrame af = alignFrame;
if (al != null && al.getHeight() > 0)
{
if (title == null)
{
title = getDefaultRetrievalTitle();
}
- if (alignFrame == null)
+ if (af == null)
{
- AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+ af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
AlignFrame.DEFAULT_HEIGHT);
if (currentFileFormat != null)
{
}
else
{
- alignFrame.viewport.addAlignment(al, title);
+ af.viewport.addAlignment(al, title);
}
}
- return al;
+ return af;
}
void showErrorMessage(final String error)