KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > model > ConfiguredFeatureAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.update.internal.ui.model;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.update.configuration.*;
15 import org.eclipse.update.core.*;
16
17 /**
18  * @version 1.0
19  * @author
20  */

21 public class ConfiguredFeatureAdapter
22     extends SimpleFeatureAdapter
23     implements IConfiguredFeatureAdapter {
24     private IConfiguredSiteAdapter adapter;
25     private boolean configured;
26     private boolean updated;
27
28     public ConfiguredFeatureAdapter(
29         IConfiguredSiteAdapter adapter,
30         IFeature feature,
31         boolean configured,
32         boolean updated,
33         boolean optional) {
34         super(feature, optional);
35         this.adapter = adapter;
36         this.configured = configured;
37         this.updated = updated;
38     }
39
40     public boolean equals(Object JavaDoc object) {
41         if (object == null)
42             return false;
43         if (object == this)
44             return true;
45         if (object instanceof ConfiguredFeatureAdapter) {
46             try {
47                 ConfiguredFeatureAdapter ad = (ConfiguredFeatureAdapter) object;
48                 return ad.getConfiguredSite().equals(getConfiguredSite())
49                     && ad.getFeature(null).equals(getFeature(null));
50             } catch (CoreException e) {
51             }
52         }
53         return false;
54     }
55
56     public IConfiguredSite getConfiguredSite() {
57         return adapter.getConfiguredSite();
58     }
59     public IInstallConfiguration getInstallConfiguration() {
60         return adapter.getInstallConfiguration();
61     }
62     public boolean isConfigured() {
63         return configured;
64     }
65
66     public boolean isUpdated() {
67         return updated;
68     }
69     public IFeatureAdapter[] getIncludedFeatures(IProgressMonitor monitor) {
70         try {
71             IIncludedFeatureReference[] included =
72                 getFeature(null).getIncludedFeatureReferences();
73             ConfiguredFeatureAdapter[] result =
74                 new ConfiguredFeatureAdapter[included.length];
75             if (monitor == null)
76                 monitor = new NullProgressMonitor();
77             SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
78             subMonitor.beginTask("", included.length); //$NON-NLS-1$
79

80             for (int i = 0; i < included.length; i++) {
81                 IIncludedFeatureReference fref = included[i];
82                 IFeature feature;
83                 boolean childConfigured = configured;
84                 boolean updated = false;
85                 try {
86                     feature = fref.getFeature(
87                             new SubProgressMonitor(subMonitor, 1));
88                     childConfigured =
89                         adapter.getConfiguredSite().isConfigured(feature);
90                     ///*
91
PluginVersionIdentifier refpid =
92                         fref.getVersionedIdentifier().getVersion();
93                     PluginVersionIdentifier fpid =
94                         feature.getVersionedIdentifier().getVersion();
95                     updated = !refpid.equals(fpid);
96                     //*/
97
} catch (CoreException e) {
98                     feature = new MissingFeature(getFeature(null), fref);
99                     childConfigured = false;
100                 }
101
102                 result[i] =
103                     new ConfiguredFeatureAdapter(
104                         adapter,
105                         feature,
106                         childConfigured,
107                         updated,
108                         fref.isOptional());
109                 result[i].setIncluded(true);
110             }
111             return result;
112         } catch (CoreException e) {
113             return new IFeatureAdapter[0];
114         }
115     }
116 }
117
Popular Tags