Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / StandardContextTypesQueryProcessor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 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.swt;
13
14 import java.util.Collections;
15 import java.util.Set;
16
17 import org.simantics.browsing.ui.NodeContext;
18 import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;
19 import org.simantics.browsing.ui.common.node.StandardNodes;
20 import org.simantics.browsing.ui.graph.impl.CommonKeys;
21 import org.simantics.browsing.ui.graph.impl.LazyGraphQueryProcessor;
22 import org.simantics.db.ReadGraph;
23 import org.simantics.db.Resource;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.ui.utils.ResourceAdaptionUtils;
26 import org.simantics.utils.Container;
27
28 public class StandardContextTypesQueryProcessor extends LazyGraphQueryProcessor<Set<Resource>> {
29
30     @Override
31     public String toString() {
32         return "Standard Context Types";
33     }
34
35     @Override
36     public Object getIdentifier() {
37         return CommonKeys.STANDARD_CONTEXT_TYPES;
38     }
39
40     @Override
41     protected Set<Resource> initial() {
42         return Collections.emptySet();
43     }
44
45     @Override
46     protected Set<Resource> compute(ReadGraph graph, NodeContext context, PrimitiveQueryKey<Container<Set<Resource>>> key) throws DatabaseException {
47         Object input = context.getConstant(StandardNodes.CONTEXT);
48         Resource resource = ResourceAdaptionUtils.toSingleResource(input);
49         if(resource != null) {
50             return graph.getTypes(resource);
51         } else {
52             return Collections.emptySet();
53         }
54     }
55
56 }