001: /* Copyright 2001-2004 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal;
007:
008: /**
009: * Events which may be arguments to the IChannel receiveEvent() method.
010: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
011: * @author andrew.petro@yale.edu
012: * @version $Revision: 36690 $ $Date: 2006-08-25 14:03:25 -0700 (Fri, 25 Aug 2006) $
013: */
014: public class PortalEvent {
015:
016: // framework-generated events
017:
018: public static final int SESSION_DONE = 1;
019: public static final int UNSUBSCRIBE = 2;
020:
021: // layout-generated events
022: public static final int EDIT_BUTTON_EVENT = 3;
023: public static final int HELP_BUTTON_EVENT = 4;
024: public static final int ABOUT_BUTTON_EVENT = 5;
025: public static final int DETACH_BUTTON_EVENT = 6;
026: public static final int MINIMIZE_EVENT = 7;
027: public static final int MAXIMIZE_EVENT = 8;
028:
029: /**
030: * The framework-generated event that is broadcast to
031: * channels that were used for a user session which is now ending.
032: * Typical usage is to trigger state cleanup in channels that are not
033: * user-session-scoped.
034: */
035: public static final PortalEvent SESSION_DONE_EVENT = new PortalEvent(
036: SESSION_DONE, "sessionDone",
037: PortalEventSource.FRAMEWORK_GENERATED);
038:
039: /**
040: * The framework-generated event that is sent to
041: * a channel when the user unsubscribes from that channel.
042: */
043: public static final PortalEvent UNSUBSCRIBE_EVENT = new PortalEvent(
044: UNSUBSCRIBE, "unsubscribe",
045: PortalEventSource.FRAMEWORK_GENERATED);
046:
047: /**
048: * The layout-generated event that is sent to
049: * a channel when the user actuates its edit control.
050: */
051: public static final PortalEvent EDIT_BUTTON = new PortalEvent(
052: EDIT_BUTTON_EVENT, "editButtonEvent",
053: PortalEventSource.LAYOUT_GENERATED);
054:
055: /**
056: * The layout-generated event that is sent to
057: * a channel when the user actuates its help control.
058: */
059: public static final PortalEvent HELP_BUTTON = new PortalEvent(
060: HELP_BUTTON_EVENT, "helpButtonEvent",
061: PortalEventSource.LAYOUT_GENERATED);
062:
063: /**
064: * The layout-generated event that is sent to
065: * a channel when the user actuates its about control.
066: */
067: public static final PortalEvent ABOUT_BUTTON = new PortalEvent(
068: ABOUT_BUTTON_EVENT, "aboutButtonEvent",
069: PortalEventSource.LAYOUT_GENERATED);
070:
071: /**
072: * The layout-generated event that is sent to
073: * a channel when the user actuates its detach control.
074: */
075: public static final PortalEvent DETACH_BUTTON = new PortalEvent(
076: DETACH_BUTTON_EVENT, "detachButtonEvent",
077: PortalEventSource.LAYOUT_GENERATED);
078:
079: /**
080: * The layout-generated event that is sent to
081: * a channel when the user actuates its minimize control.
082: */
083: public static final PortalEvent MINIMIZE = new PortalEvent(
084: MINIMIZE_EVENT, "minimizeEvent",
085: PortalEventSource.LAYOUT_GENERATED);
086:
087: /**
088: * The layout-generated event that is sent to
089: * a channel when the user actuates its maximize control.
090: */
091: public static final PortalEvent MAXIMIZE = new PortalEvent(
092: MAXIMIZE_EVENT, "maximizeEvent",
093: PortalEventSource.LAYOUT_GENERATED);
094:
095: /**
096: * Integer representation of an event. Must be one of the static integers
097: * declared in this class.
098: */
099: private final int eventNumber;
100:
101: /**
102: * String representation of the event.
103: */
104: private final String eventName;
105:
106: /**
107: * Source of the event -- curently either FRAMEWORK or LAYOUT.
108: */
109: private final PortalEventSource source;
110:
111: /**
112: * Constructor which translates from one of the integers representing a
113: * PortalEvent to the actual PortalEvent class.
114: * @param ev integer representing the event
115: * @deprecated instead reference one of the static singleton events.
116: */
117: public PortalEvent(int ev) {
118:
119: if (ev < 0 || ev > 8)
120: throw new IllegalArgumentException("The integer " + ev
121: + " does not identify a PortalEvent.");
122:
123: this .eventNumber = ev;
124:
125: final String[] eventNameArray = { "renderingDone",
126: "sessionDone", "unsubscribe", "editButtonEvent",
127: "helpButtonEvent", "aboutButtonEvent",
128: "detachButtonEvent", "minimizeEvent", "maximizeEvent", };
129:
130: this .eventName = eventNameArray[ev];
131:
132: if (ev < 3) {
133: this .source = PortalEventSource.FRAMEWORK_GENERATED;
134: } else {
135: this .source = PortalEventSource.LAYOUT_GENERATED;
136: }
137:
138: }
139:
140: /**
141: * Construct a PortalEvent instance from parameters.
142: * @param eventNumber - integer representation of event type
143: * @param eventName - String name of event
144: * @param source - source type of event
145: */
146: private PortalEvent(int eventNumber, String eventName,
147: PortalEventSource source) {
148: this .eventNumber = eventNumber;
149: this .eventName = eventName;
150: this .source = source;
151: }
152:
153: /**
154: * Get a String representing this event.
155: * @return a String representing this event.
156: */
157: public String getEventName() {
158: return this .eventName;
159: }
160:
161: /**
162: * Get an integer representing this event.
163: * @return an integer representing this event.
164: */
165: public int getEventNumber() {
166: return this .eventNumber;
167: }
168:
169: /**
170: * Get the source type of this event.
171: * @return the source type of this event.
172: */
173: public PortalEventSource getSource() {
174: return this .source;
175: }
176:
177: /**
178: * Two PortalEvents are equal if they have the same eventNumber.
179: * @param other - another object
180: * @return true if other is a PortalEvent with the same eventNumber,
181: * false otherwise
182: */
183: public boolean equals(Object other) {
184: if (other == null)
185: return false;
186: if (!(other instanceof PortalEvent))
187: return false;
188: PortalEvent otherEvent = (PortalEvent) other;
189:
190: if (otherEvent.eventNumber == this .eventNumber)
191: return true;
192:
193: return false;
194: }
195:
196: public String toString() {
197: return this.eventName;
198: }
199:
200: }
|