1 11 package org.eclipse.pde.internal.ui.editor.schema; 12 13 import org.eclipse.core.runtime.IAdapterFactory; 14 import org.eclipse.pde.internal.core.schema.SchemaElementReference; 15 import org.eclipse.pde.internal.core.ischema.*; 16 import org.eclipse.ui.views.properties.IPropertySource; 17 18 public class SchemaAdapterFactory implements IAdapterFactory { 19 private ElementPropertySource elementPropertySource; 20 private AttributePropertySource attributePropertySource; 21 22 public Object getAdapter(Object adaptableObject, Class adapterType) { 23 if (adapterType.equals(IPropertySource.class)) 24 return getProperties(adaptableObject); 25 return null; 26 } 27 public java.lang.Class [] getAdapterList() { 28 return new Class [] { IPropertySource.class }; 29 } 30 protected AttributePropertySource getAttributeProperties(ISchemaAttribute att) { 31 if (attributePropertySource == null) 32 attributePropertySource = new AttributePropertySource(att); 33 else 34 attributePropertySource.setSourceObject(att); 35 return attributePropertySource; 36 } 37 protected ElementPropertySource getElementProperties(ISchemaElement element) { 38 if (elementPropertySource == null) 39 elementPropertySource = new ElementPropertySource(element); 40 else 41 elementPropertySource.setSourceObject(element); 42 return elementPropertySource; 43 } 44 private IPropertySource getProperties(Object object) { 45 if (object instanceof ISchemaElement 46 && !(object instanceof ISchemaObjectReference)) 47 return getElementProperties((ISchemaElement) object); 48 if (object instanceof ISchemaAttribute) 49 return getAttributeProperties((ISchemaAttribute) object); 50 if (object instanceof ISchemaRepeatable) 51 return getRepeatableProperties((ISchemaRepeatable) object); 52 return null; 53 } 54 protected GrammarPropertySource getRepeatableProperties(ISchemaRepeatable obj) { 55 if (obj instanceof ISchemaCompositor) 56 return new CompositorPropertySource((ISchemaCompositor) obj); 57 if (obj instanceof SchemaElementReference) 58 return new ReferencePropertySource((SchemaElementReference)obj); 59 return null; 60 } 61 } 62 | Popular Tags |