]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/OrderedElementsRuleFactory.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / annotations / factories / OrderedElementsRuleFactory.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.objmap.graph.annotations.factories;\r
13 \r
14 import java.lang.annotation.Annotation;\r
15 import java.lang.reflect.Method;\r
16 \r
17 import org.simantics.db.ReadGraph;\r
18 import org.simantics.db.Resource;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;\r
21 import org.simantics.objmap.graph.annotations.OrderedElementsAdd;\r
22 import org.simantics.objmap.graph.annotations.OrderedElementsGet;\r
23 import org.simantics.objmap.graph.annotations.OrderedElementsRem;\r
24 import org.simantics.objmap.graph.rules.MappedElementsRule;\r
25 import org.simantics.objmap.graph.rules.domain.RelatedOrderedSetElementsAccessor;\r
26 import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;\r
27 import org.simantics.objmap.graph.rules.range.ListAccessor;\r
28 \r
29 \r
30 public class OrderedElementsRuleFactory<Range> implements ICollectionRuleFactory<Resource,Range> {\r
31         \r
32         @Override\r
33         public IBidirectionalMappingRule<Resource, Range> create(ReadGraph g, Annotation annotation,\r
34                         Method getter, Method adder, Method remover)\r
35                         throws DatabaseException {\r
36                 OrderedElementsGet getterAnn = (OrderedElementsGet)annotation;\r
37                 return new MappedElementsRule<Resource,Range>(new RelatedOrderedSetElementsAccessor(getterAnn.composition()),\r
38                                         new ListAccessor<Range,Range>(getter, adder, remover));\r
39         }\r
40         \r
41         @Override\r
42         public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {\r
43                 OrderedElementsGet getterAnn = (OrderedElementsGet)getterAnnotation;\r
44                 OrderedElementsAdd adderAnn = (OrderedElementsAdd)annotation;\r
45                 return true;\r
46         }\r
47         \r
48         @Override\r
49         public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {\r
50                 OrderedElementsGet getterAnn = (OrderedElementsGet)getterAnnotation;\r
51                 OrderedElementsRem adderAnn = (OrderedElementsRem)annotation;\r
52                 return true;\r
53         }\r
54 \r
55 }\r