Wednesday, 2 October 2013

From Query resultset to a JOptionPaneDialog

From Query resultset to a JOptionPaneDialog

I have a sparql query which returns some results. I need to let the user
to choose which of these results he will use next. I have coded this with
scanner, but I want to convert it now to a joptionpanedialog so that it is
more user friendly. I assume it is achieved via
JOptionPane.showInputDialog. However I dont know how to "translate" the
resultset in the object list of the joptionpane in the right format, and
then extract the selected elements. Any ideas how could I achieve this?
Thanks in advance
Query query = QueryFactory.create(queryString);
QueryExecution qe=
QueryExecutionFactory.create(query, model);
ResultSet resultset = qe.execSelect();
ResultSet results =
ResultSetFactory.copyResults(resultset);
final ResultSet results2 =
ResultSetFactory.copyResults(results);
System.out.println( "== Available Options ==" );
ResultSetFormatter.out(System.out, results, query);
System.out.println( "== Select Option ==" );
System.out.println( "== Type 0,1,2,3.. to choose Option
==" );
Scanner input = new Scanner( System.in );
final String inputs ;
inputs = input.next();
final String[] indices = inputs.split("\\s*,\\s*");
final List<QuerySolution> selectedSolutions = new
ArrayList<QuerySolution>( indices.length ) {{
final List<QuerySolution> solutions =
ResultSetFormatter.toList( results2 );
for ( final String index : indices ) {
add( solutions.get( Integer.valueOf( index )));
}
}};
String s = selectedSolutions.toString();
Pattern p = Pattern.compile("#([^>]+)>");
Matcher m = p.matcher(s);

No comments:

Post a Comment