]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/UserIssueTest.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / UserIssueTest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 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.issues.ui;
13
14 import org.simantics.browsing.ui.model.tests.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.variable.Variable;
19 import org.simantics.issues.ontology.IssueResource;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public class UserIssueTest implements Test {
25
26     @Override
27     public boolean isCompatible(Class<?> contentType) {
28         return Resource.class.equals(contentType) || Variable.class.equals(contentType);
29     }
30
31     @Override
32     public boolean test(ReadGraph graph, Object content) throws DatabaseException {
33         IssueResource ISSUE = IssueResource.getInstance(graph);
34         if (content instanceof Resource)
35             return graph.hasStatement((Resource) content, ISSUE.UserIssue);
36         if (content instanceof Variable) {
37             Variable v = (Variable) content;
38             Resource r = v.getPossibleRepresents(graph);
39             if (r != null)
40                 return graph.hasStatement(r, ISSUE.UserIssue);
41         }
42         return false;
43     }
44
45 }