KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > search > OptionalFeatureSearchCategory


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.search;
12
13 import java.net.*;
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.update.core.*;
18 import org.eclipse.update.search.*;
19
20 /**
21  * Searches for optional features
22  */

23 public class OptionalFeatureSearchCategory extends BaseSearchCategory {
24     private IUpdateSearchQuery[] queries;
25     private ArrayList JavaDoc vids;
26     private static final String JavaDoc CATEGORY_ID =
27         "org.eclipse.update.core.unified-search"; //$NON-NLS-1$
28

29     private class OptionalQuery implements IUpdateSearchQuery {
30         public void run(
31             ISite site,
32             String JavaDoc[] categoriesToSkip,
33             IUpdateSearchFilter filter,
34             IUpdateSearchResultCollector collector,
35             IProgressMonitor monitor) {
36
37             monitor.beginTask("", vids.size()); //$NON-NLS-1$
38
for (int i = 0; i < vids.size(); i++) {
39                 VersionedIdentifier vid = (VersionedIdentifier) vids.get(i);
40                 monitor.subTask(vid.toString());
41                 IFeature feature =
42                     createFeature(
43                         site,
44                         vid,
45                         new SubProgressMonitor(monitor, 1));
46                 if (feature!=null && filter.accept(feature))
47                     collector.accept(feature);
48             }
49         }
50
51         private IFeature createFeature(
52             ISite site,
53             VersionedIdentifier vid,
54             IProgressMonitor monitor) {
55             try {
56                 URL siteURL = site.getURL();
57                 //TODO This assumption stands only in the default case
58
// In general, feature archive URL may be mapped on site.
59
// Also, feature type may be something else (not packaged).
60
// We may need additional information (not only id and version)
61
// in order to create a feature on a site.
62
String JavaDoc relative = vid.toString();
63                 URL featureURL = new URL(siteURL, "features/" + relative+".jar"); //$NON-NLS-1$ //$NON-NLS-2$
64
return site.createFeature(
65                     "org.eclipse.update.core.packaged", //$NON-NLS-1$
66
featureURL,
67                     monitor);
68             } catch (Exception JavaDoc e) {
69                 return null;
70             }
71         }
72
73         /* (non-Javadoc)
74          * @see org.eclipse.update.internal.ui.search.ISearchQuery#getSearchSite()
75          */

76         public IQueryUpdateSiteAdapter getQuerySearchSite() {
77             return null;
78         }
79     }
80
81     public void addVersionedIdentifier(VersionedIdentifier vid) {
82         vids.add(vid);
83     }
84
85     public void clear() {
86         vids.clear();
87     }
88
89     public OptionalFeatureSearchCategory() {
90         super(CATEGORY_ID);
91         vids = new ArrayList JavaDoc();
92         queries = new IUpdateSearchQuery[] { new OptionalQuery()};
93     }
94
95     public IUpdateSearchQuery[] getQueries() {
96         return queries;
97     }
98 }
99
Popular Tags