129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.templates.Template;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import dwtx.core.runtime.Assert;
|
|
18
|
|
19
|
|
20 /**
|
|
21 * A template consisting of a name and a pattern.
|
|
22 * <p>
|
|
23 * Clients may instantiate this class. May become final in the future.
|
|
24 * </p>
|
|
25 * @since 3.0
|
|
26 * @noextend This class is not intended to be subclassed by clients.
|
|
27 */
|
|
28 public class Template {
|
|
29
|
|
30 /** The name of this template */
|
|
31 private /*final*/ String fName;
|
|
32 /** A description of this template */
|
|
33 private /*final*/ String fDescription;
|
|
34 /** The name of the context type of this template */
|
|
35 private /*final*/ String fContextTypeId;
|
|
36 /** The template pattern. */
|
|
37 private /*final*/ String fPattern;
|
|
38 /**
|
|
39 * The auto insertable property.
|
|
40 * @since 3.1
|
|
41 */
|
|
42 private final bool fIsAutoInsertable;
|
|
43
|
|
44 /**
|
|
45 * Creates an empty template.
|
|
46 */
|
|
47 public Template() {
|
|
48 this("", "", "", "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
|
49 }
|
|
50
|
|
51 /**
|
|
52 * Creates a copy of a template.
|
|
53 *
|
|
54 * @param template the template to copy
|
|
55 */
|
|
56 public Template(Template template) {
|
|
57 this(template.getName(), template.getDescription(), template.getContextTypeId(), template.getPattern(), template.isAutoInsertable());
|
|
58 }
|
|
59
|
|
60 /**
|
|
61 * Creates a template.
|
|
62 *
|
|
63 * @param name the name of the template
|
|
64 * @param description the description of the template
|
|
65 * @param contextTypeId the id of the context type in which the template can be applied
|
|
66 * @param pattern the template pattern
|
|
67 * @deprecated as of 3.1 replaced by {@link #Template(String, String, String, String, bool)}
|
|
68 */
|
|
69 public Template(String name, String description, String contextTypeId, String pattern) {
|
|
70 this(name, description, contextTypeId, pattern, true); // templates are auto insertable per default
|
|
71 }
|
|
72
|
|
73 /**
|
|
74 * Creates a template.
|
|
75 *
|
|
76 * @param name the name of the template
|
|
77 * @param description the description of the template
|
|
78 * @param contextTypeId the id of the context type in which the template can be applied
|
|
79 * @param pattern the template pattern
|
|
80 * @param isAutoInsertable the auto insertable property of the template
|
|
81 * @since 3.1
|
|
82 */
|
|
83 public Template(String name, String description, String contextTypeId, String pattern, bool isAutoInsertable) {
|
|
84 Assert.isNotNull(description);
|
|
85 fDescription= description;
|
|
86 fName= name;
|
|
87 Assert.isNotNull(contextTypeId);
|
|
88 fContextTypeId= contextTypeId;
|
|
89 fPattern= pattern;
|
|
90 fIsAutoInsertable= isAutoInsertable;
|
|
91 }
|
|
92
|
|
93 /*
|
|
94 * @see Object#hashCode()
|
|
95 */
|
|
96 public int hashCode() {
|
|
97 return fName.hashCode() ^ fPattern.hashCode() ^ fContextTypeId.hashCode();
|
|
98 }
|
|
99
|
|
100 /**
|
|
101 * Sets the description of the template.
|
|
102 *
|
|
103 * @param description the new description
|
|
104 * @deprecated Templates should never be modified
|
|
105 */
|
|
106 public void setDescription(String description) {
|
|
107 Assert.isNotNull(description);
|
|
108 fDescription= description;
|
|
109 }
|
|
110
|
|
111 /**
|
|
112 * Returns the description of the template.
|
|
113 *
|
|
114 * @return the description of the template
|
|
115 */
|
|
116 public String getDescription() {
|
|
117 return fDescription;
|
|
118 }
|
|
119
|
|
120 /**
|
|
121 * Sets the name of the context type in which the template can be applied.
|
|
122 *
|
|
123 * @param contextTypeId the new context type name
|
|
124 * @deprecated Templates should never be modified
|
|
125 */
|
|
126 public void setContextTypeId(String contextTypeId) {
|
|
127 Assert.isNotNull(contextTypeId);
|
|
128 fContextTypeId= contextTypeId;
|
|
129 }
|
|
130
|
|
131 /**
|
|
132 * Returns the id of the context type in which the template can be applied.
|
|
133 *
|
|
134 * @return the id of the context type in which the template can be applied
|
|
135 */
|
|
136 public String getContextTypeId() {
|
|
137 return fContextTypeId;
|
|
138 }
|
|
139
|
|
140 /**
|
|
141 * Sets the name of the template.
|
|
142 *
|
|
143 * @param name the name of the template
|
|
144 * @deprecated Templates should never be modified
|
|
145 */
|
|
146 public void setName(String name) {
|
|
147 fName= name;
|
|
148 }
|
|
149
|
|
150 /**
|
|
151 * Returns the name of the template.
|
|
152 *
|
|
153 * @return the name of the template
|
|
154 */
|
|
155 public String getName() {
|
|
156 return fName;
|
|
157 }
|
|
158
|
|
159 /**
|
|
160 * Sets the pattern of the template.
|
|
161 *
|
|
162 * @param pattern the new pattern of the template
|
|
163 * @deprecated Templates should never be modified
|
|
164 */
|
|
165 public void setPattern(String pattern) {
|
|
166 fPattern= pattern;
|
|
167 }
|
|
168
|
|
169 /**
|
|
170 * Returns the template pattern.
|
|
171 *
|
|
172 * @return the template pattern
|
|
173 */
|
|
174 public String getPattern() {
|
|
175 return fPattern;
|
|
176 }
|
|
177
|
|
178 /**
|
|
179 * Returns <code>true</code> if template is enabled and matches the context,
|
|
180 * <code>false</code> otherwise.
|
|
181 *
|
|
182 * @param prefix the prefix (e.g. inside a document) to match
|
|
183 * @param contextTypeId the context type id to match
|
|
184 * @return <code>true</code> if template is enabled and matches the context,
|
|
185 * <code>false</code> otherwise
|
|
186 */
|
|
187 public bool matches(String prefix, String contextTypeId) {
|
|
188 return fContextTypeId.equals(contextTypeId);
|
|
189 }
|
|
190
|
|
191 /*
|
|
192 * @see java.lang.Object#equals(java.lang.Object)
|
|
193 */
|
|
194 public bool equals(Object o) {
|
|
195 if (!(o instanceof Template))
|
|
196 return false;
|
|
197
|
|
198 Template t= (Template) o;
|
|
199 if (t is this)
|
|
200 return true;
|
|
201
|
|
202 return t.fName.equals(fName)
|
|
203 && t.fPattern.equals(fPattern)
|
|
204 && t.fContextTypeId.equals(fContextTypeId)
|
|
205 && t.fDescription.equals(fDescription)
|
|
206 && t.fIsAutoInsertable is fIsAutoInsertable;
|
|
207 }
|
|
208
|
|
209 /**
|
|
210 * Returns the auto insertable property of the template.
|
|
211 *
|
|
212 * @return the auto insertable property of the template
|
|
213 * @since 3.1
|
|
214 */
|
|
215 public bool isAutoInsertable() {
|
|
216 return fIsAutoInsertable;
|
|
217 }
|
|
218 }
|