]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.issues.common/src/org/simantics/issues/common/preferences/IssuePrefs.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / preferences / IssuePrefs.java
diff --git a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/preferences/IssuePrefs.java b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/preferences/IssuePrefs.java
new file mode 100644 (file)
index 0000000..2b7f477
--- /dev/null
@@ -0,0 +1,62 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.issues.common.preferences;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.issues.ui.ontology.IssueUIResource;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public final class IssuePrefs {\r
+\r
+    public static boolean showHiddenIssues(ReadGraph graph, Resource project) throws DatabaseException {\r
+        return testBoolean(graph, project, IssueUIResource.getInstance(graph).ShowHiddenIssues, false);\r
+    }\r
+\r
+    public static boolean showNormalIssues(ReadGraph graph, Resource project) throws DatabaseException {\r
+        return testBoolean(graph, project, IssueUIResource.getInstance(graph).ShowNormalIssues, true);\r
+    }\r
+\r
+    public static boolean showUserIssues(ReadGraph graph, Resource project) throws DatabaseException {\r
+        return testBoolean(graph, project, IssueUIResource.getInstance(graph).ShowUserIssues, true);\r
+    }\r
+\r
+    private static boolean testBoolean(ReadGraph graph, Resource project, Resource property, boolean defaultValue) throws DatabaseException {\r
+        if (project == null)\r
+            return defaultValue;\r
+        Boolean b = graph.getPossibleRelatedValue(project, property, Bindings.BOOLEAN);\r
+        return b == null ? defaultValue : b;\r
+    }\r
+\r
+    public static void setShowHiddenIssues(WriteGraph graph, Resource project, boolean show) throws DatabaseException {\r
+        setBoolean(graph, project, IssueUIResource.getInstance(graph).ShowHiddenIssues, show);\r
+    }\r
+\r
+    public static void setShowNormalIssues(WriteGraph graph, Resource project, boolean show) throws DatabaseException {\r
+        setBoolean(graph, project, IssueUIResource.getInstance(graph).ShowNormalIssues, show);\r
+    }\r
+\r
+    public static void setShowUserIssues(WriteGraph graph, Resource project, boolean show) throws DatabaseException {\r
+        setBoolean(graph, project, IssueUIResource.getInstance(graph).ShowUserIssues, show);\r
+    }\r
+\r
+    private static void setBoolean(WriteGraph graph, Resource project, Resource property, boolean value)\r
+            throws DatabaseException {\r
+        graph.claimLiteral(project, property, value, Bindings.BOOLEAN);\r
+    }\r
+\r
+}\r