package com.wincom.actor.editor.test2.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.List;
import java.util.Properties;

import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class ElementModel implements IPropertySource, Cloneable, Serializable {

	private static final long serialVersionUID = -7289522210862727774L;
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	transient protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
	protected final Properties properties = new Properties();

	private ElementModel parent;
	
	public ElementModel() { 
		log.info("new ElementModel()");
	}

	public void addPropertyChangeListener(PropertyChangeListener l) {
		listeners.addPropertyChangeListener(l);
	}

	protected void firePropertyChange(String prop, Object old, Object newValue) {
		listeners.firePropertyChange(prop, old, newValue);
	}

	protected void fireStructureChange(String prop, Object child) {
		log.debug("prop = " + prop
				+ ", child = " + child);
		listeners.firePropertyChange(prop, null, child);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		listeners.removePropertyChangeListener(l);
	}
	
	@Override
	public IPropertyDescriptor[] getPropertyDescriptors() {
		return new IPropertyDescriptor[0];
	}

	public ElementModel getParent() {
		return parent;
	}

	public void setParent(ElementModel parent) {
		this.parent = parent;
	}

	public List<ElementModel> getChildren() {
		throw new RuntimeException("unimplemented.");
	}
	
	@Override
	public Object getEditableValue() {
		log.debug("unimplemented");
		return this;
	}

	@Override
	public Object getPropertyValue(Object id) {
		return properties.get(id);
	}

	@Override
	public boolean isPropertySet(Object id) {
		return properties.containsKey(id);
	}

	@Override
	public void resetPropertyValue(Object id) {
		properties.remove(id);
	}

	@Override
	public void setPropertyValue(Object id, Object value) {
		Object old = properties.get(id);
		properties.put(id, value);
		firePropertyChange(id.toString(), old, value);
	}

}

@@ -763,33 +763,304 @@
 %0A%09pr
-ivate ElementModel parent
+otected String name;%0A%09protected ElementModel parent;%0A%0A%09public static final String PROPERTY_LAYOUT = %22NodeLayout%22;%0A%09public static final String PROPERTY_ADD = %22NodeAddChild%22;%0A%09public static final String PROPERTY_REMOVE = %22NodeRemoveChild%22;%0A%09public static final String PROPERTY_RENAME = %22NodeRename%22
 ;%0A%09%0A
@@ -1775,24 +1775,130 @@
 tor%5B0%5D;%0A%09%7D%0A%0A
+%09public String getName() %7B%0A%09%09return name;%0A%09%7D%0A%0A%09public void setName(String name) %7B%0A%09%09this.name = name;%0A%09%7D%0A%0A
 %09public Elem

modify model.