1 /*******************************************************************************
2 * Copyright (c) 2007- VTT Technical Research Centre of Finland.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * VTT Technical Research Centre of Finland - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.g2d.element.handler;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.List;
19 import org.simantics.g2d.element.IElement;
20 import org.simantics.utils.datastructures.hints.IHintContext.Key;
21 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
22 import org.simantics.utils.datastructures.valueinterface.InvalidItemException;
23 import org.simantics.utils.datastructures.valueinterface.SubscriptionException;
24 import org.simantics.utils.datastructures.valueinterface.ValueAccess;
25 import org.simantics.utils.datastructures.valueinterface.ValueMap;
26 import org.simantics.utils.datastructures.valueinterface.impl.SimpleValueMap;
27 import org.simantics.utils.datastructures.valueinterface.impl.ValueMonitor;
31 * @Author Toni Kalajainen
33 public class PropertyHandlerImpl implements PropertyHandler {
35 List<String> keys = new ArrayList<String>();
36 Set<String> keys2 = new HashSet<String>();
37 ValueMap<String> initialValues;
39 private static final Key KEY_VM = new KeyOf(ValueMonitor.class);
41 public PropertyHandlerImpl(String ... keys)
43 for (String k : keys) {
49 public PropertyHandlerImpl(Collection<String> keys, ValueMap<String> initialValues)
51 for (String k : keys) {
55 if (initialValues!=null)
56 this.initialValues = new SimpleValueMap<String>(initialValues);
60 public void enumerateProperties(Collection<String> collection) {
61 collection.addAll(keys);
65 public Object getValue(IElement e, String key) {
66 ValueMonitor<String> vm = e.getHint(KEY_VM);
67 if (vm==null) return null;
72 public void setValueSource(IElement e, ValueAccess<String> access) {
74 ValueMonitor<String> vm = e.getHint(KEY_VM);
82 ValueMonitor<String> vm = new ValueMonitor<String>(access, keys2, initialValues);
83 e.setHint(KEY_VM, vm);
85 } catch (SubscriptionException e1) {
87 } catch (InvalidItemException e1) {