KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > config > TabsModel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site (http://www.enhydra.org/).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: TabsModel.java,v 1.1 2004/05/28 19:39:27 slobodan Exp $
22  */

23 package org.enhydra.barracuda.config;
24
25 import java.util.Arrays JavaDoc;
26
27 import org.enhydra.barracuda.core.comp.*;
28 import org.apache.log4j.*;
29
30 /**
31  * TabsModel - this model doesn't actually return any data,
32  * but instead processes directives to tell the template engine
33  * which tabs are actually visible.
34  */

35 public class TabsModel extends AbstractTemplateModel {
36
37     protected static final Logger logger = Logger.getLogger(TabsModel.class.getName());
38     
39     public final static String JavaDoc CUR_TAB = "CurrentTab";
40     
41     public final static String JavaDoc COMP_TAB_COMP = "CompTab_Comp";
42     public final static String JavaDoc COMP_TAB_MODEL = "CompTab_Model";
43     public final static String JavaDoc COMP_TAB_VIEW = "CompTab_View";
44     public final static String JavaDoc COMP_TAB_REND = "CompTab_Renderer";
45     public final static String JavaDoc DATA_TAB = "DataTab";
46     public final static String JavaDoc DOM_TAB = "DomTab";
47     public final static String JavaDoc EVENT_TAB = "EventTab";
48     public final static String JavaDoc FORMS_TAB = "FormsTab";
49     public final static String JavaDoc UTIL_TAB = "UtilTab";
50     public final static String JavaDoc VIEW_TAB = "ViewTab";
51     public final static String JavaDoc ABOUT_TAB = "AboutTab";
52     
53     public static String JavaDoc[] validTabs = new String JavaDoc[] {COMP_TAB_COMP, COMP_TAB_MODEL, COMP_TAB_VIEW, COMP_TAB_REND, DATA_TAB, DOM_TAB, EVENT_TAB, FORMS_TAB, UTIL_TAB, VIEW_TAB, ABOUT_TAB};
54     
55     protected BTemplate parent = null;
56     protected String JavaDoc curTab = null;
57
58     public TabsModel(BTemplate iparent) {
59         parent = iparent;
60         Arrays.sort(validTabs);
61     }
62
63     //register the model by name
64
public String JavaDoc getName() {
65         return "Tabs";
66     }
67
68     //set the current tab
69
public void setCurrentTab(String JavaDoc tabName) {
70         //make sure we're setting it to a valid tab
71
if (tabName==null) return;
72         if (tabName.equals(curTab)) return;
73         int pos = Arrays.binarySearch(validTabs, tabName);
74         if (pos<0 || pos>=validTabs.length || !validTabs[pos].equals(tabName)) return;
75         
76         //ok...
77
if (logger.isDebugEnabled()) logger.debug("Setting curTab = "+tabName);
78         curTab = tabName;
79         if (parent!=null) parent.invalidate();
80     }
81     
82     //process directives
83
public boolean processDirective(TemplateDirective td) {
84         if (td.getCommand().equals("Is_Visible")) {
85             String JavaDoc tab = td.getKeyName();
86             if (curTab==null) setCurrentTab(tab);
87             if (logger.isDebugEnabled()) logger.debug("Checking to see if we can show "+tab+" ("+(tab.equals(curTab) ? "yes" : "no")+")");
88             if (!tab.equals(curTab)) return false; //skip this tab
89
}
90         return true; //by default, allow all directives
91
}
92 }
Popular Tags