]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/query/FlagTypeFilters.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / query / FlagTypeFilters.java
1 /*******************************************************************************
2  * Copyright (c) 2012 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.diagram.query;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.List;
18
19 import org.simantics.databoard.Bindings;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.common.request.ObjectsWithType;
23 import org.simantics.db.common.request.ResourceRead;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.layer0.Layer0;
26 import org.simantics.modeling.template2d.ontology.Template2dResource;
27
28 /**
29  * @author Tuukka Lehtonen
30  */
31 public class FlagTypeFilters extends ResourceRead<List<FlagTypeFilter>> {
32
33     public FlagTypeFilters(Resource visual) {
34         super(visual);
35     }
36
37     @Override
38     public List<FlagTypeFilter> perform(ReadGraph g) throws DatabaseException {
39         Layer0 L0 = Layer0.getInstance(g);
40         Template2dResource TEMPLATE2D = Template2dResource.getInstance(g);
41
42         Collection<Resource> filters = g.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, TEMPLATE2D.FlagTypeVisual_Filter));
43         if (filters.isEmpty())
44             return Collections.emptyList();
45
46         List<FlagTypeFilter> result = new ArrayList<FlagTypeFilter>(filters.size());
47         for (Resource node : filters) {
48             String reference = g.getPossibleRelatedValue2(node, TEMPLATE2D.FlagTypeVisual_Filter_HasProperty, Bindings.STRING);
49             String pattern = g.getPossibleRelatedValue2(node, TEMPLATE2D.FlagTypeVisual_Filter_HasPattern, Bindings.STRING);
50             Boolean matchRequired = g.getPossibleRelatedValue2(node, TEMPLATE2D.FlagTypeVisual_Filter_matchRequired, Bindings.BOOLEAN);
51             result.add( new FlagTypeFilter(node, reference, pattern, matchRequired) );
52         }
53         return result;
54     }
55
56 }