1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import java.util.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.pde.core.plugin.*; 17 import org.eclipse.pde.internal.core.ifeature.*; 18 import org.eclipse.pde.internal.ui.*; 19 import org.eclipse.ui.views.properties.*; 20 21 public class FeatureChildPropertySource extends FeaturePropertySource { 22 protected Vector descriptors; 23 public final static String KEY_ID = "FeatureEditor.ChildProp.id"; public final static String KEY_VERSION = "FeatureEditor.ChildProp.version"; public final static String KEY_OPTIONAL = 26 "FeatureEditor.ChildProp.optional"; public final static String KEY_MATCH = "FeatureEditor.ChildProp.match"; public final static String KEY_NAME = "FeatureEditor.ChildProp.name"; public final static String KEY_SEARCH_LOCATION = 30 "FeatureEditor.ChildProp.search-location"; private final static String P_ID = "id"; private final static String P_VERSION = "version"; private final static String P_OPTIONAL = "optional"; private final static String P_MATCH = "match"; private final static String P_NAME = "name"; private final static String P_SEARCH_LOCATION = "search-location"; private final static String P_OS = "os"; private final static String P_WS = "ws"; private final static String P_ARCH = "arch"; 41 public FeatureChildPropertySource(IFeatureChild child) { 42 super(child); 43 } 44 45 protected void createPropertyDescriptors() { 46 descriptors = new Vector(); 47 PropertyDescriptor desc = 48 createTextPropertyDescriptor( 49 P_ID, 50 PDEPlugin.getResourceString(KEY_ID)); 51 descriptors.addElement(desc); 52 desc = 53 createTextPropertyDescriptor( 54 P_VERSION, 55 PDEPlugin.getResourceString(KEY_VERSION)); 56 descriptors.addElement(desc); 57 58 desc = 59 createTextPropertyDescriptor( 60 P_NAME, 61 PDEPlugin.getResourceString(KEY_NAME)); 62 descriptors.addElement(desc); 63 64 desc = 65 createChoicePropertyDescriptor( 66 P_MATCH, 67 PDEPlugin.getResourceString(KEY_MATCH), 68 IMatchRules.RULE_NAME_TABLE); 69 descriptors.addElement(desc); 70 desc = 71 createChoicePropertyDescriptor( 72 P_OPTIONAL, 73 PDEPlugin.getResourceString(KEY_OPTIONAL), 74 new String [] { "false", "true" }); descriptors.addElement(desc); 76 desc = 77 createChoicePropertyDescriptor( 78 P_SEARCH_LOCATION, 79 PDEPlugin.getResourceString(KEY_SEARCH_LOCATION), 80 new String [] { "root", "self", "both" }); descriptors.addElement(desc); 82 103 104 } 105 106 116 117 public IFeatureChild getChild() { 118 return (IFeatureChild) object; 119 } 120 121 public IPropertyDescriptor[] getPropertyDescriptors() { 122 if (descriptors == null) { 123 createPropertyDescriptors(); 124 } 125 return toDescriptorArray(descriptors); 126 } 127 128 public Object getPropertyValue(Object name) { 129 if (name.equals(P_ID)) { 130 return getNonzeroValue(getChild().getId()); 131 } 132 133 if (name.equals(P_VERSION)) { 134 return getNonzeroValue(getChild().getVersion()); 135 } 136 137 if (name.equals(P_OPTIONAL)) { 138 return getChild().isOptional() ? new Integer (1) : new Integer (0); 139 } 140 if (name.equals(P_NAME)) { 141 return getChild().getName(); 142 } 143 if (name.equals(P_SEARCH_LOCATION)) { 144 int loc = getChild().getSearchLocation(); 145 return new Integer (loc); 146 } 147 if (name.equals(P_MATCH)) { 148 return new Integer (getChild().getMatch()); 149 } 150 if (name.equals(P_OS)) { 151 return getChild().getOS(); 152 } 153 if (name.equals(P_WS)) { 154 return getChild().getWS(); 155 } 156 if (name.equals(P_ARCH)) { 157 return getChild().getArch(); 158 } 159 return null; 160 } 161 162 private String getNonzeroValue(Object obj) { 163 return obj != null ? obj.toString() : ""; } 165 166 public void setElement(IFeatureEntry entry) { 167 object = entry; 168 } 169 170 public void setPropertyValue(Object name, Object value) { 171 String svalue = value.toString(); 172 String realValue = 173 svalue == null | svalue.length() == 0 ? null : svalue; 174 try { 175 if (name.equals(P_ID)) { 176 getChild().setId(realValue); 177 } else if (name.equals(P_VERSION)) { 178 getChild().setVersion(realValue); 179 } else if (name.equals(P_NAME)) { 180 getChild().setName(realValue); 181 } else if (name.equals(P_OPTIONAL)) { 182 Integer index = (Integer ) value; 183 getChild().setOptional(index.intValue() == 1); 184 } else if (name.equals(P_MATCH)) { 185 Integer index = (Integer ) value; 186 getChild().setMatch(index.intValue()); 187 } else if (name.equals(P_SEARCH_LOCATION)) { 188 Integer index = (Integer ) value; 189 getChild().setSearchLocation(index.intValue()); 190 } else if (name.equals(P_OS)) { 191 getChild().setOS(realValue); 192 } else if (name.equals(P_WS)) { 193 getChild().setWS(realValue); 194 } else if (name.equals(P_ARCH)) { 195 getChild().setArch(realValue); 196 } 197 } catch (CoreException e) { 198 PDEPlugin.logException(e); 199 } 200 } 201 } 202 | Popular Tags |