]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.event/src/org/simantics/event/view/preference/EventPrefs.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / view / preference / EventPrefs.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.event.view.preference;
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.event.ontology.EventViewResource;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public final class EventPrefs {
25
26     public static boolean hideInfoEvents(ReadGraph graph, Resource project) throws DatabaseException {
27         return testBoolean(graph, project, EventViewResource.getInstance(graph).HideInfoEvents);
28     }
29
30     public static boolean hideWarningEvents(ReadGraph graph, Resource project) throws DatabaseException {
31         return testBoolean(graph, project, EventViewResource.getInstance(graph).HideWarningEvents);
32     }
33
34     public static boolean hideReturnEvents(ReadGraph graph, Resource project) throws DatabaseException {
35         return testBoolean(graph, project, EventViewResource.getInstance(graph).HideReturnEvents);
36     }
37
38     public static boolean showHiddenEvents(ReadGraph graph, Resource project) throws DatabaseException {
39         return testBoolean(graph, project, EventViewResource.getInstance(graph).ShowHiddenEvents);
40     }
41
42     public static boolean showOnlyMilestones(ReadGraph graph, Resource project) throws DatabaseException {
43         return testBoolean(graph, project, EventViewResource.getInstance(graph).ShowOnlyMilestones);
44     }
45
46     public static boolean showOnlyActiveEvents(ReadGraph graph, Resource project) throws DatabaseException {
47         return testBoolean(graph, project, EventViewResource.getInstance(graph).ShowOnlyActiveEvents);
48     }
49
50     private static boolean testBoolean(ReadGraph graph, Resource project, Resource property) throws DatabaseException {
51         if (project == null)
52             return false;
53         return Boolean.TRUE.equals(graph.getPossibleRelatedValue(project, property, Bindings.BOOLEAN));
54     }
55
56     public static void setHideInfoEvents(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
57         setBoolean(graph, project, EventViewResource.getInstance(graph).HideInfoEvents, show);
58     }
59
60     public static void setHideWarningEvents(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
61         setBoolean(graph, project, EventViewResource.getInstance(graph).HideWarningEvents, show);
62     }
63
64     public static void setHideReturnEvents(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
65         setBoolean(graph, project, EventViewResource.getInstance(graph).HideReturnEvents, show);
66     }
67
68     public static void setShowHiddenEvents(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
69         setBoolean(graph, project, EventViewResource.getInstance(graph).ShowHiddenEvents, show);
70     }
71
72     public static void setShowOnlyMilestones(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
73         setBoolean(graph, project, EventViewResource.getInstance(graph).ShowOnlyMilestones, show);
74     }
75
76     public static void setShowOnlyActiveEvents(WriteGraph graph, Resource project, boolean show) throws DatabaseException {
77         setBoolean(graph, project, EventViewResource.getInstance(graph).ShowOnlyActiveEvents, show);
78     }
79
80     private static void setBoolean(WriteGraph graph, Resource project, Resource property, boolean value) throws DatabaseException {
81         graph.claimLiteral(project, property, value, Bindings.BOOLEAN);
82     }
83
84 }