1 11 package org.eclipse.team.internal.ccvs.ui.merge; 12 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.IAdaptable; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.team.internal.ccvs.core.CVSTag; 21 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 22 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 23 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants; 24 import org.eclipse.team.internal.ccvs.ui.Policy; 25 import org.eclipse.ui.model.IWorkbenchAdapter; 26 27 public class TagRootElement implements IWorkbenchAdapter, IAdaptable { 28 private ICVSFolder project; 29 private List cachedTags; 30 private int typeOfTagRoot; 31 32 public TagRootElement(ICVSFolder project, int typeOfTagRoot) { 33 this.typeOfTagRoot = typeOfTagRoot; 34 this.project = project; 35 } 36 37 public TagRootElement(ICVSFolder project, int typeOfTagRoot, CVSTag[] tags) { 38 this(project, typeOfTagRoot); 39 add(tags); 40 } 41 42 public Object [] getChildren(Object o) { 43 CVSTag[] childTags = new CVSTag[0]; 44 if(cachedTags==null) { 45 if(typeOfTagRoot==CVSTag.BRANCH) { 46 childTags = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownTags(project, CVSTag.BRANCH); 47 } else if(typeOfTagRoot==CVSTag.VERSION) { 48 childTags = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownTags(project, CVSTag.VERSION); 49 }else if(typeOfTagRoot==CVSTag.DATE){ 50 childTags = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownTags(project, CVSTag.DATE); 51 } 52 } else { 53 childTags = getTags(); 54 } 55 TagElement[] result = new TagElement[childTags.length]; 56 for (int i = 0; i < childTags.length; i++) { 57 result[i] = new TagElement(childTags[i]); 58 } 59 return result; 60 } 61 public void removeAll() { 62 if(cachedTags!=null) { 63 cachedTags.clear(); 64 } 65 } 66 public void add(CVSTag tag){ 67 if(cachedTags==null) { 68 cachedTags = new ArrayList (); 69 } 70 cachedTags.add(tag); 71 } 72 public void add(CVSTag[] tags) { 73 if(cachedTags==null) { 74 cachedTags = new ArrayList (tags.length); 75 } 76 cachedTags.addAll(Arrays.asList(tags)); 77 } 78 public void remove(CVSTag tag) { 79 if(cachedTags!=null) { 80 cachedTags.remove(tag); 81 } 82 } 83 public CVSTag[] getTags() { 84 if(cachedTags!=null) { 85 return (CVSTag[]) cachedTags.toArray(new CVSTag[cachedTags.size()]); 86 } else { 87 return new CVSTag[0]; 88 } 89 } 90 public Object getAdapter(Class adapter) { 91 if (adapter == IWorkbenchAdapter.class) return this; 92 return null; 93 } 94 public ImageDescriptor getImageDescriptor(Object object) { 95 if(typeOfTagRoot==CVSTag.BRANCH) { 96 return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_BRANCHES_CATEGORY); 97 } else if(typeOfTagRoot==CVSTag.DATE){ 98 return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_DATES_CATEGORY); 99 }else { 100 return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_VERSIONS_CATEGORY); 101 } 102 } 103 public String getLabel(Object o) { 104 if(typeOfTagRoot==CVSTag.BRANCH) { 105 return Policy.bind("MergeWizardEndPage.branches"); } else if(typeOfTagRoot==CVSTag.DATE){ 107 return Policy.bind("TagRootElement.0"); }else { 109 return Policy.bind("VersionsElement.versions"); } 111 } 112 public Object getParent(Object o) { 113 return null; 114 } 115 119 public int getTypeOfTagRoot() { 120 return typeOfTagRoot; 121 } 122 123 } 124 | Popular Tags |