KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > mappings > ChangeSetLabelProvider


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.ccvs.ui.mappings;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.resources.*;
17 import org.eclipse.core.resources.mapping.ResourceTraversal;
18 import org.eclipse.jface.resource.JFaceResources;
19 import org.eclipse.jface.viewers.TreePath;
20 import org.eclipse.swt.graphics.Font;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.team.core.diff.IDiffTree;
23 import org.eclipse.team.internal.ccvs.core.mapping.ChangeSetModelProvider;
24 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
25 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
26 import org.eclipse.team.internal.ccvs.ui.subscriber.CVSParticipantLabelDecorator;
27 import org.eclipse.team.internal.core.subscribers.*;
28 import org.eclipse.team.internal.ui.mapping.ResourceModelLabelProvider;
29 import org.eclipse.team.internal.ui.synchronize.ChangeSetCapability;
30 import org.eclipse.team.ui.mapping.ITeamContentProviderManager;
31 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
32 import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
33 import org.eclipse.ui.navigator.ICommonContentExtensionSite;
34
35 public class ChangeSetLabelProvider extends ResourceModelLabelProvider {
36
37     private CVSParticipantLabelDecorator decorator;
38
39     public void init(ICommonContentExtensionSite site) {
40         super.init(site);
41         ISynchronizePageConfiguration configuration = getConfiguration();
42         if (isCompare(configuration)) {
43             decorator = new CVSParticipantLabelDecorator(configuration);
44         }
45     }
46
47     private ISynchronizePageConfiguration getConfiguration() {
48         return (ISynchronizePageConfiguration)getExtensionSite().getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_PAGE_CONFIGURATION);
49     }
50     
51     private boolean isCompare(ISynchronizePageConfiguration configuration) {
52         return configuration.getParticipant() instanceof ModelCompareParticipant;
53     }
54     
55     public String JavaDoc getText(Object JavaDoc element) {
56         String JavaDoc text = super.getText(element);
57         if (decorator != null && isChangeSetsEnabled())
58             text = decorator.decorateText(text, element);
59         return text;
60     }
61     
62     private boolean isChangeSetsEnabled() {
63         String JavaDoc id = (String JavaDoc)getConfiguration().getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER);
64         return id.equals(ChangeSetModelProvider.ID);
65     }
66
67     protected String JavaDoc getDelegateText(Object JavaDoc elementOrPath) {
68         Object JavaDoc element = internalGetElement(elementOrPath);
69         if (element instanceof DiffChangeSet) {
70             DiffChangeSet set = (DiffChangeSet) element;
71             return set.getName();
72         }
73         return super.getDelegateText(elementOrPath);
74     }
75     
76     protected Image getDelegateImage(Object JavaDoc elementOrPath) {
77         Object JavaDoc element = internalGetElement(elementOrPath);
78         if (element instanceof DiffChangeSet) {
79             return getChangeSetImage();
80         }
81         return super.getDelegateImage(elementOrPath);
82     }
83
84     private Image getChangeSetImage() {
85         return getImageManager().getImage(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_CHANGELOG));
86     }
87     
88     public void dispose() {
89         if (decorator != null)
90             decorator.dispose();
91         super.dispose();
92     }
93     
94     protected boolean isBusy(Object JavaDoc elementOrPath) {
95         Object JavaDoc element = internalGetElement(elementOrPath);
96         if (element instanceof DiffChangeSet) {
97             DiffChangeSet dcs = (DiffChangeSet) element;
98             IResource[] resources = dcs.getResources();
99             for (int i = 0; i < resources.length; i++) {
100                 IResource resource = resources[i];
101                 if (getContext().getDiffTree().getProperty(resource.getFullPath(), IDiffTree.P_BUSY_HINT))
102                     return true;
103             }
104             return false;
105         }
106         return super.isBusy(elementOrPath);
107     }
108     
109     protected boolean hasDecendantConflicts(Object JavaDoc elementOrPath) {
110         Object JavaDoc element = internalGetElement(elementOrPath);
111         if (element instanceof DiffChangeSet) {
112             DiffChangeSet dcs = (DiffChangeSet) element;
113             IResource[] resources = dcs.getResources();
114             for (int i = 0; i < resources.length; i++) {
115                 IResource resource = resources[i];
116                 if (getContext().getDiffTree().getProperty(resource.getFullPath(), IDiffTree.P_HAS_DESCENDANT_CONFLICTS))
117                     return true;
118             }
119             return false;
120         }
121         if (elementOrPath instanceof TreePath && element instanceof IResource) {
122             DiffChangeSet set = internalGetChangeSet(elementOrPath);
123             if (set != null) {
124                 ResourceTraversal[] traversals = getTraversalCalculator().getTraversals(set, (TreePath)elementOrPath);
125                 return (getContext().getDiffTree().hasMatchingDiffs(traversals, CONFLICT_FILTER));
126             }
127         }
128         return super.hasDecendantConflicts(elementOrPath);
129     }
130     
131     private DiffChangeSet internalGetChangeSet(Object JavaDoc elementOrPath) {
132         if (elementOrPath instanceof TreePath) {
133             TreePath tp = (TreePath) elementOrPath;
134             Object JavaDoc o = tp.getFirstSegment();
135             if (o instanceof DiffChangeSet) {
136                 return (DiffChangeSet) o;
137             }
138         }
139         return null;
140     }
141
142     protected int getMarkerSeverity(Object JavaDoc elementOrPath) {
143         Object JavaDoc element = internalGetElement(elementOrPath);
144         if (element instanceof DiffChangeSet) {
145             DiffChangeSet dcs = (DiffChangeSet) element;
146             Set JavaDoc projects = new HashSet JavaDoc();
147             IResource[] resources = dcs.getResources();
148             int severity = -1;
149             for (int i = 0; i < resources.length; i++) {
150                 IResource resource = resources[i];
151                 IProject project = resource.getProject();
152                 if (!projects.contains(project)) {
153                     projects.add(project);
154                     int next = super.getMarkerSeverity(project);
155                     if (next == IMarker.SEVERITY_ERROR)
156                         return IMarker.SEVERITY_ERROR;
157                     if (next == IMarker.SEVERITY_WARNING)
158                         severity = next;
159                 }
160             }
161             return severity;
162         }
163         return super.getMarkerSeverity(elementOrPath);
164     }
165     
166     protected void updateLabels(Object JavaDoc[] elements) {
167         super.updateLabels(addSetsContainingElements(elements));
168     }
169
170     private Object JavaDoc[] addSetsContainingElements(Object JavaDoc[] elements) {
171         Set JavaDoc result = new HashSet JavaDoc();
172         for (int i = 0; i < elements.length; i++) {
173             Object JavaDoc object = elements[i];
174             result.add(object);
175             if (object instanceof IProject) {
176                 IProject project = (IProject) object;
177                 ChangeSet[] sets = getSetsContaing(project);
178                 for (int j = 0; j < sets.length; j++) {
179                     ChangeSet set = sets[j];
180                     result.add(set);
181                 }
182             }
183         }
184         return result.toArray();
185     }
186
187     private ChangeSet[] getSetsContaing(IProject project) {
188         return getContentProvider().getSetsShowingPropogatedStateFrom(project.getFullPath());
189     }
190
191     private ChangeSetContentProvider getContentProvider() {
192         return (ChangeSetContentProvider)getExtensionSite().getExtension().getContentProvider();
193     }
194     
195     private Object JavaDoc internalGetElement(Object JavaDoc elementOrPath) {
196         if (elementOrPath instanceof TreePath) {
197             TreePath tp = (TreePath) elementOrPath;
198             return tp.getLastSegment();
199         }
200         return elementOrPath;
201     }
202     
203     public Font getFont(Object JavaDoc element) {
204         element = internalGetElement(element);
205         if (element instanceof ActiveChangeSet && isDefaultActiveSet((ActiveChangeSet)element)) {
206             return JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
207         }
208         return super.getFont(element);
209     }
210
211     private boolean isDefaultActiveSet(ActiveChangeSet set) {
212         ChangeSetCapability changeSetCapability = getContentProvider().getChangeSetCapability();
213         if (changeSetCapability != null) {
214             ActiveChangeSetManager activeChangeSetManager = changeSetCapability.getActiveChangeSetManager();
215             if (activeChangeSetManager != null)
216                 return activeChangeSetManager.isDefault(set);
217         }
218         return false;
219     }
220
221 }
222
Popular Tags