| /******************************************************************************* |
| * Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro |
| * 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: |
| * Andras Schmidt, Andras Balogh, Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.framework.properties.providers; |
| |
| import java.util.HashSet; |
| import java.util.Properties; |
| import java.util.Set; |
| |
| import org.eclipse.viatra2.framework.properties.IViatraPropertyChangedListener; |
| import org.eclipse.viatra2.framework.properties.IViatraPropertyProvider; |
| |
| public abstract class DefaultPropertyProvider implements |
| IViatraPropertyProvider { |
| |
| protected Properties properties; |
| |
| protected String pID; |
| |
| protected HashSet<String> allids; |
| |
| protected HashSet<IViatraPropertyChangedListener> listeners; |
| |
| public final void addListener(IViatraPropertyChangedListener l) { |
| listeners.add(l); |
| } |
| |
| public final void removeListener(IViatraPropertyChangedListener l) { |
| listeners.remove(l); |
| } |
| |
| public DefaultPropertyProvider(String id) { |
| pID = id; |
| properties = new Properties(); |
| allids = new HashSet<String>(); |
| listeners = new HashSet<IViatraPropertyChangedListener>(); |
| init(); |
| } |
| |
| /** |
| * This is called in the abstract constructor, descendants should use this |
| * function to fill up the <b>allids</> HashSet with property IDs. |
| * |
| */ |
| public abstract void init(); |
| |
| public final String getProviderID() { |
| return pID; |
| } |
| |
| public final void setProperty(String id, String val) { |
| String oldval = properties.getProperty(id); |
| properties.put(id, val); |
| allids.add(id); |
| for (IViatraPropertyChangedListener l : listeners) { |
| l.propertyChanged(pID, id, oldval, val); |
| } |
| |
| } |
| |
| public final String getProperty(String id) { |
| return properties.getProperty(id); |
| } |
| |
| public final Set<String> getAllPropertyIds() { |
| return allids; |
| } |
| |
| } |