KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > forms > AbstractMultiFormDispatchForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20
21 package com.sslexplorer.core.forms;
22
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import org.apache.struts.action.ActionErrors;
29 import org.apache.struts.action.ActionMapping;
30
31 import com.sslexplorer.core.DefaultPanel;
32 import com.sslexplorer.core.Panel;
33 import com.sslexplorer.core.PanelManager;
34 import com.sslexplorer.core.actions.AbstractMultiFormDispatchAction.SubActionWrapper;
35 import com.sslexplorer.tabs.TabModel;
36
37 public abstract class AbstractMultiFormDispatchForm extends CoreForm implements TabModel {
38     private Collection JavaDoc<SubActionWrapper> subActionWrappers_;
39     private List JavaDoc<Panel> panels_;
40     private String JavaDoc selectedTab_;
41     private String JavaDoc subForm_;
42     private final int placement_;
43
44     public AbstractMultiFormDispatchForm(int placement) {
45         placement_ = placement;
46     }
47
48     public void init(Collection JavaDoc<SubActionWrapper> subActionWrappers, ActionMapping mapping, HttpServletRequest JavaDoc request) {
49         subActionWrappers_ = subActionWrappers;
50     }
51
52     public void setSubForm(String JavaDoc subForm) {
53         subForm_ = subForm;
54     }
55
56     public String JavaDoc getSubForm() {
57         return subForm_;
58     }
59     
60     public boolean isSubFormEmpty () {
61         return subForm_ == null || subForm_.length() == 0;
62     }
63
64     void resetForms(HttpServletRequest JavaDoc request) {
65         if (subActionWrappers_ != null) {
66             for (SubActionWrapper wrapper : subActionWrappers_)
67                 wrapper.getForm().reset(wrapper.getMapping(), request);
68         }
69     }
70
71     public String JavaDoc getSelectedTab() {
72         return selectedTab_;
73     }
74
75     public int getTabCount() {
76         return panels_.size();
77     }
78
79     public String JavaDoc getTabBundle(int idx) {
80         return ((Panel) panels_.get(idx)).getBundle();
81     }
82
83     public String JavaDoc getTabName(int idx) {
84         return ((Panel) panels_.get(idx)).getId();
85     }
86
87     public String JavaDoc getTabTitle(int idx) {
88         return null;
89     }
90
91     public void setSelectedTab(String JavaDoc selectedTab) {
92         selectedTab_ = selectedTab;
93     }
94
95     public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest JavaDoc request) {
96         panels_ = getPannels(request);
97         resetForms(request);
98     }
99
100     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
101         ActionErrors allActionErrors = new ActionErrors();
102         if (subActionWrappers_ != null) {
103             for (SubActionWrapper wrapper : subActionWrappers_) {
104                 ActionErrors actionErrors = wrapper.getForm().validate(mapping, request);
105                 if (null != actionErrors)
106                     allActionErrors.add(actionErrors);
107             }
108         }
109         return allActionErrors;
110     }
111     
112     public List JavaDoc<Panel> getPannels(HttpServletRequest JavaDoc request){
113         return PanelManager.getInstance().getPanels(placement_, request, null, DefaultPanel.MAIN_LAYOUT);
114     }
115 }
Popular Tags