]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/mutable/ContainerOptionalBinding.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / mutable / ContainerOptionalBinding.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.binding.mutable;
13
14 import org.simantics.databoard.binding.Binding;
15 import org.simantics.databoard.binding.OptionalBinding;
16 import org.simantics.databoard.binding.error.BindingException;
17 import org.simantics.databoard.type.OptionalType;
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         }
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