1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.accessor.interestset;
14 import org.simantics.databoard.annotations.Union;
\r
15 import org.simantics.databoard.type.ArrayType;
\r
16 import org.simantics.databoard.type.BooleanType;
\r
17 import org.simantics.databoard.type.ByteType;
\r
18 import org.simantics.databoard.type.Datatype;
\r
19 import org.simantics.databoard.type.DoubleType;
\r
20 import org.simantics.databoard.type.FloatType;
\r
21 import org.simantics.databoard.type.IntegerType;
\r
22 import org.simantics.databoard.type.LongType;
\r
23 import org.simantics.databoard.type.MapType;
\r
24 import org.simantics.databoard.type.OptionalType;
\r
25 import org.simantics.databoard.type.RecordType;
\r
26 import org.simantics.databoard.type.StringType;
\r
27 import org.simantics.databoard.type.UnionType;
\r
28 import org.simantics.databoard.type.VariantType;
\r
31 * InterestSet is a description about what is monitored in a data model.
\r
33 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
35 @Union({BooleanInterestSet.class,
36 ByteInterestSet.class,
37 IntegerInterestSet.class,
38 LongInterestSet.class,
39 FloatInterestSet.class,
40 DoubleInterestSet.class,
41 StringInterestSet.class,
42 RecordInterestSet.class,
43 ArrayInterestSet.class,
45 OptionalInterestSet.class,
46 UnionInterestSet.class,
47 VariantInterestSet.class
49 public abstract class InterestSet {
51 // private static final String[] EMPTY_ARRAY = new String[0];
\r
54 * Returns true, if interested in notifications of modifications, this question excludes
\r
55 * an interest to the values.
57 * @return true if interested in notifications
59 public abstract boolean inNotifications();
62 * Returns true, if interested in notifications of changes and the new values.
64 * @return true if interested in notifications and value
66 public abstract boolean inValues();
70 * Create a new interest set
72 * @param type the type to create interest set for
73 * @param notification interested in notification of changes, not the values
74 * @param value interested in values (includes notification)
75 * @param recursive interested in values recursivelu (includes notification)
77 public static InterestSet newInterestSet(Datatype type, boolean notification, boolean value, boolean recursive) {
79 if (type instanceof BooleanType) {
80 if (recursive) return BooleanInterestSet.MONITOR_EVERYTHING;
81 return new BooleanInterestSet(notification, value);
84 if (type instanceof ByteType) {
85 if (recursive) return ByteInterestSet.MONITOR_EVERYTHING;
86 return new ByteInterestSet(notification, value);
89 if (type instanceof IntegerType) {
90 if (recursive) return IntegerInterestSet.MONITOR_EVERYTHING;
91 return new IntegerInterestSet(notification, value);
94 if (type instanceof LongType) {
95 if (recursive) return LongInterestSet.MONITOR_EVERYTHING;
96 return new LongInterestSet(notification, value);
99 if (type instanceof FloatType) {
100 if (recursive) return FloatInterestSet.MONITOR_EVERYTHING;
101 return new FloatInterestSet(notification, value);
104 if (type instanceof DoubleType) {
105 if (recursive) return DoubleInterestSet.MONITOR_EVERYTHING;
106 return new DoubleInterestSet(notification, value);
109 if (type instanceof StringType) {
110 if (recursive) return StringInterestSet.MONITOR_EVERYTHING;
111 return new StringInterestSet(notification, value);
114 if (type instanceof OptionalType) {
115 OptionalType ot = (OptionalType) type;
116 InterestSet cis = recursive ? newInterestSet(ot.getComponentType(), notification, value, true) : null;
117 return new OptionalInterestSet(notification, value, cis );
120 if (type instanceof RecordType) {
122 return new RecordInterestSet(notification, null, value, null, null);
124 RecordType rt = (RecordType) type;
125 InterestSet[] componentInterests = new InterestSet[rt.getComponentCount()];
126 for (int i=0; i<componentInterests.length; i++) {
127 componentInterests[i] = newInterestSet( rt.getComponentType(i), notification, value, true );
129 return new RecordInterestSet(true, null, true, null, componentInterests);
132 if (type instanceof UnionType) {
134 return new UnionInterestSet(notification, value, null);
137 UnionType ut = (UnionType) type;
138 InterestSet[] componentInterests = new InterestSet[ut.getComponentCount()];
139 for (int i=0; i<componentInterests.length; i++) {
140 componentInterests[i] = newInterestSet( ut.getComponent(i).type, notification, value, true );
142 return new UnionInterestSet(notification, value, componentInterests);
145 if (type instanceof ArrayType) {
146 ArrayType at = (ArrayType) type;
147 InterestSet cis = recursive ? newInterestSet( at.componentType(), notification, value, true ) : null;
148 return new ArrayInterestSet(notification, null, value, null, cis, null);
151 if (type instanceof MapType) {
152 MapType mt = (MapType) type;
153 InterestSet cis = recursive ? newInterestSet( mt.valueType, notification, value, true ) : null;
154 return new MapInterestSet(notification, null, value, null, cis, null);
157 if (type instanceof VariantType) {
158 return new VariantInterestSet(notification, value, null, recursive);
161 throw new IllegalArgumentException(type.toSingleLineString());
164 // public String[] getCustomEvents() {
\r
165 // return customEvents;
\r
168 // public void setCustomEvents(String[] customEvents) {
\r
169 // this.customEvents = customEvents;
\r
171 /** A list of custom event types of interest */
\r
172 // public String[] customEvents = EMPTY_ARRAY;
\r