1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import java.net.*; 14 import java.util.*; 15 16 import org.eclipse.core.runtime.*; 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 URLElementPropertySource extends FeaturePropertySource { 22 private Vector descriptors; 23 private final static String P_URL = "url"; public final static String KEY_TYPE = "FeatureEditor.URLProp.type"; public final static String KEY_SITE_TYPE = "FeatureEditor.URLProp.siteType"; public final static String KEY_LABEL = "FeatureEditor.URLProp.label"; public final static String KEY_URL = "FeatureEditor.URLProp.URL"; private final static String P_TYPE = "type"; private final static String P_LABEL = "label"; private final static String P_SITE_TYPE = "siteType"; private final static String [] elementTypes = 32 { 33 null, 34 PDEPlugin.getResourceString("FeatureEditor.URLProp.type.update"), PDEPlugin.getResourceString( 36 "FeatureEditor.URLProp.type.discovery")}; 38 private final static String [] siteTypes = { "update", "web" }; 40 public URLElementPropertySource(IFeatureURLElement element) { 41 super(element); 42 } 43 public org 44 .eclipse 45 .pde 46 .internal 47 .core 48 .ifeature 49 .IFeatureURLElement getElement() { 50 return (IFeatureURLElement) object; 51 } 52 public IPropertyDescriptor[] getPropertyDescriptors() { 53 if (descriptors == null) { 54 descriptors = new Vector(); 55 PropertyDescriptor desc = 56 new PropertyDescriptor( 57 P_TYPE, 58 PDEPlugin.getResourceString(KEY_TYPE)); 59 descriptors.addElement(desc); 60 desc = 61 createTextPropertyDescriptor( 62 P_LABEL, 63 PDEPlugin.getResourceString(KEY_LABEL)); 64 descriptors.addElement(desc); 65 desc = 66 createTextPropertyDescriptor( 67 P_URL, 68 PDEPlugin.getResourceString(KEY_URL)); 69 descriptors.addElement(desc); 70 desc = 71 createChoicePropertyDescriptor( 72 P_SITE_TYPE, 73 PDEPlugin.getResourceString(KEY_SITE_TYPE), 74 siteTypes); 75 descriptors.addElement(desc); 76 } 77 return toDescriptorArray(descriptors); 78 } 79 public Object getPropertyValue(Object name) { 80 if (name.equals(P_TYPE)) { 81 return elementTypes[getElement().getElementType()]; 82 } 83 if (name.equals(P_LABEL)) { 84 return getElement().getLabel(); 85 } 86 if (name.equals(P_URL)) { 87 return getElement().getURL().toString(); 88 } 89 if (name.equals(P_SITE_TYPE)) { 90 return new Integer (getElement().getSiteType()); 91 } 92 return null; 93 } 94 public void setElement(IFeatureURLElement newElement) { 95 object = newElement; 96 } 97 public void setPropertyValue(Object name, Object value) { 98 String svalue = value.toString(); 99 String realValue = 100 svalue == null | svalue.length() == 0 ? null : svalue; 101 try { 102 if (name.equals(P_URL)) { 103 try { 104 URL url = null; 105 if (realValue != null) 106 url = new URL(realValue); 107 getElement().setURL(url); 108 } catch (MalformedURLException e) { 109 } 110 } else if (name.equals(P_LABEL)) { 111 getElement().setLabel(realValue); 112 } else if (name.equals(P_SITE_TYPE)) { 113 Integer ivalue = (Integer ) value; 114 getElement().setSiteType(ivalue.intValue()); 115 } 116 } catch (CoreException e) { 117 PDEPlugin.logException(e); 118 } 119 } 120 } 121 | Popular Tags |