1 11 package org.eclipse.update.internal.ui.model; 12 13 import java.net.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.update.configuration.*; 17 import org.eclipse.update.core.*; 18 import org.eclipse.update.internal.operations.*; 19 import org.eclipse.update.internal.search.*; 20 import org.eclipse.update.internal.ui.UpdateUI; 21 import org.eclipse.update.internal.ui.UpdateUIMessages; 22 import org.eclipse.update.search.*; 23 24 public class DiscoveryFolder extends BookmarkFolder { 25 26 private static final long serialVersionUID = 1L; 27 UpdatePolicy updatePolicy = new UpdatePolicy(); 28 29 public DiscoveryFolder() { 30 super(UpdateUIMessages.DiscoveryFolder_name); 31 setModel(UpdateUI.getDefault().getUpdateModel()); 32 } 33 public void initialize() { 34 children.clear(); 35 if (!UpdateUI.getDefault().getPluginPreferences().getBoolean(UpdateUI.P_DISCOVERY_SITES_ENABLED)) 37 return; 38 39 try { 40 URL updateMapURL = UpdateUtils.getUpdateMapURL(); 41 if (updateMapURL!=null) { 42 updatePolicy = new UpdatePolicy(); 43 IStatus status = UpdateUtils.loadUpdatePolicy(updatePolicy, updateMapURL, new NullProgressMonitor()); 45 if (status != null) { 46 UpdateUtils.log(status); 48 } 49 } 50 } catch (CoreException e) { 51 UpdateUtils.log(e.getStatus()); 53 } 54 55 try { 56 ILocalSite site = SiteManager.getLocalSite(); 57 IInstallConfiguration config = site.getCurrentConfiguration(); 58 IConfiguredSite[] csites = config.getConfiguredSites(); 59 for (int i = 0; i < csites.length; i++) { 60 IConfiguredSite csite = csites[i]; 61 IFeatureReference[] refs = csite.getConfiguredFeatures(); 62 for (int j = 0; j < refs.length; j++) { 63 IFeatureReference ref = refs[j]; 64 IFeature feature = ref.getFeature(null); 65 IURLEntry[] entries = feature.getDiscoverySiteEntries(); 66 if (entries.length > 0) { 67 if (isIncluded(ref, refs)) 69 continue; 70 addBookmarks(feature); 71 } 72 } 73 } 74 } catch (CoreException e) { 75 UpdateUI.logException(e); 76 } 77 } 78 private boolean isIncluded( 79 IFeatureReference ref, 80 IFeatureReference[] refs) { 81 try { 82 VersionedIdentifier vid = ref.getVersionedIdentifier(); 83 for (int i = 0; i < refs.length; i++) { 84 IFeatureReference candidate = refs[i]; 85 if (candidate.equals(ref)) 87 continue; 88 IFeature cfeature = candidate.getFeature(null); 89 IFeatureReference[] irefs = 90 cfeature.getIncludedFeatureReferences(); 91 for (int j = 0; j < irefs.length; j++) { 92 IFeatureReference iref = irefs[j]; 93 VersionedIdentifier ivid = iref.getVersionedIdentifier(); 94 if (ivid.equals(vid)) { 95 return true; 97 } 98 } 99 } 100 } catch (CoreException e) { 101 } 102 return false; 103 } 104 private void addBookmarks(IFeature feature) { 105 if (updatePolicy != null && updatePolicy.isLoaded()) { 108 IUpdateSiteAdapter mappedSite = updatePolicy.getMappedDiscoverySite(feature.getVersionedIdentifier().getIdentifier()); 109 if (mappedSite != null) { 110 SiteBookmark bookmark = 111 new SiteBookmark(mappedSite.getLabel(), mappedSite.getURL(), false); 112 bookmark.setReadOnly(true); 113 if (!contains(bookmark)) 114 internalAdd(bookmark); 115 return; 116 } else if (!updatePolicy.isFallbackAllowed()) { 117 return; 119 } 120 } 121 IURLEntry[] entries = feature.getDiscoverySiteEntries(); 122 for (int i = 0; i < entries.length; i++) { 123 IURLEntry entry = entries[i]; 124 SiteBookmark bookmark = 125 new SiteBookmark( 126 entry.getAnnotation(), 127 entry.getURL(), 128 entry.getType() == IURLEntry.WEB_SITE); 129 bookmark.setReadOnly(entry.getType() != IURLEntry.WEB_SITE); 130 if (!contains(bookmark)) 131 internalAdd(bookmark); 132 } 133 } 134 private boolean contains(SiteBookmark bookmark) { 135 for (int i = 0; i < children.size(); i++) { 136 Object o = children.get(i); 137 if (o instanceof SiteBookmark) { 138 if (bookmark.getURL().equals(((SiteBookmark) o).getURL())) 140 return true; 141 } 142 } 143 return false; 144 } 145 public Object [] getChildren(Object parent) { 146 if (hasChildren() == false) 147 initialize(); 148 return super.getChildren(parent); 149 } 150 } 151 | Popular Tags |