KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > templates > TemplateField


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.ui.templates;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15 /**
16  * The base class for all the template option fields. Template option is a
17  * single editable option that is exposed to the users in the wizard pages
18  * associated with templates. Although the field is associated with the template
19  * section, there is no 1/1 mapping between the field and the substitution value
20  * that can be used in the template files. In general, a subclass of this class
21  * can generate any SWT control in the provided composite.
22  *
23  * @since 2.0
24  */

25 public abstract class TemplateField {
26     private BaseOptionTemplateSection section;
27     private String JavaDoc label;
28     /**
29      * The constructor for the field.
30      *
31      * @param section
32      * the section that owns this field
33      * @param label
34      * the label of this field
35      */

36     public TemplateField(BaseOptionTemplateSection section, String JavaDoc label) {
37         this.section = section;
38         this.label = label;
39     }
40     /**
41      * Returns the field label.
42      *
43      * @return field label
44      */

45     public String JavaDoc getLabel() {
46         return label;
47     }
48     /**
49      * Changes the label of this field.
50      *
51      * @param label
52      * the new label of this field.
53      */

54     public void setLabel(String JavaDoc label) {
55         this.label = label;
56     }
57     /**
58      * Returns the template section that owns this option field.
59      *
60      * @return parent template section
61      */

62     public BaseOptionTemplateSection getSection() {
63         return section;
64     }
65     /**
66      * Factory method that creates the label in the provided parent.
67      *
68      * @param parent
69      * the parent composite to create the label in
70      * @param span
71      * number of columns that the label should span
72      * @return the newly created Label widget.
73      */

74     protected Label createLabel(Composite parent, int span) {
75         Label label = new Label(parent, SWT.NULL);
76         label.setText(getLabel());
77         return label;
78     }
79     /**
80      * Subclasses must implement this method to create the control of the
81      * template field.
82      *
83      * @param parent
84      * the parent composite the control should be created in
85      * @param span
86      * number of columns that the control should span
87      */

88     public abstract void createControl(Composite parent, int span);
89 }
90
Popular Tags