]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph/src/org/simantics/browsing/ui/graph/tester/EqualsResourceTester.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph / src / org / simantics / browsing / ui / graph / tester / EqualsResourceTester.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.tester;
13
14 import org.simantics.browsing.ui.BuiltinKeys;
15 import org.simantics.browsing.ui.NodeContext;
16 import org.simantics.browsing.ui.NodeQueryManager;
17 import org.simantics.browsing.ui.Tester;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.RequestProcessor;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.request.ReadRequest;
22 import org.simantics.db.exception.DatabaseException;
23
24 public class EqualsResourceTester implements Tester {
25
26     private Resource resource;
27     private String uri;
28
29     public EqualsResourceTester(Resource resource) {
30         this.resource = resource;
31     }
32
33     public EqualsResourceTester(RequestProcessor processor, final String uri) throws DatabaseException {
34
35         this.uri = uri;
36
37         processor.syncRequest(new ReadRequest() {
38
39             @Override
40             public void run(ReadGraph graph) {
41                 try {
42                     resource = graph.getResource(uri);
43                     assert (resource != null);
44                 } catch (DatabaseException e) {
45                     e.printStackTrace();
46                 }
47             }
48
49         });
50
51     }
52
53     @Override
54     public boolean test(NodeQueryManager manager, NodeContext context) {
55         return resource.equals(context.getConstant(BuiltinKeys.INPUT));
56     }
57
58     @Override
59     public String toString() {
60         return "Equals resource " + (uri != null ? uri : "<unknown>");
61     }
62
63 }