View Javadoc

1   /*
2   * Copyright 2002-2004 The Apache Software Foundation
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16  package org.apache.commons.jelly.tags.jface;
17  
18  import org.apache.commons.jelly.JellyTagException;
19  import org.apache.commons.jelly.tags.jface.window.ApplicationWindowImpl;
20  import org.apache.commons.jelly.tags.jface.window.ApplicationWindowTag;
21  import org.apache.commons.jelly.tags.swt.LayoutDataTag;
22  import org.eclipse.jface.window.Window;
23  import org.eclipse.swt.widgets.Control;
24  import org.eclipse.swt.widgets.Widget;
25  
26  /***
27   * Implementation of SWT LayoutDataTag
28   *  
29   * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a> 
30   */
31  public class JFaceLayoutDataTag extends LayoutDataTag {
32  
33      /***
34       * @param layoutDataClass
35       */
36      public JFaceLayoutDataTag(Class layoutDataClass) {
37          super(layoutDataClass);
38      }
39  
40      /* (non-Javadoc)
41       * @see org.apache.commons.jelly.tags.core.UseBeanTag#processBean(java.lang.String, java.lang.Object)
42       */
43      protected void processBean(String var, Object bean) throws JellyTagException {
44          Widget parent = getParentWidget();
45          Window window = null;
46          if (parent == null) {
47              window = getParentWindow();
48              if (window != null && window instanceof ApplicationWindowImpl) {
49                  parent = ((ApplicationWindowImpl) window).getContents();
50              }
51          }
52  
53          if (parent instanceof Control) {
54              Control control = (Control) parent;
55              control.setLayoutData(getBean());
56          } else {
57              throw new JellyTagException("This tag must be nested within a control widget tag");
58          }
59      }
60  
61      /***
62       * @return the parent window 
63       */
64      public Window getParentWindow() {
65          ApplicationWindowTag tag =
66              (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag.class);
67          if (tag != null) {
68              return tag.getWindow();
69          }
70          return null;
71      }
72  
73  }