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.page; 016 017 import nextapp.echo2.app.Column; 018 import nextapp.echo2.app.Extent; 019 import nextapp.echo2.app.Font; 020 import nextapp.echo2.app.Insets; 021 import nextapp.echo2.app.Row; 022 import nextapp.echo2.app.event.ActionEvent; 023 import nextapp.echo2.app.event.ActionListener; 024 import ch.uzh.ifi.attempto.acewiki.Wiki; 025 import ch.uzh.ifi.attempto.acewiki.core.ontology.Comment; 026 import ch.uzh.ifi.attempto.acewiki.core.ontology.Concept; 027 import ch.uzh.ifi.attempto.acewiki.core.ontology.Individual; 028 import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement; 029 import ch.uzh.ifi.attempto.acewiki.core.ontology.Role; 030 import ch.uzh.ifi.attempto.acewiki.core.ontology.Sentence; 031 import ch.uzh.ifi.attempto.acewiki.core.ontology.Statement; 032 import ch.uzh.ifi.attempto.acewiki.gui.CommentRow; 033 import ch.uzh.ifi.attempto.acewiki.gui.DropDownMenu; 034 import ch.uzh.ifi.attempto.acewiki.gui.TextRow; 035 import ch.uzh.ifi.attempto.acewiki.gui.Title; 036 import ch.uzh.ifi.attempto.acewiki.gui.editor.CommentEditorWindow; 037 import ch.uzh.ifi.attempto.acewiki.gui.editor.SentenceEditorHandler; 038 import ch.uzh.ifi.attempto.echocomp.SolidLabel; 039 040 /** 041 * This class stands for a wiki page that represents an ontology element and shows the 042 * article of this ontology element. 043 * 044 * @author Tobias Kuhn 045 */ 046 public abstract class ArticlePage extends WikiPage implements ActionListener { 047 048 private Column textColumn = new Column(); 049 private DropDownMenu dropDown = new DropDownMenu("gray", this); 050 051 /** 052 * Creates a new article page. 053 * 054 * @param wiki The wiki instance. 055 * @param ontologyElement The ontology element whose article should be shown. 056 */ 057 protected ArticlePage(Wiki wiki, OntologyElement ontologyElement) { 058 super(wiki, new Title(ontologyElement.getHeadword())); 059 060 addSelectedTab("Article"); 061 addTab(ontologyElement.getType(), "Word", this); 062 addTab("References", this); 063 064 dropDown.addMenuEntry("Add Sentence..."); 065 dropDown.addMenuEntry("Add Comment..."); 066 067 textColumn.setInsets(new Insets(10, 20, 0, 70)); 068 textColumn.setCellSpacing(new Extent(2)); 069 add(textColumn); 070 } 071 072 /** 073 * Creates an article page for the given ontology element. 074 * 075 * @param oe The ontology element for which an article page should be created. 076 * @param wiki The wiki instance. 077 * @return The new article page. 078 */ 079 public static ArticlePage create(OntologyElement oe, Wiki wiki) { 080 if (oe instanceof Individual) { 081 return new IndividualPage((Individual) oe, wiki); 082 } else if (oe instanceof Concept) { 083 return new ConceptPage((Concept) oe, wiki); 084 } else if (oe instanceof Role) { 085 return new RolePage((Role) oe, wiki); 086 } 087 return null; 088 } 089 090 /** 091 * Returns the ontology element of this article page. 092 * 093 * @return The ontology element. 094 */ 095 public abstract OntologyElement getOntologyElement(); 096 097 protected void doUpdate() { 098 textColumn.removeAll(); 099 100 for (Statement s : getOntologyElement().getStatements()) { 101 if (s instanceof Sentence) { 102 textColumn.add(new TextRow((Sentence) s, this)); 103 } else if (s instanceof Comment) { 104 textColumn.add(new CommentRow((Comment) s, this)); 105 } 106 } 107 108 if (getOntologyElement().getStatements().size() == 0) { 109 textColumn.add(new SolidLabel("(article is empty)", Font.ITALIC, 10)); 110 } 111 112 Row addButtonRow = new Row(); 113 addButtonRow.add(dropDown); 114 textColumn.add(addButtonRow); 115 } 116 117 public boolean equals(Object obj) { 118 if (obj instanceof ArticlePage) { 119 return getOntologyElement() == ((ArticlePage) obj).getOntologyElement(); 120 } 121 return false; 122 } 123 124 public String toString() { 125 return getOntologyElement().getWord(); 126 } 127 128 public boolean isExpired() { 129 return !getWiki().getOntology().contains(getOntologyElement()); 130 } 131 132 public void actionPerformed(ActionEvent e) { 133 if (e.getActionCommand().equals("Add Sentence...")) { 134 getWiki().log("page", "dropdown: add sentence"); 135 getWiki().showWindow(SentenceEditorHandler.generatePreditorAddWindow(null, this)); 136 } else if (e.getActionCommand().equals("Add Comment...")) { 137 getWiki().log("page", "dropdown: add comment"); 138 getWiki().showWindow(new CommentEditorWindow(null, this, false)); 139 } else if ("References".equals(e.getActionCommand())) { 140 log("page", "pressed: references"); 141 getWiki().showPage(new ReferencesPage(this)); 142 } else if ("Word".equals(e.getActionCommand())) { 143 log("page", "pressed: word"); 144 getWiki().showPage(new WordPage(this)); 145 } 146 } 147 148 }