1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.caleigo.core;
20
21 import org.caleigo.core.event.*;
22
23 /*** EntitySelection is an entity collection class that can store zero or more
24 * IEntity objects. The entities stored by this interface are type specified
25 * and must be defined by a single IEntityDescriptor.
26 *
27 * The EntitySelection differs from EntityCollection by using a contained
28 * Qualifier to define the scope of the contained entity objects. This means
29 * that the collection does not accept objects that are not qualified by the
30 * the defined Qualifier. This means that if data is change in a contained
31 * etity that "unqualifies" it it will automatically be removed from the
32 * collection. Also a call to RefreshAll uses the qualifier to search for all
33 * entities defined that it qualifies which may change the number of contained
34 * entities according to external changes in the persistent storage.
35 *
36 * IEntitySelection is ordered and contained entities can be accesed by index.
37 *
38 * @author Dennis Zikovic
39 * @version 1.00
40 *
41 *//*
42 *
43 * WHEN WHO WHY & WHAT
44 * ------------------------------------------------------------------------------
45 * 2001-10-10 Dennis Zikovic Creation
46 */
47 public class QualifiedSelection extends Selection implements IQualifiedSelection
48 {
49
50 private Qualifier mQualifier;
51
52
53
54 /*** This costructor will create a new selection object for the provided
55 * IEntityDescriptor. The selection will be loaded with entities from the
56 * default persistent storage using the provided qualifier that will define
57 * the scope of the selector.
58 */
59 public QualifiedSelection(IEntityDescriptor entityDescriptor, Qualifier qualifier)
60 {
61 super(entityDescriptor);
62 mQualifier = qualifier;
63
64
65 this.addEntityChangeListener(new EntityRemovalListener());
66
67
68 this.refreshAll();
69 }
70
71 /*** This is a copy constructor that makes a shallow copy of the contained
72 * entities in the provided selection.
73 */
74 public QualifiedSelection(IQualifiedSelection selection)
75 {
76 super(selection);
77 mQualifier = selection.getQualifier();
78
79
80 this.addEntityChangeListener(new EntityRemovalListener());
81 }
82
83
84
85 public void refreshAll()
86 {
87
88 }
89
90 public boolean doesAccept(IEntity entity)
91 {
92 return super.doesAccept(entity) && (mQualifier==null || mQualifier.doesQualify(entity));
93 }
94
95
96
97 public Qualifier getQualifier()
98 {
99 return mQualifier;
100 }
101
102 public void setQualifier(Qualifier qualifier)
103 {
104 mQualifier = qualifier;
105 }
106
107
108
109 private class EntityRemovalListener implements IEntityChangeListener
110 {
111 public void dataChanged(EntityChangeEvent event)
112 {
113 if(mQualifier!=null && !mQualifier.doesQualify(event.getSourceEntity()))
114 removeEntity(event.getSourceEntity());
115 }
116
117 public void statusChanged(EntityChangeEvent event)
118 {
119 }
120 }
121 }