Skip to content

Commit

Permalink
Restore hosted genome selection behavior -- json is downloaded to "ge…
Browse files Browse the repository at this point in the history
…nomes" folder.
  • Loading branch information
jrobinso committed Sep 26, 2024
1 parent a0df97e commit 51e5288
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/ui/IGVMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private JMenu createGenomesMenu() {

JMenu menu = new JMenu("Genomes");

loadGenomeFromServerMenuItem = new JMenuItem("Select Hosted Genome...");
loadGenomeFromServerMenuItem = new JMenuItem("Download Hosted Genome...");
loadGenomeFromServerMenuItem.addActionListener(e -> GenomeComboBox.loadGenomeFromServer());
loadGenomeFromServerMenuItem.setToolTipText(LOAD_GENOME_SERVER_TOOLTIP);
menu.add(loadGenomeFromServerMenuItem);
Expand Down
37 changes: 10 additions & 27 deletions src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import org.broad.igv.event.IGVEventBus;
import org.broad.igv.feature.genome.GenomeListItem;
import org.broad.igv.feature.genome.GenomeManager;
import org.broad.igv.feature.genome.GenomeServerException;
import org.broad.igv.ui.IGV;
import org.broad.igv.ui.UIConstants;
import org.broad.igv.ui.util.MessageUtils;
import org.broad.igv.ui.util.ProgressBar;
import org.broad.igv.ui.util.UIUtilities;
import org.broad.igv.util.LongRunningTask;

Expand Down Expand Up @@ -97,27 +95,16 @@ private void loadGenomeListItem(final GenomeListItem genomeListItem) {
return;
}

final Runnable runnable = new Runnable() {
final Runnable runnable = () -> {

public void run() {
if (genomeListItem != null && genomeListItem.getPath() != null) {

if (genomeListItem != null && genomeListItem.getPath() != null) {

//log.warn("Loading " + genomeListItem.getId());

//User selected "more", pull up dialog and revert combo box
if (genomeListItem == GenomeListItem.DOWNLOAD_ITEM) {
loadGenomeFromServer();
return;
}
if (genomeListItem == GenomeListItem.DOWNLOAD_ITEM) {
loadGenomeFromServer();
} else {

try {
GenomeManager.getInstance().loadGenomeById(genomeListItem.getId());
} catch (GenomeServerException e) {
log.error("Error loading genome: " + genomeListItem.getId() + " " + genomeListItem.getPath(), e);
JOptionPane.showMessageDialog(
IGV.getInstance().getMainFrame(),
"Error loading genome: " + genomeListItem.getDisplayableName());
GenomeManager.getInstance().loadGenomeById(genomeListItem.getId());
} catch (Exception e) {
log.error(e);
int choice = JOptionPane.showConfirmDialog(
Expand All @@ -130,10 +117,7 @@ public void run() {
refreshGenomeListComboBox();
log.error("Error initializing genome", e);
}
} finally {

}

}
}
};
Expand Down Expand Up @@ -223,21 +207,20 @@ public static void loadGenomeFromServer() {

Collection<GenomeListItem> inputListItems = GenomeListManager.getInstance().getServerGenomeList();
if (inputListItems == null) {
//Could not reach genome server. Not necessary to display a message, getServerGenomeArchiveList does it already
return;
}
GenomeSelectionDialog dialog = new GenomeSelectionDialog(IGV.getInstance().getMainFrame(), inputListItems);
UIUtilities.invokeAndWaitOnEventThread(() -> dialog.setVisible(true));

if (dialog.isCanceled()) {
// Clear the "More..." selection in pulldown
IGVEventBus.getInstance().post(new GenomeResetEvent());
} else {
List<GenomeListItem> selectedValueList = dialog.getSelectedValues();
GenomeListItem firstItem = null;
for (GenomeListItem selectedValue : selectedValueList) {
if (selectedValue != null) {
boolean success = GenomeManager.getInstance().downloadGenome(selectedValue, dialog.downloadSequence());
boolean downloadSequence = false;
boolean success = GenomeManager.getInstance().downloadGenome(selectedValue, downloadSequence);
if (success) {
GenomeListManager.getInstance().addServerGenomeItem(selectedValue);
firstItem = selectedValue;
Expand All @@ -252,7 +235,7 @@ public static void loadGenomeFromServer() {
GenomeListManager.getInstance().removeUserDefinedGenome(firstItem.getId());

// If this is a .json genome, attempt to remove existing .genome files
if(firstItem.getPath().endsWith(".json")) {
if (firstItem.getPath().endsWith(".json")) {
removeDotGenomeFile(firstItem.getId());
}

Expand All @@ -276,7 +259,7 @@ public static void loadGenomeFromServer() {
public static void removeDotGenomeFile(String id) {
try {
File dotGenomeFile = new File(DirectoryManager.getGenomeCacheDirectory(), id + ".genome");
if(dotGenomeFile.exists()) {
if (dotGenomeFile.exists()) {
dotGenomeFile.delete();
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* Dialog box for selecting genomes. User can choose from a list,
* which is filtered according to text box input
*/
public class GenomeSelectionDialog extends org.broad.igv.ui.IGVDialog {
public class GenomeSelectionDialog extends org.broad.igv.ui.IGVDialog {

private JPanel dialogPane;
private JPanel contentPanel;
Expand All @@ -57,7 +57,6 @@ public class GenomeSelectionDialog extends org.broad.igv.ui.IGVDialog {
private JTextField genomeFilter;
private JScrollPane scrollPane1;
private JList<GenomeListItem> genomeList;
private JCheckBox downloadSequenceCB;
private JPanel buttonBar;
private JButton okButton;
private JButton cancelButton;
Expand All @@ -74,7 +73,6 @@ public GenomeSelectionDialog(java.awt.Frame parent, Collection<GenomeListItem> i
super(parent);
initComponents();
initData(inputListItems);
downloadSequenceCB.setVisible(true);
}

private void initData(Collection<GenomeListItem> inputListItems) {
Expand All @@ -84,18 +82,12 @@ private void initData(Collection<GenomeListItem> inputListItems) {
}

/**
* Filter the list of displayed genomes so we only show this
* with the text the user entered.
* Filter the list of displayed genomes with the text the user entered.
*/
private void rebuildGenomeList(String filterText) {
if (genomeListModel == null) {
genomeListModel = new DefaultListModel();
UIUtilities.invokeOnEventThread(new Runnable() {
@Override
public void run() {
genomeList.setModel(genomeListModel);
}
});
UIUtilities.invokeOnEventThread(() -> genomeList.setModel(genomeListModel));
}
genomeListModel.clear();
filterText = filterText.toLowerCase().trim();
Expand All @@ -117,11 +109,9 @@ private void genomeListMouseClicked(MouseEvent e) {
switch (e.getClickCount()) {
case 1:
List<GenomeListItem> selValues = genomeList.getSelectedValuesList();
downloadSequenceCB.setEnabled(selValues != null && selValues.size() == 1);
break;
case 2:
okButtonActionPerformed(null);
break;
okButtonActionPerformed(null);
}
}

Expand All @@ -133,10 +123,6 @@ public List<GenomeListItem> getSelectedValues() {
return selectedValues;
}

public boolean downloadSequence(){
return !isCanceled() && downloadSequenceCB.isEnabled() && downloadSequenceCB.isSelected();
}

public boolean isCanceled() {
return isCanceled;
}
Expand Down Expand Up @@ -165,7 +151,6 @@ private void initComponents() {
genomeFilter = new JTextField();
scrollPane1 = new JScrollPane();
genomeList = new JList();
downloadSequenceCB = new JCheckBox();
buttonBar = new JPanel();
okButton = new JButton();
cancelButton = new JButton();
Expand Down Expand Up @@ -201,10 +186,10 @@ private void initComponents() {
{
filterPanel.setMaximumSize(new Dimension(2147483647, 28));
filterPanel.setLayout(new GridBagLayout());
((GridBagLayout)filterPanel.getLayout()).columnWidths = new int[] {0, 0, 0};
((GridBagLayout)filterPanel.getLayout()).rowHeights = new int[] {0, 0};
((GridBagLayout)filterPanel.getLayout()).columnWeights = new double[] {1.0, 1.0, 1.0E-4};
((GridBagLayout)filterPanel.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};
((GridBagLayout) filterPanel.getLayout()).columnWidths = new int[]{0, 0, 0};
((GridBagLayout) filterPanel.getLayout()).rowHeights = new int[]{0, 0};
((GridBagLayout) filterPanel.getLayout()).columnWeights = new double[]{1.0, 1.0, 1.0E-4};
((GridBagLayout) filterPanel.getLayout()).rowWeights = new double[]{1.0, 1.0E-4};

//---- label1 ----
label1.setText("Filter:");
Expand Down Expand Up @@ -246,44 +231,26 @@ public void igvMouseClicked(MouseEvent e) {
}
contentPanel.add(scrollPane1);

//---- downloadSequenceCB ----
downloadSequenceCB.setText("Download Sequence");
downloadSequenceCB.setAlignmentX(1.0F);
downloadSequenceCB.setToolTipText("Download the full sequence for this organism. Note that these files can be very large (human is about 3 gigabytes)");
downloadSequenceCB.setMaximumSize(new Dimension(1000, 23));
downloadSequenceCB.setPreferredSize(new Dimension(300, 23));
downloadSequenceCB.setMinimumSize(new Dimension(300, 23));
contentPanel.add(downloadSequenceCB);
}
dialogPane.add(contentPanel, BorderLayout.CENTER);

//======== buttonBar ========
{
buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
buttonBar.setLayout(new GridBagLayout());
((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};
((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[]{0, 85, 80};
((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[]{1.0, 0.0, 0.0};

//---- okButton ----
okButton.setText("OK");
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
okButtonActionPerformed(e);
}
});
okButton.addActionListener(e -> okButtonActionPerformed(e));
buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));

//---- cancelButton ----
cancelButton.setText("Cancel");
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelButtonActionPerformed(e);
}
});
cancelButton.addActionListener(e -> cancelButtonActionPerformed(e));
buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));
Expand Down

0 comments on commit 51e5288

Please sign in to comment.