Clover Coverage Report - KS LUM 1.2.1-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Nov 2 2011 05:59:10 EST
../../../../../../../img/srcFileCovDistChart0.png 47% of files have more coverage
124   269   51   5.9
58   208   0.41   21
21     2.43  
1    
 
  OutlineNodeModel       Line # 24 124 0% 51 203 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.lum.common.client.lo;
17   
18    import java.util.ArrayList;
19    import java.util.List;
20   
21    import com.google.gwt.event.dom.client.ChangeHandler;
22   
23    public
 
24    class OutlineNodeModel<T> {
25    private ArrayList<OutlineNode<T>> outlineNodeList = new ArrayList<OutlineNode<T>>();
26   
27    private final ArrayList<ChangeHandler> changeHandlerList = new ArrayList<ChangeHandler>();
28   
29    private OutlineNode<T> currentNode;
30   
 
31  0 toggle public void clearNodes(){
32  0 outlineNodeList = new ArrayList<OutlineNode<T>>();
33    }
 
34  0 toggle public void setCurrentNode(OutlineNode<T> aNode) {
35  0 currentNode = aNode;
36    }
37   
 
38  0 toggle public void addChangeHandler(ChangeHandler ch) {
39  0 changeHandlerList.add(ch);
40    }
41   
 
42  0 toggle private void fireChangeEvents() {
43  0 for (ChangeHandler ch : changeHandlerList) {
44  0 ch.onChange(null);
45    }
46    }
47   
 
48  0 toggle public void moveUpCurrent() {
49  0 if (this.isMoveUpable() == false) {
50  0 return;
51    }
52  0 List<OutlineNode<T>> siblingList = getSiblingList();
53  0 int indexInSibling = siblingList.indexOf(currentNode);
54  0 OutlineNode<T> nextNodeInSibling = siblingList.get(indexInSibling - 1);
55   
56  0 List<OutlineNode<T>> childList = getChildList(currentNode);
57  0 childList.add(0, currentNode);// add parent
58  0 for (int i = 0; i < childList.size(); i++) {
59  0 OutlineNode<T> aNode = childList.get(i);
60  0 outlineNodeList.remove(aNode);
61    }
62   
63  0 int moveToIndex = outlineNodeList.indexOf(nextNodeInSibling);
64   
65  0 for (int i = 0; i < childList.size(); i++) {
66  0 OutlineNode<T> aNode = childList.get(i);
67  0 outlineNodeList.add(moveToIndex + i, aNode);
68    }
69  0 fireChangeEvents();
70    }
 
71  0 toggle public void moveDownCurrent() {
72  0 if (this.isMoveDownable() == false) {
73  0 return;
74    }
75  0 int index = outlineNodeList.indexOf(currentNode);
76  0 if (index == -1 || index == outlineNodeList.size() - 1) {
77  0 return;
78    }
79  0 List<OutlineNode<T>> siblingList = getSiblingList();
80  0 int indexInSibling = siblingList.indexOf(currentNode);
81  0 OutlineNode<T> nextNodeInSibling = siblingList.get(indexInSibling + 1);
82   
83  0 List<OutlineNode<T>> childList = getChildList(currentNode);
84  0 childList.add(0, currentNode);// add parent
85  0 for (int i = 0; i < childList.size(); i++) {
86  0 OutlineNode<T> aNode = childList.get(i);
87  0 outlineNodeList.remove(aNode);
88    }
89   
90  0 List<OutlineNode<T>> nextNodeChildList = getChildList(nextNodeInSibling);
91  0 int moveToIndex = -1;
92  0 if(nextNodeChildList.size() != 0){
93  0 moveToIndex = outlineNodeList.indexOf(nextNodeChildList.get(nextNodeChildList.size()-1));
94    }else{
95  0 moveToIndex =outlineNodeList.indexOf(nextNodeInSibling);
96    }
97   
98  0 for (int i = 0; i < childList.size(); i++) {
99  0 OutlineNode<T> aNode = childList.get(i);
100  0 outlineNodeList.add(moveToIndex + 1 + i, aNode);
101    }
102   
103  0 fireChangeEvents();
104    }
105   
 
106  0 toggle public void indentCurrent() {
107  0 if (this.isIndentable()) {
108  0 currentNode.indent();
109  0 fireChangeEvents();
110    }
111    }
112   
 
113  0 toggle public void outdentCurrent() {
114  0 if (this.isOutdentable()) {
115  0 List<OutlineNode<T>> childList = getChildList(currentNode);
116  0 childList.add(0, currentNode);// add parent
117  0 for(OutlineNode<T> aNode:childList){
118  0 aNode.outdent();
119    }
120  0 fireChangeEvents();
121    }
122    }
123   
 
124  0 toggle public void deleteCurrent() {
125    // if (this.isDeletable()) {
126  0 List<OutlineNode<T>> childList = getChildList(currentNode);
127  0 childList.add(0, currentNode);// add parent
128  0 for (int i = 0; i < childList.size(); i++) {
129  0 OutlineNode<T> aNode = childList.get(i);
130  0 outlineNodeList.remove(aNode);
131    }
132  0 fireChangeEvents();
133    // }
134    }
135   
 
136  0 toggle public void addPeer() {
137  0 int index = outlineNodeList.indexOf(currentNode);
138  0 OutlineNode<T> aNode = new OutlineNode<T>();
139    // aNode.setUserObject(new TextBox());
140  0 aNode.setIndentLevel(currentNode.getIndentLevel());
141  0 outlineNodeList.add(index + 1, aNode);
142  0 fireChangeEvents();
143    }
144   
 
145  0 toggle public void addChild() {
146  0 int index = outlineNodeList.indexOf(currentNode);
147  0 OutlineNode<T> aNode = new OutlineNode<T>();
148    // aNode.setUserObject(new TextBox());
149  0 aNode.setIndentLevel(currentNode.getIndentLevel() + 1);
150  0 outlineNodeList.add(index + 1, aNode);
151  0 fireChangeEvents();
152    }
153   
 
154  0 toggle public void addOutlineNode(OutlineNode<T> aNode) {
155  0 outlineNodeList.add(aNode);
156    }
157   
 
158  0 toggle @SuppressWarnings("unchecked")
159    public OutlineNode<T>[] toOutlineNodes() {
160  0 return outlineNodeList.toArray(new OutlineNode[outlineNodeList.size()]);
161    }
162   
 
163  0 toggle public List<OutlineNode<T>> getOutlineNodes() {
164  0 return outlineNodeList;
165    }
166   
 
167  0 toggle public List<OutlineNode<T>> getChildList(OutlineNode<T> aNode) {
168  0 int index = outlineNodeList.indexOf(aNode);
169  0 List<OutlineNode<T>> childList = new ArrayList<OutlineNode<T>>();
170  0 for (int i = index + 1; i < outlineNodeList.size(); i++) {
171  0 if (outlineNodeList.get(i).getIndentLevel() > aNode.getIndentLevel()) {
172  0 childList.add(outlineNodeList.get(i));
173    } else {
174  0 break;
175    }
176    }
177  0 return childList;
178    }
179   
 
180  0 toggle public List<OutlineNode<T>> getSiblingList() {
181  0 List<OutlineNode<T>> siblingList = new ArrayList<OutlineNode<T>>();
182  0 int index = outlineNodeList.indexOf(currentNode);
183    // if first level
184  0 if (currentNode.getIndentLevel() == 0) {
185  0 for (int i = 0; i < outlineNodeList.size(); i++) {
186  0 if (outlineNodeList.get(i).getIndentLevel() == 0) {
187  0 siblingList.add(outlineNodeList.get(i));
188    }
189    }
190  0 return siblingList;
191    }
192    // not first level
193    // get parent first and then get all Siblings
194  0 OutlineNode<T> parentNode = null;
195  0 for (int i = index - 1; i >= 0; i--) {
196  0 if (outlineNodeList.get(i).getIndentLevel() - currentNode.getIndentLevel() == -1) {
197  0 parentNode = outlineNodeList.get(i);
198  0 break;
199    }
200    }
201  0 int parentIndex = outlineNodeList.indexOf(parentNode);
202  0 for (int i = parentIndex + 1; i < outlineNodeList.size(); i++) {
203  0 if (outlineNodeList.get(i).getIndentLevel() - parentNode.getIndentLevel() == 1) {
204  0 siblingList.add(outlineNodeList.get(i));
205  0 } else if (outlineNodeList.get(i).getIndentLevel() == parentNode.getIndentLevel()) {
206  0 break;
207    }
208    }
209  0 return siblingList;
210    }
211   
 
212  0 toggle public boolean isIndentable() {
213  0 int index = outlineNodeList.indexOf(currentNode);
214  0 if (index == 0) {
215  0 return false;
216    }
217    // if current node is the only child
218   
219  0 List<OutlineNode<T>> siblingList = getSiblingList();
220  0 if (siblingList.size() == 1) {
221  0 return false;
222    }
223    //first kid
224  0 int indexInSiblings = siblingList.indexOf(currentNode);
225  0 if(indexInSiblings == 0){
226  0 return false;
227    }
228   
229  0 return true;
230    }
231   
 
232  0 toggle public boolean isOutdentable() {
233  0 if (currentNode.getIndentLevel() == 0) {// first level
234  0 return false;
235    }
236  0 return true;
237    }
238   
 
239  0 toggle public boolean isMoveUpable() {
240  0 List<OutlineNode<T>> list = getSiblingList();
241  0 if (list.size() == 1) { // only child
242  0 return false;
243    }
244  0 int index = list.indexOf(currentNode);
245  0 if (index == 0) {// first child
246  0 return false;
247    }
248  0 return true;
249    }
250   
 
251  0 toggle public boolean isMoveDownable() {
252  0 List<OutlineNode<T>> list = getSiblingList();
253  0 if (list.size() == 0) { // only child
254  0 return false;
255    }
256  0 int index = list.indexOf(currentNode);
257  0 if (index == list.size() - 1) {// last child
258  0 return false;
259    }
260  0 return true;
261    }
262   
 
263  0 toggle public boolean isDeletable() {
264    // if(outlineNodeList.size() == 1){
265    // return false;
266    // }
267  0 return true;
268    }
269    }