Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 11 package org.eclipse.pde.core.plugin; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.PlatformObject; 16 import org.eclipse.osgi.service.resolver.BundleDescription; 17 18 27 public class ModelEntry extends PlatformObject { 28 29 private String fId; 30 protected ArrayList fWorkspaceEntries = new ArrayList (1); 31 protected ArrayList fExternalEntries = new ArrayList (1); 32 33 38 public ModelEntry(String id) { 39 fId = id; 40 } 41 42 47 public IPluginModelBase[] getWorkspaceModels() { 48 return (IPluginModelBase[])fWorkspaceEntries.toArray(new IPluginModelBase[fWorkspaceEntries.size()]); 49 } 50 51 58 public IPluginModelBase[] getExternalModels() { 59 return (IPluginModelBase[])fExternalEntries.toArray(new IPluginModelBase[fExternalEntries.size()]); 60 } 61 62 81 public IPluginModelBase getModel() { 82 IPluginModelBase model = getBestCandidate(getWorkspaceModels()); 83 if (model == null) 84 model = getBestCandidate(getExternalModels()); 85 return model; 86 } 87 88 private IPluginModelBase getBestCandidate(IPluginModelBase[] models) { 89 IPluginModelBase model = null; 90 for (int i = 0; i < models.length; i++) { 91 if (models[i].getBundleDescription() == null) 92 continue; 93 94 if (model == null) { 95 model = models[i]; 96 continue; 97 } 98 99 if (!model.isEnabled() && models[i].isEnabled()) { 100 model = models[i]; 101 continue; 102 } 103 104 BundleDescription current = model.getBundleDescription(); 105 BundleDescription candidate = models[i].getBundleDescription(); 106 if (!current.isResolved() && candidate.isResolved()) { 107 model = models[i]; 108 continue; 109 } 110 111 if (current.getVersion().compareTo(candidate.getVersion()) < 0) { 112 model = models[i]; 113 } 114 } 115 return model; 116 } 117 118 131 public IPluginModelBase[] getActiveModels() { 132 if (fWorkspaceEntries.size() > 0) 133 return getWorkspaceModels(); 134 135 if (fExternalEntries.size() > 0) { 136 ArrayList list = new ArrayList (fExternalEntries.size()); 137 for (int i = 0; i < fExternalEntries.size(); i++) { 138 IPluginModelBase model = (IPluginModelBase)fExternalEntries.get(i); 139 if (model.isEnabled()) 140 list.add(model); 141 } 142 return (IPluginModelBase[])list.toArray(new IPluginModelBase[list.size()]); 143 } 144 return new IPluginModelBase[0]; 145 } 146 147 152 public String getId() { 153 return fId; 154 } 155 156 165 public IPluginModelBase getModel(BundleDescription desc) { 166 if (desc == null) 167 return null; 168 169 for (int i = 0; i < fWorkspaceEntries.size(); i++) { 170 IPluginModelBase model = (IPluginModelBase)fWorkspaceEntries.get(i); 171 if (desc.equals(model.getBundleDescription())) 172 return model; 173 } 174 for (int i = 0; i < fExternalEntries.size(); i++) { 175 IPluginModelBase model = (IPluginModelBase)fExternalEntries.get(i); 176 if (desc.equals(model.getBundleDescription())) 177 return model; 178 } 179 return null; 180 } 181 182 189 public boolean hasWorkspaceModels() { 190 return !fWorkspaceEntries.isEmpty(); 191 } 192 193 200 public boolean hasExternalModels() { 201 return !fExternalEntries.isEmpty(); 202 } 203 204 } 205
| Popular Tags
|