diff options
Diffstat (limited to 'source/com/c2kernel/collection/Aggregation.java')
| -rwxr-xr-x | source/com/c2kernel/collection/Aggregation.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/source/com/c2kernel/collection/Aggregation.java b/source/com/c2kernel/collection/Aggregation.java new file mode 100755 index 0000000..72b8005 --- /dev/null +++ b/source/com/c2kernel/collection/Aggregation.java @@ -0,0 +1,111 @@ +package com.c2kernel.collection;
+
+import java.util.Iterator;
+
+import com.c2kernel.collection.gui.model.AggregationVertexOutlineCreator;
+import com.c2kernel.graph.model.*;
+import com.c2kernel.utils.*;
+
+/**
+ * @version $Revision: 1.59 $ $Date: 2004/08/10 07:56:08 $
+ * @author $Author: abranson $
+ */
+
+abstract public class Aggregation extends Parent2ChildCollection
+{
+
+ protected GraphModel mLayout = new GraphModel(new AggregationVertexOutlineCreator());
+
+ private final TypeNameAndConstructionInfo[] mVertexTypeNameAndConstructionInfo = {
+ new TypeNameAndConstructionInfo(Language.translate("Slot"), "AggregationMember")
+ };
+
+ public Aggregation()
+ {
+ setName("Aggregation");
+ mMembers = new CollectionMemberList();
+ }
+
+
+ public GraphModel getLayout()
+ {
+ return mLayout;
+ }
+
+ public void setLayout(GraphModel layout)
+ {
+ mLayout = layout;
+ }
+
+ public TypeNameAndConstructionInfo[] getVertexTypeNameAndConstructionInfo()
+ {
+ return mVertexTypeNameAndConstructionInfo;
+ }
+
+ public boolean exists(int entityKey)
+ {
+ for (int i=0; i<size(); i++)
+ {
+ AggregationMember element = (AggregationMember) mMembers.list.get(i);
+ if (element.getEntityKey() == entityKey)
+ return true;
+ }
+ return false;
+ }
+
+ public AggregationMember getMemberPair(int vertexID)
+ {
+ for (int i=0; i<size(); i++)
+ {
+ AggregationMember element = (AggregationMember) mMembers.list.get(i);
+ if (element.getID() == vertexID)
+ return element;
+ }
+ return null;
+ }
+
+ public void addMember(int entityKey, CastorHashMap props, String classProps, GraphPoint location, int w, int h)
+ throws MembershipException
+ {
+ // Create new member object
+ AggregationMember aggMem = new AggregationMember();
+ aggMem.setProperties(props);
+ aggMem.setClassProps(classProps);
+ aggMem.assignEntity(entityKey);
+
+ // create vertex
+ com.c2kernel.graph.model.Vertex vertex = new com.c2kernel.graph.model.Vertex();
+ vertex.setHeight(h); vertex.setWidth(w);
+ mLayout.addVertexAndCreateId(vertex,location);
+ aggMem.setCollection(this);
+ aggMem.setID(vertex.getID());
+ aggMem.setIsLayoutable(true);
+ aggMem.setIsComposite( RelationshipUtils.getIsComposite(entityKey) );
+ mMembers.list.add(aggMem);
+ Logger.msg(8, "AggregationDescription::addMember(" + entityKey + ") added to children linked to vertexid " + vertex.getID());
+ }
+
+
+ public void addMember(int entityKey, CastorHashMap props, String classProps) throws MembershipException
+ {
+ addMember(entityKey, props, classProps, new GraphPoint(100,100*getCounter()), 20, 20);
+ }
+
+ public void addMember(int entityKey) throws MembershipException {
+ throw new MembershipException("Aggregations cannot accept arbitrary members without type info");
+
+ }
+
+ public void removeMember(int memberId) throws MembershipException {
+ for (Iterator iter = mMembers.list.iterator(); iter.hasNext();) {
+ AggregationMember element = (AggregationMember)iter.next();
+ if (element.getID() == memberId) {
+ element.clearEntity();
+ mLayout.removeVertex(getLayout().getVertexById(memberId));
+ return;
+ }
+ }
+ throw new MembershipException("Member "+memberId+" not found");
+ }
+
+}
|
