GroupListModel newgroupmodel = new GroupListModel();
GroupListModel subscribedgroupmodel = new GroupListModel();
// popuplate models
try {
Iterator<Group> it = HibernateUtils.listGroups().iterator();
Group g;
while(it.hasNext()) {
g = it.next();
allgroupmodel.addElement(g);
if(g.isSubscribed()) {
subscribedgroupmodel.addElement(g);
}
}
} catch (JDBCConnectionException e) {
System.err.println("Cannot open connection to database.");
System.err.println("Maybe you restarted to fast? Let HSQLDB recover from last session.");
Application.getInstance().quit(Application.ERROR_CONNECTION_NOT_READY);
}
//TODO check if deserialization is really useful! Maybe it's slower then reading from database
// GroupListModel allgroupmodel = deserializeAllGroups();
// GroupListModel subscribedgroupmodel = deserializeSubscribedGroups();
// GroupListModel newgroupmodel = new GroupListModel();
// register listeners for group events
//TODO check if it is correct to let both groupmodels implement GroupListener
NNTPUtils.getInstance().addGroupListener(newgroupmodel);
NNTPUtils.getInstance().addGroupListener(allgroupmodel);
allGroupList = new JList(allgroupmodel);
allGroupList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
allGroupList.setCellRenderer(new GroupCellRenderer());
allGroupList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if(e.getValueIsAdjusting()) return;
Group g = (Group) allGroupList.getSelectedValue();
if(g == null) return;
displayArticles(g.getId());
}});
allGroupList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if(SwingUtilities.isRightMouseButton(e)) {
if(allGroupList.getSelectedValue() != null) {
// GuiUtils.showError("show group popup");
//TODO select value under mouse
GroupPopupMenu popup = new GroupPopupMenu();
popup.setLocation(e.getPoint());
popup.show((Component) e.getSource(), e.getX(), e.getY());
}
// else {
// GuiUtils.showError("no selection!");
// }
}
}
});
groupTabs.addTab("All", new JScrollPane(allGroupList));
newGroupList = new JList(newgroupmodel);
newGroupList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
newGroupList.setCellRenderer(new GroupCellRenderer());
newGroupList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if(e.getValueIsAdjusting()) return;
Group g = (Group) newGroupList.getSelectedValue();
if(g == null) return;
displayArticles(g.getId());
}});
newGroupList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if(SwingUtilities.isRightMouseButton(e)) {
if(newGroupList.getSelectedValue() != null) {
// GuiUtils.showError("show group popup");
//TODO select value under mouse
GroupPopupMenu popup = new GroupPopupMenu();
popup.setLocation(e.getPoint());
popup.show((Component) e.getSource(), e.getX(), e.getY());
}
// else {
// GuiUtils.showError("no selection!");
// }
}
}
});
groupTabs.addTab("New", new JScrollPane(newGroupList));
subscribedGroupList = new JList(subscribedgroupmodel);
subscribedGroupList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
subscribedGroupList.setCellRenderer(new GroupCellRenderer());
subscribedGroupList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if(e.getValueIsAdjusting()) return;
final Group g = (Group) subscribedGroupList.getSelectedValue();
if(g == null) return;
displayArticles(g.getId());
}});
subscribedGroupList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if(SwingUtilities.isRightMouseButton(e)) {
if(subscribedGroupList.getSelectedValue() != null) {