]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/mutable/ContainerOptionalBinding.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / mutable / ContainerOptionalBinding.java
1 /*******************************************************************************\r
2  *  Copyright (c) 2010 Association for Decentralized Information Management in\r
3  *  Industry THTH ry.\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
8  *\r
9  *  Contributors:\r
10  *      VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.databoard.binding.mutable;
13
14 import org.simantics.databoard.binding.Binding;\r
15 import org.simantics.databoard.binding.OptionalBinding;\r
16 import org.simantics.databoard.binding.error.BindingException;\r
17 import org.simantics.databoard.type.OptionalType;\r
18
19 /**
20  * Binds OptionalType to ValueContainer
21  *
22  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
23  */
24 public class ContainerOptionalBinding extends OptionalBinding {
25
26         public ContainerOptionalBinding(Binding componentBinding) {
27                 super(componentBinding);
28         }
29
30         public ContainerOptionalBinding(OptionalType type, Binding componentBinding) {
31                 super(type, componentBinding);
32         }\r
33         
34         @Override
35         public boolean hasValue(Object arg) {
36                 return ((ValueContainer)arg).value != null;
37         }
38
39         @Override
40         public Object getValue(Object arg) {
41                 return ((ValueContainer)arg).value;
42         }
43         
44         @Override
45         public Object createNoValue() {
46                 return new ValueContainer();
47         }
48         
49         @Override
50         public Object createValue(Object value) throws BindingException {
51                 ValueContainer result = new ValueContainer();
52                 result.value = value;
53                 return result;
54         }
55         
56         @Override
57         public boolean isInstance(Object obj) {
58                 return obj instanceof ValueContainer;
59         }
60         
61         @Override
62         public void setValue(Object optional, Object componentValue)
63         throws BindingException {
64                 ((ValueContainer) optional).value = componentValue;
65         }
66         
67         @Override
68         public void setNoValue(Object optional) throws BindingException {
69                 ((ValueContainer) optional).value = null;               
70         }
71 }
72