View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.binding.enables;
17  
18  import java.util.Set;
19  
20  import org.seasar.uruma.context.WidgetHandle;
21  import org.seasar.uruma.context.WindowContext;
22  import org.seasar.uruma.core.UrumaMessageCodes;
23  import org.seasar.uruma.exception.NotFoundException;
24  
25  /**
26   * EnablesDepending のセットアップを行うクラスです。<br />
27   * 
28   * @author y-komori
29   */
30  public class EnablesDependingListenerSupport {
31      private EnablesDependingListenerSupport() {
32      }
33  
34      /**
35       * {@link WindowContext} が保持する {@link EnablesDependingDef} について、{@link EnablesDependingListener}
36       * をセットアップして EnablesDepending が機能するようにします。<br />
37       * 
38       * @param context
39       *            {@link WindowContext} オブジェクト
40       */
41      public static void setupEnableDependingListeners(final WindowContext context) {
42          for (EnablesDependingDef def : context.getEnablesDependingDefList()) {
43              String targetId = def.getTargetId();
44              Set<WidgetHandle> handles = context.findWidgetHandles(targetId);
45              if (handles.size() > 0) {
46                  for (WidgetHandle handle : handles) {
47                      EnablesDependingListener listener = EnablesDependingListenerFactory
48                              .getListener(handle, def.getWidgetHandle(), def
49                                      .getType());
50                      listener.setupListener();
51                      listener.updateEnableState();
52                  }
53              } else {
54                  throw new NotFoundException(
55                          UrumaMessageCodes.ENABLES_DEPENDING_TARGET_NOT_FOUND,
56                          targetId);
57              }
58          }
59      }
60  }