| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| WidgetBinder | 
 | 
 | 0.0;0 | 
| 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.widget; | |
| 17 | ||
| 18 |  import org.eclipse.jface.viewers.Viewer; | |
| 19 |  import org.eclipse.swt.widgets.Control; | |
| 20 |  import org.seasar.framework.beans.BeanDesc; | |
| 21 |  import org.seasar.framework.beans.PropertyDesc; | |
| 22 |  import org.seasar.uruma.context.PartContext; | |
| 23 |  import org.seasar.uruma.context.WidgetHandle; | |
| 24 | ||
| 25 |  /** | |
| 26 |   * 任意のオブジェクトに対してウィジットバインディングを実行するためのクラスです。<br /> | |
| 27 |   *  | |
| 28 |   * @author y-komori | |
| 29 |   */ | |
| 30 | public class WidgetBinder { | |
| 31 | 0 |      private WidgetBinder() { | 
| 32 | ||
| 33 | 0 |      } | 
| 34 | ||
| 35 |      /** | |
| 36 |       * 指定されたオブジェクトに対して、ウィジットバインディングを行います。<br /> | |
| 37 |       * <p> | |
| 38 |       * <code>target</code> で指定されたオブジェクトに対して、<code>context</code> で指定された | |
| 39 |       * {@link PartContext} に登録されているオブジェクトをバインドします。<br /> | |
| 40 |       * 具体的には、<code>target</code> で定義されるフィールドに対し、そのフィールド名と名前が一致する | |
| 41 |       * {@link WidgetHandle} を {@link PartContext} から取得します。取得できた場合、 | |
| 42 |       * {@link WidgetHandle} が内包するオブジェクトの型がフィールドに代入可能であれば そのフィールドにセットします。<br /> | |
| 43 |       * </p> | |
| 44 |       * <p> | |
| 45 |       * また、{@link WidgetHandle} の内包するオブジェクトが {@link Viewer} のサブクラスである場合、その | |
| 46 |       * {@link Viewer} の持つ {@link Control} が代入可能であればバインドします。<br /> | |
| 47 |       * </p> | |
| 48 |       *  | |
| 49 |       * @param target | |
| 50 |       *            ターゲットオブジェクト | |
| 51 |       * @param context | |
| 52 |       *            {@link PartContext} オブジェクト | |
| 53 |       */ | |
| 54 | public static void bindWidgets(final Object target, | |
| 55 |              final PartContext context) { | |
| 56 | 268 | BeanDesc beanDesc = context.getPartActionDesc().getBeanDesc(); | 
| 57 | ||
| 58 | 268 |          int pdSize = beanDesc.getPropertyDescSize(); | 
| 59 | 1808 | for (int i = 0; i < pdSize; i++) { | 
| 60 | 1540 | PropertyDesc pd = beanDesc.getPropertyDesc(i); | 
| 61 | 1540 | Class<?> propertyType = pd.getPropertyType(); | 
| 62 | 1540 | String propertyName = pd.getPropertyName(); | 
| 63 | 1540 | WidgetHandle handle = context.getWidgetHandle(propertyName); | 
| 64 | 1540 | if (handle != null) { | 
| 65 | 236 | if (propertyType.isAssignableFrom(handle.getWidgetClass())) { | 
| 66 | 220 | pd.setValue(target, handle.getWidget()); | 
| 67 | 16 | } else if (handle.instanceOf(Viewer.class)) { | 
| 68 | 12 | Viewer viewer = handle.<Viewer> getCastWidget(); | 
| 69 | 12 | Control coltrol = viewer.getControl(); | 
| 70 | 12 |                      if (propertyType.isAssignableFrom(coltrol.getClass())) { | 
| 71 | 0 |                          pd.setValue(target, coltrol); | 
| 72 | } | |
| 73 | } | |
| 74 | } | |
| 75 | } | |
| 76 | 268 | } | 
| 77 | } |