1 11 package org.eclipse.team.internal.ccvs.ui.model; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import com.ibm.icu.text.SimpleDateFormat; 15 import java.util.Date ; 16 import java.util.Locale ; 17 import com.ibm.icu.util.TimeZone; 18 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.jobs.ISchedulingRule; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.team.core.TeamException; 24 import org.eclipse.team.internal.ccvs.core.*; 25 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; 26 import org.eclipse.team.internal.ccvs.ui.*; 27 import org.eclipse.team.internal.ccvs.ui.Policy; 28 import org.eclipse.team.internal.ccvs.ui.operations.FetchMembersOperation; 29 import org.eclipse.team.internal.ccvs.ui.operations.FetchMembersOperation.RemoteFolderFilter; 30 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; 31 import org.eclipse.ui.progress.IElementCollector; 32 33 public class CVSTagElement extends CVSModelElement implements IDeferredWorkbenchAdapter { 34 CVSTag tag; 35 ICVSRepositoryLocation root; 36 37 private static final String REPO_VIEW_LONG_FORAMT = "dd MMM yyyy HH:mm:ss"; private static final String REPO_VIEW_SHORT_FORMAT = "dd MMM yyyy"; private static final String TIME_ONLY_COLUMN_FORMAT = "HH:mm:ss"; private static SimpleDateFormat localLongFormat = new SimpleDateFormat(REPO_VIEW_LONG_FORAMT,Locale.getDefault()); 41 private static SimpleDateFormat localShortFormat = new SimpleDateFormat(REPO_VIEW_SHORT_FORMAT,Locale.getDefault()); 42 private static SimpleDateFormat timeColumnFormat = new SimpleDateFormat(TIME_ONLY_COLUMN_FORMAT, Locale.getDefault()); 43 44 static synchronized public String toDisplayString(Date date){ 45 String localTime = timeColumnFormat.format(date); 46 timeColumnFormat.setTimeZone(TimeZone.getDefault()); 47 if(localTime.equals("00:00:00")){ return localShortFormat.format(date); 49 } 50 return localLongFormat.format(date); 51 } 52 53 public CVSTagElement(CVSTag tag, ICVSRepositoryLocation root) { 54 this.tag = tag; 55 this.root = root; 56 } 57 58 public ICVSRepositoryLocation getRoot() { 59 return root; 60 } 61 62 public CVSTag getTag() { 63 return tag; 64 } 65 66 public boolean equals(Object o) { 67 if (!(o instanceof CVSTagElement)) 68 return false; 69 CVSTagElement t = (CVSTagElement) o; 70 if (!tag.equals(t.tag)) 71 return false; 72 return root.equals(t.root); 73 } 74 75 public int hashCode() { 76 return root.hashCode() ^ tag.hashCode(); 77 } 78 79 public ImageDescriptor getImageDescriptor(Object object) { 80 if (!(object instanceof CVSTagElement)) 81 return null; 82 if (tag.getType() == CVSTag.BRANCH || tag.getType() == CVSTag.HEAD) { 83 return CVSUIPlugin.getPlugin().getImageDescriptor( 84 ICVSUIConstants.IMG_TAG); 85 } else if (tag.getType() == CVSTag.VERSION) { 86 return CVSUIPlugin.getPlugin().getImageDescriptor( 87 ICVSUIConstants.IMG_PROJECT_VERSION); 88 } else { 89 return CVSUIPlugin.getPlugin().getImageDescriptor( 91 ICVSUIConstants.IMG_DATE); 92 } 93 } 94 public String getLabel(Object o) { 95 if (!(o instanceof CVSTagElement)) 96 return null; 97 CVSTag aTag = ((CVSTagElement) o).tag; 98 if(aTag.getType() == CVSTag.DATE){ 99 Date date = tag.asDate(); 100 if (date != null){ 101 return toDisplayString(date); 102 } 103 } 104 return aTag.getName(); 105 } 106 107 public String toString() { 108 return tag.getName(); 109 } 110 111 public Object getParent(Object o) { 112 if (!(o instanceof CVSTagElement)) 113 return null; 114 return ((CVSTagElement) o).root; 115 } 116 117 protected Object [] fetchChildren(Object o, IProgressMonitor monitor) throws TeamException { 118 ICVSRemoteResource[] children = CVSUIPlugin.getPlugin().getRepositoryManager().getFoldersForTag(root, tag, monitor); 119 if (getWorkingSet() != null) 120 children = CVSUIPlugin.getPlugin().getRepositoryManager().filterResources(getWorkingSet(), children); 121 return children; 122 } 123 124 public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) { 125 if (tag.getType() == CVSTag.HEAD || tag.getType() == CVSTag.DATE) { 126 try { 127 monitor = Policy.monitorFor(monitor); 128 RemoteFolder folder = new RemoteFolder(null, root, ICVSRemoteFolder.REPOSITORY_ROOT_FOLDER_NAME, tag); 129 monitor.beginTask(NLS.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren, new String [] { root.toString() }), 100); 130 FetchMembersOperation operation = new FetchMembersOperation(null, folder, collector); 131 operation.setFilter(new RemoteFolderFilter() { 132 public ICVSRemoteResource[] filter(ICVSRemoteResource[] folders) { 133 return CVSUIPlugin.getPlugin().getRepositoryManager().filterResources(getWorkingSet(), folders); 134 } 135 }); 136 operation.run(Policy.subMonitorFor(monitor, 100)); 137 } catch (final InvocationTargetException e) { 138 handle(collector, e); 139 } catch (InterruptedException e) { 140 } finally { 142 monitor.done(); 143 } 144 } else { 145 try { 146 collector.add(fetchChildren(o, monitor), monitor); 147 } catch (TeamException e) { 148 handle(collector, e); 149 } 150 } 151 } 152 153 public ISchedulingRule getRule(Object element) { 154 return new RepositoryLocationSchedulingRule(root); 155 } 156 157 public boolean isContainer() { 158 return true; 159 } 160 } 161 | Popular Tags |