|
@@ -8,8 +8,7 @@ |
8 |
8 |
|
|
9 |
9 |
|
public abstract class AttributeMetaData extends AbstractNamedMetaData<ObjectMetaData> implements MinimalAttributeMetaData, |
10 |
10 |
|
ViewSupportable, |
11 |
|
- |
Comparable<AttributeMetaData> |
12 |
|
- |
{ |
|
11 |
+ |
Comparable<AttributeMetaData> { |
13 |
12 |
|
public static final String ID_NAME = "ID"; |
14 |
13 |
|
|
15 |
14 |
|
private final AttributeSet mAttributeSet; |
|
@@ -18,8 +17,7 @@ |
18 |
17 |
|
private String mNotes = null; |
19 |
18 |
|
|
20 |
19 |
|
protected AttributeMetaData( AttributeSet pAttributeSet, Mode pMode, boolean pEditable, boolean pVirtual, PropertyMetaData[] pPropertyMetaDatas, |
21 |
|
- |
IdentifierValidator pNameValidator, String pName ) |
22 |
|
- |
{ |
|
20 |
+ |
IdentifierValidator pNameValidator, String pName ) { |
23 |
21 |
|
super( pAttributeSet.getType().toString(), pMode, pEditable, pNameValidator, pName ); |
24 |
22 |
|
|
25 |
23 |
|
mAttributeSet = pAttributeSet; |
|
@@ -28,81 +26,67 @@ |
28 |
26 |
|
} |
29 |
27 |
|
|
30 |
28 |
|
@Override |
31 |
|
- |
public int compareTo( AttributeMetaData them ) |
32 |
|
- |
{ |
|
29 |
+ |
public int compareTo( AttributeMetaData them ) { |
33 |
30 |
|
int zDiff = this.getAttributeSet().getSortIndex() - them.getAttributeSet().getSortIndex(); |
34 |
|
- |
if ( zDiff != 0 ) |
35 |
|
- |
{ |
|
31 |
+ |
if ( zDiff != 0 ) { |
36 |
32 |
|
return zDiff; |
37 |
33 |
|
} |
38 |
34 |
|
return CompareSupport.compare( this.getName(), them.getName() ); |
39 |
35 |
|
} |
40 |
36 |
|
|
41 |
|
- |
public AttributeSet getAttributeSet() |
42 |
|
- |
{ |
|
37 |
+ |
public AttributeSet getAttributeSet() { |
43 |
38 |
|
return mAttributeSet; |
44 |
39 |
|
} |
45 |
40 |
|
|
46 |
41 |
|
abstract public boolean isRelated(); |
47 |
42 |
|
|
48 |
|
- |
public boolean isVirtual() |
49 |
|
- |
{ |
|
43 |
+ |
public boolean isVirtual() { |
50 |
44 |
|
return mVirtual; |
51 |
45 |
|
} |
52 |
46 |
|
|
53 |
47 |
|
@Override |
54 |
|
- |
public Class getSimpleDataType() |
55 |
|
- |
{ |
|
48 |
+ |
public Class getSimpleDataType() { |
56 |
49 |
|
return getAttributeSetType().getSimpleDataType(); |
57 |
50 |
|
} |
58 |
51 |
|
|
59 |
52 |
|
@Override |
60 |
|
- |
public AttributeType getAttributeSetType() |
61 |
|
- |
{ |
|
53 |
+ |
public AttributeType getAttributeSetType() { |
62 |
54 |
|
return getAttributeSet().getType(); |
63 |
55 |
|
} |
64 |
56 |
|
|
65 |
|
- |
public String getNotes() |
66 |
|
- |
{ |
|
57 |
+ |
public String getNotes() { |
67 |
58 |
|
return mNotes; |
68 |
59 |
|
} |
69 |
60 |
|
|
70 |
|
- |
public void unpersistNotes( String pNotes ) |
71 |
|
- |
{ |
|
61 |
+ |
public void unpersistNotes( String pNotes ) { |
72 |
62 |
|
mNotes = pNotes; |
73 |
63 |
|
} |
74 |
64 |
|
|
75 |
|
- |
public void setNotes( String pNotes ) |
76 |
|
- |
{ |
|
65 |
+ |
public void setNotes( String pNotes ) { |
77 |
66 |
|
verifyEditability(); |
78 |
|
- |
if ( !areEqual( mNotes, pNotes ) ) |
79 |
|
- |
{ |
|
67 |
+ |
if ( !areEqual( mNotes, pNotes ) ) { |
80 |
68 |
|
mNotes = pNotes; |
81 |
69 |
|
changed(); |
82 |
70 |
|
} |
83 |
71 |
|
} |
84 |
72 |
|
|
85 |
73 |
|
@SuppressWarnings("UnusedDeclaration") |
86 |
|
- |
public Object getPropertyValue( String pName ) |
87 |
|
- |
{ |
|
74 |
+ |
public Object getPropertyValue( String pName ) { |
88 |
75 |
|
Property property = mPropertyManager.getProperty( pName ); |
89 |
76 |
|
return (property == null) ? null : property.getValue(); |
90 |
77 |
|
} |
91 |
78 |
|
|
92 |
|
- |
public PropertyManager getPropertyManager() |
93 |
|
- |
{ |
|
79 |
+ |
public PropertyManager getPropertyManager() { |
94 |
80 |
|
return mPropertyManager; |
95 |
81 |
|
} |
96 |
82 |
|
|
97 |
83 |
|
@SuppressWarnings("UnusedDeclaration") |
98 |
|
- |
public Property[] getProperties() |
99 |
|
- |
{ |
|
84 |
+ |
public Property[] getProperties() { |
100 |
85 |
|
return mPropertyManager.getProperties(); |
101 |
86 |
|
} |
102 |
87 |
|
|
103 |
88 |
|
@SuppressWarnings("UnusedDeclaration") |
104 |
|
- |
public void unpersistProperty( String pName, String pValueAsString ) |
105 |
|
- |
{ |
|
89 |
+ |
public void unpersistProperty( String pName, String pValueAsString ) { |
106 |
90 |
|
mPropertyManager.unpersistProperty( pName, pValueAsString ); |
107 |
91 |
|
} |
108 |
92 |
|
|
|
@@ -110,31 +94,24 @@ |
110 |
94 |
|
* @return null or Error |
111 |
95 |
|
*/ |
112 |
96 |
|
@SuppressWarnings("UnusedDeclaration") |
113 |
|
- |
public String setPropertyValue( String pName, Object pValue ) |
114 |
|
- |
{ |
|
97 |
+ |
public String setPropertyValue( String pName, Object pValue ) { |
115 |
98 |
|
return mPropertyManager.updatePropertyValue( pName, pValue ); |
116 |
99 |
|
} |
117 |
100 |
|
|
118 |
|
- |
public void populateFrom( AttributeReader pReader ) |
119 |
|
- |
{ |
120 |
|
- |
for ( PropertyReader zReader; null != (zReader = pReader.nextProperty()); ) |
121 |
|
- |
{ |
|
101 |
+ |
public void populateFrom( AttributeReader pReader ) { |
|
102 |
+ |
for ( PropertyReader zReader; null != (zReader = pReader.nextProperty()); ) { |
122 |
103 |
|
String zWhat = zReader.getWhat(); |
123 |
104 |
|
String zData = zReader.getData(); |
124 |
|
- |
if ( ObjectNames.NOTES.equals( zWhat ) ) |
125 |
|
- |
{ |
|
105 |
+ |
if ( ObjectNames.NOTES.equals( zWhat ) ) { |
126 |
106 |
|
unpersistNotes( zData ); |
127 |
|
- |
} |
128 |
|
- |
else |
129 |
|
- |
{ |
|
107 |
+ |
} else { |
130 |
108 |
|
mPropertyManager.unpersistProperty( zWhat, zData ); |
131 |
109 |
|
} |
132 |
110 |
|
} |
133 |
111 |
|
} |
134 |
112 |
|
|
135 |
113 |
|
@Override |
136 |
|
- |
public void setRehydrated() |
137 |
|
- |
{ |
|
114 |
+ |
public void setRehydrated() { |
138 |
115 |
|
super.setRehydrated(); |
139 |
116 |
|
mPropertyManager.setRehydrated(); |
140 |
117 |
|
} |
|
@@ -143,14 +120,12 @@ |
143 |
120 |
|
* @return null or Error |
144 |
121 |
|
*/ |
145 |
122 |
|
@Override |
146 |
|
- |
public String validatePersistable() |
147 |
|
- |
{ |
|
123 |
+ |
public String validatePersistable() { |
148 |
124 |
|
String error = super.validatePersistable(); |
149 |
125 |
|
return (error != null) ? error : mPropertyManager.validatePersistable(); |
150 |
126 |
|
} |
151 |
127 |
|
|
152 |
|
- |
public void addTo( ObjectBuilder pBuilder ) |
153 |
|
- |
{ |
|
128 |
+ |
public void addTo( ObjectBuilder pBuilder ) { |
154 |
129 |
|
AttributeBuilder zBuilder = pBuilder.createAttributeBuilder( getMetaDataType(), isVirtual(), getName(), |
155 |
130 |
|
SingleLineNotes.convertStringToLines( getNotes() ), |
156 |
131 |
|
getAdditionalValues() ); |
|
@@ -161,15 +136,13 @@ |
161 |
136 |
|
abstract protected String[] getAdditionalValues(); |
162 |
137 |
|
|
163 |
138 |
|
@Override |
164 |
|
- |
public void setUpView( NameValuesComponent pNameValuesComponent ) |
165 |
|
- |
{ |
|
139 |
+ |
public void setUpView( NameValuesComponent pNameValuesComponent ) { |
166 |
140 |
|
pNameValuesComponent.setValue( AttribNames.NAME, getName() ); |
167 |
141 |
|
pNameValuesComponent.setValue( ObjectNames.NOTES, getNotes() ); |
168 |
142 |
|
mPropertyManager.setUpView( pNameValuesComponent ); |
169 |
143 |
|
} |
170 |
144 |
|
|
171 |
|
- |
protected void saveFromViewCollectChanges( ChangeHandler pChanges, NameValuesComponent pNameValuesComponent ) |
172 |
|
- |
{ |
|
145 |
+ |
protected void saveFromViewCollectChanges( ChangeHandler pChanges, NameValuesComponent pNameValuesComponent ) { |
173 |
146 |
|
pChanges.add( checkNameChange( pNameValuesComponent.getValue( AttribNames.NAME ) ) ); |
174 |
147 |
|
pChanges.add( checkNotesChange( pNameValuesComponent.getValue( ObjectNames.NOTES ) ) ); |
175 |
148 |
|
mPropertyManager.saveFromView( pChanges, pNameValuesComponent ); |
|
@@ -179,15 +152,12 @@ |
179 |
152 |
|
* @return null or Error |
180 |
153 |
|
*/ |
181 |
154 |
|
@Override |
182 |
|
- |
public final String saveFromView( NameValuesComponent pNameValuesComponent ) |
183 |
|
- |
{ |
|
155 |
+ |
public final String saveFromView( NameValuesComponent pNameValuesComponent ) { |
184 |
156 |
|
ChangeHandler zChanges = new ChangeHandler(); |
185 |
|
- |
try |
186 |
|
- |
{ |
|
157 |
+ |
try { |
187 |
158 |
|
saveFromViewCollectChanges( zChanges, pNameValuesComponent ); |
188 |
159 |
|
} |
189 |
|
- |
catch ( RuntimeException e ) |
190 |
|
- |
{ |
|
160 |
+ |
catch ( RuntimeException e ) { |
191 |
161 |
|
return e.getMessage(); |
192 |
162 |
|
} |
193 |
163 |
|
|
|
@@ -198,15 +168,12 @@ |
198 |
168 |
|
/** |
199 |
169 |
|
* @return null or Error |
200 |
170 |
|
*/ |
201 |
|
- |
public final String deleteExisting() |
202 |
|
- |
{ |
|
171 |
+ |
public final String deleteExisting() { |
203 |
172 |
|
ChangeHandler zChanges = new ChangeHandler(); |
204 |
|
- |
try |
205 |
|
- |
{ |
|
173 |
+ |
try { |
206 |
174 |
|
deleteExistingCollectChanges( zChanges ); |
207 |
175 |
|
} |
208 |
|
- |
catch ( RuntimeException e ) |
209 |
|
- |
{ |
|
176 |
+ |
catch ( RuntimeException e ) { |
210 |
177 |
|
return e.getMessage(); |
211 |
178 |
|
} |
212 |
179 |
|
|
|
@@ -214,43 +181,34 @@ |
214 |
181 |
|
return null; |
215 |
182 |
|
} |
216 |
183 |
|
|
217 |
|
- |
public void deleteExistingCollectChanges( ChangeHandler pChanges ) |
218 |
|
- |
{ |
|
184 |
+ |
public void deleteExistingCollectChanges( ChangeHandler pChanges ) { |
219 |
185 |
|
pChanges.add( new DeleteAttribute( this ) ); |
220 |
186 |
|
} |
221 |
187 |
|
|
222 |
|
- |
public ObjectMetaData getObjectMetaData() |
223 |
|
- |
{ |
|
188 |
+ |
public ObjectMetaData getObjectMetaData() { |
224 |
189 |
|
return getOwner(); |
225 |
190 |
|
} |
226 |
191 |
|
|
227 |
|
- |
public void clearRelatedToIf( ObjectMetaData pObjectMetaData, ChangeHandler pChanges ) |
228 |
|
- |
{ |
|
192 |
+ |
public void clearRelatedToIf( ObjectMetaData pObjectMetaData, ChangeHandler pChanges ) { |
229 |
193 |
|
} |
230 |
194 |
|
|
231 |
|
- |
protected abstract static class AbstractChangeFragment implements ChangeFragment |
232 |
|
- |
{ |
|
195 |
+ |
protected abstract static class AbstractChangeFragment implements ChangeFragment { |
233 |
196 |
|
protected AttributeMetaData mCaller; |
234 |
197 |
|
|
235 |
|
- |
protected AbstractChangeFragment( AttributeMetaData pCaller ) |
236 |
|
- |
{ |
|
198 |
+ |
protected AbstractChangeFragment( AttributeMetaData pCaller ) { |
237 |
199 |
|
mCaller = pCaller; |
238 |
200 |
|
} |
239 |
201 |
|
} |
240 |
202 |
|
|
241 |
|
- |
protected ChangeFragment checkNameChange( String pNewName ) |
242 |
|
- |
{ |
|
203 |
+ |
protected ChangeFragment checkNameChange( String pNewName ) { |
243 |
204 |
|
String zError = getNameValidator().validateIdentifier( pNewName, "Attribute Name" ); |
244 |
|
- |
if ( zError != null ) |
245 |
|
- |
{ |
|
205 |
+ |
if ( zError != null ) { |
246 |
206 |
|
throw new RuntimeException( zError ); |
247 |
207 |
|
} |
248 |
208 |
|
String zCurName = getName(); |
249 |
|
- |
if ( !areEqual( zCurName, pNewName ) ) |
250 |
|
- |
{ |
|
209 |
+ |
if ( !areEqual( zCurName, pNewName ) ) { |
251 |
210 |
|
ObjectMetaData zOwner = getObjectMetaData(); |
252 |
|
- |
if ( zOwner.isUsedOwnedName( pNewName ) ) |
253 |
|
- |
{ |
|
211 |
+ |
if ( zOwner.isUsedOwnedName( pNewName ) ) { |
254 |
212 |
|
throw new RuntimeException( "Duplicate Name" ); |
255 |
213 |
|
} |
256 |
214 |
|
return createChangeNameFragment( pNewName ); |
|
@@ -258,66 +216,54 @@ |
258 |
216 |
|
return null; |
259 |
217 |
|
} |
260 |
218 |
|
|
261 |
|
- |
protected ChangeFragment createChangeNameFragment( String pNewName ) |
262 |
|
- |
{ |
|
219 |
+ |
protected ChangeFragment createChangeNameFragment( String pNewName ) { |
263 |
220 |
|
return new ChangeName( this, pNewName ); |
264 |
221 |
|
} |
265 |
222 |
|
|
266 |
|
- |
protected static class ChangeName extends AbstractChangeFragment |
267 |
|
- |
{ |
|
223 |
+ |
protected static class ChangeName extends AbstractChangeFragment { |
268 |
224 |
|
private String mNewName; |
269 |
225 |
|
|
270 |
|
- |
public ChangeName( AttributeMetaData pCaller, String pNewName ) |
271 |
|
- |
{ |
|
226 |
+ |
public ChangeName( AttributeMetaData pCaller, String pNewName ) { |
272 |
227 |
|
super( pCaller ); |
273 |
228 |
|
mNewName = pNewName; |
274 |
229 |
|
} |
275 |
230 |
|
|
276 |
231 |
|
@Override |
277 |
|
- |
public void commitChange() |
278 |
|
- |
{ |
|
232 |
+ |
public void commitChange() { |
279 |
233 |
|
mCaller.setName( mNewName ); |
280 |
234 |
|
} |
281 |
235 |
|
} |
282 |
236 |
|
|
283 |
|
- |
protected ChangeFragment checkNotesChange( String pNewNotes ) |
284 |
|
- |
{ |
|
237 |
+ |
protected ChangeFragment checkNotesChange( String pNewNotes ) { |
285 |
238 |
|
String zCurNotes = getNotes(); |
286 |
239 |
|
return !areEqual( zCurNotes, pNewNotes ) ? createChangeNotesFragment( pNewNotes ) : null; |
287 |
240 |
|
} |
288 |
241 |
|
|
289 |
|
- |
protected ChangeFragment createChangeNotesFragment( String pNewNotes ) |
290 |
|
- |
{ |
|
242 |
+ |
protected ChangeFragment createChangeNotesFragment( String pNewNotes ) { |
291 |
243 |
|
return new ChangeNotes( this, pNewNotes ); |
292 |
244 |
|
} |
293 |
245 |
|
|
294 |
|
- |
protected static class ChangeNotes extends AbstractChangeFragment |
295 |
|
- |
{ |
|
246 |
+ |
protected static class ChangeNotes extends AbstractChangeFragment { |
296 |
247 |
|
private String mNewNotes; |
297 |
248 |
|
|
298 |
|
- |
public ChangeNotes( AttributeMetaData pCaller, String pNewNotes ) |
299 |
|
- |
{ |
|
249 |
+ |
public ChangeNotes( AttributeMetaData pCaller, String pNewNotes ) { |
300 |
250 |
|
super( pCaller ); |
301 |
251 |
|
mNewNotes = pNewNotes; |
302 |
252 |
|
} |
303 |
253 |
|
|
304 |
254 |
|
@Override |
305 |
|
- |
public void commitChange() |
306 |
|
- |
{ |
|
255 |
+ |
public void commitChange() { |
307 |
256 |
|
mCaller.setNotes( mNewNotes ); |
308 |
257 |
|
} |
309 |
258 |
|
} |
310 |
259 |
|
|
311 |
|
- |
protected static class DeleteAttribute extends AbstractChangeFragment |
312 |
|
- |
{ |
313 |
|
- |
public DeleteAttribute( AttributeMetaData pCaller ) |
314 |
|
- |
{ |
|
260 |
+ |
protected static class DeleteAttribute extends AbstractChangeFragment { |
|
261 |
+ |
public DeleteAttribute( AttributeMetaData pCaller ) { |
315 |
262 |
|
super( pCaller ); |
316 |
263 |
|
} |
317 |
264 |
|
|
318 |
265 |
|
@Override |
319 |
|
- |
public void commitChange() |
320 |
|
- |
{ |
|
266 |
+ |
public void commitChange() { |
321 |
267 |
|
mCaller.getObjectMetaData().remove( mCaller ); |
322 |
268 |
|
} |
323 |
269 |
|
} |