001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.providers.window.util;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017: import java.util.Map;
018: import java.util.HashMap;
019:
020: import com.sun.portal.container.WindowState;
021: import com.sun.portal.container.ChannelMode;
022:
023: import com.sun.portal.desktop.util.Integers;
024: import com.sun.portal.providers.containers.ProviderWindowStates;
025:
026: public class ProviderRules {
027:
028: private static final Map _windowStateMap = getWindowStateMap();
029: private static final Map _windowStateReverseMap = getWindowStateReverseMap();
030:
031: private static List channelModeVHE = new ArrayList();
032: private static List channelModeVH = new ArrayList();
033: private static List windowStateMN = new ArrayList();
034: private static List windowStateALL = new ArrayList();
035:
036: static {
037: channelModeVHE.add(ChannelMode.VIEW);
038: channelModeVHE.add(ChannelMode.EDIT);
039: channelModeVHE.add(ChannelMode.HELP);
040:
041: channelModeVH.add(ChannelMode.VIEW);
042: channelModeVH.add(ChannelMode.HELP);
043:
044: // A list containing the MAX window state, to be used as
045: // allowable window state when in HELP or EDIT mode.
046: windowStateMN.add(WindowState.MAXIMIZED);
047: windowStateMN.add(WindowState.NORMAL);
048:
049: windowStateALL.add(WindowState.NORMAL);
050: windowStateALL.add(WindowState.MAXIMIZED);
051: windowStateALL.add(WindowState.MINIMIZED);
052:
053: }
054:
055: private static Map getWindowStateMap() {
056: Map _windowStateMap = new HashMap();
057:
058: _windowStateMap.put(
059: Integers.get(ProviderWindowStates.MINIMIZE),
060: WindowState.MINIMIZED);
061: _windowStateMap.put(
062: Integers.get(ProviderWindowStates.MAXIMIZE),
063: WindowState.MAXIMIZED);
064: _windowStateMap.put(Integers.get(ProviderWindowStates.NORMAL),
065: WindowState.NORMAL);
066: return _windowStateMap;
067:
068: }
069:
070: private static Map getWindowStateReverseMap() {
071:
072: Map _windowStateReverseMap = new HashMap();
073: _windowStateReverseMap.put(WindowState.MINIMIZED, Integers
074: .get(ProviderWindowStates.MINIMIZE));
075: _windowStateReverseMap.put(WindowState.MAXIMIZED, Integers
076: .get(ProviderWindowStates.MAXIMIZE));
077: _windowStateReverseMap.put(WindowState.NORMAL, Integers
078: .get(ProviderWindowStates.NORMAL));
079:
080: return _windowStateReverseMap;
081: }
082:
083: public static List getAllowableChannelModes(ChannelMode mode,
084: boolean authless) {
085:
086: if (mode == null) {
087: throw new IllegalArgumentException(
088: "mode passed is null in getAllowableChannelModes.");
089: }
090: if (authless) {
091: if (mode.equals(ChannelMode.EDIT)) {
092: //
093: // should never be here, as authless is not allowed
094: // to be in edit mode.
095: // TODO: change to assertion.
096: //throw new RuntimeException(
097: //"Authless should not be in edit mode ever.");
098: throw new AssertionError(
099: "Authless should not be in edit mode ever.");
100: }
101: //
102: // Authless user can't change to EDIT mode.
103: //
104: return channelModeVH;
105: } else {
106: // A list containing the VIEW mode and EDIT mode and HELP mode
107: // to be used as allowable modes.
108: return channelModeVHE;
109: }
110: }
111:
112: //rama
113: public static List getDefaultAllowableWindowStates(ChannelMode mode) {
114:
115: if (mode == null) {
116: throw new RuntimeException(
117: "mode passed is null in getAllowableWindowStates.");
118: }
119: if (mode.equals(ChannelMode.VIEW)) {
120: return windowStateALL;
121: } else if (mode.equals(ChannelMode.EDIT)) {
122: return windowStateMN;
123: } else if (mode.equals(ChannelMode.HELP)) {
124: return windowStateMN;
125: }
126:
127: return null;
128:
129: }
130:
131: /**
132: * Validate window state for the channelMode passed in. For Edit and
133: * Help mode, window state minimized is not allowed.
134: */
135: public static boolean validateWindowStateChange(
136: ChannelMode channelMode, WindowState windowState) {
137: boolean validState = true;
138:
139: if (channelMode == null || windowState == null) {
140: return true;
141: }
142:
143: if ((channelMode.equals(ChannelMode.EDIT) || channelMode
144: .equals(ChannelMode.HELP))) {
145: if (windowState.equals(WindowState.MINIMIZED)) {
146: validState = false;
147: }
148: }
149: return validState;
150: }
151:
152: /**
153: * Convert the window state representation used by the provider layer to
154: * the representation understood by the container layer
155: */
156: public static List mapToStandards(int[] portalWindowStates) {
157: List newList = new ArrayList();
158: for (int i = 0; portalWindowStates != null
159: && i < portalWindowStates.length; i++) {
160: WindowState winState = (WindowState) _windowStateMap
161: .get(Integers.get(portalWindowStates[i]));
162: if (winState != null) {
163: newList.add(winState);
164: }
165: }
166: return newList;
167:
168: }
169:
170: /**
171: * Convert the window state representation used by the provider layer to
172: * the representation understood by the container layer
173: */
174: public static WindowState mapToStandards(int portalWindowState) {
175: WindowState winState = (WindowState) _windowStateMap
176: .get(Integers.get(portalWindowState));
177: return winState;
178: }
179:
180: /**
181: * Convert the window state representation used by the container layer to
182: * the representation understood by the provider layer
183: */
184: public static int mapToProvider(WindowState windowState) {
185: int winState = ((Integer) _windowStateReverseMap
186: .get(windowState)).intValue();
187: return winState;
188: }
189:
190: // rama
191: public static WindowState getDefaultWindowState(
192: ChannelMode channelMode) {
193: if (ChannelMode.VIEW.equals(channelMode)) {
194: return WindowState.NORMAL;
195: } else if (ChannelMode.HELP.equals(channelMode)) {
196: return WindowState.MAXIMIZED;
197: }
198: if (ChannelMode.EDIT.equals(channelMode)) {
199: return WindowState.MAXIMIZED;
200: }
201: return WindowState.NORMAL;
202: }
203: }
|