KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 java.util.*;
14 import org.eclipse.pde.internal.ui.editor.*;
15 import org.eclipse.pde.internal.core.ischema.*;
16 import org.eclipse.ui.views.properties.*;
17 import org.eclipse.jface.viewers.*;
18
19 public abstract class SchemaObjectPropertySource implements IPropertySource {
20     private Object JavaDoc sourceObject;
21     protected boolean isSchemaObject = false;
22     class ComboProvider extends LabelProvider {
23         private String JavaDoc property;
24         private String JavaDoc[] table;
25
26         public ComboProvider(String JavaDoc property, String JavaDoc[] table) {
27             this.property = property;
28             this.table = table;
29         }
30
31         public String JavaDoc getText(Object JavaDoc obj) {
32             isSchemaObject = true;
33             Integer JavaDoc index = (Integer JavaDoc) getPropertyValue(property);
34             return table[index.intValue()];
35         }
36     }
37
38     public SchemaObjectPropertySource(Object JavaDoc object) {
39         this.sourceObject = object;
40     }
41
42     protected PropertyDescriptor createComboBoxPropertyDescriptor(String JavaDoc id, String JavaDoc name,
43             String JavaDoc[] choices) {
44         if (isEditable())
45             return new ComboBoxPropertyDescriptor(id, name, choices);
46         return new PropertyDescriptor(id, name);
47     }
48
49     protected PropertyDescriptor createTextPropertyDescriptor(String JavaDoc id, String JavaDoc name) {
50         if (isEditable())
51             return new ModifiedTextPropertyDescriptor(id, name);
52         return new PropertyDescriptor(id, name);
53     }
54
55     protected Object JavaDoc getNonzeroValue(Object JavaDoc value) {
56         if (value != null)
57             return value;
58         return ""; //$NON-NLS-1$
59
}
60
61     public java.lang.Object JavaDoc getSourceObject() {
62         return sourceObject;
63     }
64
65     public boolean isEditable() {
66         ISchemaObject schemaObject = (ISchemaObject) getSourceObject();
67         ISchema schema = schemaObject.getSchema();
68         return schema != null ? schema.isEditable() : false;
69     }
70
71     public void setSourceObject(java.lang.Object JavaDoc newSourceObject) {
72         sourceObject = newSourceObject;
73     }
74
75     protected IPropertyDescriptor[] toDescriptorArray(Vector result) {
76         IPropertyDescriptor[] array = new IPropertyDescriptor[result.size()];
77         result.copyInto(array);
78         return array;
79     }
80 }
81
Popular Tags