]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/query/FlagTables.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / query / FlagTables.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 gnu.trove.map.hash.THashMap;
15
16 import java.util.Map;
17
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.ResourceRead;
21 import org.simantics.db.common.uri.UnescapedChildMapOfResource;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.modeling.template2d.ontology.Template2dResource;
24
25 /**
26  * @author Tuukka Lehtonen
27  */
28 public class FlagTables extends ResourceRead<Map<String, Resource>> {
29
30     public FlagTables(Resource drawingTemplate) {
31         super(drawingTemplate);
32     }
33
34     @Override
35     public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
36         Map<String, Resource> childMap = graph.syncRequest(new UnescapedChildMapOfResource(resource));
37         if (childMap.isEmpty())
38             return childMap;
39
40         Template2dResource TEMPLATE2D = Template2dResource.getInstance(graph);
41         Map<String, Resource> flagTables = new THashMap<String, Resource>(childMap.size());
42         for (Map.Entry<String, Resource> entry : childMap.entrySet()) {
43             if (graph.isInstanceOf(entry.getValue(), TEMPLATE2D.FlagTable)) {
44                 flagTables.put(entry.getKey(), entry.getValue());
45             }
46         }
47
48         return flagTables;
49     }
50
51 }