X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Felement%2Fhandler%2FPropertyHandlerImpl.java.keep;h=6ceecea31c5b8a14e3559ac02d30cb5c84b92c99;hb=refs%2Fchanges%2F38%2F238%2F2;hp=8bc2b18bee798ff83097f5cf796f2dcad6fd8374;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/PropertyHandlerImpl.java.keep b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/PropertyHandlerImpl.java.keep index 8bc2b18be..6ceecea31 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/PropertyHandlerImpl.java.keep +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/PropertyHandlerImpl.java.keep @@ -1,92 +1,92 @@ -/******************************************************************************* - * Copyright (c) 2007- VTT Technical Research Centre of Finland. - * 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.g2d.element.handler; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.simantics.g2d.element.IElement; -import org.simantics.utils.datastructures.hints.IHintContext.Key; -import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; -import org.simantics.utils.datastructures.valueinterface.InvalidItemException; -import org.simantics.utils.datastructures.valueinterface.SubscriptionException; -import org.simantics.utils.datastructures.valueinterface.ValueAccess; -import org.simantics.utils.datastructures.valueinterface.ValueMap; -import org.simantics.utils.datastructures.valueinterface.impl.SimpleValueMap; -import org.simantics.utils.datastructures.valueinterface.impl.ValueMonitor; - -/** - * - * @Author Toni Kalajainen - */ -public class PropertyHandlerImpl implements PropertyHandler { - - List keys = new ArrayList(); - Set keys2 = new HashSet(); - ValueMap initialValues; - - private static final Key KEY_VM = new KeyOf(ValueMonitor.class); - - public PropertyHandlerImpl(String ... keys) - { - for (String k : keys) { - this.keys.add(k); - this.keys2.add(k); - } - } - - public PropertyHandlerImpl(Collection keys, ValueMap initialValues) - { - for (String k : keys) { - this.keys.add(k); - this.keys2.add(k); - } - if (initialValues!=null) - this.initialValues = new SimpleValueMap(initialValues); - } - - @Override - public void enumerateProperties(Collection collection) { - collection.addAll(keys); - } - - @Override - public Object getValue(IElement e, String key) { - ValueMonitor vm = e.getHint(KEY_VM); - if (vm==null) return null; - return vm.get(key); - } - - @Override - public void setValueSource(IElement e, ValueAccess access) { - if (access==null) { - ValueMonitor vm = e.getHint(KEY_VM); - if (vm!=null) { - e.removeHint(KEY_VM); - vm.dispose(); - } - return; - } - try { - ValueMonitor vm = new ValueMonitor(access, keys2, initialValues); - e.setHint(KEY_VM, vm); - vm.dispose(); - } catch (SubscriptionException e1) { - e1.printStackTrace(); - } catch (InvalidItemException e1) { - e1.printStackTrace(); - } - } - -} +/******************************************************************************* + * Copyright (c) 2007- VTT Technical Research Centre of Finland. + * 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.g2d.element.handler; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.simantics.g2d.element.IElement; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; +import org.simantics.utils.datastructures.valueinterface.InvalidItemException; +import org.simantics.utils.datastructures.valueinterface.SubscriptionException; +import org.simantics.utils.datastructures.valueinterface.ValueAccess; +import org.simantics.utils.datastructures.valueinterface.ValueMap; +import org.simantics.utils.datastructures.valueinterface.impl.SimpleValueMap; +import org.simantics.utils.datastructures.valueinterface.impl.ValueMonitor; + +/** + * + * @Author Toni Kalajainen + */ +public class PropertyHandlerImpl implements PropertyHandler { + + List keys = new ArrayList(); + Set keys2 = new HashSet(); + ValueMap initialValues; + + private static final Key KEY_VM = new KeyOf(ValueMonitor.class); + + public PropertyHandlerImpl(String ... keys) + { + for (String k : keys) { + this.keys.add(k); + this.keys2.add(k); + } + } + + public PropertyHandlerImpl(Collection keys, ValueMap initialValues) + { + for (String k : keys) { + this.keys.add(k); + this.keys2.add(k); + } + if (initialValues!=null) + this.initialValues = new SimpleValueMap(initialValues); + } + + @Override + public void enumerateProperties(Collection collection) { + collection.addAll(keys); + } + + @Override + public Object getValue(IElement e, String key) { + ValueMonitor vm = e.getHint(KEY_VM); + if (vm==null) return null; + return vm.get(key); + } + + @Override + public void setValueSource(IElement e, ValueAccess access) { + if (access==null) { + ValueMonitor vm = e.getHint(KEY_VM); + if (vm!=null) { + e.removeHint(KEY_VM); + vm.dispose(); + } + return; + } + try { + ValueMonitor vm = new ValueMonitor(access, keys2, initialValues); + e.setHint(KEY_VM, vm); + vm.dispose(); + } catch (SubscriptionException e1) { + e1.printStackTrace(); + } catch (InvalidItemException e1) { + e1.printStackTrace(); + } + } + +}