1 11 12 package org.eclipse.pde.internal.ui.wizards.product; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.action.Action; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.pde.core.plugin.IPluginAttribute; 21 import org.eclipse.pde.core.plugin.IPluginElement; 22 import org.eclipse.pde.core.plugin.IPluginExtension; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.IPluginObject; 25 import org.eclipse.pde.internal.core.util.PDETextHelper; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 28 32 public class RemoveSplashHandlerBindingAction extends Action implements 33 ISplashHandlerConstants { 34 35 private IPluginModelBase fModel; 36 37 private IProgressMonitor fMonitor; 38 39 private CoreException fException; 40 41 private String fFieldProductID; 42 43 private String fFieldTargetPackage; 44 45 48 public RemoveSplashHandlerBindingAction() { 49 reset(); 50 } 51 52 55 public void setFieldProductID(String fieldProductID) { 56 fFieldProductID = fieldProductID; 57 } 58 59 62 public void setFieldTargetPackage(String fieldTargetPackage) { 63 fFieldTargetPackage = fieldTargetPackage; 64 } 65 66 69 public void reset() { 70 fModel = null; 71 fMonitor = null; 72 fException = null; 73 74 fFieldProductID = null; 75 fFieldTargetPackage = null; 76 } 77 78 81 public void run() { 82 try { 83 updateModel(); 84 } catch (CoreException e) { 85 fException = e; 86 } 87 } 88 89 92 public void hasException() throws CoreException { 93 if (fException != null) { 95 throw fException; 96 } 97 } 98 99 102 public void setModel(IPluginModelBase model) { 103 fModel = model; 104 } 105 106 109 public void setMonitor(IProgressMonitor monitor) { 110 fMonitor = monitor; 111 } 112 113 116 private void updateModel() throws CoreException { 117 IPluginExtension extension = 121 findFirstExtension(F_SPLASH_HANDLERS_EXTENSION); 122 if (extension == null) { 124 return; 126 } 127 fMonitor.beginTask(NLS.bind(PDEUIMessages.RemoveSplashHandlerBindingAction_msgProgressRemoveProductBindings, 129 F_SPLASH_HANDLERS_EXTENSION), 1); 130 IPluginElement[] productBindingElements = 132 findProductBindingElements(extension); 133 removeMatchingProductBindingElements(extension, productBindingElements); 136 fMonitor.done(); 138 } 139 140 145 private void removeMatchingProductBindingElements(IPluginExtension extension, 146 IPluginElement[] productBindingElements) 147 throws CoreException { 148 if ((productBindingElements == null) || 150 (productBindingElements.length == 0)) { 151 return; 152 } 153 for (int i = 0; i < productBindingElements.length; i++) { 155 IPluginElement element = productBindingElements[i]; 156 IPluginAttribute productIDAttribute = 158 element.getAttribute(F_ATTRIBUTE_PRODUCT_ID); 159 if ((productIDAttribute == null) || 162 (PDETextHelper.isDefined(productIDAttribute.getValue()) == false)) { 163 extension.remove(element); 164 continue; 165 } 166 IPluginAttribute splashIDAttribute = 168 element.getAttribute(F_ATTRIBUTE_SPLASH_ID); 169 if ((splashIDAttribute == null) || 172 (PDETextHelper.isDefined(splashIDAttribute.getValue()) == false)) { 173 extension.remove(element); 174 continue; 175 } 176 if (productIDAttribute.getValue().equals(fFieldProductID) && 180 isGeneratedSplashID(splashIDAttribute.getValue())) { 181 extension.remove(element); 182 } 183 } 184 } 185 186 190 private boolean isGeneratedSplashID(String value) { 191 String [][] choices = ISplashHandlerConstants.F_SPLASH_SCREEN_TYPE_CHOICES; 192 for (int i = 0; i < choices.length; i++) { 195 String splashID = fFieldTargetPackage + '.' + choices[i][0]; 196 if (value.equals(splashID)) { 197 return true; 198 } 199 } 200 return false; 201 } 202 203 207 private IPluginElement[] findProductBindingElements(IPluginExtension extension) { 208 ArrayList elements = new ArrayList (); 209 if (extension.getChildCount() == 0) { 211 return null; 213 } 214 IPluginObject[] pluginObjects = extension.getChildren(); 215 for (int j = 0; j < pluginObjects.length; j++) { 217 if (pluginObjects[j] instanceof IPluginElement) { 218 IPluginElement element = (IPluginElement)pluginObjects[j]; 219 if (element.getName().equals(F_ELEMENT_PRODUCT_BINDING)) { 221 elements.add(element); 222 } 223 } 224 } 225 if (elements.size() == 0) { 227 return null; 228 } 229 return (IPluginElement[]) elements.toArray(new IPluginElement[elements.size()]); 231 } 232 233 237 private IPluginExtension findFirstExtension( 238 String extensionPointID) { 239 IPluginExtension[] extensions = fModel.getPluginBase().getExtensions(); 241 for (int i = 0; i < extensions.length; i++) { 243 String point = extensions[i].getPoint(); 244 if (extensionPointID.equals(point)) { 245 return extensions[i]; 246 } 247 } 248 return null; 249 } 250 251 } 252 | Popular Tags |