1 11 package org.eclipse.update.internal.ui.model; 12 import java.lang.reflect.*; 13 import java.net.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.operation.*; 17 import org.eclipse.update.core.*; 18 import org.eclipse.update.internal.ui.*; 19 20 public class FeatureReferenceAdapter extends FeatureAdapter { 21 private IFeatureReference featureRef; 22 private boolean touched; 23 24 public FeatureReferenceAdapter(IFeatureReference featureRef) { 25 this.featureRef = featureRef; 26 setIncluded(featureRef instanceof IIncludedFeatureReference); 27 } 28 29 public IFeature getFeature(IProgressMonitor monitor) throws CoreException { 30 return featureRef.getFeature(monitor); 31 } 32 33 public String getFastLabel() { 34 return featureRef.getURL().toString(); 35 } 36 37 public ISite getSite() { 38 return featureRef.getSite(); 39 } 40 41 public URL getURL() { 42 return featureRef.getURL(); 43 } 44 45 public boolean isOptional() { 46 return featureRef instanceof IIncludedFeatureReference ? 47 ((IIncludedFeatureReference)featureRef).isOptional():false; 48 } 49 50 public void touchIncludedFeatures(IRunnableContext context) { 51 if (touched) return; 52 final IFeatureReference [] included; 53 54 try { 55 included = getFeature(null).getIncludedFeatureReferences(); 56 } 57 catch (CoreException e) { 58 return; 59 } 60 if (included.length == 0) return; 61 IRunnableWithProgress op = new IRunnableWithProgress () { 62 public void run(IProgressMonitor monitor) { 63 monitor.beginTask(UpdateUIMessages.SiteBookmark_downloading, included.length); 64 for (int i=0; i<included.length; i++) { 65 IFeatureReference ref = included[i]; 66 try { 67 monitor.subTask(ref.getURL().toString()); 68 ref.getFeature(new SubProgressMonitor(monitor, 1)); 69 } 71 catch (CoreException e) { 72 } 73 } 74 monitor.done(); 75 } 76 }; 77 try { 78 context.run(true, false, op); 79 touched=true; 80 } 81 catch (InvocationTargetException e) { 82 } 83 catch (InterruptedException e) { 84 } 85 } 86 87 public IFeatureAdapter[] getIncludedFeatures(IProgressMonitor monitor) { 88 try { 89 IFeatureReference[] included = 90 getFeature(monitor).getIncludedFeatureReferences(); 91 FeatureReferenceAdapter[] result = 92 new FeatureReferenceAdapter[included.length]; 93 for (int i = 0; i < included.length; i++) { 94 result[i] = new FeatureReferenceAdapter(included[i]); 95 } 96 return result; 97 } catch (CoreException e) { 98 return new IFeatureAdapter[0]; 99 } 100 } 101 102 public IFeatureReference getFeatureReference() { 103 return featureRef; 104 } 105 } 106 | Popular Tags |