package es.iiia.shapegrammar.model;
import java.util.ArrayList;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
public class NodePropertySource implements IPropertySource {
private static final String ID = "ID";
protected NodeModel node;
public NodePropertySource(NodeModel node) {
this.node = node;
}
public Object getEditableValue() {
return null;
}
protected ArrayList<IPropertyDescriptor> getProperties() {
ArrayList<IPropertyDescriptor> properties = new ArrayList<IPropertyDescriptor>();
if (this.node instanceof NodeModel) {
properties.add(new TextPropertyDescriptor(NodeModel.PROPERTY_RENAME, "Name"));
}
return properties;
}
public IPropertyDescriptor[] getPropertyDescriptors() {
return this.getProperties().toArray(new IPropertyDescriptor[0]);
}
public Object getPropertyValue(Object id) {
if (id.equals(NodeModel.PROPERTY_RENAME)) {
return node.getName();
} else if (id.equals(ID)) {
return this.node.getId();
}
return null;
}
public boolean isPropertySet(Object id) {
return false;
}
public void resetPropertyValue(Object id) {
}
public void setPropertyValue(Object id, Object value) {
if (id.equals(NodeModel.PROPERTY_RENAME))
node.setName((String)value);
}
protected NodeModel getModel() {
return this.node;
}
}