KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > schema > SchemaAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
23         if (adapterType.equals(IPropertySource.class))
24             return getProperties(adaptableObject);
25         return null;
26     }
27     public java.lang.Class JavaDoc[] getAdapterList() {
28         return new Class JavaDoc[] { 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 JavaDoc 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