1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.accessor.interestset;
14 import org.simantics.databoard.annotations.Optional;
15 import org.simantics.databoard.type.RecordType;
18 * Interest set of a Record Type.
21 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
23 public class RecordInterestSet extends InterestSet {
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;
32 /** Interested in all values */
34 /** Interested in values by field */
35 public @Optional boolean[] values;
38 /** Component Interests by field, null array/element if no interest. */
39 public @Optional InterestSet[] componentInterests;
41 public RecordInterestSet(boolean notification, boolean[] specificNotifications, boolean value, boolean[] specificValues, InterestSet[] componentInterests) {
42 this.notification = notification;
43 this.notifications = specificNotifications;
45 this.values = specificValues;
46 this.componentInterests = componentInterests;
50 * Returns true, if interested in notifications of changes to any field assignment
52 * @return true, if interested in notifications
54 public boolean inNotifications() {
55 return notification | value;
59 * Returns true, if interested in assignment of the field at <code>fieldIndex</code>
62 * @return true, if interested in notifications of the field at <code>fieldIndex</code>
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;
76 * Returns true, if interested in value of all elements
78 * @return true, if interested in values of all elements
80 public boolean inValues() {
85 * Returns true, if interested in the complete value of the field at
86 * <code>fieldIndex</code>.
89 * @return true, if interested in the values of the field at <code>fieldIndex</code>
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;
102 * Get composite intrest for the element at <code>fieldIndex</code>
105 * @return interest of component or <code>null</code>
107 public InterestSet getComponentInterest(int fieldIndex) {
108 if (componentInterests==null) return null;
109 return componentInterests[fieldIndex];
113 * Return true there is notification interest to any component
115 * @return true if there is interest in changes of components
117 public boolean inComponentNotifications() {
118 return (notifications!=null && notifications.length>0) || (values!=null && values.length>0) || (componentInterests!=null && componentInterests.length>0);