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