package view.menu;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JMenu;
import model.array.tools.DecadeComparator;
import model.movie.Decade;
import model.query.OntologyQueryer;
import com.hp.hpl.jena.query.ResultSet;
import controller.DecadeController;
public class DecadeMenu extends JMenu {
private static final long serialVersionUID = 8647053186534487432L;
private ArrayList<Decade> decades;
private DecadeController decadeController;
public DecadeMenu(DecadeController controller) {
super("Decades");
decades = getDecades();
decadeController = controller;
for (Decade decade : decades)
add(new DecadeItem(decade.getName(), decade.getUri(), decadeController));
}
private ArrayList<Decade> getDecades() {
ArrayList<Decade> decades = new ArrayList<Decade>();
String queryText = "SELECT DISTINCT ?decade WHERE {" +
"?decade rdfs:subClassOf h2mdb:Decade . " +
"} ";
ResultSet resultSet = OntologyQueryer.resultQuery(queryText);
while(resultSet.hasNext()) {
String uri = resultSet.next().get("decade").toString();
if (uri.contains("http://h2mdb.no/") && !uri.contains("Decade"))
decades.add(new Decade(uri, uri.replace("http://h2mdb.no/", "")));
}
Collections.sort(decades, new DecadeComparator());
return decades;
}
}