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.binding.mutable;
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;
20 * Binds OptionalType to ValueContainer
22 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
24 public class ContainerOptionalBinding extends OptionalBinding {
26 public ContainerOptionalBinding(Binding componentBinding) {
27 super(componentBinding);
30 public ContainerOptionalBinding(OptionalType type, Binding componentBinding) {
31 super(type, componentBinding);
35 public boolean hasValue(Object arg) {
36 return ((ValueContainer)arg).value != null;
40 public Object getValue(Object arg) {
41 return ((ValueContainer)arg).value;
45 public Object createNoValue() {
46 return new ValueContainer();
50 public Object createValue(Object value) throws BindingException {
51 ValueContainer result = new ValueContainer();
57 public boolean isInstance(Object obj) {
58 return obj instanceof ValueContainer;
62 public void setValue(Object optional, Object componentValue)
63 throws BindingException {
64 ((ValueContainer) optional).value = componentValue;
68 public void setNoValue(Object optional) throws BindingException {
69 ((ValueContainer) optional).value = null;