1 11 package org.eclipse.pde.internal.ui.wizards.xhtml; 12 13 import java.util.ArrayList ; 14 import java.util.Hashtable ; 15 import java.util.Iterator ; 16 import java.util.Set ; 17 18 import org.eclipse.core.resources.IFile; 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.runtime.IAdaptable; 21 import org.eclipse.core.runtime.IPath; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.pde.internal.ui.PDEPluginImages; 24 import org.eclipse.ui.model.IWorkbenchAdapter; 25 26 public class TocReplaceTable { 27 28 protected class TocReplaceEntry implements IAdaptable { 29 private String fHref; 30 private String fLabel; 31 private IResource fTocFile; 32 private IFile fEntryFile; 33 private TocReplaceEntry(String href, String title, IResource parentFile) { 34 fLabel = title; 35 fHref = href; 36 fTocFile = parentFile; 37 if (fHref != null && fTocFile != null) 38 fEntryFile = fTocFile.getProject().getFile(fHref); 39 } 40 public String getHref() { 41 return fHref; 42 } 43 public IResource getTocFile() { 44 return fTocFile; 45 } 46 public String getLabel() { 47 return fLabel; 48 } 49 public boolean fileMissing() { 50 return fEntryFile == null || !fEntryFile.exists(); 51 } 52 public IFile getEntryFile() { 53 return fEntryFile; 54 } 55 public Object getAdapter(Class adapter) { 56 if (adapter == IWorkbenchAdapter.class) 57 return new IWorkbenchAdapter() { 58 public Object [] getChildren(Object o) { 59 return null; 60 } 61 public ImageDescriptor getImageDescriptor(Object object) { 62 if (fileMissing()) 63 return PDEPluginImages.DESC_ALERT_OBJ; 64 return PDEPluginImages.DESC_DISCOVERY; 65 } 66 public String getLabel(Object o) { 67 String label = TocReplaceEntry.this.getLabel(); 68 String href = TocReplaceEntry.this.getHref(); 69 return label == null ? href : href + " (" + label + ")"; } 71 public Object getParent(Object o) { 72 return TocReplaceEntry.this.getTocFile(); 73 } 74 }; 75 return null; 76 } 77 public boolean equals(Object obj) { 78 if (obj instanceof TocReplaceEntry) { 79 IPath objPath = ((TocReplaceEntry)obj).getEntryFile().getLocation(); 80 return fEntryFile.getLocation().equals(objPath); 81 } 82 return false; 83 } 84 } 85 86 private Hashtable fEntries = new Hashtable (); 87 88 public void addToTable(String href, String title, IResource tocFile) { 89 TocReplaceEntry tro = new TocReplaceEntry(href, title, tocFile); 90 if (tro.fileMissing()) 91 return; if (fEntries.containsKey(tocFile)) { 93 ArrayList tocList = (ArrayList )fEntries.get(tocFile); 94 if (!tocList.contains(tro)) 95 tocList.add(tro); 96 } else { 97 ArrayList tocList = new ArrayList (); 98 tocList.add(tro); 99 fEntries.put(tocFile, tocList); 100 } 101 } 102 103 public IResource[] getTocs() { 104 Set keys = fEntries.keySet(); 105 Iterator it = keys.iterator(); 106 IResource[] files = new IResource[fEntries.size()]; 107 int i = 0; 108 while (it.hasNext()) 109 files[i++] = (IResource)it.next(); 110 return files; 111 } 112 113 public TocReplaceEntry[] getToBeConverted(IResource file) { 114 ArrayList list = (ArrayList )fEntries.get(file); 115 return (TocReplaceEntry[]) list.toArray(new TocReplaceEntry[list.size()]); 116 } 117 118 public int numEntries() { 119 return fEntries.size(); 120 } 121 122 public void clear() { 123 fEntries.clear(); 124 } 125 126 } 127 | Popular Tags |