Skip to content

Commit

Permalink
vo: fix registry list update bug
Browse files Browse the repository at this point in the history
Make sure that the searchable registry list update action does not add
the same registry multiple times to the list.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 767307b commit 544d24f
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions vo/src/main/uk/ac/starlink/vo/RegistrySelector.java
Expand Up @@ -4,6 +4,10 @@
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -170,10 +174,31 @@ public Action getRegistryUpdateAction() {
*/
private void updateSelector( String[] acurls ) {
ComboBoxModel model = comboBox_.getModel();
if ( model instanceof MutableComboBoxModel ) {
MutableComboBoxModel mmodel = (MutableComboBoxModel) model;
for ( int i = 0; i < acurls.length; i++ ) {
mmodel.addElement( acurls[ i ] );

/* Work out which entries need to be added (not already present). */
Set<String> values = new HashSet<String>();
for ( int i = 0; i < model.getSize(); i++ ) {
values.add( (String) model.getElementAt( i ) );
}
List<String> addUrls = new ArrayList<String>();
for ( int i = 0; i < acurls.length; i++ ) {
String acurl = acurls[ i ];
if ( values.add( acurl ) ) {
addUrls.add( acurl );
}
}

/* Add them. */
if ( addUrls.size() > 0 ) {
if ( model instanceof MutableComboBoxModel ) {
MutableComboBoxModel mmodel = (MutableComboBoxModel) model;
for ( String url : addUrls ) {
mmodel.addElement( url );
}
}
else {
logger_.warning( "Can't add access URLs to immutable combo box"
+ " (" + addUrls.size() + " new URLs ignored)" );
}
}
}
Expand Down

0 comments on commit 544d24f

Please sign in to comment.