KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.io.File JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.OperationCanceledException;
19 import org.eclipse.core.runtime.Path;
20 import org.eclipse.core.runtime.PlatformObject;
21 import org.eclipse.jdt.core.IClasspathContainer;
22 import org.eclipse.jdt.core.IJavaProject;
23 import org.eclipse.jdt.core.JavaCore;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25
26 public class ModelEntry extends PlatformObject {
27     private String JavaDoc id;
28     private IPluginModelBase fWorkspaceModel;
29     private IPluginModelBase fExternalModel;
30     private RequiredPluginsClasspathContainer fClasspathContainer;
31     private boolean fInJavaSearch;
32     private PluginModelManager fManager;
33
34     public ModelEntry(PluginModelManager manager, String JavaDoc id) {
35         this.fManager = manager;
36         this.id = id;
37     }
38
39     public IPluginModelBase getActiveModel() {
40         return (fWorkspaceModel != null) ? fWorkspaceModel : fExternalModel;
41     }
42
43     public String JavaDoc getId() {
44         return id;
45     }
46
47     public Object JavaDoc[] getChildren() {
48         if (fWorkspaceModel == null && fExternalModel != null) {
49             File JavaDoc file = new File JavaDoc(fExternalModel.getInstallLocation());
50             if (!file.isFile()) {
51                 FileAdapter adapter =
52                     new EntryFileAdapter(
53                         this,
54                         file,
55                         fManager.getFileAdapterFactory());
56                 return adapter.getChildren();
57             }
58         }
59         return new Object JavaDoc[0];
60     }
61
62     public boolean isInJavaSearch() {
63         return fInJavaSearch;
64     }
65
66     void setInJavaSearch(boolean value) {
67         this.fInJavaSearch = value;
68     }
69
70     public void setWorkspaceModel(IPluginModelBase model) {
71         this.fWorkspaceModel = model;
72         fClasspathContainer = null;
73     }
74
75     public void setExternalModel(IPluginModelBase model) {
76         this.fExternalModel = model;
77         fClasspathContainer = null;
78     }
79     public IPluginModelBase getWorkspaceModel() {
80         return fWorkspaceModel;
81     }
82
83     public IPluginModelBase getExternalModel() {
84         return fExternalModel;
85     }
86     public boolean isEmpty() {
87         return fWorkspaceModel == null && fExternalModel == null;
88     }
89     public RequiredPluginsClasspathContainer getClasspathContainer(boolean reset) {
90         if (reset)
91             fClasspathContainer = null;
92         
93         if (fClasspathContainer == null)
94             fClasspathContainer =
95                 new RequiredPluginsClasspathContainer(fWorkspaceModel);
96         return fClasspathContainer;
97     }
98     public void updateClasspathContainer(boolean doCheckClasspath)
99         throws CoreException {
100         if (shouldUpdateClasspathContainer(doCheckClasspath)) {
101             IProject project = fWorkspaceModel.getUnderlyingResource().getProject();
102             IJavaProject[] javaProjects = new IJavaProject[] { JavaCore.create(project)};
103             IClasspathContainer[] containers =
104                 new IClasspathContainer[] { getClasspathContainer(true)};
105             IPath path = new Path(PDECore.CLASSPATH_CONTAINER_ID);
106             try {
107                 JavaCore.setClasspathContainer(path, javaProjects, containers, null);
108             } catch (OperationCanceledException e) {
109                 getClasspathContainer(false).reset();
110                 throw e;
111             }
112         }
113     }
114     
115     public boolean shouldUpdateClasspathContainer(boolean doCheckClasspath) throws CoreException {
116         if (fWorkspaceModel == null)
117             return false;
118         
119         IProject project = fWorkspaceModel.getUnderlyingResource().getProject();
120         if (!project.hasNature(JavaCore.NATURE_ID))
121             return false;
122         
123         if (doCheckClasspath && (!fWorkspaceModel.isLoaded()))
124             return false;
125         
126         return true;
127     }
128     
129     public static void updateUnknownClasspathContainer(IJavaProject javaProject)
130         throws CoreException {
131         if (javaProject == null)
132             return;
133         IPath path = new Path(PDECore.CLASSPATH_CONTAINER_ID);
134         JavaCore.setClasspathContainer(
135             path,
136             new IJavaProject[] { javaProject },
137             new IClasspathContainer[] {
138                  new RequiredPluginsClasspathContainer(null)},
139             null);
140     }
141     
142 }
143
Popular Tags