KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > history > FileRevisionTypedElement


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.history;
12
13 import java.net.URI JavaDoc;
14 import java.util.Date JavaDoc;
15
16 import org.eclipse.compare.ITypedElement;
17 import org.eclipse.core.resources.IStorage;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.team.core.history.IFileRevision;
20 import org.eclipse.team.internal.ui.StorageTypedElement;
21 import org.eclipse.ui.IEditorInput;
22
23 import com.ibm.icu.text.DateFormat;
24
25 /**
26  * An {@link ITypedElement} wrapper for {@link IFileRevision} for use with the
27  * Compare framework.
28  */

29 public class FileRevisionTypedElement extends StorageTypedElement {
30
31     private IFileRevision fileRevision;
32     private String JavaDoc author;
33     
34     /**
35      * Create a typed element that wraps the given file revision.
36      * @param fileRevision the file revision
37      */

38     public FileRevisionTypedElement(IFileRevision fileRevision){
39         this(fileRevision, null);
40     }
41     
42     /**
43      * Create a typed element that wraps the given file revision.
44      * @param fileRevision the file revision
45      * @param localEncoding the encoding of the local file that corresponds to the given file revision
46      */

47     public FileRevisionTypedElement(IFileRevision fileRevision, String JavaDoc localEncoding){
48         super(localEncoding);
49         Assert.isNotNull(fileRevision);
50         this.fileRevision = fileRevision;
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.team.internal.ui.StorageTypedElement#getName()
55      */

56     public String JavaDoc getName() {
57         return fileRevision.getName();
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.team.internal.ui.StorageTypedElement#getElementStorage(org.eclipse.core.runtime.IProgressMonitor)
62      */

63     protected IStorage fetchContents(IProgressMonitor monitor) throws CoreException {
64         return fileRevision.getStorage(monitor);
65     
66     }
67
68     /**
69      * Returns the unique content identifier for this element
70      * @return String the string contains a unique content id
71      */

72     public String JavaDoc getContentIdentifier() {
73         return fileRevision.getContentIdentifier();
74     }
75     
76     /**
77      * Return the human readable timestamp of this element.
78      * @return the human readable timestamp of this element
79      */

80     public String JavaDoc getTimestamp() {
81         long date = fileRevision.getTimestamp();
82         Date JavaDoc dateFromLong = new Date JavaDoc(date);
83         return DateFormat.getDateTimeInstance().format(dateFromLong);
84     }
85     
86     /**
87      * Return the file revision of this element.
88      * @return the file revision of this element
89      */

90     public IFileRevision getFileRevision(){
91         return fileRevision;
92     }
93     
94     /**
95      * Return the human readable path of this element.
96      * @return the human readable path of this element
97      */

98     public String JavaDoc getPath() {
99         URI JavaDoc uri = fileRevision.getURI();
100         if (uri != null)
101             return uri.getPath();
102         return getName();
103     }
104     
105     /* (non-Javadoc)
106      * @see org.eclipse.compare.ISharedDocumentAdapter#getDocumentKey(java.lang.Object)
107      */

108     public IEditorInput getDocumentKey(Object JavaDoc element) {
109         if (element == this && getBufferedStorage() != null) {
110             return new FileRevisionEditorInput(fileRevision, getBufferedStorage(), getLocalEncoding());
111         }
112         return null;
113     }
114     
115     /* (non-Javadoc)
116      * @see java.lang.Object#hashCode()
117      */

118     public int hashCode() {
119         return fileRevision.hashCode();
120     }
121     
122     public boolean equals(Object JavaDoc obj) {
123         if (obj == this)
124             return true;
125         if (obj instanceof FileRevisionTypedElement) {
126             FileRevisionTypedElement other = (FileRevisionTypedElement) obj;
127             return other.getFileRevision().equals(getFileRevision());
128         }
129         return false;
130     }
131
132     public String JavaDoc getAuthor() {
133         if (author == null)
134             author = fileRevision.getAuthor();
135         return author;
136     }
137
138     public void setAuthor(String JavaDoc author) {
139         this.author = author;
140     }
141
142     public void fetchAuthor(IProgressMonitor monitor) throws CoreException {
143         if (getAuthor() == null && fileRevision.isPropertyMissing()) {
144             IFileRevision other = fileRevision.withAllProperties(monitor);
145             author = other.getAuthor();
146         }
147     }
148
149     public IFileRevision getRevision() {
150         return fileRevision;
151     }
152
153 }
154
Popular Tags