01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.ui.templates;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.widgets.Composite;
14: import org.eclipse.swt.widgets.Label;
15:
16: /**
17: * The base class for all the template option fields. Template option is a
18: * single editable option that is exposed to the users in the wizard pages
19: * associated with templates. Although the field is associated with the template
20: * section, there is no 1/1 mapping between the field and the substitution value
21: * that can be used in the template files. In general, a subclass of this class
22: * can generate any SWT control in the provided composite.
23: *
24: * @since 2.0
25: */
26: public abstract class TemplateField {
27: private BaseOptionTemplateSection section;
28: private String label;
29:
30: /**
31: * The constructor for the field.
32: *
33: * @param section
34: * the section that owns this field
35: * @param label
36: * the label of this field
37: */
38: public TemplateField(BaseOptionTemplateSection section, String label) {
39: this .section = section;
40: this .label = label;
41: }
42:
43: /**
44: * Returns the field label.
45: *
46: * @return field label
47: */
48: public String getLabel() {
49: return label;
50: }
51:
52: /**
53: * Changes the label of this field.
54: *
55: * @param label
56: * the new label of this field.
57: */
58: public void setLabel(String label) {
59: this .label = label;
60: }
61:
62: /**
63: * Returns the template section that owns this option field.
64: *
65: * @return parent template section
66: */
67: public BaseOptionTemplateSection getSection() {
68: return section;
69: }
70:
71: /**
72: * Factory method that creates the label in the provided parent.
73: *
74: * @param parent
75: * the parent composite to create the label in
76: * @param span
77: * number of columns that the label should span
78: * @return the newly created Label widget.
79: */
80: protected Label createLabel(Composite parent, int span) {
81: Label label = new Label(parent, SWT.NULL);
82: label.setText(getLabel());
83: return label;
84: }
85:
86: /**
87: * Subclasses must implement this method to create the control of the
88: * template field.
89: *
90: * @param parent
91: * the parent composite the control should be created in
92: * @param span
93: * number of columns that the control should span
94: */
95: public abstract void createControl(Composite parent, int span);
96: }
|