Skip to content

Package: Property

Property

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2017 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Mat Hansen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.common;
15:
16: /**
17: * An observable value.
18: *
19: * @param <T>
20: * the type
21: * @since 1.15
22: */
23: public interface Property<T> {
24:         /**
25:          * Set the new value.
26:          *
27:          * @param value
28:          * the value
29:          */
30:         void setValue(T value);
31:
32:         /**
33:          * Get the name of the property.
34:          *
35:          * @return the value
36:          */
37:         String getName();
38:
39:         /**
40:          * Get the current value.
41:          *
42:          * @return the value
43:          */
44:         T getValue();
45:
46:         /**
47:          * Returns the default value.
48:          *
49:          * @return the value
50:          */
51:
52:         T getDefault();
53:
54:         /**
55:          * Resets the value to the initial value and returns the new value.
56:          *
57:          * @return the value
58:          */
59:         T resetToDefault();
60:
61:         /**
62:          * Dispose the value.
63:          */
64:         void dispose();
65:
66:         /**
67:          * Attach a listener.
68:          *
69:          * @param listener
70:          * the listener
71:          */
72:         void addChangeListener(ChangeListener<T> listener);
73:
74:         /**
75:          * Remove the listener.
76:          *
77:          * @param listener
78:          * the listener
79:          */
80:         void removeChangeListener(ChangeListener<T> listener);
81:
82:         /**
83:          * Listener to observe changes.
84:          *
85:          * @param <T>
86:          * the type
87:          */
88:         // @FunctionalInterface
89:         interface ChangeListener<T> {
90:                 /**
91:                  * Handle the changed value.
92:                  *
93:                  * @param property
94:                  * the property
95:                  * @param oldValue
96:                  * the old value
97:                  * @param newValue
98:                  * the new value
99:                  */
100:                 void valueChanged(Property<T> property, T oldValue, T newValue);
101:         }
102: }