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.swt;
17  
18  import java.util.Map;
19  
20  import org.apache.commons.jelly.JellyTagException;
21  import org.apache.commons.jelly.XMLOutput;
22  import org.eclipse.swt.widgets.Dialog;
23  import org.eclipse.swt.widgets.Shell;
24  import org.eclipse.swt.widgets.Widget;
25  
26  /***
27   * This tag creates an SWT dialog.
28   *
29   * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
30   *
31   */
32  public class DialogTag extends WidgetTag {
33  
34      /***
35       * @param widgetClass
36       * @param style
37       */
38      public DialogTag(Class widgetClass, int style) {
39          super(widgetClass, style);
40      }
41  
42      /***
43       * @param widgetClass
44       */
45      public DialogTag(Class widgetClass) {
46          super(widgetClass);
47      }
48  
49      // Implementation methods
50      //-------------------------------------------------------------------------
51  
52      /***
53       * Factory method to create a new dialog
54       */
55      protected Object newInstance(Class theClass, Map attributes, XMLOutput output)
56          throws JellyTagException {
57          int style = getStyle(attributes);
58  
59          // now lets call the constructor with the parent
60          Widget parent = getParentWidget();
61  
62          boolean isParentShell = parent instanceof Shell;
63          if (parent == null || !isParentShell) {
64              throw new JellyTagException("This tag must be nested within a Shell");
65          }
66  
67          Dialog dialog = (Dialog) createWidget(theClass, parent, style);
68  
69          return dialog;
70      }
71  
72  }