KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > wizards > forms > ApplicationShortcutWizardApplicationForm


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 package com.sslexplorer.applications.wizards.forms;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 import com.sslexplorer.applications.ApplicationsPlugin;
32 import com.sslexplorer.extensions.ExtensionBundle;
33 import com.sslexplorer.extensions.ExtensionDescriptor;
34 import com.sslexplorer.extensions.ExtensionBundle.ExtensionBundleStatus;
35 import com.sslexplorer.extensions.store.ExtensionStore;
36 import com.sslexplorer.wizard.AbstractWizardSequence;
37 import com.sslexplorer.wizard.forms.DefaultWizardForm;
38
39 /**
40  * Extension of a {@link com.sslexplorer.wizard.forms.DefaultWizardForm} that
41  * allows an administrator to select the application to create the shortcut for.
42  *
43  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
44  */

45 public class ApplicationShortcutWizardApplicationForm extends DefaultWizardForm {
46
47     final static Log log = LogFactory.getLog(ApplicationShortcutWizardApplicationForm.class);
48     
49     /**
50      * Sequence attribute storing the ID of the selected application
51      */

52     public final static String JavaDoc ATTR_SELECTED_APPLICATION = "selectedApplication";
53
54     // Privater instance variables
55

56     private List JavaDoc availableApplications;
57     private String JavaDoc selectedApplication;
58
59     /**
60      * Constructor
61      */

62     public ApplicationShortcutWizardApplicationForm() {
63         super(true, false, "/WEB-INF/jsp/content/applications/applicationShortcutWizard/application.jspf", "resourceName", true,
64             false, "applicationShortcutApplication", ApplicationsPlugin.MESSAGE_RESOURCES_KEY, "applicationShortcutWizard.applicationShortcutApplication", 1);
65     }
66
67     /**
68      * Get Id of the selected application extension
69      *
70      * @return selected application extension
71      */

72     public String JavaDoc getSelectedApplication() {
73         return selectedApplication;
74     }
75
76     /**
77      * Set Id of the selected application extension
78      *
79      * @param selectedApplication selected application
80      */

81     public void setSelectedApplication(String JavaDoc selectedApplication) {
82         this.selectedApplication = selectedApplication;
83     }
84
85     /**
86      * Get a list of {@link ExtensionDescriptor} objects for
87      * all available application extensions
88      *
89      * @return list of available application extensions
90      */

91     public List JavaDoc getAvailableApplications() {
92         return availableApplications;
93     }
94
95     /**
96      * Get a list of {@link ExtensionDescriptor} objects for
97      * all available application extensions
98      *
99      * @param availableApplications list of available application extensions
100      */

101     public void setParameterItems(List JavaDoc availableApplications) {
102         this.availableApplications = availableApplications;
103     }
104
105     /* (non-Javadoc)
106      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence, javax.servlet.http.HttpServletRequest)
107      */

108     public void init(AbstractWizardSequence wizardSequence, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
109         super.init(wizardSequence, request);
110         availableApplications = new ArrayList JavaDoc();
111         selectedApplication = (String JavaDoc)wizardSequence.getAttribute(ATTR_SELECTED_APPLICATION, null);
112         for (Iterator JavaDoc i = ExtensionStore.getInstance().getAllAvailableExtensionBundles().iterator(); i.hasNext();) {
113             ExtensionBundle b = (ExtensionBundle)i.next();
114             if(b.getStatus() == ExtensionBundleStatus.ACTIVATED) {
115                 for(Iterator JavaDoc j = b.iterator(); j.hasNext(); ) {
116                     ExtensionDescriptor d = (ExtensionDescriptor)j.next();
117                     
118                     // Only show extensions if the type is not hidden and the extension itself is not hidden
119
if(!d.isHidden() && !d.getExtensionType().isHidden()) {
120                         availableApplications.add(d);
121                     }
122                 }
123             }
124         }
125         this.setNextAvailable(true);
126         if(selectedApplication == null && availableApplications.size() > 0) {
127             selectedApplication = ((ExtensionDescriptor)availableApplications.get(0)).getId();
128         } else if (availableApplications.isEmpty()) {
129                 this.setNextAvailable(false);
130         }
131     }
132
133     /* (non-Javadoc)
134      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
135      */

136     public void apply(AbstractWizardSequence sequence) throws Exception JavaDoc {
137         super.apply(sequence);
138         String JavaDoc oldVal = (String JavaDoc)sequence.putAttribute(ATTR_SELECTED_APPLICATION, selectedApplication);
139         if(!selectedApplication.equals(oldVal)) {
140             sequence.removeAttribute(ApplicationShortcutWizardAdditionalDetailsForm.ATTR_PARAMETERS);
141         }
142     }
143 }
144
Popular Tags