1 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 P_LABEL_ATTRIBUTE = "labelAttribute"; 24 public static final String P_ICON = "icon"; 26 public static final String P_NAME = "name"; public static final String P_TRANSLATABLE = "translatable"; public static final String P_DEPRECATED = "deprecated"; 30 private Vector descriptors; 31 32 private static final String [] booleanTable = { "false", "true" }; 34 class LabelAttributeValidator implements ICellEditorValidator { 35 public String isValid(Object value) { 36 String 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 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); 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); 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 getPropertyValue(Object name) { 87 ISchemaElement element = (ISchemaElement) getSourceObject(); 88 if (name.equals(P_DEPRECATED)) 89 return element.isDeprecated() ? new Integer (1) : new Integer (0); 90 91 if (name.equals(P_TRANSLATABLE)) 92 return element.hasTranslatableContent() ? new Integer (1) : new Integer (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 ""; } 102 103 public boolean isPropertySet(Object property) { 104 return false; 105 } 106 107 private boolean isValidAttribute(String 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 property) { 115 } 116 117 public void setPropertyValue(Object name, Object value) { 118 SchemaElement element = (SchemaElement) getSourceObject(); 119 if (value instanceof Integer ) { 120 int index = ((Integer ) 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 svalue = (String ) 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 |