]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/interestset/RecordInterestSet.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / interestset / RecordInterestSet.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 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.databoard.accessor.interestset;
13
14 import org.simantics.databoard.annotations.Optional;
15 import org.simantics.databoard.type.RecordType;
16
17 /**
18  * Interest set of a Record Type.
19  *
20  * @see RecordType
21  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
22  */
23 public class RecordInterestSet extends InterestSet {
24
25         // Notifications
26         /** Interested in the _change_ to field assignments (excludes the value) */
27         public boolean notification;
28         /** Interested in the _change_ by field, null array/element if no interest */  
29         public @Optional boolean[] notifications;
30         
31         // Value Assignments
32         /** Interested in all values */ 
33         public boolean value;
34         /** Interested in values by field */
35         public @Optional boolean[] values;
36         
37         // Content
38         /** Component Interests by field, null array/element if no interest. */ 
39         public @Optional InterestSet[] componentInterests;
40         
41         public RecordInterestSet(boolean notification, boolean[] specificNotifications, boolean value, boolean[] specificValues, InterestSet[] componentInterests) {
42                 this.notification = notification;
43                 this.notifications = specificNotifications;
44                 this.value = value;
45                 this.values = specificValues;
46                 this.componentInterests = componentInterests;
47         }
48         
49         /**
50          * Returns true, if interested in notifications of changes to any field assignment
51          * 
52          * @return true, if interested in notifications
53          */
54         public boolean inNotifications() {
55                 return notification | value;
56         }
57
58         /**
59          * Returns true, if interested in assignment of the field at <code>fieldIndex</code>
60          * 
61          * @param fieldIndex
62          * @return true, if interested in notifications of the field at <code>fieldIndex</code>
63          */
64         public boolean inNotificationsOf(int fieldIndex) {
65                 if (notification || value) return true;         
66                 if (notifications != null && notifications[fieldIndex]) return true;
67                 if (values != null && values[fieldIndex]) return true;
68                 if (componentInterests!=null) {
69                         InterestSet compositeInterest = componentInterests[fieldIndex];
70                         return compositeInterest!=null;
71                 }
72                 return false;
73         }
74         
75         /**
76          * Returns true, if interested in value of all elements 
77          * 
78          * @return true, if interested in values of all elements
79          */
80         public boolean inValues() {
81                 return value;
82         }
83
84         /**
85          * Returns true, if interested in the complete value of the field at
86          * <code>fieldIndex</code>.
87          * 
88          * @param fieldIndex
89          * @return true, if interested in the values of the field at <code>fieldIndex</code>
90          */
91         public boolean inValuesOf(int fieldIndex) {
92                 if (value) return true;
93                 if (values!=null && values[fieldIndex]) return true;
94                 if (componentInterests!=null) {
95                         InterestSet compositeInterest = componentInterests[fieldIndex];
96                         return compositeInterest!=null;
97                 }
98                 return false;
99         }
100
101         /**
102          * Get composite intrest for the element at <code>fieldIndex</code>
103          * 
104          * @param fieldIndex
105          * @return interest of component or <code>null</code>
106          */
107         public InterestSet getComponentInterest(int fieldIndex) {
108                 if (componentInterests==null) return null;
109                 return componentInterests[fieldIndex];          
110         }
111         
112         /**
113          * Return true there is notification interest to any component
114          * 
115          * @return true if there is interest in changes of components 
116          */
117         public boolean inComponentNotifications() {
118                 return (notifications!=null && notifications.length>0) || (values!=null && values.length>0) || (componentInterests!=null && componentInterests.length>0);
119         }
120         
121 }
122