001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.panelpositioned;
035:
036: import javax.faces.component.UIComponent;
037: import javax.faces.context.FacesContext;
038: import java.io.Serializable;
039: import java.util.ArrayList;
040: import java.util.HashMap;
041: import java.util.List;
042: import java.util.Map;
043:
044: /**
045: * Used to track changes to positioned panel instances
046: */
047: public class PanelPositionedModel implements Serializable {
048:
049: private List column;
050: private Map idIndex = new HashMap();
051: private int max = 0;
052:
053: public static PanelPositionedModel build() {
054:
055: PanelPositionedModel result = new PanelPositionedModel();
056:
057: return result;
058: }
059:
060: public static PanelPositionedModel resetInstance(
061: FacesContext context, UIComponent component) {
062: Map sessionMap = context.getExternalContext().getSessionMap();
063:
064: PanelPositionedModel result = build();
065: sessionMap.put(getName(context, component), result);
066:
067: return result;
068: }
069:
070: private static String getName(FacesContext context,
071: UIComponent component) {
072: return PanelPositionedModel.class.getName() + ":"
073: + component.getClientId(context);
074: }
075:
076: public static PanelPositionedModel getInstance(
077: FacesContext context, UIComponent component) {
078: Map sessionMap = context.getExternalContext().getSessionMap();
079: PanelPositionedModel result = (PanelPositionedModel) sessionMap
080: .get(getName(context, component));
081: return result;
082: }
083:
084: private PanelPositionedModel() {
085: this .column = new ArrayList();
086: }
087:
088: public void setIndex(String id, int index) {
089: idIndex.put(id, new Integer(index));
090: }
091:
092: public int getIndex(String id) {
093: Integer I = (Integer) idIndex.get(id);
094: if (I != null) {
095: return I.intValue();
096: }
097: return -1;
098:
099: }
100:
101: public int size() {
102: return this.column.size();
103: }
104:
105: }
|