Skip to content

Commit

Permalink
Changes in query string and Metadata Parameter selection
Browse files Browse the repository at this point in the history
- ucd value is shown in the metadata parameter table
- only the servers containing at least one selected parameter will be queried
- query String is now editable
  • Loading branch information
mmpcn committed Aug 14, 2014
1 parent 941122f commit 3025239
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 131 deletions.
145 changes: 103 additions & 42 deletions splat/src/main/uk/ac/starlink/splat/vo/SSAMetadataPanel.java
Expand Up @@ -25,6 +25,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
Expand Down Expand Up @@ -101,26 +102,26 @@ public class SSAMetadataPanel extends JPanel implements ActionListener, TableMod
private HashMap<String, MetadataInputParameter> metaParam=null;

// the metadata table
private static final int NRCOLS = 5; // the number of columns in the table
private static final int NRCOLS = 6; // the number of columns in the table
// the table indexes

private static final int SELECTED_INDEX = 0;
private static final int NR_SERVERS_INDEX = 1;
private static final int NAME_INDEX = 2;
private static final int VALUE_INDEX = 3;
private static final int DESCRIPTION_INDEX = 4;
private static final int UCD_INDEX = 5;

// total number of servers that returned parameters
int nrServers;
// private int nrServers;
// the table headers
String[] headers;
String[] headersToolTips;
private String[] headers;
private String[] headersToolTips;


// cell renderer for the parameter name column
ParamCellRenderer paramRenderer=null;
private ParamCellRenderer paramRenderer=null;



/**
* Constructor:
Expand Down Expand Up @@ -169,7 +170,7 @@ public void initMetadataTable()
headers[NAME_INDEX] = "Name";
headers[VALUE_INDEX] = "Value";
headers[DESCRIPTION_INDEX] = "Description";

headers[UCD_INDEX] = "UCD";
// the tooltip Texts for the headers
headersToolTips = new String[NRCOLS];

Expand All @@ -178,7 +179,7 @@ public void initMetadataTable()
headersToolTips[NAME_INDEX] = "Parameter name";
headersToolTips[VALUE_INDEX] = "Parameter value";
headersToolTips[DESCRIPTION_INDEX] = "Description";

headersToolTips[UCD_INDEX] = "UCD";

// Table of metadata parameters goes into a scrollpane in the center of
// window (along with a set of buttons, see initUI).
Expand Down Expand Up @@ -214,9 +215,11 @@ public void initMetadataTable()
*/
public void updateMetadata(HashMap<String, MetadataInputParameter> metaParam )
{

metadataTableModel = new MetadataTableModel(headers);
metadataTable.setModel(metadataTableModel );
adjustColumns();
adjustColumns();
// ???fireProperty();
}


Expand All @@ -243,7 +246,8 @@ public String[][] getParamList()

