KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > model > CVSRemoteFilePropertySource


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ccvs.ui.model;
12
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jface.operation.IRunnableWithProgress;
18 import org.eclipse.team.core.TeamException;
19 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
20 import org.eclipse.team.internal.ccvs.core.ILogEntry;
21 import org.eclipse.team.internal.ccvs.ui.*;
22 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
23 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
24 import org.eclipse.ui.views.properties.IPropertyDescriptor;
25 import org.eclipse.ui.views.properties.IPropertySource;
26 import org.eclipse.ui.views.properties.PropertyDescriptor;
27
28 public class CVSRemoteFilePropertySource implements IPropertySource {
29     ICVSRemoteFile file;
30     ILogEntry entry;
31     boolean initialized;
32     
33     // Property Descriptors
34
static protected IPropertyDescriptor[] propertyDescriptors = new IPropertyDescriptor[5];
35     {
36         PropertyDescriptor descriptor;
37         String JavaDoc category = CVSUIMessages.cvs;
38         
39         // resource name
40
descriptor = new PropertyDescriptor(ICVSUIConstants.PROP_NAME, CVSUIMessages.CVSRemoteFilePropertySource_name);
41         descriptor.setAlwaysIncompatible(true);
42         descriptor.setCategory(category);
43         propertyDescriptors[0] = descriptor;
44         // revision
45
descriptor = new PropertyDescriptor(ICVSUIConstants.PROP_REVISION, CVSUIMessages.CVSRemoteFilePropertySource_revision);
46         descriptor.setAlwaysIncompatible(true);
47         descriptor.setCategory(category);
48         propertyDescriptors[1] = descriptor;
49         // date
50
descriptor = new PropertyDescriptor(ICVSUIConstants.PROP_DATE, CVSUIMessages.CVSRemoteFilePropertySource_date);
51         descriptor.setAlwaysIncompatible(true);
52         descriptor.setCategory(category);
53         propertyDescriptors[2] = descriptor;
54         // author
55
descriptor = new PropertyDescriptor(ICVSUIConstants.PROP_AUTHOR, CVSUIMessages.CVSRemoteFilePropertySource_author);
56         descriptor.setAlwaysIncompatible(true);
57         descriptor.setCategory(category);
58         propertyDescriptors[3] = descriptor;
59         // comment
60
descriptor = new PropertyDescriptor(ICVSUIConstants.PROP_COMMENT, CVSUIMessages.CVSRemoteFilePropertySource_comment);
61         descriptor.setAlwaysIncompatible(true);
62         descriptor.setCategory(category);
63         propertyDescriptors[4] = descriptor;
64     }
65
66     /**
67      * Create a PropertySource and store its file
68      */

69     public CVSRemoteFilePropertySource(ICVSRemoteFile file) {
70         this.file = file;
71     }
72     
73     /**
74      * Do nothing because properties are read only.
75      */

76     public Object JavaDoc getEditableValue() {
77         return this;
78     }
79
80     /**
81      * Return the Property Descriptors for the receiver.
82      */

83     public IPropertyDescriptor[] getPropertyDescriptors() {
84         return propertyDescriptors;
85     }
86
87     /*
88      * @see IPropertySource#getPropertyValue(Object)
89      */

90     public Object JavaDoc getPropertyValue(Object JavaDoc id) {
91         if (!initialized) {
92             initialize();
93             initialized = true;
94         }
95         if (id.equals(ICVSUIConstants.PROP_NAME)) {
96             return file.getName();
97         }
98         if (entry != null) {
99             if (id.equals(ICVSUIConstants.PROP_REVISION)) {
100                 return entry.getRevision();
101             }
102             if (id.equals(ICVSUIConstants.PROP_DATE)) {
103                 return entry.getDate();
104             }
105             if (id.equals(ICVSUIConstants.PROP_AUTHOR)) {
106                 return entry.getAuthor();
107             }
108             if (id.equals(ICVSUIConstants.PROP_COMMENT)) {
109                 return entry.getComment();
110             }
111         }
112         return ""; //$NON-NLS-1$
113
}
114
115     /**
116      * Answer true if the value of the specified property
117      * for this object has been changed from the default.
118      */

119     public boolean isPropertySet(Object JavaDoc property) {
120         return false;
121     }
122     /**
123      * Reset the specified property's value to its default value.
124      * Do nothing because properties are read only.
125      *
126      * @param property The property to reset.
127      */

128     public void resetPropertyValue(Object JavaDoc property) {
129     }
130     /**
131      * Do nothing because properties are read only.
132      */

133     public void setPropertyValue(Object JavaDoc name, Object JavaDoc value) {
134     }
135     
136     private void initialize() {
137         try {
138             CVSUIPlugin.runWithProgress(null, true /*cancelable*/, new IRunnableWithProgress() {
139                 public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
140                     try {
141                         ILogEntry[] entries = file.getLogEntries(monitor);
142                         String JavaDoc revision = file.getRevision();
143                         for (int i = 0; i < entries.length; i++) {
144                             if (entries[i].getRevision().equals(revision)) {
145                                 entry = entries[i];
146                                 return;
147                             }
148                         }
149                     } catch (TeamException e) {
150                         throw new InvocationTargetException JavaDoc(e);
151                     }
152                 }
153             });
154         } catch (InterruptedException JavaDoc e) { // ignore cancellation
155
} catch (InvocationTargetException JavaDoc e) {
156             CVSUIPlugin.openError(null, null, null, e);
157         }
158     }
159 }
160
Popular Tags