View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.components;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.rice.krad.demo.uif.form.KradSampleAppForm;
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.container.Group;
24  import org.kuali.rice.krad.uif.container.TabGroup;
25  import org.kuali.rice.krad.uif.element.ContentElementBase;
26  import org.kuali.rice.krad.uif.field.FieldGroup;
27  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
28  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
29  import org.kuali.rice.krad.uif.widget.SyntaxHighlighter;
30  
31  /**
32   * The ComponentExhibit component is used to display demostrations of various components along with their source code
33   * and documentation
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class ComponentExhibit extends ContentElementBase {
38  
39      private List<Group> demoGroups;
40      private List<String> demoSourceCode;
41      private List<String> additionalDemoSourceCode1 = new ArrayList<String>();
42      private List<String> additionalDemoSourceCode2 = new ArrayList<String>();
43      private SyntaxHighlighter sourceCodeViewer;
44      private SyntaxHighlighter additionalSourceCodeViewer1;
45      private SyntaxHighlighter additionalSourceCodeViewer2;
46      private FieldGroup docLinkFields;
47      private TabGroup tabGroup;
48  
49      /**
50       * Setup the tabGroup with the demoGroups and setup the sourceCodeViewer
51       *
52       * @see Component#performInitialization(org.kuali.rice.krad.uif.view.View, Object)
53       */
54      @Override
55      public void performInitialization(Object model) {
56          //Setup tabGroup
57          List<Component> tabItems = new ArrayList<Component>();
58          tabItems.addAll(tabGroup.getItems());
59          tabItems.addAll(demoGroups);
60          tabGroup.setItems(tabItems);
61  
62          //populate the currently selected example
63          int currentIndice = 0;
64          if (model instanceof KradSampleAppForm) {
65              KradSampleAppForm kradSampleAppForm = (KradSampleAppForm) model;
66              if (kradSampleAppForm.getCurrentExampleIndex() != null) {
67                  currentIndice = Integer.parseInt(kradSampleAppForm.getCurrentExampleIndex());
68              }
69              String id =  demoGroups.get(currentIndice).getId();
70              tabGroup.setDefaultActiveTabId(id);
71          }
72  
73          //source code viewer setup
74          if(demoSourceCode != null && !demoSourceCode.isEmpty() && currentIndice < demoSourceCode.size()){
75              sourceCodeViewer.setSourceCode(demoSourceCode.get(currentIndice));
76          }
77  
78          if(additionalDemoSourceCode1 != null && !additionalDemoSourceCode1.isEmpty() && currentIndice < additionalDemoSourceCode1.size()
79                  && additionalDemoSourceCode1.get(currentIndice) != null){
80              additionalSourceCodeViewer1.setSourceCode(additionalDemoSourceCode1.get(currentIndice));
81          }
82  
83          if(additionalDemoSourceCode2 != null && !additionalDemoSourceCode2.isEmpty() && currentIndice < additionalDemoSourceCode2.size()
84                          && additionalDemoSourceCode2.get(currentIndice) != null){
85              additionalSourceCodeViewer2.setSourceCode(additionalDemoSourceCode2.get(currentIndice));
86          }
87      }
88  
89      /**
90       * Get the demoGroups demonstrating the component's features
91       *
92       * @return the demoGroups
93       */
94      @ViewLifecycleRestriction
95      public List<Group> getDemoGroups() {
96          return demoGroups;
97      }
98  
99      /**
100      * Sets the demoGroups.  This SHOULD NOT be set by xml - use ComponentLibraryView's setDemoGroups.
101      *
102      * @param demoGroups
103      */
104     public void setDemoGroups(List<Group> demoGroups) {
105         this.demoGroups = demoGroups;
106     }
107 
108     /**
109      * Get the xml sourceCode for the demoGroups' features being demonstrated.
110      *
111      * @return the sourceCode
112      */
113     public List<String> getDemoSourceCode() {
114         return demoSourceCode;
115     }
116 
117     /**
118      * Sets the demoSourceCode. This SHOULD NOT be set by xml - ComponentLibraryView will automatically read the source.
119      *
120      * @param demoSourceCode
121      */
122     public void setDemoSourceCode(List<String> demoSourceCode) {
123         this.demoSourceCode = demoSourceCode;
124     }
125 
126     /**
127      * The SyntaxHighlighter component being used by the exhibit to show the demoSourceCode
128      *
129      * @return the SyntaxHighlighter component
130      */
131     public SyntaxHighlighter getSourceCodeViewer() {
132         return sourceCodeViewer;
133     }
134 
135     /**
136      * Set the SyntaxHighlighter sourceCodeViewer component
137      *
138      * @param sourceCodeViewer
139      */
140     public void setSourceCodeViewer(SyntaxHighlighter sourceCodeViewer) {
141         this.sourceCodeViewer = sourceCodeViewer;
142     }
143 
144     /**
145      * Get the FieldGroup that contains links to the documentation
146      * TODO not yet used
147      * @return the FieldGroup that contains documentation links
148      */
149     @ViewLifecycleRestriction
150     public FieldGroup getDocLinkFields() {
151         return docLinkFields;
152     }
153 
154     /**
155      * Sets the docLinkFields fieldGroup
156      * @param docLinkFields
157      */
158     public void setDocLinkFields(FieldGroup docLinkFields) {
159         this.docLinkFields = docLinkFields;
160     }
161 
162     /**
163      * Get the tabGroup used to display the demoGroups
164      *
165      * @return the tabGroup used to display the demoGroups
166      */
167     public TabGroup getTabGroup() {
168         return tabGroup;
169     }
170 
171     /**
172      * Set the tabGroup used to display the demoGroups
173      *
174      * @param tabGroup
175      */
176     public void setTabGroup(TabGroup tabGroup) {
177         this.tabGroup = tabGroup;
178     }
179 
180     public List<String> getAdditionalDemoSourceCode1() {
181         return additionalDemoSourceCode1;
182     }
183 
184     public void setAdditionalDemoSourceCode1(List<String> additionalDemoSourceCode1) {
185         this.additionalDemoSourceCode1 = additionalDemoSourceCode1;
186     }
187 
188     public List<String> getAdditionalDemoSourceCode2() {
189         return additionalDemoSourceCode2;
190     }
191 
192     public void setAdditionalDemoSourceCode2(List<String> additionalDemoSourceCode2) {
193         this.additionalDemoSourceCode2 = additionalDemoSourceCode2;
194     }
195 
196     public SyntaxHighlighter getAdditionalSourceCodeViewer1() {
197         return additionalSourceCodeViewer1;
198     }
199 
200     public void setAdditionalSourceCodeViewer1(SyntaxHighlighter additionalSourceCodeViewer1) {
201         this.additionalSourceCodeViewer1 = additionalSourceCodeViewer1;
202     }
203 
204     public SyntaxHighlighter getAdditionalSourceCodeViewer2() {
205         return additionalSourceCodeViewer2;
206     }
207 
208     public void setAdditionalSourceCodeViewer2(SyntaxHighlighter additionalSourceCodeViewer2) {
209         this.additionalSourceCodeViewer2 = additionalSourceCodeViewer2;
210     }
211 }