KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > search > PluginSearchScope


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  *******************************************************************************/

11 package org.eclipse.pde.internal.core.search;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashSet JavaDoc;
15
16 import org.eclipse.pde.core.plugin.IPluginModelBase;
17 import org.eclipse.pde.core.plugin.PluginRegistry;
18
19 public class PluginSearchScope {
20
21     public static final int SCOPE_WORKSPACE = 0;
22     public static final int SCOPE_SELECTION = 1;
23     public static final int SCOPE_WORKING_SETS = 2;
24     
25     public static final int EXTERNAL_SCOPE_NONE = 0;
26     public static final int EXTERNAL_SCOPE_ENABLED = 1;
27     public static final int EXTERNAL_SCOPE_ALL = 2;
28     
29     private int workspaceScope;
30     private int externalScope;
31     private HashSet JavaDoc selectedResources;
32     
33     /**
34      * Create a scope object with the provided arguments.
35      * @param workspaceScope one of SCOPE_WORKSPACE, SCOPE_SELECTION,
36      * SCOPE_WORKING_SETS
37      * @param externalScope one of EXTERNAL_SCOPE_NONE, EXTERNAL_SCOPE_ENABLED,
38      * EXTERNAL_SCOPE_ALL
39      * @param workingSets goes with SCOPE_WORKING_SETS, otherwise null
40      */

41     public PluginSearchScope(
42         int workspaceScope,
43         int externalScope,
44         HashSet JavaDoc selectedResources) {
45             this.workspaceScope = workspaceScope;
46             this.externalScope = externalScope;
47             this.selectedResources = selectedResources;
48     }
49     
50     
51     /**
52      * Creates a default scope object that will return all the entries in the
53      * PluginSearchScope. It is equivalent to workspace scope being set to
54      * 'Workspace' and external scope being set to 'Only Enabled'
55      */

56     public PluginSearchScope() {
57         this(SCOPE_WORKSPACE, EXTERNAL_SCOPE_ENABLED, null);
58     }
59     
60     private void addExternalModel(IPluginModelBase candidate, ArrayList JavaDoc result) {
61         if (externalScope == EXTERNAL_SCOPE_ALL)
62             result.add(candidate);
63         else if (externalScope == EXTERNAL_SCOPE_ENABLED && candidate.isEnabled())
64             result.add(candidate);
65     }
66     
67     private void addWorkspaceModel(IPluginModelBase candidate, ArrayList JavaDoc result) {
68         if (workspaceScope == SCOPE_WORKSPACE) {
69             result.add(candidate);
70         } else if (selectedResources.contains(candidate.getUnderlyingResource().getProject())) {
71                 result.add(candidate);
72         }
73     }
74         
75     public IPluginModelBase[] getMatchingModels() {
76         ArrayList JavaDoc result = new ArrayList JavaDoc();
77         IPluginModelBase[] models = PluginRegistry.getAllModels();
78         for (int i = 0; i < models.length; i++) {
79             if (models[i].getUnderlyingResource() != null) {
80                 addWorkspaceModel(models[i], result);
81             } else {
82                 addExternalModel(models[i], result);
83             }
84         }
85         return (IPluginModelBase[]) result.toArray(new IPluginModelBase[result.size()]);
86     }
87     
88 }
89
Popular Tags