]> gerrit.simantics Code Review - simantics/3d.git/blob
1f535add03da8429df812690284cf1d5fa338238
[simantics/3d.git] /
1 package org.simantics.g3d.objmap.annotations.factories;\r
2 \r
3 import java.lang.annotation.Annotation;\r
4 import java.lang.reflect.Method;\r
5 \r
6 import org.simantics.db.ReadGraph;\r
7 import org.simantics.db.exception.DatabaseException;\r
8 import org.simantics.g3d.objmap.annotations.RelatedElementsAdd;\r
9 import org.simantics.g3d.objmap.annotations.RelatedElementsGet;\r
10 import org.simantics.g3d.objmap.annotations.RelatedElementsRem;\r
11 import org.simantics.g3d.objmap.rules.factory.ICollectionRuleFactory;\r
12 import org.simantics.g3d.objmap.rules.range.CollectionAccessor;\r
13 import org.simantics.objmap.IMappingRule;\r
14 import org.simantics.objmap.rules.MappedElementsRule;\r
15 import org.simantics.objmap.rules.domain.RelatedObjectsAccessor;\r
16 \r
17 public class RelatedElementsRuleFactory implements ICollectionRuleFactory {\r
18         \r
19         @Override\r
20         public IMappingRule create(ReadGraph g, Annotation annotation,\r
21                         Method getter, Method adder, Method remover)\r
22                         throws DatabaseException {\r
23                 RelatedElementsGet getterAnn = (RelatedElementsGet)annotation;\r
24                 return new MappedElementsRule(new RelatedObjectsAccessor(g.getResource(getterAnn.value()),true),\r
25                                         new CollectionAccessor<Object>(getter, adder, remover));\r
26         }\r
27         \r
28         @Override\r
29         public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {\r
30                 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;\r
31                 RelatedElementsAdd adderAnn = (RelatedElementsAdd)annotation;\r
32                 return getterAnn.value().equals(adderAnn.value());\r
33         }\r
34         \r
35         @Override\r
36         public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {\r
37                 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;\r
38                 RelatedElementsRem adderAnn = (RelatedElementsRem)annotation;\r
39                 return getterAnn.value().equals(adderAnn.value());\r
40         }\r
41 \r
42 }\r