001/**
002 * Copyright 2005-2015 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 */
016package org.kuali.rice.krad.demo.uif.components;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.kuali.rice.krad.demo.uif.form.KradSampleAppForm;
022import org.kuali.rice.krad.uif.component.Component;
023import org.kuali.rice.krad.uif.container.Group;
024import org.kuali.rice.krad.uif.container.TabGroup;
025import org.kuali.rice.krad.uif.element.ContentElementBase;
026import org.kuali.rice.krad.uif.field.FieldGroup;
027import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
028import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
029import org.kuali.rice.krad.uif.widget.SyntaxHighlighter;
030
031/**
032 * The ComponentExhibit component is used to display demostrations of various components along with their source code
033 * and documentation
034 *
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037public class ComponentExhibit extends ContentElementBase {
038
039    private List<Group> demoGroups;
040    private List<String> demoSourceCode;
041    private List<String> additionalDemoSourceCode1 = new ArrayList<String>();
042    private List<String> additionalDemoSourceCode2 = new ArrayList<String>();
043    private SyntaxHighlighter sourceCodeViewer;
044    private SyntaxHighlighter additionalSourceCodeViewer1;
045    private SyntaxHighlighter additionalSourceCodeViewer2;
046    private FieldGroup docLinkFields;
047    private TabGroup tabGroup;
048
049    /**
050     * Setup the tabGroup with the demoGroups and setup the sourceCodeViewer
051     *
052     * @see Component#performInitialization(org.kuali.rice.krad.uif.view.View, Object)
053     */
054    @Override
055    public void performInitialization(Object model) {
056        //Setup tabGroup
057        List<Component> tabItems = new ArrayList<Component>();
058        tabItems.addAll(tabGroup.getItems());
059        tabItems.addAll(demoGroups);
060        tabGroup.setItems(tabItems);
061
062        //populate the currently selected example
063        int currentIndice = 0;
064        if (model instanceof KradSampleAppForm) {
065            KradSampleAppForm kradSampleAppForm = (KradSampleAppForm) model;
066            if (kradSampleAppForm.getCurrentExampleIndex() != null) {
067                currentIndice = Integer.parseInt(kradSampleAppForm.getCurrentExampleIndex());
068            }
069            String id =  demoGroups.get(currentIndice).getId();
070            tabGroup.setDefaultActiveTabId(id);
071        }
072
073        //source code viewer setup
074        if(demoSourceCode != null && !demoSourceCode.isEmpty() && currentIndice < demoSourceCode.size()){
075            sourceCodeViewer.setSourceCode(demoSourceCode.get(currentIndice));
076        }
077
078        if(additionalDemoSourceCode1 != null && !additionalDemoSourceCode1.isEmpty() && currentIndice < additionalDemoSourceCode1.size()
079                && additionalDemoSourceCode1.get(currentIndice) != null){
080            additionalSourceCodeViewer1.setSourceCode(additionalDemoSourceCode1.get(currentIndice));
081        }
082
083        if(additionalDemoSourceCode2 != null && !additionalDemoSourceCode2.isEmpty() && currentIndice < additionalDemoSourceCode2.size()
084                        && additionalDemoSourceCode2.get(currentIndice) != null){
085            additionalSourceCodeViewer2.setSourceCode(additionalDemoSourceCode2.get(currentIndice));
086        }
087    }
088
089    /**
090     * Get the demoGroups demonstrating the component's features
091     *
092     * @return the demoGroups
093     */
094    @ViewLifecycleRestriction
095    public List<Group> getDemoGroups() {
096        return demoGroups;
097    }
098
099    /**
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}