]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/InheritsQueryProcessor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / InheritsQueryProcessor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.browsing.ui.graph.impl;
13
14 import java.util.Collections;
15 import java.util.Set;
16
17 import org.simantics.browsing.ui.BuiltinKeys;
18 import org.simantics.browsing.ui.NodeContext;
19 import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.common.ResourceArray;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.utils.Container;
25
26 public class InheritsQueryProcessor extends LazyGraphQueryProcessor<Set<Resource>> {
27
28     @Override
29     public String toString() {
30         return "InheritsProcessor";
31     }
32
33     @Override
34     public Object getIdentifier() {
35         return CommonKeys.INHERITS;
36     }
37
38     @Override
39     protected Set<Resource> initial() {
40         return Collections.emptySet();
41     }
42
43     @Override
44     protected Set<Resource> compute(ReadGraph graph, NodeContext context, PrimitiveQueryKey<Container<Set<Resource>>> key) throws DatabaseException {
45         Object input = context.getConstant(BuiltinKeys.INPUT);
46         if (input instanceof Resource) {
47             return graph.getSupertypes((Resource) input);
48         } else if (input instanceof ResourceArray) {
49             return graph.getSupertypes(((ResourceArray) input).resources[0]);
50         }
51         return Collections.emptySet();
52     }
53
54 }