View Javadoc

1   /**
2    * Copyright 2005-2013 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  /** utility class for copying widgets. */
19  final class WidgetCopy {
20  
21      private WidgetCopy() {
22          throw new IllegalArgumentException("do not call.");
23      }
24  
25      public static RemotableAbstractWidget.Builder toBuilder(RemotableWidgetContract w) {
26          if (w == null) {
27              throw new IllegalArgumentException("w is null");
28          }
29  
30          if (w instanceof RemotableDatepicker || w instanceof RemotableDatepicker.Builder) return RemotableDatepicker.Builder.create();
31          if (w instanceof RemotableTextExpand || w instanceof RemotableTextExpand.Builder) return RemotableTextExpand.Builder.create();
32  
33          if (w instanceof RemotableQuickFinder) {
34              RemotableQuickFinder.Builder b = RemotableQuickFinder.Builder.create(((RemotableQuickFinder) w).getBaseLookupUrl(),  ((RemotableQuickFinder) w).getDataObjectClass());
35              b.setFieldConversions(((RemotableQuickFinder) w).getFieldConversions());
36              b.setLookupParameters(((RemotableQuickFinder) w).getLookupParameters());
37              return b;
38          } else if (w instanceof RemotableQuickFinder.Builder) {
39              RemotableQuickFinder.Builder b = RemotableQuickFinder.Builder.create(((RemotableQuickFinder.Builder) w).getBaseLookupUrl(),  ((RemotableQuickFinder.Builder) w).getDataObjectClass());
40              b.setFieldConversions(((RemotableQuickFinder.Builder) w).getFieldConversions());
41              b.setLookupParameters(((RemotableQuickFinder.Builder) w).getLookupParameters());
42              return b;
43          }
44          throw new UnsupportedOperationException(w.getClass().getName() + " not supported");
45      }
46  }