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 ch.uzh.ifi.attempto.acewiki.Wiki;
018 import ch.uzh.ifi.attempto.acewiki.gui.Title;
019 import ch.uzh.ifi.attempto.echocomp.HSpace;
020 import ch.uzh.ifi.attempto.echocomp.Label;
021 import ch.uzh.ifi.attempto.echocomp.SmallButton;
022 import ch.uzh.ifi.attempto.echocomp.Style;
023 import ch.uzh.ifi.attempto.echocomp.VSpace;
024 import nextapp.echo2.app.Border;
025 import nextapp.echo2.app.Button;
026 import nextapp.echo2.app.Color;
027 import nextapp.echo2.app.Column;
028 import nextapp.echo2.app.Extent;
029 import nextapp.echo2.app.Font;
030 import nextapp.echo2.app.Insets;
031 import nextapp.echo2.app.Row;
032 import nextapp.echo2.app.event.ActionListener;
033
034 /**
035 * This is the superclass of all page classes. It represents a wiki page of AceWiki.
036 *
037 * @author Tobias Kuhn
038 */
039 public abstract class WikiPage extends Column {
040
041 private Wiki wiki;
042 private Title title;
043 private Row tabRow;
044
045 /**
046 * Initializes a new wiki page.
047 *
048 * @param wiki The wiki instance.
049 * @param title The title component.
050 */
051 public WikiPage(Wiki wiki, Title title) {
052 this.wiki = wiki;
053 this.title = title;
054
055 tabRow = new Row();
056 tabRow.setInsets(new Insets(10, 0, 0, 0));
057 add(tabRow);
058 add(new VSpace(20));
059 add(title);
060 addHorizontalLine();
061 }
062
063 /**
064 * Checks whether the page still exists and updates the page content.
065 */
066 public final void update() {
067 if (isExpired()) {
068 removeAll();
069 add(new ErrorPage(wiki, "This article does no longer exist."));
070 } else {
071 doUpdate();
072 }
073 }
074
075 /**
076 * Updates the page content.
077 */
078 protected void doUpdate() {}
079
080 /**
081 * Returns the wiki instance this page belongs to.
082 *
083 * @return The wiki instance.
084 */
085 public Wiki getWiki() {
086 return wiki;
087 }
088
089 /**
090 * Returns the title component.
091 *
092 * @return The title component.
093 */
094 protected Title getTitle() {
095 return title;
096 }
097
098 /**
099 * Writes a log entry.
100 *
101 * @param type The type of the log entry.
102 * @param text The log text.
103 */
104 protected void log(String type, String text) {
105 wiki.log(type, text);
106 }
107
108 /**
109 * Checks if the page has expired. A page has expired it represents an ontology
110 * element that has been deleted.
111 *
112 * @return true if the page has expired.
113 */
114 public boolean isExpired() {
115 return false;
116 }
117
118 /**
119 * Adds a new tab to the tab row.
120 *
121 * @param tabName The name of the tab.
122 * @param actionCommand The action command that is given to the action event object.
123 * @param actionListener The actionlistener.
124 */
125 protected void addTab(String tabName, String actionCommand, ActionListener actionListener) {
126 SmallButton b = new SmallButton(tabName, actionListener, true);
127 if (actionCommand != null) {
128 b.setActionCommand(actionCommand);
129 }
130 tabRow.add(b);
131 tabRow.add(new HSpace(8));
132 tabRow.add(createTabSeparator());
133 tabRow.add(new HSpace(8));
134 }
135
136 /**
137 * Adds a new tab to the tab row.
138 *
139 * @param tabName The name of the tab.
140 * @param actionListener The actionlistener.
141 */
142 protected void addTab(String tabName, ActionListener actionListener) {
143 addTab(tabName, null, actionListener);
144 }
145
146 /**
147 * Adds a new tab to the tab row that is currently selected.
148 *
149 * @param tabName The name of the tab.
150 */
151 protected void addSelectedTab(String tabName) {
152 tabRow.add(new SmallButton(tabName, null, false));
153 tabRow.add(new HSpace(8));
154 tabRow.add(createTabSeparator());
155 tabRow.add(new HSpace(8));
156 }
157
158 private Button createTabSeparator() {
159 Button tabSeparator = new Button();
160 tabSeparator.setBorder(new Border(1, Color.DARKGRAY, Border.STYLE_SOLID));
161 tabSeparator.setHeight(new Extent(12));
162 return tabSeparator;
163 }
164
165 /**
166 * Adds a horizontal line to the page content.
167 */
168 protected void addHorizontalLine() {
169 Column horizontalLine = new Column();
170 horizontalLine.setInsets(new Insets(10, 0, 10, 0));
171 Column c = new Column();
172 c.setBackground(Color.DARKGRAY);
173 c.setInsets(new Insets(0, 1, 0, 0));
174 horizontalLine.add(c);
175 add(horizontalLine);
176 }
177
178 /**
179 * Adds a headline to the page content.
180 *
181 * @param text The headline text.
182 */
183 protected void addHeadline(String text) {
184 Row headline = new Row();
185 headline.setInsets(new Insets(10, 10, 0, 0));
186 Label title = new Label(text);
187 title.setFont(new Font(Style.fontTypeface, Font.ITALIC | Font.UNDERLINE, new Extent(13)));
188 title.setLineWrap(false);
189 headline.add(title);
190 add(headline);
191 }
192
193 public abstract boolean equals(Object obj);
194
195 }