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