001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra 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 on
007: * the Enhydra web site (http://www.enhydra.org/).
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
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: TabsModel.java,v 1.1 2006-09-11 12:30:02 sinisa Exp $
022: */
023: package org.enhydra.barracuda.config;
024:
025: import java.util.Arrays;
026:
027: import org.barracudamvc.core.comp.*;
028: import org.apache.log4j.*;
029:
030: /**
031: * TabsModel - this model doesn't actually return any data,
032: * but instead processes directives to tell the template engine
033: * which tabs are actually visible.
034: */
035: public class TabsModel extends AbstractTemplateModel {
036:
037: protected static final Logger logger = Logger
038: .getLogger(TabsModel.class.getName());
039:
040: public final static String CUR_TAB = "CurrentTab";
041:
042: public final static String COMP_TAB_COMP = "CompTab_Comp";
043: public final static String COMP_TAB_MODEL = "CompTab_Model";
044: public final static String COMP_TAB_VIEW = "CompTab_View";
045: public final static String COMP_TAB_REND = "CompTab_Renderer";
046: public final static String DATA_TAB = "DataTab";
047: public final static String DOM_TAB = "DomTab";
048: public final static String EVENT_TAB = "EventTab";
049: public final static String FORMS_TAB = "FormsTab";
050: public final static String UTIL_TAB = "UtilTab";
051: public final static String VIEW_TAB = "ViewTab";
052: public final static String ABOUT_TAB = "AboutTab";
053:
054: public static String[] validTabs = new String[] { COMP_TAB_COMP,
055: COMP_TAB_MODEL, COMP_TAB_VIEW, COMP_TAB_REND, DATA_TAB,
056: DOM_TAB, EVENT_TAB, FORMS_TAB, UTIL_TAB, VIEW_TAB,
057: ABOUT_TAB };
058:
059: protected BTemplate parent = null;
060: protected String curTab = null;
061:
062: public TabsModel(BTemplate iparent) {
063: parent = iparent;
064: Arrays.sort(validTabs);
065: }
066:
067: //register the model by name
068: public String getName() {
069: return "Tabs";
070: }
071:
072: //set the current tab
073: public void setCurrentTab(String tabName) {
074: //make sure we're setting it to a valid tab
075: if (tabName == null)
076: return;
077: if (tabName.equals(curTab))
078: return;
079: int pos = Arrays.binarySearch(validTabs, tabName);
080: if (pos < 0 || pos >= validTabs.length
081: || !validTabs[pos].equals(tabName))
082: return;
083:
084: //ok...
085: if (logger.isDebugEnabled())
086: logger.debug("Setting curTab = " + tabName);
087: curTab = tabName;
088: if (parent != null)
089: parent.invalidate();
090: }
091:
092: //process directives
093: public boolean processDirective(TemplateDirective td) {
094: if (td.getCommand().equals("Is_Visible")) {
095: String tab = td.getKeyName();
096: if (curTab == null)
097: setCurrentTab(tab);
098: if (logger.isDebugEnabled())
099: logger.debug("Checking to see if we can show " + tab
100: + " (" + (tab.equals(curTab) ? "yes" : "no")
101: + ")");
102: if (!tab.equals(curTab))
103: return false; //skip this tab
104: }
105: return true; //by default, allow all directives
106: }
107: }
|