|
@@ -1,745 +1,745 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.aokeyhole; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.aokeyhole.objects.*; |
5 |
|
- |
import org.litesoft.aokeyhole.objects.attributes.*; |
6 |
|
- |
import org.litesoft.aokeyhole.objects.factories.*; |
7 |
|
- |
import org.litesoft.aokeyhole.objects.support.*; |
8 |
|
- |
import org.litesoft.aokeyhole.persist.*; |
9 |
|
- |
import org.litesoft.aokeyhole.toolkit.*; |
10 |
|
- |
import org.litesoft.aokeyhole.toolkit.editorviewer.*; |
11 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
12 |
|
- |
|
13 |
|
- |
import javax.swing.*; |
14 |
|
- |
import java.io.*; |
15 |
|
- |
import java.util.*; |
16 |
|
- |
import java.util.concurrent.*; |
17 |
|
- |
|
18 |
|
- |
public abstract class AbstractMain implements ActionsListener, |
19 |
|
- |
NewAttributeTypeSelectionListener, |
20 |
|
- |
NameValueChangedByUserListener, |
21 |
|
- |
NewObjectTypeSelectionListener, |
22 |
|
- |
ChangeCallback { |
23 |
|
- |
private static final String BASE_VERSION = "1.30"; |
24 |
|
- |
|
25 |
|
- |
private BlockingQueue<Runnable> mNonUIrunnables = new LinkedBlockingQueue<Runnable>(); |
26 |
|
- |
// Constructor... |
27 |
|
- |
private final SubSystemFactory mSubSystemFactory; |
28 |
|
- |
private final EditViewPanelFactory mEditViewPanelFactory; |
29 |
|
- |
private final SubSystemPersister[] mPersisters; |
30 |
|
- |
private final boolean mEditable; |
31 |
|
- |
|
32 |
|
- |
private String mVersion = BASE_VERSION; |
33 |
|
- |
|
34 |
|
- |
// unpersistAllObjects... |
35 |
|
- |
private SystemMetaData mSystemMetaData; |
36 |
|
- |
private SubSystemMetaData mSubSystemForSaving = null; |
37 |
|
- |
|
38 |
|
- |
// start |
39 |
|
- |
private EditViewPanelController mEditViewPanelController = null; |
40 |
|
- |
|
41 |
|
- |
// setter... |
42 |
|
- |
private ObjectListUpdater mObjectListUpdater = null; |
43 |
|
- |
|
44 |
|
- |
// Normal User Interaction... |
45 |
|
- |
private ActionsControllableNameValuesComponent mCurrentEditViewPanel = null; |
46 |
|
- |
|
47 |
|
- |
private ObjectMetaData mSelectedObject = null; |
48 |
|
- |
private boolean mNewObject = false; |
49 |
|
- |
private ObjectSet mNewObjectSet; |
50 |
|
- |
|
51 |
|
- |
private AttributeMetaData mSelectedAttribute = null; |
52 |
|
- |
private boolean mNewAttribute = false; |
53 |
|
- |
private boolean mNewAttributeVirtual; |
54 |
|
- |
private AttributeSet mNewAttributeSet; |
55 |
|
- |
|
56 |
|
- |
protected AbstractMain( SubSystemFactory pSubSystemFactory, EditViewPanelFactory pEditViewPanelFactory, boolean pReadOnly, SubSystemPersister... pPersisters ) |
57 |
|
- |
throws IOException { |
58 |
|
- |
mSubSystemFactory = pSubSystemFactory; |
59 |
|
- |
mEditViewPanelFactory = pEditViewPanelFactory; |
60 |
|
- |
if ( (mPersisters = pPersisters).length == 0 ) { |
61 |
|
- |
throw new IllegalArgumentException( "No Data Sources Provided" ); |
62 |
|
- |
} |
63 |
|
- |
mEditable = !(pReadOnly || getLastPersister().isReadOnly()); |
64 |
|
- |
|
65 |
|
- |
unpersistAllObjects(); |
66 |
|
- |
|
67 |
|
- |
mVersion = BASE_VERSION + "-" + mSystemMetaData.getVersion(); |
68 |
|
- |
} |
69 |
|
- |
|
70 |
|
- |
@SuppressWarnings({"UnusedDeclaration"}) |
71 |
|
- |
public String getVersion() { |
72 |
|
- |
return mVersion; |
73 |
|
- |
} |
74 |
|
- |
|
75 |
|
- |
public SystemMetaData getSystemMetaData() { |
76 |
|
- |
return mSystemMetaData; |
77 |
|
- |
} |
78 |
|
- |
|
79 |
|
- |
@SuppressWarnings({"UnusedDeclaration"}) |
80 |
|
- |
public SubSystemMetaData getSubSystemForSaving() { |
81 |
|
- |
return mSubSystemForSaving; |
82 |
|
- |
} |
83 |
|
- |
|
84 |
|
- |
public void persistSubSystem( SubSystemWriter pSubSystemWriter ) |
85 |
|
- |
throws IOException { |
86 |
|
- |
if ( mEditable ) { |
87 |
|
- |
pSubSystemWriter.write(); |
88 |
|
- |
} |
89 |
|
- |
} |
90 |
|
- |
|
91 |
|
- |
private SubSystemPersister getLastPersister() { |
92 |
|
- |
return mPersisters[mPersisters.length - 1]; |
93 |
|
- |
} |
94 |
|
- |
|
95 |
|
- |
/** |
96 |
|
- |
* Called during Construction on the "main" Thread |
97 |
|
- |
*/ |
98 |
|
- |
protected ObjectListClickListener createObjectListClickListener() { |
99 |
|
- |
return new OurObjectListClickListener(); |
100 |
|
- |
} |
101 |
|
- |
|
102 |
|
- |
/** |
103 |
|
- |
* Called during Construction on the "main" Thread |
104 |
|
- |
*/ |
105 |
|
- |
protected BoxedTextClickListener createBoxedTextClickListener() { |
106 |
|
- |
return new OurBoxedTextClickListener(); |
107 |
|
- |
} |
108 |
|
- |
|
109 |
|
- |
/** |
110 |
|
- |
* Called during Construction on the "main" Thread |
111 |
|
- |
*/ |
112 |
|
- |
protected void setObjectListUpdater( ObjectListUpdater pObjectListUpdater ) { |
113 |
|
- |
mObjectListUpdater = pObjectListUpdater; |
114 |
|
- |
} |
115 |
|
- |
|
116 |
|
- |
/** |
117 |
|
- |
* Should be called on the "main" Thread! |
118 |
|
- |
*/ |
119 |
|
- |
private void unpersistAllObjects() |
120 |
|
- |
throws IOException { |
121 |
|
- |
SystemMetaData zSMD = new SystemMetaData( mEditable, BASE_VERSION, mSubSystemFactory ); |
122 |
|
- |
|
123 |
|
- |
SubSystemMetaData lastSS = null; |
124 |
|
- |
for ( int i = 0; i < mPersisters.length; i++ ) { |
125 |
|
- |
SubSystemPersister zPersister = mPersisters[i]; |
126 |
|
- |
lastSS = zSMD.unpersistSubSystemMetaData( i, zPersister ).loadObjects(); |
127 |
|
- |
} |
128 |
|
- |
zSMD.setRehydrated(); |
129 |
|
- |
|
130 |
|
- |
mSystemMetaData = zSMD; |
131 |
|
- |
if ( mEditable ) { |
132 |
|
- |
mSubSystemForSaving = lastSS; |
133 |
|
- |
} |
134 |
|
- |
} |
135 |
|
- |
|
136 |
|
- |
/** |
137 |
|
- |
* Running on the "main" Thread |
138 |
|
- |
*/ |
139 |
|
- |
public void start() { |
140 |
|
- |
mEditViewPanelController = mEditViewPanelFactory |
141 |
|
- |
.createEditViewPanelController( mEditable, getLastPersister().getName(), mSystemMetaData.getObjectSets(), mSystemMetaData.getAttributeSets(), |
142 |
|
- |
this, this, this, this ); |
143 |
|
- |
|
144 |
|
- |
mSystemMetaData.add( buildUI( mVersion, mEditViewPanelController ) ); |
145 |
|
- |
|
146 |
|
- |
mSystemMetaData.add( this ); |
147 |
|
- |
|
148 |
|
- |
mObjectListUpdater.updateObjectList( mSystemMetaData.getSortedObjectMetaDatas() ); |
149 |
|
- |
|
150 |
|
- |
showUI(); |
151 |
|
- |
|
152 |
|
- |
runMainThreadLoop(); |
153 |
|
- |
} |
154 |
|
- |
|
155 |
|
- |
/** |
156 |
|
- |
* Running on the "main" Thread |
157 |
|
- |
*/ |
158 |
|
- |
public synchronized void runMainThreadLoop() { |
159 |
|
- |
for ( Runnable zRunnable; null != (zRunnable = waitForMainThreadRunnable()); ) { |
160 |
|
- |
try { |
161 |
|
- |
zRunnable.run(); |
162 |
|
- |
} |
163 |
|
- |
catch ( RuntimeException e ) { |
164 |
|
- |
e.printStackTrace(); |
165 |
|
- |
updateStatus( e.getMessage() ); |
166 |
|
- |
} |
167 |
|
- |
} |
168 |
|
- |
} |
169 |
|
- |
|
170 |
|
- |
/** |
171 |
|
- |
* Running on the "main" Thread |
172 |
|
- |
*/ |
173 |
|
- |
private Runnable waitForMainThreadRunnable() { |
174 |
|
- |
while ( true ) { |
175 |
|
- |
try { |
176 |
|
- |
Runnable zRunnable = mNonUIrunnables.take(); |
177 |
|
- |
if ( zRunnable != null ) { |
178 |
|
- |
return zRunnable; |
179 |
|
- |
} |
180 |
|
- |
} |
181 |
|
- |
catch ( InterruptedException e ) { |
182 |
|
- |
return null; |
183 |
|
- |
} |
184 |
|
- |
} |
185 |
|
- |
} |
186 |
|
- |
|
187 |
|
- |
// Called by Either ("main" or "UI" Event) Thread... |
188 |
|
- |
private void postMainThreadRunnable( String pWhat, Runnable pRunnable ) { |
189 |
|
- |
try { |
190 |
|
- |
mNonUIrunnables.put( pRunnable ); |
191 |
|
- |
} |
192 |
|
- |
catch ( InterruptedException e ) { |
193 |
|
- |
e.printStackTrace(); |
194 |
|
- |
updateStatus( "Time out / Interruption attempting to " + pWhat ); |
195 |
|
- |
} |
196 |
|
- |
} |
197 |
|
- |
|
198 |
|
- |
// Called by Either ("main" or "UI" Event) Thread... |
199 |
|
- |
private void postUiThreadRunnable( String pWhat, Runnable pRunnable ) { |
200 |
|
- |
try { |
201 |
|
- |
SwingUtilities.invokeLater( pRunnable ); |
202 |
|
- |
} |
203 |
|
- |
catch ( RuntimeException e ) { |
204 |
|
- |
e.printStackTrace(); |
205 |
|
- |
updateStatus( "Exception attempting to " + pWhat + " of: " + e.getMessage() ); |
206 |
|
- |
} |
207 |
|
- |
} |
208 |
|
- |
|
209 |
|
- |
/** |
210 |
|
- |
* Called on the "UI" Event Thread |
211 |
|
- |
*/ |
212 |
|
- |
protected void save( final SubSystemWriter pSubSystemWriter ) { |
213 |
|
- |
postMainThreadRunnable( "Save Changes", new Runnable() { |
214 |
|
- |
// Called on the "main" Thread |
215 |
|
- |
@Override |
216 |
|
- |
public void run() { |
217 |
|
- |
if ( !mEditable ) { |
218 |
|
- |
updateStatus( "No Persistable" ); |
219 |
|
- |
} else { |
220 |
|
- |
try { |
221 |
|
- |
persistSubSystem( pSubSystemWriter ); |
222 |
|
- |
getSystemMetaData().clearChangeIndicators(); |
223 |
|
- |
updateStatus( "Save Complete" ); |
224 |
|
- |
} |
225 |
|
- |
catch ( IOException e ) { |
226 |
|
- |
e.printStackTrace(); |
227 |
|
- |
updateStatus( e.getMessage() ); |
228 |
|
- |
} |
229 |
|
- |
catch ( RuntimeException e ) { |
230 |
|
- |
e.printStackTrace(); |
231 |
|
- |
updateStatus( e.getMessage() ); |
232 |
|
- |
} |
233 |
|
- |
} |
234 |
|
- |
} |
235 |
|
- |
} ); |
236 |
|
- |
} |
237 |
|
- |
|
238 |
|
- |
private class CurrentDisplayState { |
239 |
|
- |
private ObjectMetaData mCurrentSelectedObject = null; |
240 |
|
- |
private AttributeMetaData mCurrentSelectedAttribute = null; |
241 |
|
- |
|
242 |
|
- |
private CurrentDisplayState() { |
243 |
|
- |
if ( !mNewObject ) { |
244 |
|
- |
mCurrentSelectedObject = mSelectedObject; |
245 |
|
- |
if ( !mNewAttribute ) { |
246 |
|
- |
mCurrentSelectedAttribute = mSelectedAttribute; |
247 |
|
- |
} |
248 |
|
- |
} |
249 |
|
- |
} |
250 |
|
- |
|
251 |
|
- |
public void restore() { |
252 |
|
- |
if ( mCurrentSelectedObject != null ) { |
253 |
|
- |
if ( null != (mSelectedObject = mSystemMetaData.getObject( mCurrentSelectedObject.getName() )) ) { |
254 |
|
- |
selectObjectExisting(); |
255 |
|
- |
if ( mCurrentSelectedAttribute != null ) { |
256 |
|
- |
if ( null != (mSelectedAttribute = mSelectedObject.getAttribute( mCurrentSelectedAttribute.getName() )) ) { |
257 |
|
- |
selectAttribExisting(); |
258 |
|
- |
} |
259 |
|
- |
} |
260 |
|
- |
} |
261 |
|
- |
} |
262 |
|
- |
} |
263 |
|
- |
} |
264 |
|
- |
|
265 |
|
- |
/** |
266 |
|
- |
* Called on the "UI" Event Thread |
267 |
|
- |
*/ |
268 |
|
- |
protected void refresh() { |
269 |
|
- |
final CurrentDisplayState mCurrentState = new CurrentDisplayState(); |
270 |
|
- |
clearSelections(); // Show Nothing... |
271 |
|
- |
updateStatus( "Refreshing..." ); |
272 |
|
- |
|
273 |
|
- |
postMainThreadRunnable( "Refresh", new Runnable() { |
274 |
|
- |
// Called on the "main" Thread |
275 |
|
- |
@Override |
276 |
|
- |
public void run() { |
277 |
|
- |
refreshStep2( mCurrentState ); |
278 |
|
- |
} |
279 |
|
- |
} ); |
280 |
|
- |
} |
281 |
|
- |
|
282 |
|
- |
/** |
283 |
|
- |
* Called on the "main" Thread |
284 |
|
- |
*/ |
285 |
|
- |
protected void refreshStep2( final CurrentDisplayState pCurrentState ) { |
286 |
|
- |
try { |
287 |
|
- |
List<ChangeCallback> zCallbacks = mSystemMetaData.getChangeCallbacks(); |
288 |
|
- |
unpersistAllObjects(); |
289 |
|
- |
for ( ChangeCallback zCallback : zCallbacks ) { |
290 |
|
- |
mSystemMetaData.add( zCallback ); |
291 |
|
- |
} |
292 |
|
- |
postUiThreadRunnable( "Refresh", new Runnable() { |
293 |
|
- |
// Called on the "UI" Event Thread |
294 |
|
- |
@Override |
295 |
|
- |
public void run() { |
296 |
|
- |
refreshStep3( pCurrentState ); |
297 |
|
- |
} |
298 |
|
- |
} ); |
299 |
|
- |
} |
300 |
|
- |
catch ( IOException e ) { |
301 |
|
- |
e.printStackTrace(); |
302 |
|
- |
updateStatus( e.getMessage() ); |
303 |
|
- |
} |
304 |
|
- |
catch ( RuntimeException e ) { |
305 |
|
- |
e.printStackTrace(); |
306 |
|
- |
updateStatus( e.getMessage() ); |
307 |
|
- |
} |
308 |
|
- |
} |
309 |
|
- |
|
310 |
|
- |
/** |
311 |
|
- |
* Called on the "UI" Event Thread |
312 |
|
- |
*/ |
313 |
|
- |
protected void refreshStep3( CurrentDisplayState pCurrentState ) { |
314 |
|
- |
mObjectListUpdater.updateObjectList( mSystemMetaData.getSortedObjectMetaDatas() ); |
315 |
|
- |
pCurrentState.restore(); |
316 |
|
- |
clearStatus(); |
317 |
|
- |
} |
318 |
|
- |
|
319 |
|
- |
/** |
320 |
|
- |
* Called during Construction on the "main" Thread |
321 |
|
- |
*/ |
322 |
|
- |
abstract protected ChangeCallback buildUI( String pVersion, EditViewPanelController pEditViewPanelController ); |
323 |
|
- |
|
324 |
|
- |
/** |
325 |
|
- |
* Called during Construction on the "main" Thread |
326 |
|
- |
*/ |
327 |
|
- |
abstract protected void showUI(); |
328 |
|
- |
|
329 |
|
- |
/** |
330 |
|
- |
* Called on BOTH the Main & UI Event Thread |
331 |
|
- |
* |
332 |
|
- |
* @param pMessage |
333 |
|
- |
* |
334 |
|
- |
* @return pMessage |
335 |
|
- |
*/ |
336 |
|
- |
abstract protected String updateStatus( String pMessage ); |
337 |
|
- |
|
338 |
|
- |
/** |
339 |
|
- |
* Called on the UI Event Thread |
340 |
|
- |
*/ |
341 |
|
- |
abstract protected void setStatus( String pMessage ); |
342 |
|
- |
|
343 |
|
- |
/** |
344 |
|
- |
* Called on the UI Event Thread |
345 |
|
- |
*/ |
346 |
|
- |
abstract protected ObjectAndAttributesWithOneDegreeSeperationView createObjectAndAttributesWithOneDegreeSeperationView(); |
347 |
|
- |
|
348 |
|
- |
/** |
349 |
|
- |
* Called on the UI Event Thread |
350 |
|
- |
*/ |
351 |
|
- |
abstract protected void setObjectAndAttributesWithOneDegreeSeperationView( ObjectAndAttributesWithOneDegreeSeperationView pOAV ); |
352 |
|
- |
|
353 |
|
- |
/** |
354 |
|
- |
* Called on the UI Event Thread |
355 |
|
- |
*/ |
356 |
|
- |
@Override |
357 |
|
- |
public void namedValueChangedByUser( String pName ) { |
358 |
|
- |
if ( mCurrentEditViewPanel != null ) { |
359 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, true ); |
360 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_REVERT, true ); |
361 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_DELETE, false ); |
362 |
|
- |
|
363 |
|
- |
if ( AttribNamesRelated.RELATED_TO.equals( pName ) ) { |
364 |
|
- |
boolean zToManys = !currentAttributeIsToMany(); |
365 |
|
- |
ObjectMetaData object = mSystemMetaData.getObject( mCurrentEditViewPanel.getValue( pName ) ); |
366 |
|
- |
String[] options = (object == null) ? new String[0] : object.getSortedRelatedPersistedAttributeNamesTo( zToManys, mSelectedObject ); |
367 |
|
- |
mCurrentEditViewPanel.setOptions( AttribNamesRelatedPersisted.BACK_REF, options ); |
368 |
|
- |
} |
369 |
|
- |
} |
370 |
|
- |
// System.out.println( "Hook for special behavior on namedValueChangedByUser: " + pName ); |
371 |
|
- |
} |
372 |
|
- |
|
373 |
|
- |
private boolean currentAttributeIsToMany() { |
374 |
|
- |
AttributeSet zSet = mNewAttribute ? mNewAttributeSet : mSelectedAttribute.getAttributeSet(); |
375 |
|
- |
return A_ToMany.TYPE.equals( zSet.getType() ); |
376 |
|
- |
} |
377 |
|
- |
|
378 |
|
- |
/** |
379 |
|
- |
* Called on the UI Event Thread |
380 |
|
- |
*/ |
381 |
|
- |
private void clearSelections() { |
382 |
|
- |
mSelectedObject = null; |
383 |
|
- |
mSelectedAttribute = null; |
384 |
|
- |
mCurrentEditViewPanel = null; |
385 |
|
- |
mNewObject = false; |
386 |
|
- |
mNewAttribute = false; |
387 |
|
- |
mEditViewPanelController.showBlank(); |
388 |
|
- |
clearStatus(); |
389 |
|
- |
} |
390 |
|
- |
|
391 |
|
- |
/** |
392 |
|
- |
* Called on the UI Event Thread |
393 |
|
- |
*/ |
394 |
|
- |
private void clearStatus() { |
395 |
|
- |
if ( mSelectedObject != null ) { |
396 |
|
- |
updateStatus( mSelectedObject.getOwner().getName() ); |
397 |
|
- |
return; |
398 |
|
- |
} |
399 |
|
- |
if ( mNewObject ) { |
400 |
|
- |
updateStatus( mSubSystemForSaving.getName() ); |
401 |
|
- |
return; |
402 |
|
- |
} |
403 |
|
- |
updateStatus( null ); |
404 |
|
- |
} |
405 |
|
- |
|
406 |
|
- |
/** |
407 |
|
- |
* Called on the UI Event Thread |
408 |
|
- |
*/ |
409 |
|
- |
private void selectObjectNew() { |
410 |
|
- |
setObjectAndAttributesWithOneDegreeSeperationView( null ); |
411 |
|
- |
mObjectListUpdater.clearSelectedObject(); |
412 |
|
- |
clearSelections(); |
413 |
|
- |
mNewObject = true; |
414 |
|
- |
clearStatus(); |
415 |
|
- |
mEditViewPanelController.showNewObjectTypeSelector( mSubSystemForSaving ); |
416 |
|
- |
} |
417 |
|
- |
|
418 |
|
- |
/** |
419 |
|
- |
* Called on the UI Event Thread |
420 |
|
- |
*/ |
421 |
|
- |
private void selectObjectExisting() { |
422 |
|
- |
mSelectedAttribute = null; |
423 |
|
- |
mCurrentEditViewPanel = mEditViewPanelController.showObjectExisting( mSelectedObject ); |
424 |
|
- |
setUpViewSupportable( mSelectedObject ); |
425 |
|
- |
} |
426 |
|
- |
|
427 |
|
- |
/** |
428 |
|
- |
* Called on the UI Event Thread |
429 |
|
- |
*/ |
430 |
|
- |
private void selectObjectFromList( String pName ) { |
431 |
|
- |
clearSelections(); |
432 |
|
- |
if ( showObjectGraph( pName ) ) { |
433 |
|
- |
selectObjectExisting(); |
434 |
|
- |
} |
435 |
|
- |
} |
436 |
|
- |
|
437 |
|
- |
/** |
438 |
|
- |
* Called on the UI Event Thread |
439 |
|
- |
*/ |
440 |
|
- |
private void selectObjectRelated( String pName ) { |
441 |
|
- |
if ( ObjectNames.VARIES_RELATED_TO.equals( pName ) ) { |
442 |
|
- |
updateStatus( "Can NOT navigate to a 'variable' relationship" ); |
443 |
|
- |
return; |
444 |
|
- |
} |
445 |
|
- |
clearSelections(); |
446 |
|
- |
if ( showObjectGraph( pName ) ) { |
447 |
|
- |
mObjectListUpdater.setSelectedObject( mSystemMetaData.getObject( pName ) ); |
448 |
|
- |
selectObjectExisting(); |
449 |
|
- |
} |
450 |
|
- |
} |
451 |
|
- |
|
452 |
|
- |
/** |
453 |
|
- |
* Called on the UI Event Thread |
454 |
|
- |
*/ |
455 |
|
- |
private void selectObjectMain() { |
456 |
|
- |
selectObjectExisting(); |
457 |
|
- |
} |
458 |
|
- |
|
459 |
|
- |
/** |
460 |
|
- |
* Called on the UI Event Thread |
461 |
|
- |
*/ |
462 |
|
- |
private void selectAttribExisting( String pName ) { |
463 |
|
- |
if ( pName != null ) { |
464 |
|
- |
pName = pName.trim(); |
465 |
|
- |
if ( pName.startsWith( "*" ) ) { |
466 |
|
- |
pName = pName.substring( 1 ).trim(); |
467 |
|
- |
} |
468 |
|
- |
if ( pName.endsWith( "*" ) ) { |
469 |
|
- |
pName = pName.substring( 0, pName.length() - 1 ).trim(); |
470 |
|
- |
} |
471 |
|
- |
} |
472 |
|
- |
mSelectedAttribute = mSelectedObject.getAttribute( pName ); |
473 |
|
- |
if ( mSelectedAttribute == null ) { |
474 |
|
- |
mCurrentEditViewPanel = null; |
475 |
|
- |
mEditViewPanelController.showBlank(); |
476 |
|
- |
System.err.println( "selectAttribExisting ?: " + pName ); |
477 |
|
- |
return; |
478 |
|
- |
} |
479 |
|
- |
selectAttribExisting(); |
480 |
|
- |
} |
481 |
|
- |
|
482 |
|
- |
/** |
483 |
|
- |
* Called on the UI Event Thread |
484 |
|
- |
*/ |
485 |
|
- |
private void selectAttribExisting() { |
486 |
|
- |
mNewAttribute = false; |
487 |
|
- |
mCurrentEditViewPanel = mEditViewPanelController.showAttribExisting( mSelectedAttribute ); |
488 |
|
- |
NameValuesComponent zValuesComponent = setUpViewSupportable( mSelectedAttribute ); |
489 |
|
- |
if ( mSelectedAttribute instanceof AttributeMetaDataRelatedPersisted && mSelectedAttribute.isEditable() ) { |
490 |
|
- |
AttributeMetaDataRelatedPersisted zMDR = (AttributeMetaDataRelatedPersisted) mSelectedAttribute; |
491 |
|
- |
String zRelatedTo = zMDR.getRelatedTo(); |
492 |
|
- |
String zBackAttrib = zMDR.getBackAttrib(); |
493 |
|
- |
if ( Strings.isNotNullOrEmpty( zRelatedTo ) && Strings.isNotNullOrEmpty( zBackAttrib ) ) { |
494 |
|
- |
ObjectMetaData zObjectMetaData = mSystemMetaData.getObject( zRelatedTo ); |
495 |
|
- |
if ( zObjectMetaData != null ) { |
496 |
|
- |
if ( zObjectMetaData.getAttribute( zBackAttrib ) == null ) { |
497 |
|
- |
zMDR.unpersistBackAttrib( null ); |
498 |
|
- |
zValuesComponent.setValue( AttribNamesRelatedPersisted.BACK_REF, "!" + zBackAttrib ); |
499 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, true ); |
500 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_DELETE, false ); |
501 |
|
- |
} |
502 |
|
- |
} |
503 |
|
- |
} |
504 |
|
- |
} |
505 |
|
- |
} |
506 |
|
- |
|
507 |
|
- |
/** |
508 |
|
- |
* Called on the UI Event Thread |
509 |
|
- |
*/ |
510 |
|
- |
private void selectAttribNew() { |
511 |
|
- |
mSelectedAttribute = null; |
512 |
|
- |
mCurrentEditViewPanel = null; |
513 |
|
- |
mNewAttribute = true; |
514 |
|
- |
clearStatus(); |
515 |
|
- |
mEditViewPanelController.showNewAttributeTypeSelector( mSelectedObject ); |
516 |
|
- |
} |
517 |
|
- |
|
518 |
|
- |
@Override |
519 |
|
- |
public void newObjectTypeSelected( ObjectSet pObjectSet ) { |
520 |
|
- |
mCurrentEditViewPanel = mEditViewPanelController.showObjectNew( mSubSystemForSaving, mNewObjectSet = pObjectSet ); |
521 |
|
- |
mCurrentEditViewPanel.initializeView(); |
522 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, false ); |
523 |
|
- |
clearStatus(); |
524 |
|
- |
} |
525 |
|
- |
|
526 |
|
- |
@Override |
527 |
|
- |
public void newAttributeTypeSelected( boolean pVirtual, AttributeSet pAttributeSet ) { |
528 |
|
- |
mSelectedAttribute = null; |
529 |
|
- |
mCurrentEditViewPanel = mEditViewPanelController.showAttributeNew( mSelectedObject, mNewAttributeVirtual = pVirtual, mNewAttributeSet = pAttributeSet ); |
530 |
|
- |
mCurrentEditViewPanel.initializeView(); |
531 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, false ); |
532 |
|
- |
} |
533 |
|
- |
|
534 |
|
- |
@Override |
535 |
|
- |
public void changeStateUpdated( Changeable pChangeable ) { |
536 |
|
- |
if ( mSelectedObject != null ) { |
537 |
|
- |
showObjectGraph( mSelectedObject.getName() ); |
538 |
|
- |
} |
539 |
|
- |
if ( mSystemMetaData.objectListHasChanged() ) { |
540 |
|
- |
mObjectListUpdater.updateObjectList( mSystemMetaData.getSortedObjectMetaDatas() ); |
541 |
|
- |
} |
542 |
|
- |
} |
543 |
|
- |
|
544 |
|
- |
/** |
545 |
|
- |
* Called on the "UI" Event Thread |
546 |
|
- |
*/ |
547 |
|
- |
private boolean showObjectGraph( String pObjectName ) { |
548 |
|
- |
if ( mSelectedObject != null ) { |
549 |
|
- |
mSelectedObject.remove( this ); |
550 |
|
- |
mSelectedObject = null; |
551 |
|
- |
} |
552 |
|
- |
setObjectAndAttributesWithOneDegreeSeperationView( null ); // turn off display |
553 |
|
- |
if ( pObjectName != null ) { |
554 |
|
- |
mSelectedObject = mSystemMetaData.getObject( pObjectName ); |
555 |
|
- |
} |
556 |
|
- |
if ( mSelectedObject == null ) { |
557 |
|
- |
return false; |
558 |
|
- |
} |
559 |
|
- |
mSelectedObject.add( this ); |
560 |
|
- |
|
561 |
|
- |
ObjectAndAttributesWithOneDegreeSeperationView oneDegreeSepView = createObjectAndAttributesWithOneDegreeSeperationView(); |
562 |
|
- |
oneDegreeSepView.changeObjectName( mSelectedObject.getName() ); |
563 |
|
- |
oneDegreeSepView.setParentName( mSelectedObject.getParentName() ); |
564 |
|
- |
oneDegreeSepView.setGeneratedRelationsByParentNames( mSelectedObject.getSortedChildNames() ); |
565 |
|
- |
List<AttributeMetaData> attributes = mSelectedObject.getSortedAttributes(); |
566 |
|
- |
for ( AttributeMetaData attribute : attributes ) { |
567 |
|
- |
String zChanged = attribute.isChanged() ? " * " : " "; |
568 |
|
- |
String zName = zChanged + attribute.getName() + zChanged; |
569 |
|
- |
if ( attribute instanceof AttributeMetaDataSimple ) { |
570 |
|
- |
oneDegreeSepView.addSimpleAttribute( zName, attribute.isVirtual() ); |
571 |
|
- |
} else { |
572 |
|
- |
AttributeMetaDataRelated rmd = (AttributeMetaDataRelated) attribute; |
573 |
|
- |
if ( rmd.getRelatedTo() == null ) { |
574 |
|
- |
oneDegreeSepView.addRelatedAttributeToSelf( zName, attribute.isVirtual() ); |
575 |
|
- |
} else { |
576 |
|
- |
oneDegreeSepView.addRelatedAttribute( zName, attribute.isVirtual(), rmd.getRelatedTo() ); |
577 |
|
- |
} |
578 |
|
- |
} |
579 |
|
- |
} |
580 |
|
- |
if ( mSelectedObject.isEditable() ) { |
581 |
|
- |
oneDegreeSepView.addNewAttributeOption(); |
582 |
|
- |
} |
583 |
|
- |
setObjectAndAttributesWithOneDegreeSeperationView( oneDegreeSepView ); |
584 |
|
- |
return true; |
585 |
|
- |
} |
586 |
|
- |
|
587 |
|
- |
/** |
588 |
|
- |
* Called on the UI Event Thread |
589 |
|
- |
*/ |
590 |
|
- |
private NameValuesComponent setUpViewSupportable( ViewSupportable pViewSupportable ) { |
591 |
|
- |
clearStatus(); |
592 |
|
- |
NameValuesComponent zValuesComponent = mCurrentEditViewPanel.setUpView( pViewSupportable ); |
593 |
|
- |
buttonsToInitialState(); |
594 |
|
- |
return zValuesComponent; |
595 |
|
- |
} |
596 |
|
- |
|
597 |
|
- |
/** |
598 |
|
- |
* Called on the UI Event Thread |
599 |
|
- |
*/ |
600 |
|
- |
private void buttonsToInitialState() { |
601 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, false ); |
602 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_REVERT, false ); |
603 |
|
- |
mCurrentEditViewPanel.actionEnable( ACTION_DELETE, true ); |
604 |
|
- |
} |
605 |
|
- |
|
606 |
|
- |
/** |
607 |
|
- |
* Called on the UI Event Thread |
608 |
|
- |
*/ |
609 |
|
- |
@Override |
610 |
|
- |
public void actionRequested( String pAction ) { |
611 |
|
- |
// System.out.println( "actionRequested: " + pAction ); |
612 |
|
- |
if ( ACTION_CANCEL.equals( pAction ) ) { |
613 |
|
- |
if ( mSelectedObject != null ) { |
614 |
|
- |
selectObjectExisting(); |
615 |
|
- |
} else { |
616 |
|
- |
clearSelections(); |
617 |
|
- |
} |
618 |
|
- |
return; |
619 |
|
- |
} |
620 |
|
- |
if ( ACTION_REVERT.equals( pAction ) ) { |
621 |
|
- |
if ( mSelectedAttribute != null ) { |
622 |
|
- |
selectAttribExisting(); |
623 |
|
- |
} else if ( mSelectedObject != null ) { |
624 |
|
- |
selectObjectExisting(); |
625 |
|
- |
} else { |
626 |
|
- |
clearSelections(); |
627 |
|
- |
} |
628 |
|
- |
return; |
629 |
|
- |
} |
630 |
|
- |
if ( ACTION_DELETE.equals( pAction ) ) { |
631 |
|
- |
if ( mSelectedAttribute != null ) { |
632 |
|
- |
if ( null == updateStatus( mSelectedAttribute.deleteExisting() ) ) { |
633 |
|
- |
selectObjectExisting(); |
634 |
|
- |
} |
635 |
|
- |
} else if ( mSelectedObject != null ) { |
636 |
|
- |
if ( null == updateStatus( mSelectedObject.deleteExisting() ) ) { |
637 |
|
- |
clearSelections(); |
638 |
|
- |
} |
639 |
|
- |
} |
640 |
|
- |
return; |
641 |
|
- |
} |
642 |
|
- |
if ( ACTION_SAVE.equals( pAction ) ) { |
643 |
|
- |
if ( mSelectedAttribute != null ) { |
644 |
|
- |
if ( null == updateStatus( mCurrentEditViewPanel.update( mSelectedAttribute ) ) ) { |
645 |
|
- |
selectAttribExisting(); |
646 |
|
- |
} |
647 |
|
- |
} else if ( mNewAttribute ) { |
648 |
|
- |
if ( null == updateStatus( verifyNameEntered() ) ) { |
649 |
|
- |
AttributeMetaData newAttribute = mSelectedObject.createAttributeMetaData( mNewAttributeSet.getType(), mNewAttributeVirtual ); |
650 |
|
- |
if ( null == updateStatus( mCurrentEditViewPanel.update( newAttribute ) ) ) { |
651 |
|
- |
newAttribute.setNewSaved(); |
652 |
|
- |
selectAttribExisting( newAttribute.getName() ); |
653 |
|
- |
} |
654 |
|
- |
} |
655 |
|
- |
} else if ( mSelectedObject != null ) { |
656 |
|
- |
ObjectMetaData zObjectMetaData = mSelectedObject; |
657 |
|
- |
if ( null == updateStatus( mCurrentEditViewPanel.update( mSelectedObject ) ) ) { |
658 |
|
- |
selectObjectRelated( zObjectMetaData.getName() ); // Will force the Object To Be Selected |
659 |
|
- |
} |
660 |
|
- |
} else if ( mNewObject ) { |
661 |
|
- |
if ( null == updateStatus( verifyNameEntered() ) ) { |
662 |
|
- |
ObjectMetaData newObject = mSubSystemForSaving.createObjectMetaData( mNewObjectSet ); |
663 |
|
- |
if ( null == updateStatus( mCurrentEditViewPanel.update( newObject ) ) ) { |
664 |
|
- |
newObject.setNewSaved(); |
665 |
|
- |
selectObjectRelated( newObject.getName() ); // Will force the Object To Be Selected |
666 |
|
- |
} |
667 |
|
- |
} |
668 |
|
- |
} |
669 |
|
- |
return; |
670 |
|
- |
} |
671 |
|
- |
System.out.println( "What the ????: '" + pAction + "' actionRequested" ); |
672 |
|
- |
} |
673 |
|
- |
|
674 |
|
- |
private String verifyNameEntered() { |
675 |
|
- |
String zName = mCurrentEditViewPanel.getValue( AttribNames.NAME ); |
676 |
|
- |
if ( zName != null ) { |
677 |
|
- |
if ( zName.trim().length() != 0 ) { |
678 |
|
- |
return null; |
679 |
|
- |
} |
680 |
|
- |
} |
681 |
|
- |
return "Name is Requred!"; |
682 |
|
- |
} |
683 |
|
- |
|
684 |
|
- |
/** |
685 |
|
- |
* Called on the UI Event Thread |
686 |
|
- |
*/ |
687 |
|
- |
private class OurBoxedTextClickListener implements BoxedTextClickListener { |
688 |
|
- |
@Override |
689 |
|
- |
public void clickedOn( BoxedText pBoxedText ) { |
690 |
|
- |
switch ( pBoxedText.getType() ) { |
691 |
|
- |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_OBJECT_RELATED: |
692 |
|
- |
selectObjectRelated( pBoxedText.getName() ); |
693 |
|
- |
break; |
694 |
|
- |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_OBJECT_MAIN: |
695 |
|
- |
selectObjectMain(); |
696 |
|
- |
break; |
697 |
|
- |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_ATTRIB_EXISTING: |
698 |
|
- |
selectAttribExisting( pBoxedText.getName() ); |
699 |
|
- |
break; |
700 |
|
- |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_ATTRIB_NEW: |
701 |
|
- |
selectAttribNew(); |
702 |
|
- |
break; |
703 |
|
- |
default: |
704 |
|
- |
updateStatus( "Unknown Box (" + pBoxedText.getName() + ") of Type (" + pBoxedText.getType() + ") clicked" ); |
705 |
|
- |
break; |
706 |
|
- |
} |
707 |
|
- |
} |
708 |
|
- |
} |
709 |
|
- |
|
710 |
|
- |
/** |
711 |
|
- |
* Called on the UI Event Thread |
712 |
|
- |
*/ |
713 |
|
- |
private class OurObjectListClickListener implements ObjectListClickListener { |
714 |
|
- |
@Override |
715 |
|
- |
public boolean requestSaveAllowed() { |
716 |
|
- |
return mEditable; |
717 |
|
- |
} |
718 |
|
- |
|
719 |
|
- |
@Override |
720 |
|
- |
public void requestSave() { |
721 |
|
- |
updateStatus( "Saving..." ); |
722 |
|
- |
save( mSubSystemForSaving.toSubSystemWriter() ); |
723 |
|
- |
} |
724 |
|
- |
|
725 |
|
- |
@Override |
726 |
|
- |
public boolean createNewAllowed() { |
727 |
|
- |
return mEditable; |
728 |
|
- |
} |
729 |
|
- |
|
730 |
|
- |
@Override |
731 |
|
- |
public void createNewRequested() { |
732 |
|
- |
selectObjectNew(); |
733 |
|
- |
} |
734 |
|
- |
|
735 |
|
- |
@Override |
736 |
|
- |
public void refreshRequested() { |
737 |
|
- |
refresh(); |
738 |
|
- |
} |
739 |
|
- |
|
740 |
|
- |
@Override |
741 |
|
- |
public void selected( ObjectMetaData pObjectMetaData ) { |
742 |
|
- |
selectObjectFromList( (pObjectMetaData != null) ? pObjectMetaData.getName() : null ); |
743 |
|
- |
} |
744 |
|
- |
} |
745 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.aokeyhole; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.aokeyhole.objects.*; |
|
5 |
+ |
import org.litesoft.aokeyhole.objects.attributes.*; |
|
6 |
+ |
import org.litesoft.aokeyhole.objects.factories.*; |
|
7 |
+ |
import org.litesoft.aokeyhole.objects.support.*; |
|
8 |
+ |
import org.litesoft.aokeyhole.persist.*; |
|
9 |
+ |
import org.litesoft.aokeyhole.toolkit.*; |
|
10 |
+ |
import org.litesoft.aokeyhole.toolkit.editorviewer.*; |
|
11 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
12 |
+ |
|
|
13 |
+ |
import javax.swing.*; |
|
14 |
+ |
import java.io.*; |
|
15 |
+ |
import java.util.*; |
|
16 |
+ |
import java.util.concurrent.*; |
|
17 |
+ |
|
|
18 |
+ |
public abstract class AbstractMain implements ActionsListener, |
|
19 |
+ |
NewAttributeTypeSelectionListener, |
|
20 |
+ |
NameValueChangedByUserListener, |
|
21 |
+ |
NewObjectTypeSelectionListener, |
|
22 |
+ |
ChangeCallback { |
|
23 |
+ |
private static final String BASE_VERSION = "1.30"; |
|
24 |
+ |
|
|
25 |
+ |
private BlockingQueue<Runnable> mNonUIrunnables = new LinkedBlockingQueue<Runnable>(); |
|
26 |
+ |
// Constructor... |
|
27 |
+ |
private final SubSystemFactory mSubSystemFactory; |
|
28 |
+ |
private final EditViewPanelFactory mEditViewPanelFactory; |
|
29 |
+ |
private final SubSystemPersister[] mPersisters; |
|
30 |
+ |
private final boolean mEditable; |
|
31 |
+ |
|
|
32 |
+ |
private String mVersion = BASE_VERSION; |
|
33 |
+ |
|
|
34 |
+ |
// unpersistAllObjects... |
|
35 |
+ |
private SystemMetaData mSystemMetaData; |
|
36 |
+ |
private SubSystemMetaData mSubSystemForSaving = null; |
|
37 |
+ |
|
|
38 |
+ |
// start |
|
39 |
+ |
private EditViewPanelController mEditViewPanelController = null; |
|
40 |
+ |
|
|
41 |
+ |
// setter... |
|
42 |
+ |
private ObjectListUpdater mObjectListUpdater = null; |
|
43 |
+ |
|
|
44 |
+ |
// Normal User Interaction... |
|
45 |
+ |
private ActionsControllableNameValuesComponent mCurrentEditViewPanel = null; |
|
46 |
+ |
|
|
47 |
+ |
private ObjectMetaData mSelectedObject = null; |
|
48 |
+ |
private boolean mNewObject = false; |
|
49 |
+ |
private ObjectSet mNewObjectSet; |
|
50 |
+ |
|
|
51 |
+ |
private AttributeMetaData mSelectedAttribute = null; |
|
52 |
+ |
private boolean mNewAttribute = false; |
|
53 |
+ |
private boolean mNewAttributeVirtual; |
|
54 |
+ |
private AttributeSet mNewAttributeSet; |
|
55 |
+ |
|
|
56 |
+ |
protected AbstractMain( SubSystemFactory pSubSystemFactory, EditViewPanelFactory pEditViewPanelFactory, boolean pReadOnly, SubSystemPersister... pPersisters ) |
|
57 |
+ |
throws IOException { |
|
58 |
+ |
mSubSystemFactory = pSubSystemFactory; |
|
59 |
+ |
mEditViewPanelFactory = pEditViewPanelFactory; |
|
60 |
+ |
if ( (mPersisters = pPersisters).length == 0 ) { |
|
61 |
+ |
throw new IllegalArgumentException( "No Data Sources Provided" ); |
|
62 |
+ |
} |
|
63 |
+ |
mEditable = !(pReadOnly || getLastPersister().isReadOnly()); |
|
64 |
+ |
|
|
65 |
+ |
unpersistAllObjects(); |
|
66 |
+ |
|
|
67 |
+ |
mVersion = BASE_VERSION + "-" + mSystemMetaData.getVersion(); |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
@SuppressWarnings({"UnusedDeclaration"}) |
|
71 |
+ |
public String getVersion() { |
|
72 |
+ |
return mVersion; |
|
73 |
+ |
} |
|
74 |
+ |
|
|
75 |
+ |
public SystemMetaData getSystemMetaData() { |
|
76 |
+ |
return mSystemMetaData; |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
@SuppressWarnings({"UnusedDeclaration"}) |
|
80 |
+ |
public SubSystemMetaData getSubSystemForSaving() { |
|
81 |
+ |
return mSubSystemForSaving; |
|
82 |
+ |
} |
|
83 |
+ |
|
|
84 |
+ |
public void persistSubSystem( SubSystemWriter pSubSystemWriter ) |
|
85 |
+ |
throws IOException { |
|
86 |
+ |
if ( mEditable ) { |
|
87 |
+ |
pSubSystemWriter.write(); |
|
88 |
+ |
} |
|
89 |
+ |
} |
|
90 |
+ |
|
|
91 |
+ |
private SubSystemPersister getLastPersister() { |
|
92 |
+ |
return mPersisters[mPersisters.length - 1]; |
|
93 |
+ |
} |
|
94 |
+ |
|
|
95 |
+ |
/** |
|
96 |
+ |
* Called during Construction on the "main" Thread |
|
97 |
+ |
*/ |
|
98 |
+ |
protected ObjectListClickListener createObjectListClickListener() { |
|
99 |
+ |
return new OurObjectListClickListener(); |
|
100 |
+ |
} |
|
101 |
+ |
|
|
102 |
+ |
/** |
|
103 |
+ |
* Called during Construction on the "main" Thread |
|
104 |
+ |
*/ |
|
105 |
+ |
protected BoxedTextClickListener createBoxedTextClickListener() { |
|
106 |
+ |
return new OurBoxedTextClickListener(); |
|
107 |
+ |
} |
|
108 |
+ |
|
|
109 |
+ |
/** |
|
110 |
+ |
* Called during Construction on the "main" Thread |
|
111 |
+ |
*/ |
|
112 |
+ |
protected void setObjectListUpdater( ObjectListUpdater pObjectListUpdater ) { |
|
113 |
+ |
mObjectListUpdater = pObjectListUpdater; |
|
114 |
+ |
} |
|
115 |
+ |
|
|
116 |
+ |
/** |
|
117 |
+ |
* Should be called on the "main" Thread! |
|
118 |
+ |
*/ |
|
119 |
+ |
private void unpersistAllObjects() |
|
120 |
+ |
throws IOException { |
|
121 |
+ |
SystemMetaData zSMD = new SystemMetaData( mEditable, BASE_VERSION, mSubSystemFactory ); |
|
122 |
+ |
|
|
123 |
+ |
SubSystemMetaData lastSS = null; |
|
124 |
+ |
for ( int i = 0; i < mPersisters.length; i++ ) { |
|
125 |
+ |
SubSystemPersister zPersister = mPersisters[i]; |
|
126 |
+ |
lastSS = zSMD.unpersistSubSystemMetaData( i, zPersister ).loadObjects(); |
|
127 |
+ |
} |
|
128 |
+ |
zSMD.setRehydrated(); |
|
129 |
+ |
|
|
130 |
+ |
mSystemMetaData = zSMD; |
|
131 |
+ |
if ( mEditable ) { |
|
132 |
+ |
mSubSystemForSaving = lastSS; |
|
133 |
+ |
} |
|
134 |
+ |
} |
|
135 |
+ |
|
|
136 |
+ |
/** |
|
137 |
+ |
* Running on the "main" Thread |
|
138 |
+ |
*/ |
|
139 |
+ |
public void start() { |
|
140 |
+ |
mEditViewPanelController = mEditViewPanelFactory |
|
141 |
+ |
.createEditViewPanelController( mEditable, getLastPersister().getName(), mSystemMetaData.getObjectSets(), mSystemMetaData.getAttributeSets(), |
|
142 |
+ |
this, this, this, this ); |
|
143 |
+ |
|
|
144 |
+ |
mSystemMetaData.add( buildUI( mVersion, mEditViewPanelController ) ); |
|
145 |
+ |
|
|
146 |
+ |
mSystemMetaData.add( this ); |
|
147 |
+ |
|
|
148 |
+ |
mObjectListUpdater.updateObjectList( mSystemMetaData.getSortedObjectMetaDatas() ); |
|
149 |
+ |
|
|
150 |
+ |
showUI(); |
|
151 |
+ |
|
|
152 |
+ |
runMainThreadLoop(); |
|
153 |
+ |
} |
|
154 |
+ |
|
|
155 |
+ |
/** |
|
156 |
+ |
* Running on the "main" Thread |
|
157 |
+ |
*/ |
|
158 |
+ |
public synchronized void runMainThreadLoop() { |
|
159 |
+ |
for ( Runnable zRunnable; null != (zRunnable = waitForMainThreadRunnable()); ) { |
|
160 |
+ |
try { |
|
161 |
+ |
zRunnable.run(); |
|
162 |
+ |
} |
|
163 |
+ |
catch ( RuntimeException e ) { |
|
164 |
+ |
e.printStackTrace(); |
|
165 |
+ |
updateStatus( e.getMessage() ); |
|
166 |
+ |
} |
|
167 |
+ |
} |
|
168 |
+ |
} |
|
169 |
+ |
|
|
170 |
+ |
/** |
|
171 |
+ |
* Running on the "main" Thread |
|
172 |
+ |
*/ |
|
173 |
+ |
private Runnable waitForMainThreadRunnable() { |
|
174 |
+ |
while ( true ) { |
|
175 |
+ |
try { |
|
176 |
+ |
Runnable zRunnable = mNonUIrunnables.take(); |
|
177 |
+ |
if ( zRunnable != null ) { |
|
178 |
+ |
return zRunnable; |
|
179 |
+ |
} |
|
180 |
+ |
} |
|
181 |
+ |
catch ( InterruptedException e ) { |
|
182 |
+ |
return null; |
|
183 |
+ |
} |
|
184 |
+ |
} |
|
185 |
+ |
} |
|
186 |
+ |
|
|
187 |
+ |
// Called by Either ("main" or "UI" Event) Thread... |
|
188 |
+ |
private void postMainThreadRunnable( String pWhat, Runnable pRunnable ) { |
|
189 |
+ |
try { |
|
190 |
+ |
mNonUIrunnables.put( pRunnable ); |
|
191 |
+ |
} |
|
192 |
+ |
catch ( InterruptedException e ) { |
|
193 |
+ |
e.printStackTrace(); |
|
194 |
+ |
updateStatus( "Time out / Interruption attempting to " + pWhat ); |
|
195 |
+ |
} |
|
196 |
+ |
} |
|
197 |
+ |
|
|
198 |
+ |
// Called by Either ("main" or "UI" Event) Thread... |
|
199 |
+ |
private void postUiThreadRunnable( String pWhat, Runnable pRunnable ) { |
|
200 |
+ |
try { |
|
201 |
+ |
SwingUtilities.invokeLater( pRunnable ); |
|
202 |
+ |
} |
|
203 |
+ |
catch ( RuntimeException e ) { |
|
204 |
+ |
e.printStackTrace(); |
|
205 |
+ |
updateStatus( "Exception attempting to " + pWhat + " of: " + e.getMessage() ); |
|
206 |
+ |
} |
|
207 |
+ |
} |
|
208 |
+ |
|
|
209 |
+ |
/** |
|
210 |
+ |
* Called on the "UI" Event Thread |
|
211 |
+ |
*/ |
|
212 |
+ |
protected void save( final SubSystemWriter pSubSystemWriter ) { |
|
213 |
+ |
postMainThreadRunnable( "Save Changes", new Runnable() { |
|
214 |
+ |
// Called on the "main" Thread |
|
215 |
+ |
@Override |
|
216 |
+ |
public void run() { |
|
217 |
+ |
if ( !mEditable ) { |
|
218 |
+ |
updateStatus( "No Persistable" ); |
|
219 |
+ |
} else { |
|
220 |
+ |
try { |
|
221 |
+ |
persistSubSystem( pSubSystemWriter ); |
|
222 |
+ |
getSystemMetaData().clearChangeIndicators(); |
|
223 |
+ |
updateStatus( "Save Complete" ); |
|
224 |
+ |
} |
|
225 |
+ |
catch ( IOException e ) { |
|
226 |
+ |
e.printStackTrace(); |
|
227 |
+ |
updateStatus( e.getMessage() ); |
|
228 |
+ |
} |
|
229 |
+ |
catch ( RuntimeException e ) { |
|
230 |
+ |
e.printStackTrace(); |
|
231 |
+ |
updateStatus( e.getMessage() ); |
|
232 |
+ |
} |
|
233 |
+ |
} |
|
234 |
+ |
} |
|
235 |
+ |
} ); |
|
236 |
+ |
} |
|
237 |
+ |
|
|
238 |
+ |
private class CurrentDisplayState { |
|
239 |
+ |
private ObjectMetaData mCurrentSelectedObject = null; |
|
240 |
+ |
private AttributeMetaData mCurrentSelectedAttribute = null; |
|
241 |
+ |
|
|
242 |
+ |
private CurrentDisplayState() { |
|
243 |
+ |
if ( !mNewObject ) { |
|
244 |
+ |
mCurrentSelectedObject = mSelectedObject; |
|
245 |
+ |
if ( !mNewAttribute ) { |
|
246 |
+ |
mCurrentSelectedAttribute = mSelectedAttribute; |
|
247 |
+ |
} |
|
248 |
+ |
} |
|
249 |
+ |
} |
|
250 |
+ |
|
|
251 |
+ |
public void restore() { |
|
252 |
+ |
if ( mCurrentSelectedObject != null ) { |
|
253 |
+ |
if ( null != (mSelectedObject = mSystemMetaData.getObject( mCurrentSelectedObject.getName() )) ) { |
|
254 |
+ |
selectObjectExisting(); |
|
255 |
+ |
if ( mCurrentSelectedAttribute != null ) { |
|
256 |
+ |
if ( null != (mSelectedAttribute = mSelectedObject.getAttribute( mCurrentSelectedAttribute.getName() )) ) { |
|
257 |
+ |
selectAttribExisting(); |
|
258 |
+ |
} |
|
259 |
+ |
} |
|
260 |
+ |
} |
|
261 |
+ |
} |
|
262 |
+ |
} |
|
263 |
+ |
} |
|
264 |
+ |
|
|
265 |
+ |
/** |
|
266 |
+ |
* Called on the "UI" Event Thread |
|
267 |
+ |
*/ |
|
268 |
+ |
protected void refresh() { |
|
269 |
+ |
final CurrentDisplayState mCurrentState = new CurrentDisplayState(); |
|
270 |
+ |
clearSelections(); // Show Nothing... |
|
271 |
+ |
updateStatus( "Refreshing..." ); |
|
272 |
+ |
|
|
273 |
+ |
postMainThreadRunnable( "Refresh", new Runnable() { |
|
274 |
+ |
// Called on the "main" Thread |
|
275 |
+ |
@Override |
|
276 |
+ |
public void run() { |
|
277 |
+ |
refreshStep2( mCurrentState ); |
|
278 |
+ |
} |
|
279 |
+ |
} ); |
|
280 |
+ |
} |
|
281 |
+ |
|
|
282 |
+ |
/** |
|
283 |
+ |
* Called on the "main" Thread |
|
284 |
+ |
*/ |
|
285 |
+ |
protected void refreshStep2( final CurrentDisplayState pCurrentState ) { |
|
286 |
+ |
try { |
|
287 |
+ |
List<ChangeCallback> zCallbacks = mSystemMetaData.getChangeCallbacks(); |
|
288 |
+ |
unpersistAllObjects(); |
|
289 |
+ |
for ( ChangeCallback zCallback : zCallbacks ) { |
|
290 |
+ |
mSystemMetaData.add( zCallback ); |
|
291 |
+ |
} |
|
292 |
+ |
postUiThreadRunnable( "Refresh", new Runnable() { |
|
293 |
+ |
// Called on the "UI" Event Thread |
|
294 |
+ |
@Override |
|
295 |
+ |
public void run() { |
|
296 |
+ |
refreshStep3( pCurrentState ); |
|
297 |
+ |
} |
|
298 |
+ |
} ); |
|
299 |
+ |
} |
|
300 |
+ |
catch ( IOException e ) { |
|
301 |
+ |
e.printStackTrace(); |
|
302 |
+ |
updateStatus( e.getMessage() ); |
|
303 |
+ |
} |
|
304 |
+ |
catch ( RuntimeException e ) { |
|
305 |
+ |
e.printStackTrace(); |
|
306 |
+ |
updateStatus( e.getMessage() ); |
|
307 |
+ |
} |
|
308 |
+ |
} |
|
309 |
+ |
|
|
310 |
+ |
/** |
|
311 |
+ |
* Called on the "UI" Event Thread |
|
312 |
+ |
*/ |
|
313 |
+ |
protected void refreshStep3( CurrentDisplayState pCurrentState ) { |
|
314 |
+ |
mObjectListUpdater.updateObjectList( mSystemMetaData.getSortedObjectMetaDatas() ); |
|
315 |
+ |
pCurrentState.restore(); |
|
316 |
+ |
clearStatus(); |
|
317 |
+ |
} |
|
318 |
+ |
|
|
319 |
+ |
/** |
|
320 |
+ |
* Called during Construction on the "main" Thread |
|
321 |
+ |
*/ |
|
322 |
+ |
abstract protected ChangeCallback buildUI( String pVersion, EditViewPanelController pEditViewPanelController ); |
|
323 |
+ |
|
|
324 |
+ |
/** |
|
325 |
+ |
* Called during Construction on the "main" Thread |
|
326 |
+ |
*/ |
|
327 |
+ |
abstract protected void showUI(); |
|
328 |
+ |
|
|
329 |
+ |
/** |
|
330 |
+ |
* Called on BOTH the Main & UI Event Thread |
|
331 |
+ |
* |
|
332 |
+ |
* @param pMessage |
|
333 |
+ |
* |
|
334 |
+ |
* @return pMessage |
|
335 |
+ |
*/ |
|
336 |
+ |
abstract protected String updateStatus( String pMessage ); |
|
337 |
+ |
|
|
338 |
+ |
/** |
|
339 |
+ |
* Called on the UI Event Thread |
|
340 |
+ |
*/ |
|
341 |
+ |
abstract protected void setStatus( String pMessage ); |
|
342 |
+ |
|
|
343 |
+ |
/** |
|
344 |
+ |
* Called on the UI Event Thread |
|
345 |
+ |
*/ |
|
346 |
+ |
abstract protected ObjectAndAttributesWithOneDegreeSeperationView createObjectAndAttributesWithOneDegreeSeperationView(); |
|
347 |
+ |
|
|
348 |
+ |
/** |
|
349 |
+ |
* Called on the UI Event Thread |
|
350 |
+ |
*/ |
|
351 |
+ |
abstract protected void setObjectAndAttributesWithOneDegreeSeperationView( ObjectAndAttributesWithOneDegreeSeperationView pOAV ); |
|
352 |
+ |
|
|
353 |
+ |
/** |
|
354 |
+ |
* Called on the UI Event Thread |
|
355 |
+ |
*/ |
|
356 |
+ |
@Override |
|
357 |
+ |
public void namedValueChangedByUser( String pName ) { |
|
358 |
+ |
if ( mCurrentEditViewPanel != null ) { |
|
359 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, true ); |
|
360 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_REVERT, true ); |
|
361 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_DELETE, false ); |
|
362 |
+ |
|
|
363 |
+ |
if ( AttribNamesRelated.RELATED_TO.equals( pName ) ) { |
|
364 |
+ |
boolean zToManys = !currentAttributeIsToMany(); |
|
365 |
+ |
ObjectMetaData object = mSystemMetaData.getObject( mCurrentEditViewPanel.getValue( pName ) ); |
|
366 |
+ |
String[] options = (object == null) ? new String[0] : object.getSortedRelatedPersistedAttributeNamesTo( zToManys, mSelectedObject ); |
|
367 |
+ |
mCurrentEditViewPanel.setOptions( AttribNamesRelatedPersisted.BACK_REF, options ); |
|
368 |
+ |
} |
|
369 |
+ |
} |
|
370 |
+ |
// System.out.println( "Hook for special behavior on namedValueChangedByUser: " + pName ); |
|
371 |
+ |
} |
|
372 |
+ |
|
|
373 |
+ |
private boolean currentAttributeIsToMany() { |
|
374 |
+ |
AttributeSet zSet = mNewAttribute ? mNewAttributeSet : mSelectedAttribute.getAttributeSet(); |
|
375 |
+ |
return A_ToMany.TYPE.equals( zSet.getType() ); |
|
376 |
+ |
} |
|
377 |
+ |
|
|
378 |
+ |
/** |
|
379 |
+ |
* Called on the UI Event Thread |
|
380 |
+ |
*/ |
|
381 |
+ |
private void clearSelections() { |
|
382 |
+ |
mSelectedObject = null; |
|
383 |
+ |
mSelectedAttribute = null; |
|
384 |
+ |
mCurrentEditViewPanel = null; |
|
385 |
+ |
mNewObject = false; |
|
386 |
+ |
mNewAttribute = false; |
|
387 |
+ |
mEditViewPanelController.showBlank(); |
|
388 |
+ |
clearStatus(); |
|
389 |
+ |
} |
|
390 |
+ |
|
|
391 |
+ |
/** |
|
392 |
+ |
* Called on the UI Event Thread |
|
393 |
+ |
*/ |
|
394 |
+ |
private void clearStatus() { |
|
395 |
+ |
if ( mSelectedObject != null ) { |
|
396 |
+ |
updateStatus( mSelectedObject.getOwner().getName() ); |
|
397 |
+ |
return; |
|
398 |
+ |
} |
|
399 |
+ |
if ( mNewObject ) { |
|
400 |
+ |
updateStatus( mSubSystemForSaving.getName() ); |
|
401 |
+ |
return; |
|
402 |
+ |
} |
|
403 |
+ |
updateStatus( null ); |
|
404 |
+ |
} |
|
405 |
+ |
|
|
406 |
+ |
/** |
|
407 |
+ |
* Called on the UI Event Thread |
|
408 |
+ |
*/ |
|
409 |
+ |
private void selectObjectNew() { |
|
410 |
+ |
setObjectAndAttributesWithOneDegreeSeperationView( null ); |
|
411 |
+ |
mObjectListUpdater.clearSelectedObject(); |
|
412 |
+ |
clearSelections(); |
|
413 |
+ |
mNewObject = true; |
|
414 |
+ |
clearStatus(); |
|
415 |
+ |
mEditViewPanelController.showNewObjectTypeSelector( mSubSystemForSaving ); |
|
416 |
+ |
} |
|
417 |
+ |
|
|
418 |
+ |
/** |
|
419 |
+ |
* Called on the UI Event Thread |
|
420 |
+ |
*/ |
|
421 |
+ |
private void selectObjectExisting() { |
|
422 |
+ |
mSelectedAttribute = null; |
|
423 |
+ |
mCurrentEditViewPanel = mEditViewPanelController.showObjectExisting( mSelectedObject ); |
|
424 |
+ |
setUpViewSupportable( mSelectedObject ); |
|
425 |
+ |
} |
|
426 |
+ |
|
|
427 |
+ |
/** |
|
428 |
+ |
* Called on the UI Event Thread |
|
429 |
+ |
*/ |
|
430 |
+ |
private void selectObjectFromList( String pName ) { |
|
431 |
+ |
clearSelections(); |
|
432 |
+ |
if ( showObjectGraph( pName ) ) { |
|
433 |
+ |
selectObjectExisting(); |
|
434 |
+ |
} |
|
435 |
+ |
} |
|
436 |
+ |
|
|
437 |
+ |
/** |
|
438 |
+ |
* Called on the UI Event Thread |
|
439 |
+ |
*/ |
|
440 |
+ |
private void selectObjectRelated( String pName ) { |
|
441 |
+ |
if ( ObjectNames.VARIES_RELATED_TO.equals( pName ) ) { |
|
442 |
+ |
updateStatus( "Can NOT navigate to a 'variable' relationship" ); |
|
443 |
+ |
return; |
|
444 |
+ |
} |
|
445 |
+ |
clearSelections(); |
|
446 |
+ |
if ( showObjectGraph( pName ) ) { |
|
447 |
+ |
mObjectListUpdater.setSelectedObject( mSystemMetaData.getObject( pName ) ); |
|
448 |
+ |
selectObjectExisting(); |
|
449 |
+ |
} |
|
450 |
+ |
} |
|
451 |
+ |
|
|
452 |
+ |
/** |
|
453 |
+ |
* Called on the UI Event Thread |
|
454 |
+ |
*/ |
|
455 |
+ |
private void selectObjectMain() { |
|
456 |
+ |
selectObjectExisting(); |
|
457 |
+ |
} |
|
458 |
+ |
|
|
459 |
+ |
/** |
|
460 |
+ |
* Called on the UI Event Thread |
|
461 |
+ |
*/ |
|
462 |
+ |
private void selectAttribExisting( String pName ) { |
|
463 |
+ |
if ( pName != null ) { |
|
464 |
+ |
pName = pName.trim(); |
|
465 |
+ |
if ( pName.startsWith( "*" ) ) { |
|
466 |
+ |
pName = pName.substring( 1 ).trim(); |
|
467 |
+ |
} |
|
468 |
+ |
if ( pName.endsWith( "*" ) ) { |
|
469 |
+ |
pName = pName.substring( 0, pName.length() - 1 ).trim(); |
|
470 |
+ |
} |
|
471 |
+ |
} |
|
472 |
+ |
mSelectedAttribute = mSelectedObject.getAttribute( pName ); |
|
473 |
+ |
if ( mSelectedAttribute == null ) { |
|
474 |
+ |
mCurrentEditViewPanel = null; |
|
475 |
+ |
mEditViewPanelController.showBlank(); |
|
476 |
+ |
System.err.println( "selectAttribExisting ?: " + pName ); |
|
477 |
+ |
return; |
|
478 |
+ |
} |
|
479 |
+ |
selectAttribExisting(); |
|
480 |
+ |
} |
|
481 |
+ |
|
|
482 |
+ |
/** |
|
483 |
+ |
* Called on the UI Event Thread |
|
484 |
+ |
*/ |
|
485 |
+ |
private void selectAttribExisting() { |
|
486 |
+ |
mNewAttribute = false; |
|
487 |
+ |
mCurrentEditViewPanel = mEditViewPanelController.showAttribExisting( mSelectedAttribute ); |
|
488 |
+ |
NameValuesComponent zValuesComponent = setUpViewSupportable( mSelectedAttribute ); |
|
489 |
+ |
if ( mSelectedAttribute instanceof AttributeMetaDataRelatedPersisted && mSelectedAttribute.isEditable() ) { |
|
490 |
+ |
AttributeMetaDataRelatedPersisted zMDR = (AttributeMetaDataRelatedPersisted) mSelectedAttribute; |
|
491 |
+ |
String zRelatedTo = zMDR.getRelatedTo(); |
|
492 |
+ |
String zBackAttrib = zMDR.getBackAttrib(); |
|
493 |
+ |
if ( Currently.isNotNullOrEmpty( zRelatedTo ) && Currently.isNotNullOrEmpty( zBackAttrib ) ) { |
|
494 |
+ |
ObjectMetaData zObjectMetaData = mSystemMetaData.getObject( zRelatedTo ); |
|
495 |
+ |
if ( zObjectMetaData != null ) { |
|
496 |
+ |
if ( zObjectMetaData.getAttribute( zBackAttrib ) == null ) { |
|
497 |
+ |
zMDR.unpersistBackAttrib( null ); |
|
498 |
+ |
zValuesComponent.setValue( AttribNamesRelatedPersisted.BACK_REF, "!" + zBackAttrib ); |
|
499 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, true ); |
|
500 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_DELETE, false ); |
|
501 |
+ |
} |
|
502 |
+ |
} |
|
503 |
+ |
} |
|
504 |
+ |
} |
|
505 |
+ |
} |
|
506 |
+ |
|
|
507 |
+ |
/** |
|
508 |
+ |
* Called on the UI Event Thread |
|
509 |
+ |
*/ |
|
510 |
+ |
private void selectAttribNew() { |
|
511 |
+ |
mSelectedAttribute = null; |
|
512 |
+ |
mCurrentEditViewPanel = null; |
|
513 |
+ |
mNewAttribute = true; |
|
514 |
+ |
clearStatus(); |
|
515 |
+ |
mEditViewPanelController.showNewAttributeTypeSelector( mSelectedObject ); |
|
516 |
+ |
} |
|
517 |
+ |
|
|
518 |
+ |
@Override |
|
519 |
+ |
public void newObjectTypeSelected( ObjectSet pObjectSet ) { |
|
520 |
+ |
mCurrentEditViewPanel = mEditViewPanelController.showObjectNew( mSubSystemForSaving, mNewObjectSet = pObjectSet ); |
|
521 |
+ |
mCurrentEditViewPanel.initializeView(); |
|
522 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, false ); |
|
523 |
+ |
clearStatus(); |
|
524 |
+ |
} |
|
525 |
+ |
|
|
526 |
+ |
@Override |
|
527 |
+ |
public void newAttributeTypeSelected( boolean pVirtual, AttributeSet pAttributeSet ) { |
|
528 |
+ |
mSelectedAttribute = null; |
|
529 |
+ |
mCurrentEditViewPanel = mEditViewPanelController.showAttributeNew( mSelectedObject, mNewAttributeVirtual = pVirtual, mNewAttributeSet = pAttributeSet ); |
|
530 |
+ |
mCurrentEditViewPanel.initializeView(); |
|
531 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, false ); |
|
532 |
+ |
} |
|
533 |
+ |
|
|
534 |
+ |
@Override |
|
535 |
+ |
public void changeStateUpdated( Changeable pChangeable ) { |
|
536 |
+ |
if ( mSelectedObject != null ) { |
|
537 |
+ |
showObjectGraph( mSelectedObject.getName() ); |
|
538 |
+ |
} |
|
539 |
+ |
if ( mSystemMetaData.objectListHasChanged() ) { |
|
540 |
+ |
mObjectListUpdater.updateObjectList( mSystemMetaData.getSortedObjectMetaDatas() ); |
|
541 |
+ |
} |
|
542 |
+ |
} |
|
543 |
+ |
|
|
544 |
+ |
/** |
|
545 |
+ |
* Called on the "UI" Event Thread |
|
546 |
+ |
*/ |
|
547 |
+ |
private boolean showObjectGraph( String pObjectName ) { |
|
548 |
+ |
if ( mSelectedObject != null ) { |
|
549 |
+ |
mSelectedObject.remove( this ); |
|
550 |
+ |
mSelectedObject = null; |
|
551 |
+ |
} |
|
552 |
+ |
setObjectAndAttributesWithOneDegreeSeperationView( null ); // turn off display |
|
553 |
+ |
if ( pObjectName != null ) { |
|
554 |
+ |
mSelectedObject = mSystemMetaData.getObject( pObjectName ); |
|
555 |
+ |
} |
|
556 |
+ |
if ( mSelectedObject == null ) { |
|
557 |
+ |
return false; |
|
558 |
+ |
} |
|
559 |
+ |
mSelectedObject.add( this ); |
|
560 |
+ |
|
|
561 |
+ |
ObjectAndAttributesWithOneDegreeSeperationView oneDegreeSepView = createObjectAndAttributesWithOneDegreeSeperationView(); |
|
562 |
+ |
oneDegreeSepView.changeObjectName( mSelectedObject.getName() ); |
|
563 |
+ |
oneDegreeSepView.setParentName( mSelectedObject.getParentName() ); |
|
564 |
+ |
oneDegreeSepView.setGeneratedRelationsByParentNames( mSelectedObject.getSortedChildNames() ); |
|
565 |
+ |
List<AttributeMetaData> attributes = mSelectedObject.getSortedAttributes(); |
|
566 |
+ |
for ( AttributeMetaData attribute : attributes ) { |
|
567 |
+ |
String zChanged = attribute.isChanged() ? " * " : " "; |
|
568 |
+ |
String zName = zChanged + attribute.getName() + zChanged; |
|
569 |
+ |
if ( attribute instanceof AttributeMetaDataSimple ) { |
|
570 |
+ |
oneDegreeSepView.addSimpleAttribute( zName, attribute.isVirtual() ); |
|
571 |
+ |
} else { |
|
572 |
+ |
AttributeMetaDataRelated rmd = (AttributeMetaDataRelated) attribute; |
|
573 |
+ |
if ( rmd.getRelatedTo() == null ) { |
|
574 |
+ |
oneDegreeSepView.addRelatedAttributeToSelf( zName, attribute.isVirtual() ); |
|
575 |
+ |
} else { |
|
576 |
+ |
oneDegreeSepView.addRelatedAttribute( zName, attribute.isVirtual(), rmd.getRelatedTo() ); |
|
577 |
+ |
} |
|
578 |
+ |
} |
|
579 |
+ |
} |
|
580 |
+ |
if ( mSelectedObject.isEditable() ) { |
|
581 |
+ |
oneDegreeSepView.addNewAttributeOption(); |
|
582 |
+ |
} |
|
583 |
+ |
setObjectAndAttributesWithOneDegreeSeperationView( oneDegreeSepView ); |
|
584 |
+ |
return true; |
|
585 |
+ |
} |
|
586 |
+ |
|
|
587 |
+ |
/** |
|
588 |
+ |
* Called on the UI Event Thread |
|
589 |
+ |
*/ |
|
590 |
+ |
private NameValuesComponent setUpViewSupportable( ViewSupportable pViewSupportable ) { |
|
591 |
+ |
clearStatus(); |
|
592 |
+ |
NameValuesComponent zValuesComponent = mCurrentEditViewPanel.setUpView( pViewSupportable ); |
|
593 |
+ |
buttonsToInitialState(); |
|
594 |
+ |
return zValuesComponent; |
|
595 |
+ |
} |
|
596 |
+ |
|
|
597 |
+ |
/** |
|
598 |
+ |
* Called on the UI Event Thread |
|
599 |
+ |
*/ |
|
600 |
+ |
private void buttonsToInitialState() { |
|
601 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_SAVE, false ); |
|
602 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_REVERT, false ); |
|
603 |
+ |
mCurrentEditViewPanel.actionEnable( ACTION_DELETE, true ); |
|
604 |
+ |
} |
|
605 |
+ |
|
|
606 |
+ |
/** |
|
607 |
+ |
* Called on the UI Event Thread |
|
608 |
+ |
*/ |
|
609 |
+ |
@Override |
|
610 |
+ |
public void actionRequested( String pAction ) { |
|
611 |
+ |
// System.out.println( "actionRequested: " + pAction ); |
|
612 |
+ |
if ( ACTION_CANCEL.equals( pAction ) ) { |
|
613 |
+ |
if ( mSelectedObject != null ) { |
|
614 |
+ |
selectObjectExisting(); |
|
615 |
+ |
} else { |
|
616 |
+ |
clearSelections(); |
|
617 |
+ |
} |
|
618 |
+ |
return; |
|
619 |
+ |
} |
|
620 |
+ |
if ( ACTION_REVERT.equals( pAction ) ) { |
|
621 |
+ |
if ( mSelectedAttribute != null ) { |
|
622 |
+ |
selectAttribExisting(); |
|
623 |
+ |
} else if ( mSelectedObject != null ) { |
|
624 |
+ |
selectObjectExisting(); |
|
625 |
+ |
} else { |
|
626 |
+ |
clearSelections(); |
|
627 |
+ |
} |
|
628 |
+ |
return; |
|
629 |
+ |
} |
|
630 |
+ |
if ( ACTION_DELETE.equals( pAction ) ) { |
|
631 |
+ |
if ( mSelectedAttribute != null ) { |
|
632 |
+ |
if ( null == updateStatus( mSelectedAttribute.deleteExisting() ) ) { |
|
633 |
+ |
selectObjectExisting(); |
|
634 |
+ |
} |
|
635 |
+ |
} else if ( mSelectedObject != null ) { |
|
636 |
+ |
if ( null == updateStatus( mSelectedObject.deleteExisting() ) ) { |
|
637 |
+ |
clearSelections(); |
|
638 |
+ |
} |
|
639 |
+ |
} |
|
640 |
+ |
return; |
|
641 |
+ |
} |
|
642 |
+ |
if ( ACTION_SAVE.equals( pAction ) ) { |
|
643 |
+ |
if ( mSelectedAttribute != null ) { |
|
644 |
+ |
if ( null == updateStatus( mCurrentEditViewPanel.update( mSelectedAttribute ) ) ) { |
|
645 |
+ |
selectAttribExisting(); |
|
646 |
+ |
} |
|
647 |
+ |
} else if ( mNewAttribute ) { |
|
648 |
+ |
if ( null == updateStatus( verifyNameEntered() ) ) { |
|
649 |
+ |
AttributeMetaData newAttribute = mSelectedObject.createAttributeMetaData( mNewAttributeSet.getType(), mNewAttributeVirtual ); |
|
650 |
+ |
if ( null == updateStatus( mCurrentEditViewPanel.update( newAttribute ) ) ) { |
|
651 |
+ |
newAttribute.setNewSaved(); |
|
652 |
+ |
selectAttribExisting( newAttribute.getName() ); |
|
653 |
+ |
} |
|
654 |
+ |
} |
|
655 |
+ |
} else if ( mSelectedObject != null ) { |
|
656 |
+ |
ObjectMetaData zObjectMetaData = mSelectedObject; |
|
657 |
+ |
if ( null == updateStatus( mCurrentEditViewPanel.update( mSelectedObject ) ) ) { |
|
658 |
+ |
selectObjectRelated( zObjectMetaData.getName() ); // Will force the Object To Be Selected |
|
659 |
+ |
} |
|
660 |
+ |
} else if ( mNewObject ) { |
|
661 |
+ |
if ( null == updateStatus( verifyNameEntered() ) ) { |
|
662 |
+ |
ObjectMetaData newObject = mSubSystemForSaving.createObjectMetaData( mNewObjectSet ); |
|
663 |
+ |
if ( null == updateStatus( mCurrentEditViewPanel.update( newObject ) ) ) { |
|
664 |
+ |
newObject.setNewSaved(); |
|
665 |
+ |
selectObjectRelated( newObject.getName() ); // Will force the Object To Be Selected |
|
666 |
+ |
} |
|
667 |
+ |
} |
|
668 |
+ |
} |
|
669 |
+ |
return; |
|
670 |
+ |
} |
|
671 |
+ |
System.out.println( "What the ????: '" + pAction + "' actionRequested" ); |
|
672 |
+ |
} |
|
673 |
+ |
|
|
674 |
+ |
private String verifyNameEntered() { |
|
675 |
+ |
String zName = mCurrentEditViewPanel.getValue( AttribNames.NAME ); |
|
676 |
+ |
if ( zName != null ) { |
|
677 |
+ |
if ( zName.trim().length() != 0 ) { |
|
678 |
+ |
return null; |
|
679 |
+ |
} |
|
680 |
+ |
} |
|
681 |
+ |
return "Name is Requred!"; |
|
682 |
+ |
} |
|
683 |
+ |
|
|
684 |
+ |
/** |
|
685 |
+ |
* Called on the UI Event Thread |
|
686 |
+ |
*/ |
|
687 |
+ |
private class OurBoxedTextClickListener implements BoxedTextClickListener { |
|
688 |
+ |
@Override |
|
689 |
+ |
public void clickedOn( BoxedText pBoxedText ) { |
|
690 |
+ |
switch ( pBoxedText.getType() ) { |
|
691 |
+ |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_OBJECT_RELATED: |
|
692 |
+ |
selectObjectRelated( pBoxedText.getName() ); |
|
693 |
+ |
break; |
|
694 |
+ |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_OBJECT_MAIN: |
|
695 |
+ |
selectObjectMain(); |
|
696 |
+ |
break; |
|
697 |
+ |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_ATTRIB_EXISTING: |
|
698 |
+ |
selectAttribExisting( pBoxedText.getName() ); |
|
699 |
+ |
break; |
|
700 |
+ |
case ObjectAndAttributesWithOneDegreeSeperationView.TYPE_ATTRIB_NEW: |
|
701 |
+ |
selectAttribNew(); |
|
702 |
+ |
break; |
|
703 |
+ |
default: |
|
704 |
+ |
updateStatus( "Unknown Box (" + pBoxedText.getName() + ") of Type (" + pBoxedText.getType() + ") clicked" ); |
|
705 |
+ |
break; |
|
706 |
+ |
} |
|
707 |
+ |
} |
|
708 |
+ |
} |
|
709 |
+ |
|
|
710 |
+ |
/** |
|
711 |
+ |
* Called on the UI Event Thread |
|
712 |
+ |
*/ |
|
713 |
+ |
private class OurObjectListClickListener implements ObjectListClickListener { |
|
714 |
+ |
@Override |
|
715 |
+ |
public boolean requestSaveAllowed() { |
|
716 |
+ |
return mEditable; |
|
717 |
+ |
} |
|
718 |
+ |
|
|
719 |
+ |
@Override |
|
720 |
+ |
public void requestSave() { |
|
721 |
+ |
updateStatus( "Saving..." ); |
|
722 |
+ |
save( mSubSystemForSaving.toSubSystemWriter() ); |
|
723 |
+ |
} |
|
724 |
+ |
|
|
725 |
+ |
@Override |
|
726 |
+ |
public boolean createNewAllowed() { |
|
727 |
+ |
return mEditable; |
|
728 |
+ |
} |
|
729 |
+ |
|
|
730 |
+ |
@Override |
|
731 |
+ |
public void createNewRequested() { |
|
732 |
+ |
selectObjectNew(); |
|
733 |
+ |
} |
|
734 |
+ |
|
|
735 |
+ |
@Override |
|
736 |
+ |
public void refreshRequested() { |
|
737 |
+ |
refresh(); |
|
738 |
+ |
} |
|
739 |
+ |
|
|
740 |
+ |
@Override |
|
741 |
+ |
public void selected( ObjectMetaData pObjectMetaData ) { |
|
742 |
+ |
selectObjectFromList( (pObjectMetaData != null) ? pObjectMetaData.getName() : null ); |
|
743 |
+ |
} |
|
744 |
+ |
} |
|
745 |
+ |
} |