KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > WorkspaceFeatureModelManager


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
12
13 import java.util.HashMap JavaDoc;
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 JavaDoc();
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 JavaDoc 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