1 11 package org.eclipse.pde.internal.ui.wizards.product; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.jface.operation.IRunnableWithProgress; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.pde.core.IBaseModel; 22 import org.eclipse.pde.core.plugin.IFragmentModel; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.PluginRegistry; 25 import org.eclipse.pde.internal.core.ibundle.IBundle; 26 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModel; 27 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 28 import org.eclipse.pde.internal.core.ibundle.IManifestHeader; 29 import org.eclipse.pde.internal.core.plugin.WorkspaceFragmentModel; 30 import org.eclipse.pde.internal.core.plugin.WorkspacePluginModel; 31 import org.eclipse.pde.internal.core.text.bundle.BundleSymbolicNameHeader; 32 import org.eclipse.pde.internal.ui.PDEPlugin; 33 import org.eclipse.pde.internal.ui.PDEUIMessages; 34 import org.eclipse.pde.internal.ui.util.ModelModification; 35 import org.eclipse.pde.internal.ui.util.PDEModelUtility; 36 import org.eclipse.swt.widgets.Shell; 37 import org.osgi.framework.Constants; 38 39 public abstract class BaseManifestOperation implements IRunnableWithProgress { 40 41 private Shell fShell; 42 protected String fPluginId; 43 44 public BaseManifestOperation(Shell shell, String pluginId) { 45 fShell = shell; 46 fPluginId = pluginId; 47 } 48 49 protected Shell getShell() { 50 return fShell; 51 } 52 53 protected IFile getFile() { 54 IPluginModelBase model = PluginRegistry.findModel(fPluginId); 55 IProject project = model.getUnderlyingResource().getProject(); 56 String filename = model instanceof IFragmentModel ? "fragment.xml" : "plugin.xml"; return project.getFile(filename); 58 } 59 60 protected IPluginModelBase getModel(IFile file) { 61 if ("plugin.xml".equals(file.getName())) return new WorkspacePluginModel(file, false); 63 return new WorkspaceFragmentModel(file, false); 64 } 65 66 protected void updateSingleton(IProgressMonitor monitor) throws CoreException { 67 IPluginModelBase plugin = PluginRegistry.findModel(fPluginId); 68 if (plugin instanceof IBundlePluginModel) { 69 IFile file = (IFile)plugin.getUnderlyingResource(); 70 IStatus status = PDEPlugin.getWorkspace().validateEdit(new IFile[] { file }, fShell); 71 if (status.getSeverity() != IStatus.OK) 72 throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.pde.ui", IStatus.ERROR, NLS.bind(PDEUIMessages.ProductDefinitionOperation_readOnly, fPluginId), null)); 74 ModelModification mod = new ModelModification(file) { 75 protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { 76 if (!(model instanceof IBundlePluginModelBase)) 77 return; 78 IBundlePluginModelBase modelBase = (IBundlePluginModelBase)model; 79 IBundle bundle = modelBase.getBundleModel().getBundle(); 80 IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_SYMBOLICNAME); 81 if (header instanceof BundleSymbolicNameHeader) { 82 BundleSymbolicNameHeader symbolic = (BundleSymbolicNameHeader)header; 83 if (!symbolic.isSingleton()) 84 symbolic.setSingleton(true); 85 } 86 } 87 }; 88 PDEModelUtility.modifyModel(mod, null); 89 } 90 } 91 } 92 | Popular Tags |