1 11 package org.eclipse.pde.internal.core.search; 12 13 import java.util.ArrayList ; 14 import java.util.HashSet ; 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 selectedResources; 32 33 41 public PluginSearchScope( 42 int workspaceScope, 43 int externalScope, 44 HashSet selectedResources) { 45 this.workspaceScope = workspaceScope; 46 this.externalScope = externalScope; 47 this.selectedResources = selectedResources; 48 } 49 50 51 56 public PluginSearchScope() { 57 this(SCOPE_WORKSPACE, EXTERNAL_SCOPE_ENABLED, null); 58 } 59 60 private void addExternalModel(IPluginModelBase candidate, ArrayList 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 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 result = new ArrayList (); 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 |