001 // This file is part of the Attempto Java Packages. 002 // Copyright 2008-2009, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch). 003 // 004 // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the 005 // terms of the GNU Lesser General Public License as published by the Free Software Foundation, 006 // either version 3 of the License, or (at your option) any later version. 007 // 008 // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY 009 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 // PURPOSE. See the GNU Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with the Attempto 013 // Java Packages. If not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.acewiki.gui; 016 017 import nextapp.echo2.app.Alignment; 018 import nextapp.echo2.app.Color; 019 import nextapp.echo2.app.Column; 020 import nextapp.echo2.app.Font; 021 import nextapp.echo2.app.Row; 022 import nextapp.echo2.app.event.ActionEvent; 023 import nextapp.echo2.app.event.ActionListener; 024 import nextapp.echo2.app.layout.RowLayoutData; 025 import ch.uzh.ifi.attempto.acewiki.Wiki; 026 import ch.uzh.ifi.attempto.acewiki.core.ontology.Comment; 027 import ch.uzh.ifi.attempto.acewiki.gui.editor.CommentEditorWindow; 028 import ch.uzh.ifi.attempto.acewiki.gui.editor.SentenceEditorHandler; 029 import ch.uzh.ifi.attempto.acewiki.gui.page.ArticlePage; 030 import ch.uzh.ifi.attempto.acewiki.gui.page.WikiPage; 031 import ch.uzh.ifi.attempto.echocomp.HSpace; 032 import ch.uzh.ifi.attempto.echocomp.Label; 033 import ch.uzh.ifi.attempto.echocomp.MessageWindow; 034 import ch.uzh.ifi.attempto.echocomp.VSpace; 035 036 /** 037 * This class represents a comment row that consists of a drop down menu and a comment text. 038 * 039 * @author Tobias Kuhn 040 */ 041 public class CommentRow extends Column implements ActionListener { 042 043 private static final long serialVersionUID = -540135972060005725L; 044 045 private Comment comment; 046 private Wiki wiki; 047 private WikiPage hostPage; 048 049 private Row commentRow = new Row(); 050 private DropDownMenu dropDown; 051 052 /** 053 * Creates a new comment row. 054 * 055 * @param comment The comment to be shown. 056 * @param hostPage The host page of the comment row. 057 */ 058 public CommentRow(Comment comment, WikiPage hostPage) { 059 this.comment = comment; 060 this.hostPage = hostPage; 061 this.wiki = hostPage.getWiki(); 062 update(); 063 } 064 065 private void update() { 066 dropDown = new DropDownMenu("gray", this); 067 dropDown.addMenuEntry("Edit..."); 068 dropDown.addMenuEntry("Add Sentence..."); 069 dropDown.addMenuEntry("Add Comment..."); 070 dropDown.addMenuEntry("Delete"); 071 RowLayoutData layout = new RowLayoutData(); 072 layout.setAlignment(new Alignment(Alignment.CENTER, Alignment.TOP)); 073 dropDown.setLayoutData(layout); 074 075 Column c = new Column(); 076 for (String s : (comment.getText() + " ").split("\\n")) { 077 Row r = new Row(); 078 r.add(new VSpace(17)); 079 r.add(new HSpace(s.replaceFirst("^(\\s*).*$", "$1").length() * 5)); 080 Label textLabel = new Label(s, Font.ITALIC); 081 textLabel.setForeground(new Color(170, 170, 170)); 082 r.add(textLabel); 083 c.add(r); 084 } 085 086 removeAll(); 087 commentRow.removeAll(); 088 commentRow.add(dropDown); 089 commentRow.add(new HSpace(5)); 090 commentRow.add(c); 091 commentRow.add(new HSpace(10)); 092 add(commentRow); 093 } 094 095 public void actionPerformed(ActionEvent e) { 096 if (e.getActionCommand().equals("Edit...")) { 097 wiki.log("page", "dropdown: edit comment: " + comment.getText()); 098 wiki.showWindow(new CommentEditorWindow(comment, (ArticlePage) hostPage, true)); 099 } else if (e.getActionCommand().equals("Add Sentence...")) { 100 wiki.log("page", "dropdown: add sentence"); 101 wiki.showWindow(SentenceEditorHandler.generatePreditorAddWindow(comment, (ArticlePage) hostPage)); 102 } else if (e.getActionCommand().equals("Add Comment...")) { 103 wiki.log("page", "dropdown: add comment"); 104 wiki.showWindow(new CommentEditorWindow(comment, (ArticlePage) hostPage, false)); 105 } else if (e.getActionCommand().equals("Delete")) { 106 wiki.log("page", "dropdown: delete sentence: " + comment.getText()); 107 wiki.showWindow(new MessageWindow("Delete", "Do you really want to delete this comment?", null, this, "Yes", "No")); 108 } else if (e.getSource() instanceof MessageWindow && e.getActionCommand().equals("Yes")) { 109 wiki.log("page", "dropdown: delete confirmed: " + comment.getText()); 110 comment.getOwner().remove(comment); 111 wiki.update(); 112 wiki.refresh(); 113 } 114 } 115 116 }