1 11 package org.eclipse.pde.internal.core; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.IResourceChangeEvent; 18 import org.eclipse.core.resources.IResourceDelta; 19 import org.eclipse.pde.core.IModelProviderEvent; 20 import org.eclipse.pde.internal.core.feature.WorkspaceFeatureModel; 21 import org.eclipse.pde.internal.core.ifeature.IFeatureModel; 22 23 public class WorkspaceFeatureModelManager extends WorkspaceModelManager { 24 25 protected boolean isInterestingProject(IProject project) { 26 return isFeatureProject(project); 27 } 28 29 protected void createModel(IProject project, boolean notify) { 30 if (project.exists(ICoreConstants.FEATURE_PATH)) { 31 WorkspaceFeatureModel model = new WorkspaceFeatureModel(project.getFile(ICoreConstants.FEATURE_PATH)); 32 loadModel(model, false); 33 if (fModels == null) 34 fModels = new HashMap (); 35 fModels.put(project, model); 36 if (notify) 37 addChange(model, IModelProviderEvent.MODELS_ADDED); 38 } 39 } 40 41 protected void handleFileDelta(IResourceDelta delta) { 42 IFile file = (IFile)delta.getResource(); 43 if (file.getProjectRelativePath().equals(ICoreConstants.FEATURE_PATH)) { 44 IProject project = file.getProject(); 45 Object model = getModel(project); 46 int kind = delta.getKind(); 47 if (kind == IResourceDelta.REMOVED && model != null) { 48 removeModel(project); 49 } else if (kind == IResourceDelta.ADDED || model == null) { 50 createModel(file.getProject(), true); 51 } else if (kind == IResourceDelta.CHANGED 52 && (IResourceDelta.CONTENT & delta.getFlags()) != 0) { 53 loadModel((IFeatureModel)model, true); 54 addChange(model, IModelProviderEvent.MODELS_CHANGED); 55 } 56 } 57 } 58 59 protected void addListeners() { 60 int event = IResourceChangeEvent.PRE_CLOSE|IResourceChangeEvent.POST_CHANGE; 61 PDECore.getWorkspace().addResourceChangeListener(this, event); 62 } 63 64 protected void removeListeners() { 65 PDECore.getWorkspace().removeResourceChangeListener(this); 66 super.removeListeners(); 67 } 68 69 protected IFeatureModel[] getFeatureModels() { 70 initialize(); 71 return (IFeatureModel[])fModels.values().toArray(new IFeatureModel[fModels.size()]); 72 } 73 74 protected IFeatureModel getFeatureModel(IProject project) { 75 return (IFeatureModel)getModel(project); 76 } 77 78 } 79 | Popular Tags |