View Javadoc
1   /**
2    * Copyright 2005-2015 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      private ControlCopy() {
25          throw new IllegalArgumentException("do not call.");
26      }
27  
28      public static RemotableAbstractControl.Builder toBuilder(RemotableControlContract c) {
29          if (c == null) {
30              throw new IllegalArgumentException("c is null");
31          }
32          if (c instanceof RemotableCheckbox || c instanceof RemotableCheckbox.Builder) return RemotableCheckbox.Builder.create();
33          if (c instanceof RemotableCheckboxGroup || c instanceof RemotableCheckboxGroup.Builder) return RemotableCheckboxGroup.Builder.create(((KeyLabeled)c).getKeyLabels());
34          if (c instanceof RemotableHiddenInput || c instanceof RemotableHiddenInput.Builder) return RemotableHiddenInput.Builder.create();
35          if (c instanceof RemotablePasswordInput || c instanceof RemotablePasswordInput.Builder){
36              RemotablePasswordInput.Builder b = RemotablePasswordInput.Builder.create();
37              b.setSize(((Sized) c).getSize());
38              return b;
39          }
40          if (c instanceof RemotableRadioButtonGroup || c instanceof RemotableRadioButtonGroup.Builder) return RemotableRadioButtonGroup.Builder.create(((KeyLabeled)c).getKeyLabels());
41          if (c instanceof RemotableSelect) {
42              RemotableSelect sc = (RemotableSelect) c;
43              RemotableSelect.Builder b = RemotableSelect.Builder.create(sc.getKeyLabels());
44  
45              final List<RemotableSelectGroup.Builder> temp = new ArrayList<RemotableSelectGroup.Builder>();
46              if (sc.getGroups() != null) {
47                  for (RemotableSelectGroup attr : sc.getGroups()) {
48                      temp.add(RemotableSelectGroup.Builder.create(attr.getKeyLabels(), attr.getLabel()));
49                  }
50              }
51  
52              b.setGroups(temp);
53              b.setSize(sc.getSize());
54              b.setMultiple(sc.isMultiple());
55              return b;
56          }
57          if (c instanceof RemotableSelect.Builder) {
58              RemotableSelect.Builder sc = (RemotableSelect.Builder) c;
59              RemotableSelect.Builder b = RemotableSelect.Builder.create(sc.getKeyLabels());
60              b.setGroups(sc.getGroups());
61              b.setSize(sc.getSize());
62              b.setMultiple(sc.isMultiple());
63              return b;
64          }
65          if(c instanceof RemotableTextarea || c instanceof RemotableTextarea.Builder) {
66              RemotableTextarea.Builder b = RemotableTextarea.Builder.create();
67              b.setWatermark(((Watermarked) c).getWatermark());
68              b.setCols(((RowsCols) c).getCols());
69              b.setRows(((RowsCols) c).getRows());
70              return b;
71          }
72          if(c instanceof RemotableTextInput || c instanceof RemotableTextInput.Builder) {
73              RemotableTextInput.Builder b = RemotableTextInput.Builder.create();
74              b.setWatermark(((Watermarked) c).getWatermark());
75              b.setSize(((Sized) c).getSize());
76              return b;
77          }
78          throw new UnsupportedOperationException(c.getClass().getName() + " not supported");
79      }
80  }