Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ControlCopy |
|
| 15.0;15 |
1 | /** | |
2 | * Copyright 2005-2011 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.core.api.uif; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import java.util.List; | |
20 | ||
21 | /** utility class for copying controls. */ | |
22 | final class ControlCopy { | |
23 | ||
24 | 0 | private ControlCopy() { |
25 | 0 | throw new IllegalArgumentException("do not call."); |
26 | } | |
27 | ||
28 | public static RemotableAbstractControl.Builder toBuilder(Control c) { | |
29 | 0 | if (c == null) { |
30 | 0 | throw new IllegalArgumentException("c is null"); |
31 | } | |
32 | ||
33 | 0 | if (c instanceof RemotableCheckboxGroup || c instanceof RemotableCheckboxGroup.Builder) return RemotableCheckboxGroup.Builder.create(((KeyLabeled)c).getKeyLabels()); |
34 | 0 | if (c instanceof RemotableHiddenInput || c instanceof RemotableHiddenInput.Builder) return RemotableHiddenInput.Builder.create(); |
35 | 0 | if (c instanceof RemotablePasswordInput || c instanceof RemotablePasswordInput.Builder){ |
36 | 0 | RemotablePasswordInput.Builder b = RemotablePasswordInput.Builder.create(); |
37 | 0 | b.setSize(((Sized) c).getSize()); |
38 | 0 | return b; |
39 | } | |
40 | 0 | if (c instanceof RemotableRadioButtonGroup || c instanceof RemotableRadioButtonGroup.Builder) return RemotableRadioButtonGroup.Builder.create(((KeyLabeled)c).getKeyLabels()); |
41 | 0 | if (c instanceof RemotableSelect) { |
42 | 0 | RemotableSelect sc = (RemotableSelect) c; |
43 | 0 | RemotableSelect.Builder b = RemotableSelect.Builder.create(sc.getKeyLabels()); |
44 | ||
45 | 0 | final List<RemotableSelectGroup.Builder> temp = new ArrayList<RemotableSelectGroup.Builder>(); |
46 | 0 | if (sc.getGroups() != null) { |
47 | 0 | for (RemotableSelectGroup attr : sc.getGroups()) { |
48 | 0 | temp.add(RemotableSelectGroup.Builder.create(attr.getKeyLabels(), attr.getLabel())); |
49 | } | |
50 | } | |
51 | ||
52 | 0 | b.setGroups(temp); |
53 | 0 | b.setSize(sc.getSize()); |
54 | 0 | b.setMultiple(sc.isMultiple()); |
55 | 0 | return b; |
56 | } | |
57 | 0 | if (c instanceof RemotableSelect.Builder) { |
58 | 0 | RemotableSelect.Builder sc = (RemotableSelect.Builder) c; |
59 | 0 | RemotableSelect.Builder b = RemotableSelect.Builder.create(sc.getKeyLabels()); |
60 | 0 | b.setGroups(sc.getGroups()); |
61 | 0 | b.setSize(sc.getSize()); |
62 | 0 | b.setMultiple(sc.isMultiple()); |
63 | 0 | return b; |
64 | } | |
65 | 0 | if(c instanceof RemotableTextarea || c instanceof RemotableTextarea.Builder) { |
66 | 0 | RemotableTextarea.Builder b = RemotableTextarea.Builder.create(); |
67 | 0 | b.setWatermark(((Watermarked) c).getWatermark()); |
68 | 0 | b.setCols(((RowsCols) c).getCols()); |
69 | 0 | b.setRows(((RowsCols) c).getRows()); |
70 | 0 | return b; |
71 | } | |
72 | 0 | if(c instanceof RemotableTextInput || c instanceof RemotableTextInput.Builder) { |
73 | 0 | RemotableTextInput.Builder b = RemotableTextInput.Builder.create(); |
74 | 0 | b.setWatermark(((Watermarked) c).getWatermark()); |
75 | 0 | b.setSize(((Sized) c).getSize()); |
76 | 0 | return b; |
77 | } | |
78 | 0 | throw new UnsupportedOperationException(c.getClass().getName() + " not supported"); |
79 | } | |
80 | } |