1 11 package org.eclipse.pde.internal.ui.util; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.pde.core.IBaseModel; 19 20 25 public abstract class ModelModification { 26 27 private IFile fModelFile; 28 private IFile fManifestFile; 29 private IFile fXMLFile; 30 private IFile fPropertiesFile; 31 private boolean fIsBundleModel; 32 33 37 public ModelModification(IFile modelFile) { 38 singleFileModification(modelFile); 39 } 40 41 42 48 public ModelModification(IFile bundleFile, IFile xmlFile) { 49 createFullBundleModification(bundleFile, xmlFile); 50 } 51 52 59 public ModelModification(IProject project) { 60 IFile xml = project.getFile(PDEModelUtility.F_PLUGIN); 61 if (!xml.exists()) 62 xml = project.getFile(PDEModelUtility.F_FRAGMENT); 63 if (!xml.exists()) 64 xml = null; 65 IFile manifest = project.getFile(PDEModelUtility.F_MANIFEST_FP); 66 if (!manifest.exists() && xml != null) 67 singleFileModification(xml); 68 else if (manifest.exists()) 69 createFullBundleModification(manifest, xml); 70 } 71 72 private void singleFileModification(IFile file) { 73 assignFile(file); 74 if (fManifestFile != null) 75 fModelFile = fManifestFile; 76 else if (fXMLFile != null) 77 fModelFile = fXMLFile; 78 else if (fPropertiesFile != null) 79 fModelFile = fPropertiesFile; 80 fIsBundleModel = file.getName().equals(PDEModelUtility.F_MANIFEST); 81 } 82 83 private void createFullBundleModification(IFile bundleFile, IFile xmlFile) { 84 assignFile(bundleFile); 85 assignFile(xmlFile); 86 87 Assert.isNotNull(fManifestFile); 88 fModelFile = fManifestFile; 89 fIsBundleModel = true; 90 } 91 92 private void assignFile(IFile file) { 93 if (file == null) 94 return; 95 String name = file.getName(); 96 if (name.equals(PDEModelUtility.F_MANIFEST)) 97 fManifestFile = file; 98 else if (name.equals(PDEModelUtility.F_PLUGIN) || name.equals(PDEModelUtility.F_FRAGMENT)) 99 fXMLFile = file; 100 else if (name.endsWith(PDEModelUtility.F_PROPERTIES)) 101 fPropertiesFile = file; 102 } 103 104 111 protected abstract void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException; 112 113 protected final IFile getFile() { 114 return fModelFile; 115 } 116 117 protected final IFile getManifestFile() { 118 return fManifestFile; 119 } 120 121 protected final IFile getXMLFile() { 122 return fXMLFile; 123 } 124 125 protected final IFile getPropertiesFile() { 126 return fPropertiesFile; 127 } 128 129 protected final boolean isFullBundleModification() { 130 return fIsBundleModel; 131 } 132 133 public boolean saveOpenEditor() { 134 return true; 135 } 136 } 137 | Popular Tags |