KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.osgi.util.NLS;
14 import org.eclipse.pde.internal.core.schema.*;
15 import java.util.*;
16 import org.eclipse.pde.internal.core.ischema.*;
17 import org.eclipse.ui.views.properties.*;
18 import org.eclipse.jface.viewers.*;
19 import org.eclipse.pde.internal.ui.*;
20
21 public class ElementPropertySource extends SchemaObjectPropertySource {
22     public static final String JavaDoc P_LABEL_ATTRIBUTE = "labelAttribute"; //$NON-NLS-1$
23

24     public static final String JavaDoc P_ICON = "icon"; //$NON-NLS-1$
25

26     public static final String JavaDoc P_NAME = "name"; //$NON-NLS-1$
27
public static final String JavaDoc P_TRANSLATABLE = "translatable"; //$NON-NLS-1$
28
public static final String JavaDoc P_DEPRECATED = "deprecated"; //$NON-NLS-1$
29

30     private Vector descriptors;
31     
32     private static final String JavaDoc[] booleanTable = { "false", "true" }; //$NON-NLS-1$ //$NON-NLS-2$
33

34     class LabelAttributeValidator implements ICellEditorValidator {
35         public String JavaDoc isValid(Object JavaDoc value) {
36             String JavaDoc svalue = value.toString();
37             if (isValidAttribute(svalue) == false) {
38                 return NLS.bind(PDEUIMessages.SchemaEditor_ElementPR_invalid, svalue);
39             }
40             return null;
41         }
42     }
43
44     public ElementPropertySource(ISchemaElement extension) {
45         super(extension);
46     }
47
48     private void fixReferences(SchemaElement element) {
49         ((Schema) element.getSchema()).updateReferencesFor(element);
50     }
51
52     public Object JavaDoc getEditableValue() {
53         return null;
54     }
55
56     public IPropertyDescriptor[] getPropertyDescriptors() {
57         if (descriptors == null) {
58             descriptors = new Vector();
59             PropertyDescriptor desc = createTextPropertyDescriptor(
60                     P_LABEL_ATTRIBUTE, PDEUIMessages.SchemaEditor_ElementPR_labelAttribute);
61             desc.setValidator(new LabelAttributeValidator());
62             descriptors.addElement(desc);
63             
64             desc = createTextPropertyDescriptor(P_ICON, PDEUIMessages.SchemaEditor_ElementPR_icon);
65             descriptors.addElement(desc);
66             
67             desc = createTextPropertyDescriptor(P_NAME, PDEUIMessages.SchemaEditor_ElementPR_name);
68             descriptors.addElement(desc);
69             
70             desc = createComboBoxPropertyDescriptor(P_TRANSLATABLE, PDEUIMessages.ElementPropertySource_translatable, booleanTable); //$NON-NLS-1$
71
if (desc instanceof ComboBoxPropertyDescriptor)
72                 ((ComboBoxPropertyDescriptor) desc).setLabelProvider(new ComboProvider(
73                         P_TRANSLATABLE, booleanTable));
74             descriptors.addElement(desc);
75
76             desc = createComboBoxPropertyDescriptor(P_DEPRECATED, PDEUIMessages.ElementPropertySource_deprecated, booleanTable); //$NON-NLS-1$
77
if (desc instanceof ComboBoxPropertyDescriptor)
78                 ((ComboBoxPropertyDescriptor) desc).setLabelProvider(new ComboProvider(
79                         P_DEPRECATED, booleanTable));
80             descriptors.addElement(desc);
81
82         }
83         return toDescriptorArray(descriptors);
84     }
85
86     public Object JavaDoc getPropertyValue(Object JavaDoc name) {
87         ISchemaElement element = (ISchemaElement) getSourceObject();
88         if (name.equals(P_DEPRECATED))
89             return element.isDeprecated() ? new Integer JavaDoc(1) : new Integer JavaDoc(0);
90             
91         if (name.equals(P_TRANSLATABLE))
92             return element.hasTranslatableContent() ? new Integer JavaDoc(1) : new Integer JavaDoc(0);
93             
94         if (name.equals(P_LABEL_ATTRIBUTE))
95             return getNonzeroValue(element.getLabelProperty());
96         if (name.equals(P_ICON))
97             return getNonzeroValue(element.getIconProperty());
98         if (name.equals(P_NAME))
99             return getNonzeroValue(element.getName());
100         return ""; //$NON-NLS-1$
101
}
102
103     public boolean isPropertySet(Object JavaDoc property) {
104         return false;
105     }
106
107     private boolean isValidAttribute(String JavaDoc name) {
108         if (name == null || name.length() == 0)
109             return true;
110         ISchemaElement element = (ISchemaElement) getSourceObject();
111         return element.getAttribute(name) != null;
112     }
113
114     public void resetPropertyValue(Object JavaDoc property) {
115     }
116
117     public void setPropertyValue(Object JavaDoc name, Object JavaDoc value) {
118         SchemaElement element = (SchemaElement) getSourceObject();
119         if (value instanceof Integer JavaDoc) {
120             int index = ((Integer JavaDoc) value).intValue();
121             if (name.equals(P_TRANSLATABLE)) {
122                 element.setTranslatableProperty(index == 1);
123             } else if (name.equals(P_DEPRECATED)) {
124                 element.setDeprecatedProperty(index == 1);
125             }
126         } else {
127             String JavaDoc svalue = (String JavaDoc) value;
128             if (name.equals(P_LABEL_ATTRIBUTE))
129                 element.setLabelProperty(svalue);
130             else if (name.equals(P_ICON))
131                 element.setIconProperty(svalue);
132             else if (name.equals(P_NAME)) {
133                 element.setName(svalue);
134                 fixReferences(element);
135             }
136         }
137     }
138 }
139
Popular Tags