1 19 package org.lucane.applications.forum.gui; 20 21 import javax.swing.event.TreeSelectionEvent ; 22 import javax.swing.event.TreeSelectionListener ; 23 import javax.swing.tree.DefaultMutableTreeNode ; 24 import javax.swing.tree.TreePath ; 25 26 import org.lucane.applications.forum.ForumPlugin; 27 import org.lucane.applications.forum.model.ForumInfo; 28 import org.lucane.applications.forum.model.ForumMessage; 29 import org.lucane.client.widgets.DialogBox; 30 31 public class MessageSelectionListener implements TreeSelectionListener 32 { 33 private MainWindow ui; 34 private ForumPlugin plugin; 35 36 public MessageSelectionListener(ForumPlugin plugin, MainWindow ui) 37 { 38 this.plugin = plugin; 39 this.ui = ui; 40 } 41 42 public void valueChanged(TreeSelectionEvent tse) 43 { 44 TreePath selection = ui.getMessages().getSelectionPath(); 45 ForumInfo forum = ui.getForumList().getSelectedForum(); 46 ui.refreshButtons(forum); 47 48 if(selection != null) 49 { 50 DefaultMutableTreeNode node = (DefaultMutableTreeNode )selection.getLastPathComponent(); 51 ForumMessage msg = (ForumMessage)node.getUserObject(); 52 try { 53 msg = plugin.getMessageContent(forum.getName(), msg); 54 } catch (Exception e) { 55 DialogBox.error(plugin.tr("err.unableToGetMessageContent") + e); 56 e.printStackTrace(); 57 } 58 59 ui.getMessageAuthor().setText(msg.getAuthor()); 60 ui.getMessageDate().setText(msg.getDate().toString()); 61 ui.getMessageContent().setText(msg.getContent()); 62 } 63 else 64 { 65 ui.getMessageAuthor().setText(""); 66 ui.getMessageDate().setText(""); 67 ui.getMessageContent().setText(""); 68 } 69 } 70 } | Popular Tags |