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