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.widgets.Link;
19  import org.seasar.uruma.annotation.RenderingPolicy.ConversionType;
20  import org.seasar.uruma.component.jface.LinkComponent;
21  import org.seasar.uruma.renderer.RendererSupportUtil;
22  
23  /**
24   * {@link Link} のレンダリングを行うクラスです。<br />
25   * 
26   * @author bskuroneko
27   */
28  public class LinkRenderer extends AbstractControlRenderer<LinkComponent, Link> {
29  
30      /*
31       * @see org.seasar.uruma.renderer.impl.AbstractControlRenderer#doRenderControl(org.seasar.uruma.component.jface.ControlComponent,
32       *      org.eclipse.swt.widgets.Control)
33       */
34      @Override
35      protected void doRenderControl(final LinkComponent controlComponent,
36              final Link control) {
37          setText(controlComponent, control);
38      }
39  
40      private void setText(final LinkComponent controlComponent,
41              final Link control) {
42          String value = controlComponent.text;
43          String text = (String) RendererSupportUtil.convertValue(
44                  controlComponent, value, ConversionType.TEXT);
45          if (text.indexOf("<a") == -1 && text.indexOf("</a") == -1) {
46              text = "<a>" + text + "</a>";
47          }
48          control.setText(text);
49      }
50  
51      /*
52       * @see org.seasar.uruma.renderer.impl.AbstractWidgetRenderer#getWidgetType()
53       */
54      @Override
55      protected Class<Link> getWidgetType() {
56          return Link.class;
57      }
58  }