diff options
author | Michael Valenta | 2006-03-16 15:54:03 +0000 |
---|---|---|
committer | Michael Valenta | 2006-03-16 15:54:03 +0000 |
commit | d16c7056064dfaa618ae784dc6167a4c9798e80c (patch) | |
tree | a3636cb11df927d96dfe2f0d46b3c719b90de363 | |
parent | dbcc353cf92cb2963423b8ed05765a3f92c2d5cb (diff) | |
download | eclipse.platform.team-branch_20060314_ModelDecoration.tar.gz eclipse.platform.team-branch_20060314_ModelDecoration.tar.xz eclipse.platform.team-branch_20060314_ModelDecoration.zip |
Committing to branch awaiting approvalbranch_20060314_ModelDecoration
8 files changed, 214 insertions, 395 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java index e253ca5c9..712b3de73 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java @@ -18,9 +18,7 @@ import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.team.core.mapping.IStorageMerger; -import org.eclipse.team.core.subscribers.Subscriber; import org.eclipse.team.internal.core.*; -import org.eclipse.team.internal.core.mapping.WorkspaceSubscriber; /** * The Team class provides a global point of reference for the global ignore set @@ -457,19 +455,6 @@ public final class Team { return fFileContentManager; } - /** - * Returns a subscriber that provides access to the synchronization state - * of the workspace for those projects that provide it. - * - * @return a subscriber that provides access to the synchronization state - * of the workspace. - * - * @since 3.2 - */ - public static Subscriber getWorkspaceSubscriber() { - return WorkspaceSubscriber.getInstance(); - } - /** * Creates a storage merger for the given content type. * If no storage merger is registered for the given content type <code>null</code> is returned. diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/WorkspaceSubscriber.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/WorkspaceSubscriber.java deleted file mode 100644 index 7c1530814..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/WorkspaceSubscriber.java +++ /dev/null @@ -1,350 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.core.mapping; - -import java.util.*; - -import org.eclipse.core.resources.*; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.*; -import org.eclipse.team.core.*; -import org.eclipse.team.core.diff.IDiff; -import org.eclipse.team.core.diff.IDiffVisitor; -import org.eclipse.team.core.subscribers.*; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.SyncInfoSet; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.core.variants.IResourceVariantComparator; -import org.eclipse.team.internal.core.*; - -/** - * A workspace subscriber is a special subscriber tat delegates to - * the subscribers associated with each project through the - * {@link RepositoryProvider} API. - * @since 3.2 - */ -public class WorkspaceSubscriber extends Subscriber implements ISubscriberChangeListener, IRepositoryProviderListener, IResourceChangeListener { - - private static WorkspaceSubscriber instance; - private Map projects = new HashMap(); - - public static synchronized WorkspaceSubscriber getInstance() { - if (instance == null) { - instance = new WorkspaceSubscriber(); - } - return instance; - } - - public WorkspaceSubscriber() { - // Add subscribers for all projects that have them - RepositoryProviderManager.getInstance().addListener(this); - ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); - IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (int i = 0; i < allProjects.length; i++) { - IProject project = allProjects[i]; - handleProject(project); - } - } - - private void handleProject(IProject project) { - if (RepositoryProvider.isShared(project)) { - try { - String currentId = project.getPersistentProperty(TeamPlugin.PROVIDER_PROP_KEY); - if (currentId != null) { - RepositoryProviderType type = RepositoryProviderType.getProviderType(currentId); - if (type != null) { - Subscriber subscriber = type.getSubscriber(); - if (subscriber != null) { - subscriber.addListener(this); - projects.put(project, subscriber); - } - } - } - } catch (CoreException e) { - TeamPlugin.log(e); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#getName() - */ - public String getName() { - return Messages.WorkspaceSubscriber_0; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#isSupervised(org.eclipse.core.resources.IResource) - */ - public boolean isSupervised(IResource resource) throws TeamException { - Subscriber subscriber = getSubscriber(resource); - if (subscriber != null) - return subscriber.isSupervised(resource); - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#members(org.eclipse.core.resources.IResource) - */ - public IResource[] members(IResource resource) throws TeamException { - Subscriber subscriber = getSubscriber(resource); - if (subscriber != null) - return subscriber.members(resource); - if (resource instanceof IContainer) { - IContainer container = (IContainer) resource; - try { - return container.members(); - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } - return new IResource[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#roots() - */ - public IResource[] roots() { - return (IProject[]) projects.keySet().toArray(new IProject[projects.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#getDiff(org.eclipse.core.resources.IResource) - */ - public IDiff getDiff(IResource resource) throws CoreException { - Subscriber subscriber = getSubscriber(resource); - if (subscriber != null) - return subscriber.getDiff(resource); - return super.getDiff(resource); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#getSyncInfo(org.eclipse.core.resources.IResource) - */ - public SyncInfo getSyncInfo(IResource resource) throws TeamException { - Subscriber subscriber = getSubscriber(resource); - if (subscriber != null) - return subscriber.getSyncInfo(resource); - return null; - } - - /** - * Return a dummy comparator. The comparator should not be used by clients. - * - * @see org.eclipse.team.core.subscribers.Subscriber#getResourceComparator() - */ - public IResourceVariantComparator getResourceComparator() { - return new IResourceVariantComparator() { - public boolean isThreeWay() { - return true; - } - public boolean compare(IResourceVariant base, IResourceVariant remote) { - return false; - } - public boolean compare(IResource local, IResourceVariant remote) { - return false; - } - - }; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#refresh(org.eclipse.core.resources.mapping.ResourceTraversal[], org.eclipse.core.runtime.IProgressMonitor) - */ - public void refresh(ResourceTraversal[] traversals, IProgressMonitor monitor) throws TeamException { - try { - List errors = new ArrayList(); - Subscriber[] subscribers = getSubscribers(); - monitor.beginTask(null, subscribers.length * 100); - for (int i = 0; i < subscribers.length; i++) { - Subscriber subscriber = subscribers[i]; - try { - subscriber.refresh(traversals, Policy.subMonitorFor(monitor, 100)); - } catch (TeamException e) { - errors.add(e); - } - } - try { - handleErrors((CoreException[]) errors.toArray(new CoreException[errors.size()])); - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } finally { - monitor.done(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#refresh(org.eclipse.core.resources.IResource[], int, org.eclipse.core.runtime.IProgressMonitor) - */ - public void refresh(IResource[] resources, int depth, - IProgressMonitor monitor) throws TeamException { - refresh(new ResourceTraversal[] { new ResourceTraversal(resources, depth, IResource.NONE)}, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#accept(org.eclipse.core.resources.mapping.ResourceTraversal[], org.eclipse.team.core.diff.IDiffVisitor) - */ - public void accept(ResourceTraversal[] traversals, IDiffVisitor visitor) throws CoreException { - List errors = new ArrayList(); - Subscriber[] subscribers = getSubscribers(); - for (int i = 0; i < subscribers.length; i++) { - Subscriber subscriber = subscribers[i]; - try { - subscriber.accept(traversals, visitor); - } catch (CoreException e) { - errors.add(e); - } - } - handleErrors((CoreException[]) errors.toArray(new CoreException[errors.size()])); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#accept(org.eclipse.core.resources.IResource[], int, org.eclipse.team.core.diff.IDiffVisitor) - */ - public void accept(IResource[] resources, int depth, IDiffVisitor visitor) throws CoreException { - accept(new ResourceTraversal[] { new ResourceTraversal(resources, depth, IResource.NONE)}, visitor); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#getState(org.eclipse.core.resources.mapping.ResourceMapping, int, org.eclipse.core.runtime.IProgressMonitor) - */ - public int getState(ResourceMapping mapping, int stateMask, IProgressMonitor monitor) throws CoreException { - int state = 0; - try { - List errors = new ArrayList(); - Subscriber[] subscribers = getSubscribers(mapping.getProjects()); - monitor.beginTask(null, subscribers.length * 100); - for (int i = 0; i < subscribers.length; i++) { - Subscriber subscriber = subscribers[i]; - try { - int subscriberState = subscriber.getState(mapping, stateMask, Policy.subMonitorFor(monitor, 100)); - state |= subscriberState; - } catch (TeamException e) { - errors.add(e); - } - } - handleErrors((CoreException[]) errors.toArray(new CoreException[errors.size()])); - } finally { - monitor.done(); - } - return state & stateMask; - } - - private Subscriber[] getSubscribers(IProject[] projects) { - for (int i = 0; i < projects.length; i++) { - IProject project = projects[i]; - if (!this.projects.containsKey(project)) { - handleProject(project); - } - } - return getSubscribers(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#collectOutOfSync(org.eclipse.core.resources.IResource[], int, org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor) - */ - public void collectOutOfSync(IResource[] resources, int depth, SyncInfoSet set, IProgressMonitor monitor) { - try { - Subscriber[] subscribers = getSubscribers(); - monitor.beginTask(null, subscribers.length * 100); - for (int i = 0; i < subscribers.length; i++) { - Subscriber subscriber = subscribers[i]; - subscriber.collectOutOfSync(resources, depth, set, Policy.subMonitorFor(monitor, 100)); - } - } finally { - monitor.done(); - } - } - - private Subscriber[] getSubscribers() { - Set result = new HashSet(); - for (Iterator iter = projects.values().iterator(); iter.hasNext();) { - Subscriber subscriber = (Subscriber) iter.next(); - result.add(subscriber); - } - return (Subscriber[]) result.toArray(new Subscriber[result.size()]); - } - - /* - * Return the subscriber for the given resource if the resource - * is in the scope of this subscriber. - */ - private Subscriber getSubscriber(IResource resource) { - return (Subscriber)projects.get(resource.getProject()); - } - - private void handleErrors(CoreException[] exceptions) throws CoreException { - if (exceptions.length == 0) - return; - if (exceptions.length == 1) - throw exceptions[0]; - MultiStatus result = new MultiStatus(TeamPlugin.ID, 0, Messages.WorkspaceSubscriber_1, null); - for (int i = 0; i < exceptions.length; i++) { - CoreException exception = exceptions[i]; - IStatus status = new Status( - exception.getStatus().getSeverity(), - exception.getStatus().getPlugin(), - exception.getStatus().getCode(), - exception.getStatus().getMessage(), - exception); - result.add(status); - } - throw new TeamException(result); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.ISubscriberChangeListener#subscriberResourceChanged(org.eclipse.team.core.subscribers.ISubscriberChangeEvent[]) - */ - public void subscriberResourceChanged(ISubscriberChangeEvent[] deltas) { - fireTeamResourceChange(deltas); - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.core.IRepositoryProviderListener#providerMapped(org.eclipse.team.core.RepositoryProvider) - */ - public void providerMapped(RepositoryProvider provider) { - // Record the subscriber. No need to fire an event since the subscriber should - Subscriber subscriber = provider.getSubscriber(); - if (subscriber != null) - projects.put(provider.getProject(), subscriber); - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.core.IRepositoryProviderListener#providerUnmapped(org.eclipse.core.resources.IProject) - */ - public void providerUnmapped(IProject project) { - // We'll remove the project. No need to fire an event since the subscriber should have done that - projects.remove(project); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) - */ - public void resourceChanged(IResourceChangeEvent event) { - IResourceDelta delta = event.getDelta(); - IResourceDelta[] projectDeltas = delta.getAffectedChildren(IResourceDelta.ADDED | IResourceDelta.CHANGED); - for (int i = 0; i < projectDeltas.length; i++) { - IResourceDelta projectDelta = projectDeltas[i]; - IResource resource = projectDelta.getResource(); - if ((projectDelta.getFlags() & IResourceDelta.OPEN) != 0 - && resource.getType() == IResource.PROJECT) { - IProject project = (IProject)resource; - if (project.isAccessible()) { - handleProject(project); - } else { - projects.remove(project); - } - } - } - } -} diff --git a/bundles/org.eclipse.team.cvs.ui/plugin.xml b/bundles/org.eclipse.team.cvs.ui/plugin.xml index eddd8c79b..567a4266e 100644 --- a/bundles/org.eclipse.team.cvs.ui/plugin.xml +++ b/bundles/org.eclipse.team.cvs.ui/plugin.xml @@ -1550,6 +1550,11 @@ class="org.eclipse.team.internal.ccvs.ui.model.CVSAdapterFactory"> <adapter type="org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter"/> </factory> + <factory + adaptableType="org.eclipse.team.internal.ccvs.core.CVSTeamProviderType" + class="org.eclipse.team.internal.ccvs.ui.model.CVSAdapterFactory"> + <adapter type="org.eclipse.team.ui.mapping.ITeamStateProvider"/> + </factory> </extension> <extension point="org.eclipse.team.ui.teamDecorators"> diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecoration.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecoration.java index 8c749070b..5b195f6ce 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecoration.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecoration.java @@ -20,11 +20,13 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IDecoration; import org.eclipse.swt.graphics.*; +import org.eclipse.team.core.diff.IThreeWayDiff; import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager; import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot; import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.ui.ISharedImages; +import org.eclipse.team.ui.synchronize.TeamStateDescription; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.themes.ITheme; @@ -75,6 +77,7 @@ public class CVSDecoration { private String repository; private ICVSRepositoryLocation location; private String keywordSubstitution; + private int stateFlags; // Text formatters private String fileFormatter; @@ -93,7 +96,7 @@ public class CVSDecoration { // List of preferences used to configure the decorations that // are applied. private Preferences preferences; - + /* * Define a cached image descriptor which only creates the image data once */ @@ -286,6 +289,8 @@ public class CVSDecoration { if (isWatchEditEnabled() && resourceType == IResource.FILE && !isReadOnly() && isHasRemote()) { return edited; } + if (needsMerge) + return merged; // show checked in if (preferences.getBoolean(ICVSUIConstants.PREF_SHOW_HASREMOTE_DECORATION) && isHasRemote()) { if ((resourceType == IResource.FOLDER || resourceType == IResource.PROJECT) && isVirtualFolder()) { @@ -293,8 +298,6 @@ public class CVSDecoration { } return checkedIn; } - if (needsMerge) - return merged; //nothing matched return null; @@ -429,4 +432,34 @@ public class CVSDecoration { public void setVirtualFolder(boolean virtualFolder) { this.virtualFolder = virtualFolder; } + + public void setStateFlags(int stateFlags) { + this.stateFlags = stateFlags; + if ((stateFlags & IThreeWayDiff.OUTGOING) != 0) { + setDirty(true); + } + } + + public TeamStateDescription asTeamStateDescription(String[] properties) { + TeamStateDescription desc = new CVSTeamStateDescription(stateFlags); + Object o = computeImage(); + if (o != null && isRequestedProperty(properties, CVSTeamStateDescription.PROP_RESOURCE_STATE)) { + desc.setProperty(CVSTeamStateDescription.PROP_RESOURCE_STATE, o); + } + if (tag != null && isRequestedProperty(properties, CVSTeamStateDescription.PROP_TAG)) { + desc.setProperty(CVSTeamStateDescription.PROP_TAG, tag); + } + return desc; + } + + private boolean isRequestedProperty(String[] properties, String property) { + if (properties == null) + return true; + for (int i = 0; i < properties.length; i++) { + String string = properties[i]; + if (string.equals(property)) + return true; + } + return false; + } } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java index 3a8037330..d0612d2ae 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java @@ -15,7 +15,7 @@ import java.text.SimpleDateFormat; import java.util.*; import org.eclipse.core.resources.*; -import org.eclipse.core.resources.mapping.ResourceMapping; +import org.eclipse.core.resources.mapping.*; import org.eclipse.core.runtime.*; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; @@ -162,7 +162,7 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig handleException(element, e); } catch (IllegalStateException e) { // This is thrown by Core if the workspace is in an illegal state - // If we are not active, ignore it. Otherwise, propogate it. + // If we are not active, ignore it. Otherwise, propagate it. // (see bug 78303) if (Platform.getBundle(CVSUIPlugin.ID).getState() == Bundle.ACTIVE) { throw e; @@ -170,7 +170,7 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig } } - private IResource getResource(Object element) { + private static IResource getResource(Object element) { if (element instanceof ResourceMapping) { element = ((ResourceMapping) element).getModelObject(); } @@ -191,27 +191,41 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig return false; } - private CVSDecoration decorate(Object element, SynchronizationStateTester tester) throws CoreException { + public static CVSDecoration decorate(Object element, SynchronizationStateTester tester) throws CoreException { IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); CVSDecoration result = new CVSDecoration(); // First, decorate the synchronization state - if (tester.isStateDecorationEnabled()) { - if (tester.isSupervised(element)) { + int state = IDiff.NO_CHANGE; + if (tester.isDecorationEnabled(element)) { + if (isSupervised(element)) { result.setHasRemote(true); - int state = tester.getState(element, + state = tester.getState(element, store.getBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY) ? IDiff.ADD | IDiff.REMOVE | IDiff.CHANGE | IThreeWayDiff.OUTGOING : 0, new NullProgressMonitor()); - if ((state & IThreeWayDiff.OUTGOING) != 0) { - result.setDirty(true); - } + result.setStateFlags(state); } else { result.setIgnored(true); } } + // Tag + if (!result.isIgnored()) { + CVSTag tag = getTagToShow(element); + if (tag != null) { + String name = tag.getName(); + if (tag.getType() == CVSTag.DATE) { + Date date = tag.asDate(); + if (date != null) { + name = decorateFormatter.format(date); + } + } + result.setTag(name); + } + } + // If the element adapts to a single resource, add additional decorations IResource resource = getResource(element); if (resource == null) { @@ -219,9 +233,37 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig } else { decorate(resource, result); } + tester.elementDecorated(element, result.asTeamStateDescription(null)); return result; } + private static boolean isSupervised(Object element) throws CoreException { + IResource[] resources = getTraversalRoots(element); + for (int i = 0; i < resources.length; i++) { + IResource resource = resources[i]; + if (getSubscriber().isSupervised(resource)) + return true; + } + return false; + } + + private static IResource[] getTraversalRoots(Object element) throws CoreException { + Set result = new HashSet(); + ResourceMapping mapping = Utils.getResourceMapping(element); + if (mapping != null) { + ResourceTraversal[] traversals = mapping.getTraversals(ResourceMappingContext.LOCAL_CONTEXT, null); + for (int i = 0; i < traversals.length; i++) { + ResourceTraversal traversal = traversals[i]; + IResource[] resources = traversal.getResources(); + for (int j = 0; j < resources.length; j++) { + IResource resource = resources[j]; + result.add(resource); + } + } + } + return (IResource[]) result.toArray(new IResource[result.size()]); + } + private static void decorate(IResource resource, CVSDecoration cvsDecoration) throws CVSException { IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); @@ -250,18 +292,6 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig // Has a remote //cvsDecoration.setHasRemote(CVSWorkspaceRoot.hasRemote(resource)); } - // Tag - CVSTag tag = getTagToShow(resource); - if (tag != null) { - String name = tag.getName(); - if (tag.getType() == CVSTag.DATE) { - Date date = tag.asDate(); - if (date != null) { - name = decorateFormatter.format(date); - } - } - cvsDecoration.setTag(name); - } // Is a new resource if (store.getBoolean(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION)) { if (cvsResource.exists()) { @@ -333,6 +363,37 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig cvsDecoration.setWatchEditEnabled(provider.isWatchEditEnabled()); } + protected static CVSTag getTagToShow(Object element) throws CoreException { + IResource r = getResource(element); + if (r != null) + return getTagToShow(r); + IResource[] resources = getTraversalRoots(element); + boolean first = true; + CVSTag tag = null; + for (int i = 0; i < resources.length; i++) { + IResource resource = resources[i]; + if (getSubscriber().isSupervised(resource)) { + CVSTag nextTag = getTagToShow(resource); + if (first) { + tag = nextTag; + first = false; + } else if (!equals(tag, nextTag)) { + return null; + } + + } + } + return tag; + } + + private static boolean equals(CVSTag tag, CVSTag nextTag) { + if (tag == nextTag) + return true; + if (tag == null || nextTag == null) + return false; + return tag.getName().equals(nextTag.getName()); + } + /** * Only show the tag if the resources tag is different than the parents. Or else, tag * names will clutter the text decorations. diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSTeamStateDescription.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSTeamStateDescription.java new file mode 100644 index 000000000..1b1f59e17 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSTeamStateDescription.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui; + +import org.eclipse.team.ui.synchronize.TeamStateDescription; + +/** + * A state description for the CVS decorations. We only need to + * enumerate the states that can be associated with model + * elements that don't have a one-to-one mapping to resources + */ +public class CVSTeamStateDescription extends TeamStateDescription { + + /** + * Property representing the image overlay + */ + public static final String PROP_RESOURCE_STATE = "resourceState"; //$NON-NLS-1$ + public static final String PROP_TAG = "tag"; //$NON-NLS-1$ + + public CVSTeamStateDescription(int state) { + super(state); + } +} diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSTeamStateProvider.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSTeamStateProvider.java new file mode 100644 index 000000000..3acb8a1b0 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSTeamStateProvider.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.core.subscribers.Subscriber; +import org.eclipse.team.ui.mapping.*; +import org.eclipse.team.ui.synchronize.SubscriberTeamStateProvider; + +public class CVSTeamStateProvider extends SubscriberTeamStateProvider { + + public CVSTeamStateProvider(Subscriber subscriber) { + super(subscriber); + } + + public ITeamStateDescription getStateDescription(Object element, final int requestedStateMask, String[] properties, IProgressMonitor monitor) throws CoreException { + if (properties != null && properties.length == 0) { + return new CVSTeamStateDescription(getSynchronizationState(element, requestedStateMask, monitor)); + } + CVSDecoration d = CVSLightweightDecorator.decorate(element, new SynchronizationStateTester() { + public int getState(Object element, int stateMask, IProgressMonitor monitor) throws CoreException { + if (requestedStateMask != USE_DECORATED_STATE_MASK) { + stateMask = requestedStateMask & stateMask; + } + return getSynchronizationState(element, requestedStateMask & stateMask, monitor); + } + }); + return d.asTeamStateDescription(properties); + } +} diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSAdapterFactory.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSAdapterFactory.java index ef0aa7440..3f999b1df 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSAdapterFactory.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSAdapterFactory.java @@ -14,19 +14,23 @@ package org.eclipse.team.internal.ccvs.ui.model; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.team.internal.ccvs.core.*; import org.eclipse.team.internal.ccvs.ui.CVSHistoryPageSource; +import org.eclipse.team.internal.ccvs.ui.CVSTeamStateProvider; import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot; import org.eclipse.team.ui.history.IHistoryPageSource; import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter; +import org.eclipse.team.ui.mapping.ITeamStateProvider; import org.eclipse.ui.model.IWorkbenchAdapter; import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; import org.eclipse.ui.views.properties.IPropertySource; public class CVSAdapterFactory implements IAdapterFactory { - private Object fileAdapter = new RemoteFileElement(); - private Object folderAdapter = new RemoteFolderElement(); - private Object rootAdapter = new CVSRepositoryRootElement(); + private static Object fileAdapter = new RemoteFileElement(); + private static Object folderAdapter = new RemoteFolderElement(); + private static Object rootAdapter = new CVSRepositoryRootElement(); - private Object historyParticipant = new CVSHistoryPageSource(); + private static Object historyParticipant = new CVSHistoryPageSource(); + + private static Object teamStateProvider; // Property cache private Object cachedPropertyObject = null; @@ -56,6 +60,14 @@ public class CVSAdapterFactory implements IAdapterFactory { return historyParticipant; } + if (ITeamStateProvider.class == adapterType) { + synchronized (this) { + if (teamStateProvider == null) + teamStateProvider = new CVSTeamStateProvider(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber()); + } + return teamStateProvider; + } + return null; } @@ -76,8 +88,11 @@ public class CVSAdapterFactory implements IAdapterFactory { * Method declared on IAdapterFactory. */ public Class[] getAdapterList() { - return new Class[] {IWorkbenchAdapter.class, IPropertySource.class, IDeferredWorkbenchAdapter.class, IHistoryPageSource.class, ISynchronizationCompareAdapter.class}; + return new Class[] { IWorkbenchAdapter.class, IPropertySource.class, + IDeferredWorkbenchAdapter.class, IHistoryPageSource.class, + ISynchronizationCompareAdapter.class, ITeamStateProvider.class }; } + /** * Returns the property source for the given object. Caches * the result because the property sheet is extremely inefficient, |