1 11 package org.eclipse.pde.internal.ui.wizards.product; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Status; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.eclipse.pde.core.plugin.PluginRegistry; 23 import org.eclipse.pde.internal.core.iproduct.IProduct; 24 import org.eclipse.pde.internal.ui.PDEUIMessages; 25 import org.eclipse.swt.widgets.Shell; 26 27 28 public class SynchronizationOperation extends ProductDefinitionOperation { 29 30 public SynchronizationOperation(IProduct product, Shell shell, IProject project) { 31 super(product, getPluginId(product), getProductId(product), product.getApplication(), shell, project); 32 } 33 34 private static String getProductId(IProduct product) { 35 String full = product.getId(); 36 int index = full.lastIndexOf('.'); 37 return index != -1 ? full.substring(index + 1) : full; 38 } 39 40 private static String getPluginId(IProduct product) { 41 String full = product.getId(); 42 int index = full.lastIndexOf('.'); 43 return index != -1 ? full.substring(0, index) : full; 44 } 45 46 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 47 IPluginModelBase model = PluginRegistry.findModel(fPluginId); 48 if (model == null) { 49 String message = PDEUIMessages.SynchronizationOperation_noDefiningPlugin; 50 throw new InvocationTargetException (createCoreException(message)); 51 } 52 53 if (model.getUnderlyingResource() == null) { 54 String id = model.getPluginBase().getId(); 55 String message = PDEUIMessages.SynchronizationOperation_externalPlugin; 56 throw new InvocationTargetException (createCoreException(NLS.bind(message, id))); 57 } 58 59 super.run(monitor); 60 } 61 62 private CoreException createCoreException(String message) { 63 IStatus status = new Status(IStatus.ERROR, "org.eclipse.pde.ui", IStatus.ERROR, message, null); return new CoreException(status); 65 } 66 67 } 68 | Popular Tags |