metadataList[row][NR_SERVERS_INDEX] = Integer.toString(mip.getCounter());//+"/"+Integer.toString(nrServers); // nr supporting servers
metadataList[row][NAME_INDEX] = mip.getName().replace("INPUT:", ""); // name
metadataList[row][VALUE_INDEX] = mip.getValue(); // value (default value or "")
metadataList[row][VALUE_INDEX] = ""; //mip.getValue();
metadataList[row][UCD_INDEX] = mip.getUCD();
String unit = mip.getUnit();
String desc = mip.getDescription();
desc = desc.replaceAll("\n+", "<br>");
Expand Down Expand Up @@ -284,11 +288,12 @@ private void adjustColumns() {
metadataTable.getColumnModel().getColumn(SELECTED_INDEX).setCellEditor(new DefaultCellEditor(cb));
metadataTable.getColumnModel().getColumn(SELECTED_INDEX).setMaxWidth(30);
metadataTable.getColumnModel().getColumn(SELECTED_INDEX).setMinWidth(30);
metadataTable.getColumnModel().getColumn(NR_SERVERS_INDEX).setMaxWidth(60);
metadataTable.getColumnModel().getColumn(NAME_INDEX).setMinWidth(150);
metadataTable.getColumnModel().getColumn(VALUE_INDEX).setMinWidth(150);
metadataTable.getColumnModel().getColumn(NR_SERVERS_INDEX).setMaxWidth(0);
metadataTable.getColumnModel().getColumn(NAME_INDEX).setMinWidth(100);
metadataTable.getColumnModel().getColumn(VALUE_INDEX).setMinWidth(100);
metadataTable.getColumnModel().getColumn(VALUE_INDEX).setCellEditor(new DefaultCellEditor(tf));
metadataTable.getColumnModel().getColumn(NAME_INDEX).setCellRenderer(paramRenderer);
metadataTable.getColumnModel().getColumn(NAME_INDEX).setCellRenderer(paramRenderer);
metadataTable.getColumnModel().getColumn(UCD_INDEX).setMinWidth(100);
metadataTable.getColumnModel().getColumn (DESCRIPTION_INDEX).setMaxWidth(0);
// Remove the description column. Its contents will not be removed. They'll be displayed as tooltip text in the NAME_INDEX column.
metadataTable.removeColumn(metadataTable.getColumnModel().getColumn (DESCRIPTION_INDEX));
Expand All @@ -304,19 +309,50 @@ private void adjustColumns() {
public String getParamsQueryString()
{
String query="";

HashMap <String, String> UCDList = new HashMap <String, String> () ;
// iterate through all rows
// String suffix = "";
for (int i=0; i< metadataTable.getRowCount(); i++)
{
if (rowChecked( i ))
{
String val = getTableData(i,VALUE_INDEX).toString().trim();
if (val != null && val.length() > 0) {
String name = getTableData(i,NAME_INDEX).toString().trim();
String ucd = (String) getTableData(i,UCD_INDEX);
String name = (String) getTableData(i,NAME_INDEX);

/* if (ucd.endsWith("max") )
suffix = "max";
else if (ucd.endsWith("min") )
suffix = "min";
*/
if (val != null && val.length() > 0) { // all non-empty values
if ( ucd != null && ! ucd.isEmpty()) // if there are no UCDs assigned just add the parameters to the query string
UCDList.put(ucd, val);
query += "&"+name+"="+val;
}
}
}
}
/*
// set the same value and add to the query all params with the same UCD as the selected parameters
for (int i=0; i< metadataTable.getRowCount(); i++)
{
String suffix2 = "";
String ucd = (String) getTableData(i,UCD_INDEX);
if ( ucd != null && !ucd.isEmpty() && UCDList.containsKey(ucd))
{
if (ucd.endsWith("max") )
suffix2 = "max";
else if (ucd.endsWith("min") )
suffix2 = "min";
if ( suffix.isEmpty() || suffix.equals(suffix2) )
{
String name = getTableData(i,NAME_INDEX).toString().trim();
query += "&"+name+"="+UCDList.get(ucd);
}
}
}
*/
return query;
}

Expand Down Expand Up @@ -365,7 +401,7 @@ private void setTableData(String newValue, int row, int col )
*/
protected void initUI()
{
// this.setPreferredSize(new Dimension(500,150));
this.setPreferredSize(new Dimension(500,150));
setLayout( new BorderLayout() );

JScrollPane scroller = new JScrollPane( metadataTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
Expand Down Expand Up @@ -503,7 +539,9 @@ public void actionPerformed(ActionEvent e) {
}
if ( command.equals( "load" ) ) // read saved table values from a file
{

readMetadataFromFile();
fireProperty();
}
// if ( command.equals( "refresh" ) ) // add new server to list
// {
Expand Down Expand Up @@ -538,17 +576,31 @@ public void openWindow()
}

/**
* Remove selected Parameter from table
* Select all Parameters from table
*/
public void removeSelectedMetadata()
public void selectAll()
{
int [] selRows = metadataTable.getSelectedRows();
for (int i=0; i<selRows.length; i++) {

MetadataTableModel mtm = (MetadataTableModel) metadataTable.getModel();
for (int i=0; i<mtm.getRowCount(); i++) {
//deselect it first to remove from query string
metadataTable.getModel().setValueAt(Boolean.FALSE, i, SELECTED_INDEX);
metadataTableModel.removeRow(selRows[i]);
mtm.setValueAt(Boolean.TRUE, i, SELECTED_INDEX);

}
fireProperty();
}
/**
* Deselect all Parameters from table
*/
public void deselectAll()
{

MetadataTableModel mtm = (MetadataTableModel) metadataTable.getModel();
for (int i=0; i<mtm.getRowCount(); i++) {
//deselect it first to remove from query string
mtm.setValueAt(Boolean.FALSE, i, SELECTED_INDEX);
}
fireProperty();
}
/**
* Reset all fields
Expand All @@ -561,6 +613,7 @@ private void resetFields()
setTableData("", i,VALUE_INDEX);
}
}
fireProperty();
} //resetFields

/**
Expand Down Expand Up @@ -690,7 +743,17 @@ private void readTable(File paramFile) throws IOException, FileNotFoundExceptio
} //readTable()



/**
* Remove all rows from the table
* @param mip the metadata parameter that will be added to the table
*/
// checkbox included
public void removeAll( ) {
MetadataTableModel mtm = (MetadataTableModel) metadataTable.getModel();
mtm.setRowCount(0);

}

/**
* Adds a new row to the table
* @param mip the metadata parameter that will be added to the table
Expand All @@ -708,8 +771,11 @@ public void addRow (MetadataInputParameter mip, boolean selected) {
paramRow[NR_SERVERS_INDEX] = Integer.toString(mip.getCounter());//+"/"+Integer.toString(nrServers); // nr supporting servers
paramRow[NAME_INDEX] = mip.getName().replace("INPUT:", ""); // name
paramRow[VALUE_INDEX] = mip.getValue(); // value (default value or "")
paramRow[UCD_INDEX] = mip.getUCD();
String unit = mip.getUnit();
String desc = mip.getDescription();
//String utype = mip.getUtype();

if (desc != null)
{
// remove newline, tabs, and multiple spaces
Expand Down Expand Up @@ -743,37 +809,27 @@ public void addRow (MetadataInputParameter mip, boolean selected) {

if ( selected ) {
mtm.setValueAt(true, mtm.getRowCount()-1, SELECTED_INDEX);
// metadataTable.removeColumn(metadataTable.getColumnModel().getColumn (SELECTED_INDEX));
}
// if (mtm.getRowCount() )
this.setPreferredSize( new Dimension(100,metadataTable.getRowHeight()*8));

// else
// this.setPreferredSize( new Dimension(500,metadataTable.getRowHeight()*(mtm.getRowCount()+4)));

// this.repaint();


} //addRow

// public void setTableWidth(int w) {
// this.setPreferredSize(new Dimension( w, metadataTable.getRowHeight()*8));
// }


/**
* Set number of servers to the respective column in the table
* @param counter the nr of servers supporting the parameter
* @param name the name of the parameter
*/
public void setNrServers(int counter, String name) {
public void setNrServers(int counter, String UCD) {

// boolean found=false;
int row=0;
String paramName = name.replace("INPUT:", "");
// String paramName = name.replace("INPUT:", "");
MetadataTableModel mtm = (MetadataTableModel) metadataTable.getModel();

while (row<mtm.getRowCount() )
{
if ( mtm.getValueAt(row, NAME_INDEX).toString().equalsIgnoreCase(paramName)) {
if ( mtm.getValueAt(row, UCD_INDEX).toString().equalsIgnoreCase(UCD)) {

mtm.setValueAt(counter, row, NR_SERVERS_INDEX);
return;
Expand All @@ -789,8 +845,13 @@ public void setNrServers(int counter, String name) {
*/
public void tableChanged(TableModelEvent tme) {

if ( (tme.getColumn() != TableModelEvent.ALL_COLUMNS) && (tme.getColumn() == SELECTED_INDEX || tme.getColumn() == VALUE_INDEX) )
this.firePropertyChange("changeQuery", false, true);
}
// fire this only in certain events
public void fireProperty()
{
this.firePropertyChange("changeQuery", false, true);

}


Expand Down
63 changes: 61 additions & 2 deletions splat/src/main/uk/ac/starlink/splat/vo/SSAQuery.java
Expand Up @@ -13,6 +13,7 @@
import java.net.URL;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.util.ArrayList;

import jsky.coords.DMS;
import jsky.coords.HMS;
Expand Down Expand Up @@ -91,6 +92,12 @@ public class SSAQuery
/** The DataLink input parameters */
private DataLinkParams dataLinkParams = null;

/** Extended Query with metadata parameters */
private String extendedQuery = "";

/** Extended Query with metadata parameters */
private String queryText = "";

/**
* Create an instance with the given base URL for an SSA service.
*/
Expand Down Expand Up @@ -135,7 +142,7 @@ public SSAQuery( SSAPRegResource server )
// interface.
this.description = server.getShortName();
}

/**
* Set the position used for the query. The values are in degrees and must
* be in ICRS (FK5/J2000 will do if accuracy isn't a problem). To not
Expand Down Expand Up @@ -404,6 +411,58 @@ public void setServer( SSAPRegResource server) {
public String getShortName() {
return this.description;
}


public void setQuery(String q) {
this.queryText = q.substring("<SERVER>?".length(), q.length());
}

public String getQueryText() {
return this.queryText;

}
// public String getExtendedQuery() {
// return this.extendedQuery;
// }

/**
* Parse a query line into an array of parameter names
* returns the extended parameters
*/
public ArrayList<String> getParamList( String queryparams) {

ArrayList<String> extp = new ArrayList <String>();
//String sub = "";
String[] paramdata = queryparams.split("&");
for ( int i = 1; i<paramdata.length; i++) { // the first one is thrown away
String param = paramdata[i].substring(0, paramdata[i].indexOf("="));
if ( !param.equals("TARGETNAME") && !param.equals("POS") && !param.equals("SIZE") &&
!param.equals("BAND") && !param.equals("TIME") && !param.equals("FORMAT") &&
!param.equals("WAVECALIB") && !param.equals("FLUXCALIB"))
extp.add(param);
}


//ArrayList<String> extp = new ArrayList<String>();
if (extp.isEmpty())
return null;
else return extp;
}


/**
* Returns the full request URL as String
*/
public URL getRequestURL()
throws MalformedURLException, UnsupportedEncodingException
{
String newURL = this.baseURL;
if ( newURL.indexOf( '?' ) == -1 ) // No ? in URL.
newURL += ( "?" );
else if ( newURL.indexOf('?') != newURL.length()-1 ) //? is not at the end
newURL += ( "&" );

newURL += this.queryText;
return new URL(newURL);

}
}

0 comments on commit 3025239

Please sign in to comment.