From 489b545a2ff79aada6e3eb9cbd6173ebf5dfd505 Mon Sep 17 00:00:00 2001 From: Mark Taylor Date: Thu, 3 Jul 2014 11:07:45 +0100 Subject: [PATCH] topcat: fix CDS X-Match MOC downloads to use table ID not alias Thomas Boch (CDS) requests that MOC downloads should use VizieR table ID not the X-Match alias (though either seems to work at time of writing). This means we have to wait for the metadata to be downloaded. Rearrange the scheduling of the relevant downloads accordingly. --- .../topcat/join/CdsTableSelector.java | 82 +++++++++++++------ 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/topcat/src/main/uk/ac/starlink/topcat/join/CdsTableSelector.java b/topcat/src/main/uk/ac/starlink/topcat/join/CdsTableSelector.java index 66f8d29e49..7041911541 100644 --- a/topcat/src/main/uk/ac/starlink/topcat/join/CdsTableSelector.java +++ b/topcat/src/main/uk/ac/starlink/topcat/join/CdsTableSelector.java @@ -177,13 +177,20 @@ public void setEnabled( boolean isEnabled ) { private void updateTableName() { String tableName = (String) nameSelector_.getSelectedItem(); tableName_ = tableName; - metaDownloader_.setTableName( tableName ); - mocDownloader_.setTableName( tableName ); - /* If the new table is non-null, update state with information - * that has to be downloaded from remote services. - * For each item, do the update synchronously if the data is - * known to be available immediately, otherwise asynchronously. */ + /* Reset the downloaded coverage information. Action will be taken + * by the setMetadata method to populate this with non-empty + * coverage information when metadata is available. */ + mocDownloader_.setTableName( null ); + if ( mocFuture_ != null ) { + mocFuture_.cancel( true ); + } + + /* If the new table is non-null, update the displayed metadata + * as downloaded from the remote metadata service. + * Do the update synchronously if the data is known to be available + * immediately, otherwise asynchronously. */ + metaDownloader_.setTableName( tableName ); if ( tableName != null ) { /* Update table metadata. */ @@ -205,26 +212,6 @@ public void run() { } } ); } - - /* Update table coverage. */ - if ( mocDownloader_.isComplete() ) { - setMoc( mocDownloader_.getData() ); - } - else { - if ( mocFuture_ != null ) { - mocFuture_.cancel( true ); - } - mocFuture_ = mocExecutor_.submit( new Runnable() { - public final void run() { - final MocCoverage moc = mocDownloader_.waitForData(); - SwingUtilities.invokeLater( new Runnable() { - public void run() { - setMoc( moc ); - } - } ); - } - } ); - } } } @@ -243,6 +230,8 @@ private void setMetadata( VizierMeta meta ) { alias = meta.getPrettyName(); description = meta.getDescription(); nrow = meta.getRowCount(); + + /* Display the alias only if it differs from the name. */ if ( alias != null && alias.equals( name ) ) { alias = null; } @@ -254,6 +243,37 @@ private void setMetadata( VizierMeta meta ) { nrow == null ? null : TopcatUtils.formatLong( nrow.longValue() ) ); + + /* Having got the metadata (successfully or otherwise) + * we can now get the MOC, asynchronously if required. + * It would be more straightforward and reliable to get the MOC + * concurrently as soon as the alias-or-id entered by the user + * is known, but Thomas Boch (CDS) advises/requests that by + * preference the table name rather than alias should be used + * for MOC retrieval (though by alias usually seems to work), + * and we may not have the name until we have the metadata. + * But if the name is not available for some reason, fall back + * to what we have, which is whatever the user entered. */ + String mocName = name == null ? getTableName() : name; + mocDownloader_.setTableName( mocName ); + if ( mocDownloader_.isComplete() ) { + setMoc( mocDownloader_.getData() ); + } + else { + if ( mocFuture_ != null ) { + mocFuture_.cancel( true ); + } + mocFuture_ = mocExecutor_.submit( new Runnable() { + public final void run() { + final MocCoverage moc = mocDownloader_.waitForData(); + SwingUtilities.invokeLater( new Runnable() { + public void run() { + setMoc( moc ); + } + } ); + } + } ); + } } /** @@ -392,6 +412,16 @@ public void setTableName( String tableName ) { tableName_ = tableName; } + /** + * Returns the table name or ID for which this dowloader is currently + * configured. + * + * @return table name or ID + */ + public String getTableName() { + return tableName_; + } + @Override public MocCoverage getData() { Coverage.Amount amount = moc_ == null ? null : moc_.getAmount();