Mercurial > projects > dwt-addons
annotate dwtx/jface/text/templates/persistence/TemplatePersistenceData.d @ 133:7d818bd32d63
Fix ctors to this with gvim regexp
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 01:29:22 +0200 |
parents | c4fb132a086c |
children | 02cd5f1224d3 |
rev | line source |
---|---|
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.persistence.TemplatePersistenceData; | |
14 | |
131 | 15 import dwtx.jface.text.templates.persistence.TemplateReaderWriter; // packageimport |
16 import dwtx.jface.text.templates.persistence.TemplatePersistenceMessages; // packageimport | |
17 import dwtx.jface.text.templates.persistence.TemplateStore; // packageimport | |
18 | |
19 | |
129 | 20 import dwt.dwthelper.utils; |
21 | |
22 | |
23 import dwtx.core.runtime.Assert; | |
24 import dwtx.jface.text.templates.Template; | |
25 | |
26 | |
27 /** | |
28 * TemplatePersistenceData stores information about a template. It uniquely | |
29 * references contributed templates via their id. Contributed templates may be | |
30 * deleted or modified. All template may be enabled or not. | |
31 * <p> | |
32 * Clients may use this class, although this is not usually needed except when | |
33 * implementing a custom template preference page or template store. This class | |
34 * is not intended to be subclassed. | |
35 * </p> | |
36 * | |
37 * @since 3.0 | |
38 * @noextend This class is not intended to be subclassed by clients. | |
39 */ | |
40 public class TemplatePersistenceData { | |
41 private final Template fOriginalTemplate; | |
42 private final String fId; | |
43 private final bool fOriginalIsEnabled; | |
44 | |
45 private Template fCustomTemplate= null; | |
46 private bool fIsDeleted= false; | |
47 private bool fCustomIsEnabled= true; | |
48 | |
49 /** | |
50 * Creates a new, user-added instance that is not linked to a contributed | |
51 * template. | |
52 * | |
53 * @param template the template which is stored by the new instance | |
54 * @param enabled whether the template is enabled | |
55 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
56 public this(Template template, bool enabled) { |
129 | 57 this(template, enabled, null); |
58 } | |
59 | |
60 /** | |
61 * Creates a new instance. If <code>id</code> is not <code>null</code>, | |
62 * the instance is represents a template that is contributed and can be | |
63 * identified via its id. | |
64 * | |
65 * @param template the template which is stored by the new instance | |
66 * @param enabled whether the template is enabled | |
67 * @param id the id of the template, or <code>null</code> if a user-added | |
68 * instance should be created | |
69 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
70 public this(Template template, bool enabled, String id) { |
129 | 71 Assert.isNotNull(template); |
72 fOriginalTemplate= template; | |
73 fCustomTemplate= template; | |
74 fOriginalIsEnabled= enabled; | |
75 fCustomIsEnabled= enabled; | |
76 fId= id; | |
77 } | |
78 | |
79 /** | |
80 * Returns the id of this template store, or <code>null</code> if there is none. | |
81 * | |
82 * @return the id of this template store | |
83 */ | |
84 public String getId() { | |
85 return fId; | |
86 } | |
87 | |
88 /** | |
89 * Returns the deletion state of the stored template. This is only relevant | |
90 * of contributed templates. | |
91 * | |
92 * @return the deletion state of the stored template | |
93 */ | |
94 public bool isDeleted() { | |
95 return fIsDeleted; | |
96 } | |
97 | |
98 /** | |
99 * Sets the deletion state of the stored template. | |
100 * | |
101 * @param isDeleted the deletion state of the stored template | |
102 */ | |
103 public void setDeleted(bool isDeleted) { | |
104 fIsDeleted= isDeleted; | |
105 } | |
106 | |
107 /** | |
108 * Returns the template encapsulated by the receiver. | |
109 * | |
110 * @return the template encapsulated by the receiver | |
111 */ | |
112 public Template getTemplate() { | |
113 return fCustomTemplate; | |
114 } | |
115 | |
116 | |
117 /** | |
118 * Sets the template encapsulated by the receiver. | |
119 * | |
120 * @param template the new template | |
121 */ | |
122 public void setTemplate(Template template) { | |
123 fCustomTemplate= template; | |
124 } | |
125 | |
126 /** | |
127 * Returns whether the receiver represents a custom template, i.e. is either | |
128 * a user-added template or a contributed template that has been modified. | |
129 * | |
130 * @return <code>true</code> if the contained template is a custom | |
131 * template and cannot be reconstructed from the contributed | |
132 * templates | |
133 */ | |
134 public bool isCustom() { | |
135 return fId is null | |
136 || fIsDeleted | |
137 || fOriginalIsEnabled !is fCustomIsEnabled | |
138 || !fOriginalTemplate.equals(fCustomTemplate); | |
139 } | |
140 | |
141 /** | |
142 * Returns whether the receiver represents a modified template, i.e. a | |
143 * contributed template that has been changed. | |
144 * | |
145 * @return <code>true</code> if the contained template is contributed but has been modified, <code>false</code> otherwise | |
146 */ | |
147 public bool isModified() { | |
148 return isCustom() && !isUserAdded(); | |
149 } | |
150 | |
151 /** | |
152 * Returns <code>true</code> if the contained template was added by a | |
153 * user, i.e. does not reference a contributed template. | |
154 * | |
155 * @return <code>true</code> if the contained template was added by a user, <code>false</code> otherwise | |
156 */ | |
157 public bool isUserAdded() { | |
158 return fId is null; | |
159 } | |
160 | |
161 | |
162 /** | |
163 * Reverts the template to its original setting. | |
164 */ | |
165 public void revert() { | |
166 fCustomTemplate= fOriginalTemplate; | |
167 fCustomIsEnabled= fOriginalIsEnabled; | |
168 fIsDeleted= false; | |
169 } | |
170 | |
171 | |
172 /** | |
173 * Returns the enablement state of the contained template. | |
174 * | |
175 * @return the enablement state of the contained template | |
176 */ | |
177 public bool isEnabled() { | |
178 return fCustomIsEnabled; | |
179 } | |
180 | |
181 /** | |
182 * Sets the enablement state of the contained template. | |
183 * | |
184 * @param isEnabled the new enablement state of the contained template | |
185 */ | |
186 public void setEnabled(bool isEnabled) { | |
187 fCustomIsEnabled= isEnabled; | |
188 } | |
189 } |