001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: PortletTitleBarEventImpl.java 6385 2007-10-25 14:02:26Z wehrens $
004: */
005: package org.gridsphere.layout.event.impl;
006:
007: import org.gridsphere.layout.PortletComponent;
008: import org.gridsphere.layout.PortletTitleBar;
009: import org.gridsphere.layout.event.ComponentAction;
010: import org.gridsphere.layout.event.PortletTitleBarEvent;
011: import org.gridsphere.portlet.impl.SportletProperties;
012: import org.gridsphere.portletcontainer.GridSphereEvent;
013:
014: import javax.portlet.PortletMode;
015: import javax.portlet.WindowState;
016: import javax.servlet.http.HttpServletRequest;
017:
018: /**
019: * A <code>PortletTitleBarEventImpl</code> is the concrete implementation of
020: * <code>PortletTitleBarEvent</code>
021: */
022: public class PortletTitleBarEventImpl implements PortletTitleBarEvent {
023:
024: private ComponentAction action = null;
025: private int id;
026: private PortletTitleBar titleBar = null;
027: private boolean hasStateAction = false;
028: private boolean hasModeAction = false;
029: private PortletMode portletMode;
030: private WindowState windowState;
031:
032: /**
033: * Constructs an instance of a PortletTitleBarEventImpl from a general
034: * portal event and the portlet title bar component id
035: *
036: * @param titleBar the portlet title bar
037: * @param event the GridSphereEvent
038: * @param id the portlet title bar component id
039: */
040: public PortletTitleBarEventImpl(PortletTitleBar titleBar,
041: GridSphereEvent event, int id) {
042: this .titleBar = titleBar;
043: HttpServletRequest request = event.getHttpServletRequest();
044: this .id = id;
045: String pMode = request
046: .getParameter(SportletProperties.PORTLET_MODE);
047: if (pMode != null) {
048: action = PortletTitleBarEvent.TitleBarAction.MODE_MODIFY;
049: hasModeAction = true;
050: try {
051: portletMode = new PortletMode(pMode);
052: } catch (Exception e) {
053: portletMode = PortletMode.VIEW;
054: }
055: }
056: String wState = request
057: .getParameter(SportletProperties.PORTLET_WINDOW);
058: if (wState != null) {
059: action = PortletTitleBarEvent.TitleBarAction.WINDOW_MODIFY;
060: hasStateAction = true;
061: if (wState != null) {
062: try {
063: windowState = new WindowState(wState);
064: } catch (Exception e) {
065: windowState = WindowState.NORMAL;
066: }
067: }
068: }
069: }
070:
071: public boolean hasAction() {
072: return (action != null);
073: }
074:
075: /**
076: * Returns the portlet title bar event action
077: *
078: * @return the portlet title bar event action
079: */
080: public ComponentAction getAction() {
081: return action;
082: }
083:
084: /**
085: * Returns the portlet title bar mode
086: *
087: * @return mode the portlet title bar mode
088: */
089: public PortletMode getMode() {
090: return portletMode;
091: }
092:
093: /**
094: * Returns the portlet title bar window state
095: *
096: * @return the portlet title bar window state
097: */
098: public WindowState getState() {
099: return windowState;
100: }
101:
102: /**
103: * Returns true if this title bar event signals a window state change
104: *
105: * @return true if this title bar event signals a window state change
106: */
107: public boolean hasWindowStateAction() {
108: return hasStateAction;
109: }
110:
111: /**
112: * Returns true if this title bar event signals a portlet mode change
113: *
114: * @return true if this title bar event signals a portlet mode change
115: */
116: public boolean hasPortletModeAction() {
117: return hasModeAction;
118: }
119:
120: public PortletComponent getPortletComponent() {
121: return titleBar;
122: }
123:
124: /**
125: * Returns the portlet title bar component id
126: *
127: * @return the portlet title bar component id
128: */
129: public int getID() {
130: return id;
131: }
132:
133: }
|