KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > IncludedFeatureReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 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  * James D Miles (IBM Corp.) - bug 182625, Missing constructor
11  *******************************************************************************/

12 package org.eclipse.update.core;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.update.configuration.IConfiguredSite;
20 import org.eclipse.update.core.model.IncludedFeatureReferenceModel;
21 import org.eclipse.update.internal.core.Messages;
22 import org.eclipse.update.internal.core.UpdateCore;
23
24 /**
25  * This is a utility class representing the options of a nested feature.
26  * Feature will include other features. This class will represent the options of the inclusion.
27  * <p>
28  * Clients may instantiate; not intended to be subclassed by clients.
29  * </p>
30  * <p>
31  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
32  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
33  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
34  * (repeatedly) as the API evolves.
35  * </p>
36  * @see org.eclipse.update.core.VersionedIdentifier
37  * @since 2.0.1
38  */

39 public class IncludedFeatureReference
40     extends IncludedFeatureReferenceModel
41     implements IIncludedFeatureReference {
42
43     /**
44      * Construct a included feature reference
45      *
46      * @since 2.1
47      */

48     public IncludedFeatureReference() {
49         super();
50     }
51
52     /**
53      * Construct a feature options
54      *
55      * @param includedFeatureRef reference to clone
56      * @since 2.0.2
57      */

58     public IncludedFeatureReference(IIncludedFeatureReference includedFeatureRef) {
59         super((IncludedFeatureReferenceModel) includedFeatureRef);
60     }
61
62     /**
63      * Constructor IncludedFeatureReference.
64      * @param featureReference
65      */

66     public IncludedFeatureReference(IFeatureReference featureReference) {
67         super(featureReference);
68     }
69     
70     public IncludedFeatureReference(IncludedFeatureReferenceModel includedFeatureRefModel){
71         super(includedFeatureRefModel);
72     }
73
74     /*
75      * Method isDisabled.
76      * @return boolean
77      */

78     private boolean isDisabled() {
79         IConfiguredSite cSite = getSite().getCurrentConfiguredSite();
80         if (cSite == null)
81             return false;
82         IFeatureReference[] configured = cSite.getConfiguredFeatures();
83         for (int i = 0; i < configured.length; i++) {
84             if (this.equals(configured[i]))
85                 return false;
86         }
87         return true;
88         // // FIXME: the above code was commented out and returned false.
89
// // Should this be commented out again?
90
// return false;
91
}
92
93     /*
94      * Method isInstalled.
95      * @return boolean
96      */

97     private boolean isUninstalled() {
98         if (!isDisabled())
99             return false;
100         IFeatureReference[] installed = getSite().getFeatureReferences();
101         for (int i = 0; i < installed.length; i++) {
102             if (this.equals(installed[i]))
103                 return false;
104         }
105         // if we reached this point, the configured site exists and it does not
106
// contain this feature reference, so clearly the feature is uninstalled
107
return true;
108     }
109
110     /**
111      * @see org.eclipse.update.core.IIncludedFeatureReference#getFeature(boolean,
112      * IConfiguredSite)
113      * @deprecated use getFeature(IProgressMonitor)
114      */

115     public IFeature getFeature(
116         boolean perfectMatch,
117         IConfiguredSite configuredSite)
118         throws CoreException {
119         return getFeature(null);
120     }
121
122     /**
123      * @see org.eclipse.update.core.IIncludedFeatureReference#getFeature(boolean,
124      * IConfiguredSite,IProgressMonitor)
125      * @deprecated use getFeature(IProgressMonitor)
126      */

127     public IFeature getFeature(
128         boolean perfectMatch,
129         IConfiguredSite configuredSite,
130         IProgressMonitor monitor)
131         throws CoreException {
132             return getFeature(monitor);
133     }
134
135     /**
136      * @see org.eclipse.update.core.IFeatureReference#getFeature()
137      * @deprecated use getFeature(IProgressMonitor)
138      */

139     public IFeature getFeature() throws CoreException {
140         return getFeature(null);
141     }
142     /**
143      * @see org.eclipse.update.core.IFeatureReference#getFeature
144      * (IProgressMonitor)
145      */

146     public IFeature getFeature(IProgressMonitor monitor) throws CoreException {
147         if (isUninstalled())
148             throw new CoreException(new Status(IStatus.ERROR, UpdateCore.getPlugin().getBundle().getSymbolicName(), IStatus.OK, NLS.bind(Messages.IncludedFeatureReference_featureUninstalled, (new String JavaDoc[] { getFeatureIdentifier() })), null));
149         else
150             return super.getFeature(monitor);
151     }
152 }
153
Popular Tags