]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.common/src/org/simantics/issues/common/preferences/IssuePrefs.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / preferences / IssuePrefs.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 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.issues.common.preferences;
13
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.issues.ui.ontology.IssueUIResource;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public final class IssuePrefs {
25
26     public static boolean showHiddenIssues(ReadGraph graph, Resource project) throws DatabaseException {
27         return testBoolean(graph, project, IssueUIResource.getInstance(graph).ShowHiddenIssues, false);
28     }
29
30     public static boolean showNormalIssues(ReadGraph graph, Resource project) throws DatabaseException {
31         return testBoolean(graph, project, IssueUIResource.getInstance(graph).ShowNormalIssues, true);
32     }
33
34     public static boolean showUserIssues(ReadGraph graph, Resource project) throws DatabaseException {
35         return testBoolean(graph, project, IssueUIResource.getInstance(graph).ShowUserIssues, true);
36     }
37
38     private static boolean testBoolean(ReadGraph graph, Resource project, Resource property, boolean defaultValue) throws DatabaseException {
39         if (project == null)
40             return defaultValue;
41         Boolean b = graph.getPossibleRelatedValue(project, property, Bindings.BOOLEAN);
42         return b == null ? defaultValue : b;
43     }
44
45     public static void setShowHiddenIssues(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
46         setBoolean(graph, project, IssueUIResource.getInstance(graph).ShowHiddenIssues, show);
47     }
48
49     public static void setShowNormalIssues(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
50         setBoolean(graph, project, IssueUIResource.getInstance(graph).ShowNormalIssues, show);
51     }
52
53     public static void setShowUserIssues(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
54         setBoolean(graph, project, IssueUIResource.getInstance(graph).ShowUserIssues, show);
55     }
56
57     private static void setBoolean(WriteGraph graph, Resource project, Resource property, boolean value)
58             throws DatabaseException {
59         graph.claimLiteral(project, property, value, Bindings.BOOLEAN);
60     }
61
62 }