1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.jface.viewers.*; 15 import org.eclipse.pde.core.plugin.*; 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.swt.graphics.*; 20 import org.eclipse.ui.views.properties.*; 21 22 public class ReferencePropertySource extends FeatureEntryPropertySource { 23 private IPluginBase pluginBase; 24 private Image errorImage; 25 public final static String KEY_NAME = "FeatureEditor.ReferenceProp.name"; public final static String KEY_VERSION = 27 "FeatureEditor.ReferenceProp.version"; public final static String KEY_ORIGINAL_VERSION = 29 "FeatureEditor.ReferenceProp.originalVersion"; 31 private final static String P_NAME = "name"; private final static String P_VERSION = "version"; private final static String P_REF_VERSION = "ref_version"; 35 public class VersionProvider extends LabelProvider { 36 public Image getImage(Object obj) { 37 String originalVersion = getOriginalVersion(); 38 IFeaturePlugin ref = getPluginReference(); 39 boolean inSync = ref.getVersion().equals(originalVersion); 40 return inSync ? null : errorImage; 41 } 42 } 43 44 public ReferencePropertySource( 45 IFeaturePlugin reference, 46 Image errorImage) { 47 super(reference); 48 this.errorImage = errorImage; 49 } 50 private String getOriginalVersion() { 51 IPluginBase pluginBase = getPluginBase(); 52 if (pluginBase == null) 53 return ""; return pluginBase.getVersion(); 55 } 56 private IPluginBase getPluginBase() { 57 if (pluginBase == null) { 58 IFeaturePlugin reference = getPluginReference(); 59 if (reference.getModel().getUnderlyingResource() == null) 60 return null; 61 String id = reference.getId(); 62 WorkspaceModelManager manager = 63 PDECore.getDefault().getWorkspaceModelManager(); 64 IPluginModelBase[] models = null; 65 if (reference.isFragment()) { 66 models = manager.getFragmentModels(); 67 } else { 68 models = manager.getPluginModels(); 69 } 70 for (int i = 0; i < models.length; i++) { 71 IPluginModelBase modelBase = models[i]; 72 IPluginBase candidate = modelBase.getPluginBase(); 73 if (candidate.getId().equals(id)) { 74 pluginBase = candidate; 75 break; 76 } 77 } 78 } 79 return pluginBase; 80 } 81 public IFeaturePlugin getPluginReference() { 82 return (IFeaturePlugin) object; 83 } 84 protected void createPropertyDescriptors() { 85 super.createPropertyDescriptors(); 86 PropertyDescriptor desc; 87 desc = 88 new PropertyDescriptor( 89 P_NAME, 90 PDEPlugin.getResourceString(KEY_NAME)); 91 descriptors.addElement(desc); 92 desc = 93 createTextPropertyDescriptor( 94 P_VERSION, 95 PDEPlugin.getResourceString(KEY_VERSION)); 96 descriptors.addElement(desc); 98 desc = 99 new PropertyDescriptor( 100 P_REF_VERSION, 101 PDEPlugin.getResourceString(KEY_ORIGINAL_VERSION)); 102 103 } 104 105 public Object getPropertyValue(Object name) { 106 if (name.equals(P_NAME)) { 107 return getPluginReference().getLabel(); 108 } 109 if (name.equals(P_VERSION)) { 110 return getPluginReference().getVersion(); 111 } 112 if (name.equals(P_REF_VERSION)) { 113 return getOriginalVersion(); 114 } 115 return super.getPropertyValue(name); 116 } 117 public void setElement(IFeaturePlugin plugin) { 118 object = plugin; 119 } 120 public void setPropertyValue(Object name, Object value) { 121 String svalue = value.toString(); 122 String realValue = 123 svalue == null | svalue.length() == 0 ? null : svalue; 124 try { 125 if (name.equals(P_NAME)) { 126 getPluginReference().setLabel(realValue); 127 } else if (name.equals(P_VERSION)) { 128 getPluginReference().setVersion(realValue); 129 } else super.setPropertyValue(name, value); 130 } catch (CoreException e) { 131 PDEPlugin.logException(e); 132 } 133 } 134 } 135 | Popular Tags |