View Javadoc

1   /**
2    * Copyright 2005-2013 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 org.kuali.rice.krad.uif.component.Component;
19  import org.kuali.rice.krad.uif.container.Group;
20  import org.kuali.rice.krad.uif.container.TabGroup;
21  import org.kuali.rice.krad.uif.element.ContentElementBase;
22  import org.kuali.rice.krad.uif.field.FieldGroup;
23  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
24  import org.kuali.rice.krad.uif.view.View;
25  import org.kuali.rice.krad.uif.widget.SyntaxHighlighter;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * The ComponentExhibit component is used to display demostrations of various components along with their source code
32   * and documentation
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class ComponentExhibit extends ContentElementBase {
37  
38      private List<Group> demoGroups;
39      private List<String> demoSourceCode;
40      private List<String> additionalDemoSourceCode1 = new ArrayList<String>();
41      private List<String> additionalDemoSourceCode2 = new ArrayList<String>();
42      private SyntaxHighlighter sourceCodeViewer;
43      private SyntaxHighlighter additionalSourceCodeViewer1;
44      private SyntaxHighlighter additionalSourceCodeViewer2;
45      private FieldGroup docLinkFields;
46      private TabGroup tabGroup;
47  
48      /**
49       * Setup the tabGroup with the demoGroups and setup the sourceCodeViewer
50       *
51       * @see Component#performInitialization(org.kuali.rice.krad.uif.view.View, Object)
52       */
53      @Override
54      public void performInitialization(Object model) {
55          //Setup tabGroup
56          List<Component> tabItems = new ArrayList<Component>();
57          tabItems.addAll(tabGroup.getItems());
58          tabItems.addAll(demoGroups);
59          tabGroup.setItems(tabItems);
60  
61          //source code viewer setup
62          if(demoSourceCode != null && !demoSourceCode.isEmpty()){
63              sourceCodeViewer.setSourceCode(demoSourceCode.get(0));
64          }
65  
66          if(additionalDemoSourceCode1 != null && !additionalDemoSourceCode1.isEmpty()
67                  && additionalDemoSourceCode1.get(0) != null){
68              additionalSourceCodeViewer1.setSourceCode(additionalDemoSourceCode1.get(0));
69          }
70  
71          if(additionalDemoSourceCode2 != null && !additionalDemoSourceCode2.isEmpty()
72                          && additionalDemoSourceCode2.get(0) != null){
73              additionalSourceCodeViewer2.setSourceCode(additionalDemoSourceCode2.get(0));
74          }
75      }
76  
77      /**
78       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
79       */
80      @Override
81      public List<Component> getComponentsForLifecycle() {
82          List<Component> components = new ArrayList<Component>();
83  
84          components.add(sourceCodeViewer);
85          components.add(additionalSourceCodeViewer1);
86          components.add(additionalSourceCodeViewer2);
87          components.add(tabGroup);
88  
89          return components;
90      }
91  
92      /**
93       * Get the demoGroups demonstrating the component's features
94       *
95       * @return the demoGroups
96       */
97      public List<Group> getDemoGroups() {
98          return demoGroups;
99      }
100 
101     /**
102      * Sets the demoGroups.  This SHOULD NOT be set by xml - use ComponentLibraryView's setDemoGroups.
103      *
104      * @param demoGroups
105      */
106     public void setDemoGroups(List<Group> demoGroups) {
107         this.demoGroups = demoGroups;
108     }
109 
110     /**
111      * Get the xml sourceCode for the demoGroups' features being demonstrated.
112      *
113      * @return the sourceCode
114      */
115     public List<String> getDemoSourceCode() {
116         return demoSourceCode;
117     }
118 
119     /**
120      * Sets the demoSourceCode. This SHOULD NOT be set by xml - ComponentLibraryView will automatically read the source.
121      *
122      * @param demoSourceCode
123      */
124     public void setDemoSourceCode(List<String> demoSourceCode) {
125         this.demoSourceCode = demoSourceCode;
126     }
127 
128     /**
129      * The SyntaxHighlighter component being used by the exhibit to show the demoSourceCode
130      *
131      * @return the SyntaxHighlighter component
132      */
133     public SyntaxHighlighter getSourceCodeViewer() {
134         return sourceCodeViewer;
135     }
136 
137     /**
138      * Set the SyntaxHighlighter sourceCodeViewer component
139      *
140      * @param sourceCodeViewer
141      */
142     public void setSourceCodeViewer(SyntaxHighlighter sourceCodeViewer) {
143         this.sourceCodeViewer = sourceCodeViewer;
144     }
145 
146     /**
147      * Get the FieldGroup that contains links to the documentation
148      * TODO not yet used
149      * @return the FieldGroup that contains documentation links
150      */
151     public FieldGroup getDocLinkFields() {
152         return docLinkFields;
153     }
154 
155     /**
156      * Sets the docLinkFields fieldGroup
157      * @param docLinkFields
158      */
159     public void setDocLinkFields(FieldGroup docLinkFields) {
160         this.docLinkFields = docLinkFields;
161     }
162 
163     /**
164      * Get the tabGroup used to display the demoGroups
165      *
166      * @return the tabGroup used to display the demoGroups
167      */
168     public TabGroup getTabGroup() {
169         return tabGroup;
170     }
171 
172     /**
173      * Set the tabGroup used to display the demoGroups
174      *
175      * @param tabGroup
176      */
177     public void setTabGroup(TabGroup tabGroup) {
178         this.tabGroup = tabGroup;
179     }
180 
181     public List<String> getAdditionalDemoSourceCode1() {
182         return additionalDemoSourceCode1;
183     }
184 
185     public void setAdditionalDemoSourceCode1(List<String> additionalDemoSourceCode1) {
186         this.additionalDemoSourceCode1 = additionalDemoSourceCode1;
187     }
188 
189     public List<String> getAdditionalDemoSourceCode2() {
190         return additionalDemoSourceCode2;
191     }
192 
193     public void setAdditionalDemoSourceCode2(List<String> additionalDemoSourceCode2) {
194         this.additionalDemoSourceCode2 = additionalDemoSourceCode2;
195     }
196 
197     public SyntaxHighlighter getAdditionalSourceCodeViewer1() {
198         return additionalSourceCodeViewer1;
199     }
200 
201     public void setAdditionalSourceCodeViewer1(SyntaxHighlighter additionalSourceCodeViewer1) {
202         this.additionalSourceCodeViewer1 = additionalSourceCodeViewer1;
203     }
204 
205     public SyntaxHighlighter getAdditionalSourceCodeViewer2() {
206         return additionalSourceCodeViewer2;
207     }
208 
209     public void setAdditionalSourceCodeViewer2(SyntaxHighlighter additionalSourceCodeViewer2) {
210         this.additionalSourceCodeViewer2 = additionalSourceCodeViewer2;
211     }
212 
213     /**
214      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
215      */
216     @Override
217     protected <T> void copyProperties(T component) {
218         super.copyProperties(component);
219 
220         ComponentExhibit exhibitCopy = (ComponentExhibit) component;
221 
222         if (this.demoGroups != null) {
223             List<Group> demoGroupsCopy = new ArrayList<Group>();
224 
225             for (Group demoGroup : this.demoGroups) {
226                 demoGroupsCopy.add((Group) demoGroup.copy());
227             }
228             exhibitCopy.setDemoGroups(demoGroupsCopy);
229         }
230 
231         if (this.demoSourceCode != null) {
232             exhibitCopy.setDemoSourceCode(new ArrayList<String>(this.demoSourceCode));
233         }
234 
235         if (this.additionalDemoSourceCode1 != null) {
236             exhibitCopy.setAdditionalDemoSourceCode1(new ArrayList<String>(this.additionalDemoSourceCode1));
237         }
238 
239         if (this.additionalDemoSourceCode2 != null) {
240             exhibitCopy.setAdditionalDemoSourceCode2(new ArrayList<String>(this.additionalDemoSourceCode2));
241         }
242 
243         if (this.sourceCodeViewer != null) {
244             exhibitCopy.setSourceCodeViewer((SyntaxHighlighter) this.sourceCodeViewer.copy());
245         }
246 
247         if (this.additionalSourceCodeViewer1 != null) {
248             exhibitCopy.setAdditionalSourceCodeViewer1((SyntaxHighlighter) this.additionalSourceCodeViewer1.copy());
249         }
250 
251         if (this.additionalSourceCodeViewer2 != null) {
252             exhibitCopy.setAdditionalSourceCodeViewer2((SyntaxHighlighter) this.additionalSourceCodeViewer2.copy());
253         }
254 
255         if (this.docLinkFields != null) {
256             exhibitCopy.setDocLinkFields((FieldGroup) this.docLinkFields.copy());
257         }
258 
259         if (this.tabGroup != null) {
260             exhibitCopy.setTabGroup((TabGroup) this.tabGroup.copy());
261         }
262     }
263 }