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.internal.core.*; 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 FeatureEntryPropertySource extends FeaturePropertySource { 22 protected Vector descriptors; 23 public final static String KEY_ID = "FeatureEditor.ReferenceProp.id"; public final static String KEY_VERSION = 25 "FeatureEditor.ReferenceProp.version"; public final static String KEY_DOWNLOAD_SIZE = 27 "FeatureEditor.ReferenceProp.download-size"; public final static String KEY_INSTALL_SIZE = 29 "FeatureEditor.ReferenceProp.install-size"; 31 private final static String P_ID = "id"; private final static String P_OS = "os"; private final static String P_WS = "ws"; private final static String P_NL = "nl"; private final static String P_ARCH = "arch"; private final static String P_INSTALL_SIZE = "install-size"; private final static String P_DOWNLOAD_SIZE = "download-size"; 39 public FeatureEntryPropertySource(IFeatureEntry entry) { 40 super(entry); 41 } 42 43 protected void createPropertyDescriptors() { 44 descriptors = new Vector(); 45 PropertyDescriptor desc = 46 new PropertyDescriptor(P_ID, PDEPlugin.getResourceString(KEY_ID)); 47 descriptors.addElement(desc); 48 desc = 49 createTextPropertyDescriptor( 50 P_INSTALL_SIZE, 51 PDEPlugin.getResourceString(KEY_INSTALL_SIZE)); 52 descriptors.addElement(desc); 53 desc = 54 createTextPropertyDescriptor( 55 P_DOWNLOAD_SIZE, 56 PDEPlugin.getResourceString(KEY_DOWNLOAD_SIZE)); 57 descriptors.addElement(desc); 58 59 desc = createChoicePropertyDescriptor(P_OS, P_OS, getOSChoices()); 60 descriptors.addElement(desc); 61 desc = createChoicePropertyDescriptor(P_WS, P_WS, getWSChoices()); 62 descriptors.addElement(desc); 63 desc = createChoicePropertyDescriptor(P_NL, P_NL, getNLChoices()); 64 descriptors.addElement(desc); 65 desc = createChoicePropertyDescriptor(P_ARCH, P_ARCH, getArchChoices()); 66 descriptors.addElement(desc); 67 } 68 69 public IFeatureEntry getEntry() { 70 return (IFeatureEntry)object; 71 } 72 73 public IPropertyDescriptor[] getPropertyDescriptors() { 74 if (descriptors == null) { 75 createPropertyDescriptors(); 76 } 77 return toDescriptorArray(descriptors); 78 } 79 80 private PropertyDescriptor createChoicePropertyDescriptor( 81 String name, 82 String displayName, 83 Choice[] choices) { 84 return new PortabilityChoiceDescriptor( 85 name, 86 displayName, 87 choices, 88 !isEditable()); 89 } 90 91 public Object getPropertyValue(Object name) { 92 if (name.equals(P_ID)) { 93 return getEntry().getId(); 94 } 95 96 if (name.equals(P_INSTALL_SIZE)) { 97 long installSize = getEntry().getInstallSize(); 98 if (installSize == -1) 99 return ""; else 101 return "" + installSize; } 103 if (name.equals(P_DOWNLOAD_SIZE)) { 104 long downloadSize = getEntry().getDownloadSize(); 105 if (downloadSize == -1) 106 return ""; else 108 return "" + downloadSize; } 110 if (name.equals(P_OS)) { 111 return getEntry().getOS(); 112 } 113 if (name.equals(P_WS)) { 114 return getEntry().getWS(); 115 } 116 if (name.equals(P_NL)) { 117 return getEntry().getNL(); 118 } 119 if (name.equals(P_ARCH)) { 120 return getEntry().getArch(); 121 } 122 return null; 123 } 124 public void setElement(IFeatureEntry entry) { 125 object = entry; 126 } 127 public void setPropertyValue(Object name, Object value) { 128 String svalue = value.toString(); 129 String realValue = 130 svalue == null | svalue.length() == 0 ? null : svalue; 131 try { 132 if (name.equals(P_OS)) { 133 getEntry().setOS(realValue); 134 } else if (name.equals(P_WS)) { 135 getEntry().setWS(realValue); 136 } else if (name.equals(P_NL)) { 137 getEntry().setNL(realValue); 138 } else if (name.equals(P_ARCH)) { 139 getEntry().setArch(realValue); 140 } else if (name.equals(P_DOWNLOAD_SIZE)) { 141 long lvalue = getLong(realValue); 142 getEntry().setDownloadSize(lvalue); 143 } else if (name.equals(P_INSTALL_SIZE)) { 144 long lvalue = getLong(realValue); 145 getEntry().setInstallSize(lvalue); 146 } 147 } catch (CoreException e) { 148 PDEPlugin.logException(e); 149 } 150 } 151 152 private long getLong(String svalue) { 153 if (svalue == null) 154 return -1; 155 try { 156 return Long.parseLong(svalue); 157 } catch (NumberFormatException e) { 158 return -1; 159 } 160 } 161 162 public static Choice[] getOSChoices() { 163 return TargetPlatform.getOSChoices(); 164 } 165 166 public static Choice[] getWSChoices() { 167 return TargetPlatform.getWSChoices(); 168 } 169 170 public static Choice[] getArchChoices() { 171 return TargetPlatform.getArchChoices(); 172 } 173 174 public static Choice[] getNLChoices() { 175 return TargetPlatform.getNLChoices(); 176 } 177 } 178 | Popular Tags |