001 // This file is part of AceWiki. 002 // Copyright 2008-2012, AceWiki developers. 003 // 004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU 005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of 006 // the License, or (at your option) any later version. 007 // 008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 010 // Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If 013 // not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.acewiki.gui; 016 017 import nextapp.echo.app.Border; 018 import nextapp.echo.app.Button; 019 import nextapp.echo.app.Color; 020 import nextapp.echo.app.Column; 021 import nextapp.echo.app.Component; 022 import nextapp.echo.app.Extent; 023 import nextapp.echo.app.Font; 024 import nextapp.echo.app.Insets; 025 import nextapp.echo.app.Row; 026 import nextapp.echo.app.event.ActionListener; 027 import ch.uzh.ifi.attempto.acewiki.Wiki; 028 import ch.uzh.ifi.attempto.acewiki.core.LanguageUtils; 029 import ch.uzh.ifi.attempto.acewiki.core.OntologyElement; 030 import ch.uzh.ifi.attempto.echocomp.HSpace; 031 import ch.uzh.ifi.attempto.echocomp.Label; 032 import ch.uzh.ifi.attempto.echocomp.SmallButton; 033 import ch.uzh.ifi.attempto.echocomp.Style; 034 import ch.uzh.ifi.attempto.echocomp.VSpace; 035 036 /** 037 * This is the superclass of all page classes. It represents a wiki page of AceWiki. 038 * 039 * @author Tobias Kuhn 040 */ 041 public abstract class WikiPage extends Column { 042 043 private static final long serialVersionUID = -1972548696966691981L; 044 045 private Wiki wiki; 046 private Row tabRow; 047 048 /** 049 * Initializes a new wiki page. 050 * 051 * @param wiki The wiki instance. 052 */ 053 public WikiPage(Wiki wiki) { 054 this.wiki = wiki; 055 056 setInsets(new Insets(0, 0, 0, 40)); 057 058 tabRow = new Row(); 059 tabRow.setInsets(new Insets(10, 0, 0, 0)); 060 add(tabRow); 061 add(new VSpace(20)); 062 } 063 064 /** 065 * Checks whether the page still exists and updates the page content. 066 */ 067 public final void update() { 068 if (isExpired()) { 069 removeAll(); 070 add(new ErrorPage(wiki, "This article does no longer exist.")); 071 } else { 072 doUpdate(); 073 } 074 } 075 076 /** 077 * Updates the page content. 078 */ 079 protected void doUpdate() {} 080 081 /** 082 * Returns the wiki instance this page belongs to. 083 * 084 * @return The wiki instance. 085 */ 086 public Wiki getWiki() { 087 return wiki; 088 } 089 090 /** 091 * Writes a log entry. 092 * 093 * @param type The type of the log entry. 094 * @param text The log text. 095 */ 096 protected void log(String type, String text) { 097 wiki.log(type, text); 098 } 099 100 /** 101 * Checks if the page has expired. A page has expired it represents an ontology 102 * element that has been deleted. 103 * 104 * @return true if the page has expired. 105 */ 106 public boolean isExpired() { 107 return false; 108 } 109 110 /** 111 * Adds a new tab to the tab row. 112 * 113 * @param tabName The name of the tab. 114 * @param actionListener The actionlistener. 115 */ 116 protected void addTab(String tabName, ActionListener actionListener) { 117 SmallButton b = new SmallButton(tabName, actionListener, true); 118 b.setActionCommand(tabName); 119 tabRow.add(b); 120 tabRow.add(new HSpace(8)); 121 tabRow.add(createTabSeparator()); 122 tabRow.add(new HSpace(8)); 123 } 124 125 /** 126 * Adds a new tab to the tab row that is currently selected. 127 * 128 * @param tabName The name of the tab. 129 */ 130 protected void addSelectedTab(String tabName) { 131 tabRow.add(new SmallButton(tabName, null, false)); 132 tabRow.add(new HSpace(8)); 133 tabRow.add(createTabSeparator()); 134 tabRow.add(new HSpace(8)); 135 } 136 137 private Button createTabSeparator() { 138 Button tabSeparator = new Button(); 139 tabSeparator.setBorder(new Border(1, Color.DARKGRAY, Border.STYLE_SOLID)); 140 tabSeparator.setHeight(new Extent(12)); 141 return tabSeparator; 142 } 143 144 /** 145 * Adds a horizontal line to the page content. 146 */ 147 protected void addHorizontalLine() { 148 Column horizontalLine = new Column(); 149 horizontalLine.setInsets(new Insets(10, 0, 10, 0)); 150 Column c = new Column(); 151 c.setBackground(Color.DARKGRAY); 152 c.setInsets(new Insets(0, 1, 0, 0)); 153 horizontalLine.add(c); 154 add(horizontalLine); 155 } 156 157 /** 158 * Adds a headline to the page content. 159 * 160 * @param text The headline text. 161 */ 162 protected void addHeadline(String text) { 163 addHeadline(text, null); 164 } 165 166 /** 167 * Adds a headline to the page content. The component is shown after the headline text. 168 * 169 * @param text The headline text. 170 * @param comp 171 */ 172 protected void addHeadline(String text, Component comp) { 173 Row headline = new Row(); 174 headline.setInsets(new Insets(10, 10, 10, 0)); 175 headline.setCellSpacing(new Extent(5)); 176 Label title = new Label(text); 177 title.setFont(new Font(Style.fontTypeface, Font.ITALIC | Font.UNDERLINE, new Extent(13))); 178 title.setLineWrap(false); 179 headline.add(title); 180 if (comp != null) { 181 headline.add(comp); 182 } 183 add(headline); 184 } 185 186 /** 187 * Returns the heading text for the given ontology element. 188 * 189 * @param oe The ontology element. 190 * @return The heading. 191 */ 192 protected String getHeading(OntologyElement oe) { 193 return LanguageUtils.getHeading(oe); 194 } 195 196 public abstract boolean equals(Object obj); 197 198 }