001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.demo.uif.components;
017    
018    import org.kuali.rice.krad.uif.component.Component;
019    import org.kuali.rice.krad.uif.container.Group;
020    import org.kuali.rice.krad.uif.container.TabGroup;
021    import org.kuali.rice.krad.uif.element.ContentElementBase;
022    import org.kuali.rice.krad.uif.field.FieldGroup;
023    import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
024    import org.kuali.rice.krad.uif.view.View;
025    import org.kuali.rice.krad.uif.widget.SyntaxHighlighter;
026    
027    import java.util.ArrayList;
028    import java.util.List;
029    
030    /**
031     * The ComponentExhibit component is used to display demostrations of various components along with their source code
032     * and documentation
033     *
034     * @author Kuali Rice Team (rice.collab@kuali.org)
035     */
036    public class ComponentExhibit extends ContentElementBase {
037    
038        private List<Group> demoGroups;
039        private List<String> demoSourceCode;
040        private List<String> additionalDemoSourceCode1 = new ArrayList<String>();
041        private List<String> additionalDemoSourceCode2 = new ArrayList<String>();
042        private SyntaxHighlighter sourceCodeViewer;
043        private SyntaxHighlighter additionalSourceCodeViewer1;
044        private SyntaxHighlighter additionalSourceCodeViewer2;
045        private FieldGroup docLinkFields;
046        private TabGroup tabGroup;
047    
048        /**
049         * Setup the tabGroup with the demoGroups and setup the sourceCodeViewer
050         *
051         * @see Component#performInitialization(org.kuali.rice.krad.uif.view.View, Object)
052         */
053        @Override
054        public void performInitialization(Object model) {
055            //Setup tabGroup
056            List<Component> tabItems = new ArrayList<Component>();
057            tabItems.addAll(tabGroup.getItems());
058            tabItems.addAll(demoGroups);
059            tabGroup.setItems(tabItems);
060    
061            //source code viewer setup
062            if(demoSourceCode != null && !demoSourceCode.isEmpty()){
063                sourceCodeViewer.setSourceCode(demoSourceCode.get(0));
064            }
065    
066            if(additionalDemoSourceCode1 != null && !additionalDemoSourceCode1.isEmpty()
067                    && additionalDemoSourceCode1.get(0) != null){
068                additionalSourceCodeViewer1.setSourceCode(additionalDemoSourceCode1.get(0));
069            }
070    
071            if(additionalDemoSourceCode2 != null && !additionalDemoSourceCode2.isEmpty()
072                            && additionalDemoSourceCode2.get(0) != null){
073                additionalSourceCodeViewer2.setSourceCode(additionalDemoSourceCode2.get(0));
074            }
075        }
076    
077        /**
078         * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
079         */
080        @Override
081        public List<Component> getComponentsForLifecycle() {
082            List<Component> components = new ArrayList<Component>();
083    
084            components.add(sourceCodeViewer);
085            components.add(additionalSourceCodeViewer1);
086            components.add(additionalSourceCodeViewer2);
087            components.add(tabGroup);
088    
089            return components;
090        }
091    
092        /**
093         * Get the demoGroups demonstrating the component's features
094         *
095         * @return the demoGroups
096         */
097        public List<Group> getDemoGroups() {
098            return demoGroups;
099        }
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    }