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.renderer.impl;
17  
18  import org.eclipse.swt.graphics.Image;
19  import org.eclipse.swt.widgets.TreeItem;
20  import org.seasar.eclipse.common.util.ImageManager;
21  import org.seasar.uruma.component.jface.TreeItemComponent;
22  import org.seasar.uruma.util.PathUtil;
23  
24  /**
25   * {@link TreeItem} のレンダリングを行うクラスです。<br />
26   * 
27   * @author y-komori
28   */
29  public class TreeItemRenderer extends
30          AbstractWidgetRenderer<TreeItemComponent, TreeItem> {
31  
32      /*
33       * @see org.seasar.uruma.renderer.impl.AbstractWidgetRenderer#doRender(org.seasar.uruma.component.UIComponent,
34       *      org.eclipse.swt.widgets.Widget)
35       */
36      @Override
37      protected void doRender(final TreeItemComponent uiComponent,
38              final TreeItem widget) {
39          renderText(uiComponent, widget);
40          renderImage(uiComponent, widget);
41      }
42  
43      /*
44       * @see org.seasar.uruma.renderer.impl.AbstractWidgetRenderer#getWidgetType()
45       */
46      @Override
47      protected Class<TreeItem> getWidgetType() {
48          return TreeItem.class;
49      }
50  
51      protected void renderText(final TreeItemComponent component,
52              final TreeItem widget) {
53          String text = component.text;
54          if (text != null) {
55              widget.setText(text);
56          }
57      }
58  
59      protected void renderImage(final TreeItemComponent component,
60              final TreeItem widget) {
61          String value = component.image;
62  
63          if (value != null) {
64              Image image = ImageManager.getImage(value);
65              if (image == null) {
66                  String path = PathUtil.createPath(component.getBasePath(),
67                          value);
68                  image = ImageManager.loadImage(path);
69              }
70              widget.setImage(image);
71          }
72      }
73  }