X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Faccessor%2Fjava%2FJavaBoolean.java;fp=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Faccessor%2Fjava%2FJavaBoolean.java;h=b532e978a33495b82139034a0ad5a744acdd5d81;hp=f436dd2302bee6b652d04916ea41ce43d3be489e;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaBoolean.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaBoolean.java index f436dd230..b532e978a 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaBoolean.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaBoolean.java @@ -1,35 +1,35 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.databoard.accessor.java; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.accessor.Accessor; -import org.simantics.databoard.accessor.BooleanAccessor; -import org.simantics.databoard.accessor.error.AccessorConstructionException; -import org.simantics.databoard.accessor.error.AccessorException; -import org.simantics.databoard.accessor.error.ReferenceException; -import org.simantics.databoard.accessor.event.Event; -import org.simantics.databoard.accessor.event.ValueAssigned; -import org.simantics.databoard.accessor.impl.AccessorParams; -import org.simantics.databoard.accessor.impl.ListenerEntry; -import org.simantics.databoard.accessor.interestset.BooleanInterestSet; -import org.simantics.databoard.accessor.reference.ChildReference; -import org.simantics.databoard.binding.ArrayBinding; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.BooleanBinding; -import org.simantics.databoard.binding.RecordBinding; -import org.simantics.databoard.binding.VariantBinding; -import org.simantics.databoard.binding.error.BindingException; -import org.simantics.databoard.type.BooleanType; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.accessor.Accessor; +import org.simantics.databoard.accessor.BooleanAccessor; +import org.simantics.databoard.accessor.error.AccessorConstructionException; +import org.simantics.databoard.accessor.error.AccessorException; +import org.simantics.databoard.accessor.error.ReferenceException; +import org.simantics.databoard.accessor.event.Event; +import org.simantics.databoard.accessor.event.ValueAssigned; +import org.simantics.databoard.accessor.impl.AccessorParams; +import org.simantics.databoard.accessor.impl.ListenerEntry; +import org.simantics.databoard.accessor.interestset.BooleanInterestSet; +import org.simantics.databoard.accessor.reference.ChildReference; +import org.simantics.databoard.binding.ArrayBinding; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.BooleanBinding; +import org.simantics.databoard.binding.RecordBinding; +import org.simantics.databoard.binding.VariantBinding; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.type.BooleanType; /** * Accessor to a Java Object of Boolean Type. @@ -52,44 +52,44 @@ public class JavaBoolean extends JavaObject implements BooleanAccessor { } @Override - public boolean getValue() throws AccessorException { + public boolean getValue() throws AccessorException { readLock(); try { return getBinding().getValue_(object); } catch (BindingException e) { throw new AccessorException(e); - } finally { - readLock(); + } finally { + readLock(); } } @Override - public void setValue(boolean newValue) throws AccessorException { - if (newValue == getValue()) return; + public void setValue(boolean newValue) throws AccessorException { + if (newValue == getValue()) return; writeLock(); - try { - if (binding.isImmutable() && parent!=null && parent instanceof JavaArray) { - JavaObject jo = (JavaObject) parent; - ArrayBinding ab = (ArrayBinding) jo.binding; - Object nv = getBinding().create(newValue); - ab.set(jo.object, (Integer)keyInParent, nv); - this.object = nv; - } else if (binding.isImmutable() && parent!=null && parent instanceof JavaRecord) { - JavaObject jo = (JavaObject) parent; - RecordBinding rb = (RecordBinding) jo.binding; - Object nv = getBinding().create(newValue); - rb.setComponent(jo.object, (Integer)keyInParent, nv); - this.object = nv; - } else if (binding.isImmutable() && parent!=null && parent instanceof JavaVariant) { - JavaObject jo = (JavaObject) parent; - VariantBinding vb = (VariantBinding) ((JavaVariant)parent).binding; - Object nv = getBinding().create(newValue); - vb.setContent(jo.object, getBinding(), nv); - this.object = nv; - } else { - // Set value - getBinding().setValue(object, newValue); - } + try { + if (binding.isImmutable() && parent!=null && parent instanceof JavaArray) { + JavaObject jo = (JavaObject) parent; + ArrayBinding ab = (ArrayBinding) jo.binding; + Object nv = getBinding().create(newValue); + ab.set(jo.object, (Integer)keyInParent, nv); + this.object = nv; + } else if (binding.isImmutable() && parent!=null && parent instanceof JavaRecord) { + JavaObject jo = (JavaObject) parent; + RecordBinding rb = (RecordBinding) jo.binding; + Object nv = getBinding().create(newValue); + rb.setComponent(jo.object, (Integer)keyInParent, nv); + this.object = nv; + } else if (binding.isImmutable() && parent!=null && parent instanceof JavaVariant) { + JavaObject jo = (JavaObject) parent; + VariantBinding vb = (VariantBinding) ((JavaVariant)parent).binding; + Object nv = getBinding().create(newValue); + vb.setContent(jo.object, getBinding(), nv); + this.object = nv; + } else { + // Set value + getBinding().setValue(object, newValue); + } // Notify ListenerEntry le = listeners; @@ -104,13 +104,13 @@ public class JavaBoolean extends JavaObject implements BooleanAccessor { } catch (BindingException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @Override - public void setValue(Binding binding, Object newValue) throws AccessorException { + public void setValue(Binding binding, Object newValue) throws AccessorException { try { boolean nv = ((BooleanBinding)binding).getValue_(newValue); setValue(nv); @@ -128,13 +128,13 @@ public class JavaBoolean extends JavaObject implements BooleanAccessor { @Override Event applyLocal(Event e, boolean makeRollback) throws AccessorException { - Event rollback = null; - rollback = makeRollback ? new ValueAssigned( Bindings.BOOLEAN, getValue() ) : null; - if (e instanceof ValueAssigned) { - ValueAssigned va = (ValueAssigned) e; - if (va.newValue == null) throw new AccessorException("Boolean value expected, got null"); - setValue(va.newValue.getBinding(), va.newValue.getValue()); - return rollback; + Event rollback = null; + rollback = makeRollback ? new ValueAssigned( Bindings.BOOLEAN, getValue() ) : null; + if (e instanceof ValueAssigned) { + ValueAssigned va = (ValueAssigned) e; + if (va.newValue == null) throw new AccessorException("Boolean value expected, got null"); + setValue(va.newValue.getBinding(), va.newValue.getValue()); + return rollback; } else throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Boolean"); }