001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.example.common.framework.context;
016:
017: import java.io.Serializable;
018: import org.araneaframework.Widget;
019:
020: /**
021: * A context consisting of Widgets that could be switched through different
022: * requests. Default page index is 0. <code>submit()</code>,
023: * <code>cancel()</code> and all <code>gotoXXX()</code> methods invoke all
024: * event listeners with respective method.
025: *
026: * @see org.araneaframework.example.common.framework.container.StandardWizardWidget
027: * @author Rein Raudjärv <reinra@ut.ee>
028: */
029: public interface WizardContext {
030:
031: /*
032: * Modify pages
033: */
034:
035: /**
036: * Adds new page with specific index (current page indexes are modified
037: * respectively). Wizard must be initialized before adding pages to it.
038: *
039: * @param index
040: * page index.
041: * @param page
042: * page.
043: * @throws Exception
044: */
045: void addPage(int index, Widget page) throws Exception;
046:
047: /**
048: * Adds new page as last element. Wizard must be initialized before adding
049: * pages to it.
050: *
051: * @param page
052: * page.
053: * @throws Exception
054: */
055: void addPage(Widget page) throws Exception;
056:
057: /**
058: * Removes a page. Next (previous if this was the last one) page will be
059: * selected.
060: *
061: * @param page
062: * page.
063: * @throws Exception
064: */
065: void removePage(Widget page) throws Exception;
066:
067: /**
068: * Removes a page. Next (previous if this was the last one) page will be
069: * selected.
070: *
071: * @param index
072: * page index.
073: * @throws Exception
074: */
075: void removePage(int index) throws Exception;
076:
077: /**
078: * Removes all pages. Page index will be reset to 0.
079: *
080: * @throws Exception
081: */
082: void clearPages() throws Exception;
083:
084: /*
085: * Goto page
086: */
087:
088: /**
089: * Switch to the next page.
090: */
091: void gotoNext();
092:
093: /**
094: * Switch to the previous page.
095: */
096: void gotoPrevious();
097:
098: /**
099: * Switch to the first page.
100: */
101: void gotoFirst();
102:
103: /**
104: * Switch to the last page.
105: */
106: void gotoLast();
107:
108: /**
109: * Switch to the specified page.
110: *
111: * @param page
112: * page.
113: */
114: void gotoPage(Widget page);
115:
116: /**
117: * Switch to a page with specified index.
118: *
119: * @param index
120: * page index.
121: */
122: void gotoPage(int index);
123:
124: /*
125: * Read only methods
126: */
127:
128: /**
129: * Returns a page with specified index.
130: *
131: * @param index
132: * page index.
133: * @return page with specified index.
134: */
135: Widget getPage(int index);
136:
137: /**
138: * Returns all pages.
139: *
140: * @return all pages.
141: */
142: Widget[] getAllPages();
143:
144: /**
145: * Returns an index of specified page.
146: *
147: * @param page
148: * page.
149: * @return page index.
150: */
151: int getIndexOfPage(Widget page);
152:
153: /**
154: * Count all pages.
155: *
156: * @return page count.
157: */
158: int countPages();
159:
160: /**
161: * Returns whether the specified page has been added.
162: *
163: * @param page
164: * page.
165: * @return whether the specified page has been added.
166: */
167: boolean containsPage(Widget page);
168:
169: /**
170: * Returns whether the specified index match the page index bounds.
171: *
172: * @param index
173: * page index.
174: * @return whether the specified index match the page index bounds.
175: */
176: boolean containsIndex(int index);
177:
178: /**
179: * Returns the index of current page.
180: *
181: * @return page index.
182: */
183: int getCurrentPageIndex();
184:
185: /**
186: * Returns the current page.
187: *
188: * @return page.
189: */
190: Widget getCurrentPage();
191:
192: /*
193: * Submit & cancel
194: */
195:
196: /**
197: * Calls onSubmit() on eventListeners.
198: */
199: void submit();
200:
201: /**
202: * Calls onCancel() on eventListeners.
203: */
204: void cancel();
205:
206: /*
207: * Event listeners
208: */
209:
210: /**
211: * Adds new event listener.
212: *
213: * @param listener
214: * listener.
215: */
216: void addEventListener(EventListener listener);
217:
218: /**
219: * Removes a specified event listener.
220: *
221: * @param listener
222: * listener.
223: */
224: void removeEventListener(EventListener listener);
225:
226: /**
227: * Removes all event listeners.
228: */
229: void clearEventListeners();
230:
231: /**
232: * The event listener for providing callbacks <code>onGoto(Widget page)</code>,
233: * <code>onSubmit</code> and <code>onCancel</code>.
234: * <code>onGoto(Widget page)</code> gets called when <code>gotoXXX()</code>
235: * is invoked or current page index is modified due to removing a page.
236: * <code>onSubmit</code> gets called when <code>submit()</code> is
237: * invoked. <code>onCancel</code> gets called when <code>cancel()</code>
238: * is invoked.
239: */
240: interface EventListener extends Serializable {
241: /**
242: * Callback handling a change of current page.
243: *
244: * @param page
245: * the page got activated.
246: */
247: void onGoto(Widget page) throws Exception;
248:
249: /**
250: * Callback handling a <code>submit()</code> call.
251: */
252: void onSubmit() throws Exception;
253:
254: /**
255: * Callback handling a <code>cancel()</code> call.
256: */
257: void onCancel() throws Exception;
258: }
259: }
|