]> gerrit.simantics Code Review - simantics/3d.git/blob
cb914170396e7fd2f872fe7a10204a4af6eae1ef
[simantics/3d.git] /
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.g3d.objmap.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.exception.DatabaseException;\r
19 import org.simantics.g3d.objmap.annotations.RelatedElementsAdd;\r
20 import org.simantics.g3d.objmap.annotations.RelatedElementsGet;\r
21 import org.simantics.g3d.objmap.annotations.RelatedElementsRem;\r
22 import org.simantics.g3d.objmap.rules.factory.ICollectionRuleFactory;\r
23 import org.simantics.g3d.objmap.rules.range.CollectionAccessor;\r
24 import org.simantics.objmap.IMappingRule;\r
25 import org.simantics.objmap.rules.MappedElementsRule;\r
26 import org.simantics.objmap.rules.domain.RelatedObjectsAccessor;\r
27 \r
28 public class RelatedElementsRuleFactory implements ICollectionRuleFactory {\r
29         \r
30         @Override\r
31         public IMappingRule create(ReadGraph g, Annotation annotation,\r
32                         Method getter, Method adder, Method remover)\r
33                         throws DatabaseException {\r
34                 RelatedElementsGet getterAnn = (RelatedElementsGet)annotation;\r
35                 return new MappedElementsRule(new RelatedObjectsAccessor(g.getResource(getterAnn.value()),true),\r
36                                         new CollectionAccessor<Object>(getter, adder, remover));\r
37         }\r
38         \r
39         @Override\r
40         public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {\r
41                 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;\r
42                 RelatedElementsAdd adderAnn = (RelatedElementsAdd)annotation;\r
43                 return getterAnn.value().equals(adderAnn.value());\r
44         }\r
45         \r
46         @Override\r
47         public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {\r
48                 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;\r
49                 RelatedElementsRem adderAnn = (RelatedElementsRem)annotation;\r
50                 return getterAnn.value().equals(adderAnn.value());\r
51         }\r
52 \r
53 }\r