KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
13  * The base class of all the template options. Options have unique name and a
14  * value that can be changed. The value of the option is automatically available
15  * to the template files - can be accessed by substitution (e.g. $value_name$)
16  * or as part of conditional code generation (e.g. if value_name).
17  *
18  * @since 2.0
19  */

20 public abstract class TemplateOption extends TemplateField {
21     private String JavaDoc name;
22     private Object JavaDoc value;
23     private boolean enabled = true;
24     private boolean required;
25     /**
26      * Creates a new option for the provided template section.
27      *
28      * @param section
29      * the parent template section
30      * @param name
31      * the unique name of this option
32      * @param label
33      * presentable label of this option
34      */

35     public TemplateOption(BaseOptionTemplateSection section, String JavaDoc name,
36             String JavaDoc label) {
37         super(section, label);
38         this.name = name;
39     }
40     /**
41      * Returns the unique name of this option
42      *
43      * @return option name
44      */

45     public String JavaDoc getName() {
46         return name;
47     }
48     /**
49      * Changes the unique name of this option
50      *
51      * @param name
52      * the new option name
53      */

54     public void setName(String JavaDoc name) {
55         this.name = name;
56     }
57     /**
58      * Returns the value of this option.
59      *
60      * @return the current value
61      */

62     public Object JavaDoc getValue() {
63         return value;
64     }
65     /**
66      * Returns whether this option is currently empty. The actual semantics of
67      * the result depends on the implementing option.
68      *
69      * @return <samp>true </samp> if option is empty, </samp> false otherwise.
70      */

71     public boolean isEmpty() {
72         return false;
73     }
74     /**
75      * Marks this option as required. Required options must be set by the user.
76      * An option that is empty and is marked required will be flagged as an
77      * error in the wizard.
78      *
79      * @param required
80      * the new value of the property
81      * @see #isEmpty
82      */

83     public void setRequired(boolean required) {
84         this.required = required;
85     }
86     /**
87      * Returns whether this option is required (cannot be empty)
88      *
89      * @return <samp>true </samp> if this option is required, <samp>false
90      * </samp> otherwise.
91      */

92     public boolean isRequired() {
93         return required;
94     }
95     /**
96      * Sets the new value of this option.
97      *
98      * @param value
99      * the new value
100      */

101     public void setValue(Object JavaDoc value) {
102         this.value = value;
103     }
104     /**
105      * Returns whether this option is enabled. The actual presentation of
106      * enabled state depends on the implementing option.
107      *
108      * @return <samp>true </samp> if option is enabled and can be modified.
109      */

110     public boolean isEnabled() {
111         return enabled;
112     }
113     /**
114      * Sets the enabled state of this option. The action presentation of the
115      * enabled state depends on the implementing option.
116      *
117      * @param enabled
118      * the new enabled state
119      */

120     public void setEnabled(boolean enabled) {
121         this.enabled = enabled;
122     }
123     /**
124      * Returns the label of this option that can be presented in the messages to
125      * the user. The default implementation trims the 'label' property from
126      * mnemonics and from the trailing column.
127      */

128     public String JavaDoc getMessageLabel() {
129         String JavaDoc label = getLabel();
130         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
131         for (int i = 0; i < label.length(); i++) {
132             char c = label.charAt(i);
133             if (c == '(' && i < label.length() - 1) {
134                 char c2 = label.charAt(i + 1);
135                 if (c2 == '&') {
136                     // DBCS mnemonic sequence "(&<char>)"
137
// It is OK to truncate the label
138
// at this point
139
break;
140                 }
141             }
142             if (c != '&' && c != ':')
143                 buf.append(c);
144         }
145         return buf.toString();
146     }
147 }
148
Popular Tags