Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2004-02-02 15:26:52 -0500
committerJean Michel-Lemieux2004-02-02 15:26:52 -0500
commit725e99cc9c62049e10a4f1310033b07261a4ce66 (patch)
treeb0b60b05732dd7d568e4a6e1795f8cff4223cf14
parent27fbb256382e6819ada2efdbef5c043275a07640 (diff)
downloadeclipse.platform.team-branch_20040201_beforeeclipsecon_jean-michel.tar.gz
eclipse.platform.team-branch_20040201_beforeeclipsecon_jean-michel.tar.xz
eclipse.platform.team-branch_20040201_beforeeclipsecon_jean-michel.zip
-rw-r--r--bundles/org.eclipse.team.ui/TODO-syncview.txt4
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java16
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenFileInSystemEditorAction.java14
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenWithActionGroup.java13
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java19
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/compare/LocalResourceTypedElement.java5
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/views/TreeViewerUtils.java28
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffNode.java79
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/actions/RefreshAction.java20
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeBuilder.java15
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeSorter.java5
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoLabelProvider.java180
12 files changed, 161 insertions, 237 deletions
diff --git a/bundles/org.eclipse.team.ui/TODO-syncview.txt b/bundles/org.eclipse.team.ui/TODO-syncview.txt
index 54ec58d4f..5a524adde 100644
--- a/bundles/org.eclipse.team.ui/TODO-syncview.txt
+++ b/bundles/org.eclipse.team.ui/TODO-syncview.txt
@@ -116,4 +116,6 @@ x memory and sync set disposal in syncsetcompare input!!!! VERY IMPORTANT!!!
- need tests for these scenarios to ensure generated event is correct after addition and removal
- there are several places in SyncInfoSet and in the DiffNodes where we must use the workspace root
as the input resource to imply get all members? Maybe this should be cleaned up a bit.
-- SyncInfoSet must be cleaned up a lot, the API is vague and method names are not clear. \ No newline at end of file
+- SyncInfoSet must be cleaned up a lot, the API is vague and method names are not clear.
+- SyncInfoDiffNode doesn't have to return a resource or a syncinfo. By definition a diff node already has API
+for returning a sync kind getKind() and access to all three resources getRight(), getLeft(), getAncestor(). \ No newline at end of file
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
index 43357fdba..e13c4b93a 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
@@ -27,6 +27,7 @@ import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.ISubscriberResource;
import org.eclipse.team.core.subscribers.SyncInfo;
import org.eclipse.team.ui.TeamImages;
+import org.eclipse.team.ui.synchronize.SyncInfoDiffNode;
import org.eclipse.team.ui.synchronize.TeamSubscriberParticipant;
import org.eclipse.ui.*;
import org.eclipse.team.internal.ui.Policy;
@@ -384,13 +385,18 @@ public class Utils {
List resources = new ArrayList();
for (int i = 0; i < elements.length; i++) {
Object element = elements[i];
+ IResource resource = null;
if(element instanceof IResource) {
- resources.add(element);
+ resource = (IResource)element;
} else if(element instanceof IAdaptable) {
- IResource resource = (IResource)((IAdaptable)element).getAdapter(IResource.class);
- if(resource != null) {
- resources.add(resource);
- }
+ resource = (IResource)((IAdaptable)element).getAdapter(IResource.class);
+
+ } else if(element instanceof SyncInfoDiffNode) {
+ resource = ((SyncInfoDiffNode)element).getResource();
+ }
+
+ if(resource != null) {
+ resources.add(resource);
}
}
return (IResource[]) resources.toArray(new IResource[resources.size()]);
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenFileInSystemEditorAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenFileInSystemEditorAction.java
index 2a5efc2a2..8564d3d8e 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenFileInSystemEditorAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenFileInSystemEditorAction.java
@@ -14,7 +14,7 @@ import java.util.*;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.team.internal.ui.synchronize.views.TreeViewerUtils;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.actions.OpenFileAction;
@@ -28,19 +28,11 @@ public class OpenFileInSystemEditorAction extends OpenFileAction {
* @see org.eclipse.ui.actions.SelectionListenerAction#getSelectedResources()
*/
protected List getSelectedResources() {
- List resources = new ArrayList();
IStructuredSelection selection = getStructuredSelection();
- for (Iterator e = selection.iterator(); e.hasNext();) {
- Object next = e.next();
- IResource resource = TreeViewerUtils.getResource(next);
- if(resource != null) {
- resources.add(resource);
- }
- }
- return resources;
+ IResource[] resources = Utils.getResources(selection.toArray());
+ return Arrays.asList(resources);
}
-
/* (non-Javadoc)
* @see org.eclipse.ui.actions.SelectionListenerAction#getSelectedNonResources()
*/
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenWithActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenWithActionGroup.java
index e34a484cc..482148ac1 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenWithActionGroup.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenWithActionGroup.java
@@ -15,7 +15,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.team.internal.ui.synchronize.views.TreeViewerUtils;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.synchronize.*;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.actions.OpenWithMenu;
@@ -60,11 +60,14 @@ public class OpenWithActionGroup extends ActionGroup {
if (selection == null || selection.size() != 1)
return;
Object element = selection.getFirstElement();
- IResource resource = TreeViewerUtils.getResource(element);
- if (!(resource instanceof IFile)) {
- return;
+ IResource resources[] = Utils.getResources(new Object[] {element});
+ IResource resource = null;
+ if(resources.length == 1) {
+ resource = resources[0];
}
-
+
+ if(resource.getType() != IResource.FILE) return;
+
menu.add(openInCompareAction);
if(!((resource.exists()))) {
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java
index ebca84301..d4cac9366 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.synchronize.actions;
-import java.util.*;
+import java.util.Iterator;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
@@ -20,7 +20,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.internal.ui.Policy;
-import org.eclipse.team.internal.ui.synchronize.views.TreeViewerUtils;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.*;
@@ -66,15 +66,7 @@ public class RefactorActionGroup extends ActionGroup {
}
private IStructuredSelection convertSelection(IStructuredSelection selection) {
- List resources = new ArrayList();
- Iterator it = selection.iterator();
- while(it.hasNext()) {
- IResource resource = TreeViewerUtils.getResource(it.next());
- if(resource != null) {
- resources.add(resource);
- }
- }
- return new StructuredSelection(resources);
+ return new StructuredSelection(Utils.getResources(selection.toArray()));
}
public void fillActionBars(IActionBars actionBars) {
@@ -129,7 +121,10 @@ public class RefactorActionGroup extends ActionGroup {
resource = (IResource)adaptable.getAdapter(IResource.class);
}
if(resource == null) {
- resource = TreeViewerUtils.getResource(next);
+ IResource[] r = Utils.getResources(new Object[] {next});
+ if(r.length == 1) {
+ resource = r[0];
+ }
}
if (resource == null || (resource.getType() & resourceMask) == 0) {
return false;
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/compare/LocalResourceTypedElement.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/compare/LocalResourceTypedElement.java
index f62246052..f8a9759cd 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/compare/LocalResourceTypedElement.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/compare/LocalResourceTypedElement.java
@@ -28,7 +28,10 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
/**
- * LocalResourceTypedElement
+ * A resource node that is not buffered. Changes made to it are applied directly
+ * to the underlying resource.
+ *
+ * @since 3.0
*/
public class LocalResourceTypedElement extends ResourceNode {
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/views/TreeViewerUtils.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/views/TreeViewerUtils.java
index 6499e77f3..f1ae3d876 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/views/TreeViewerUtils.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/views/TreeViewerUtils.java
@@ -10,13 +10,9 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.synchronize.views;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.team.core.subscribers.SyncInfo;
-import org.eclipse.team.ui.synchronize.SyncInfoDiffNode;
public class TreeViewerUtils {
/**
@@ -167,28 +163,4 @@ public class TreeViewerUtils {
return item;
}
-
- /**
- * Returns the implementation of SyncInfo for the given
- * object. Returns <code>null</code> if the adapter is not defined or the
- * object is not adaptable.
- */
- public static SyncInfo getSyncInfo(Object o) {
- if (!(o instanceof IAdaptable)) {
- return null;
- }
- return (SyncInfo) ((IAdaptable) o).getAdapter(SyncInfo.class);
- }
-
- public static IResource getResource(Object obj) {
- SyncInfo info = getSyncInfo(obj);
- if (info == null) {
- if (obj instanceof SyncInfoDiffNode) {
- return ((SyncInfoDiffNode)obj).getResource();
- }
- } else {
- return info.getLocal();
- }
- return null;
- }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffNode.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffNode.java
index 87818e5ea..ae1769376 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffNode.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffNode.java
@@ -11,6 +11,7 @@
package org.eclipse.team.ui.synchronize;
import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.ResourceNode;
import org.eclipse.compare.structuremergeviewer.DiffNode;
import org.eclipse.compare.structuremergeviewer.IDiffContainer;
import org.eclipse.core.resources.IResource;
@@ -26,9 +27,8 @@ import org.eclipse.ui.model.IWorkbenchAdapter;
public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbenchAdapter {
- private IResource resource;
private SyncInfoSet syncSet;
- private SyncInfo info;
+ private SyncInfo info;
/**
* Create an ITypedElement for the given local resource. The returned ITypedElement
@@ -111,9 +111,7 @@ public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbench
*/
public SyncInfoDiffNode(IDiffContainer parent, SyncInfoSet set, IResource resource) {
this(parent, createBaseTypeElement(set, resource), createLocalTypeElement(set, resource), createRemoteTypeElement(set, resource), getSyncKind(set, resource));
- this.syncSet = set;
- this.resource = resource;
- this.info = null;
+ this.syncSet = set;
}
/**
@@ -125,32 +123,36 @@ public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbench
public SyncInfoDiffNode(SyncInfo info) {
this(null, createBaseTypeElement(info), createLocalTypeElement(info), createRemoteTypeElement(info), info.getKind());
this.info = info;
- this.syncSet = null;
- this.resource = info.getLocal();
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class adapter) {
- if (adapter == SyncInfo.class) {
- return getSyncInfo();
- }
if(adapter == IWorkbenchAdapter.class) {
return this;
}
return null;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.team.ui.sync.ISynchronizeViewNode#getSyncInfo()
+
+ /**
+ * Return the <code>SyncInfoSet</code> from which this diff node was derived.
+ * @return a <code>SyncInfoSet</code>
*/
- public SyncInfo getSyncInfo() {
- SyncInfoSet input = getSyncInfoSet();
- if(info != null) {
- return info;
- } else if(input != null && resource != null) {
- return input.getSyncInfo(resource);
+ public SyncInfoSet getSyncInfoSet() {
+ return syncSet;
+ }
+
+ /**
+ * Helper method that returns the resource associated with this node. A node is not
+ * required to have an associated local resource.
+ * @return the resource associated with this node or <code>null</code> if the local
+ * contributor is not a resource.
+ */
+ public IResource getResource() {
+ ITypedElement element = getLeft();
+ if(element instanceof ResourceNode) {
+ return ((ResourceNode)element).getResource();
}
return null;
}
@@ -161,7 +163,9 @@ public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbench
*/
public SyncInfo[] getDescendantSyncInfos() {
SyncInfoSet input = getSyncInfoSet();
- if(input != null && getResource() != null) {
+ IResource resource = getResource();
+ SyncInfo info = getSyncInfo();
+ if(input != null && resource != null) {
return input.getOutOfSyncDescendants(resource);
} else if(info != null) {
return new SyncInfo[] {info};
@@ -188,13 +192,6 @@ public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbench
}
return resource.hashCode();
}
-
- /**
- * @return IResource The receiver's resource
- */
- public IResource getResource() {
- return resource;
- }
/* (non-Javadoc)
* @see java.lang.Object#toString()
@@ -225,28 +222,11 @@ public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbench
}
/**
- * Return the <code>SyncInfoSet</code> from which this diff node was derived.
- * @return a <code>SyncInfoSet</code>
- */
- public SyncInfoSet getSyncInfoSet() {
- return syncSet;
- }
-
- /**
- * Indicates whether the diff node represents a resource path or a single level.
- * This is used by the <code>SyncViewerSorter</code> to determine whether to compare
- * the full path of two resources or justtheir names.
- * @return whether the node represents a resource path
- */
- public boolean isResourcePath() {
- return false;
- }
-
- /**
* Return whether this diff node has descendant conflicts in the view in which it appears.
* @return whether the node has descendant conflicts
*/
public boolean hasDecendantConflicts() {
+ IResource resource = getResource();
// If this node has no resource, we can't tell
// The subclass which created the node with no resource should have overridden this method
if (resource != null && resource.getType() == IResource.FILE) return false;
@@ -264,6 +244,12 @@ public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbench
return false;
}
+ protected SyncInfo getSyncInfo() {
+ return info;
+ }
+
+ /** WorkbenchAdapter methods **/
+
/* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
*/
@@ -301,7 +287,8 @@ public class SyncInfoDiffNode extends DiffNode implements IAdaptable, IWorkbench
* @see org.eclipse.compare.structuremergeviewer.DiffNode#getName()
*/
public String getName() {
- if (getResource() != null) {
+ IResource resource = getResource();
+ if (resource != null) {
return resource.getName();
}
return super.getName();
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/actions/RefreshAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/actions/RefreshAction.java
index 072afcb68..1b9c38e1a 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/actions/RefreshAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/actions/RefreshAction.java
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.team.ui.synchronize.actions;
-import java.util.*;
-
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
@@ -21,7 +19,6 @@ import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.internal.ui.jobs.RefreshSubscriberJob;
import org.eclipse.team.internal.ui.synchronize.IRefreshSubscriberListener;
-import org.eclipse.team.internal.ui.synchronize.views.TreeViewerUtils;
/**
* A general refresh action that will refresh a subscriber in the background.
@@ -57,7 +54,7 @@ public class RefreshAction extends Action {
public void run() {
ISelection selection = selectionProvider.getSelection();
if(selection instanceof IStructuredSelection) {
- IResource[] resources = getResources((IStructuredSelection)selection);
+ IResource[] resources = Utils.getResources(((IStructuredSelection)selection).toArray());
if (refreshAll || resources.length == 0) {
// If no resources are selected, refresh all the subscriber roots
resources = collector.getRoots();
@@ -65,19 +62,4 @@ public class RefreshAction extends Action {
run(description, resources, collector, listener);
}
}
-
- private IResource[] getResources(IStructuredSelection selection) {
- if(selection == null) {
- return new IResource[0];
- }
- List resources = new ArrayList();
- Iterator it = selection.iterator();
- while(it.hasNext()) {
- IResource resource = TreeViewerUtils.getResource(it.next());
- if(resource != null) {
- resources.add(resource);
- }
- }
- return (IResource[]) resources.toArray(new IResource[resources.size()]);
- }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeBuilder.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeBuilder.java
index 7bb773fa1..dd51d7399 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeBuilder.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeBuilder.java
@@ -63,14 +63,15 @@ public class SyncInfoDiffNodeBuilder implements ISyncSetChangedListener {
if (container instanceof SyncInfoDiffNode) {
SyncInfoDiffNode parentNode = (SyncInfoDiffNode)container;
IResource resource = parentNode.getResource();
- if (resource != null) {
- IResource[] children = parentNode.getSyncInfoSet().members(resource);
- SyncInfoDiffNode[] nodes = new SyncInfoDiffNode[children.length];
- for (int i = 0; i < children.length; i++) {
- nodes[i] = createChildNode(parentNode, children[i]);
- }
- return nodes;
+ if (resource == null) {
+ resource = ResourcesPlugin.getWorkspace().getRoot();
+ }
+ IResource[] children = parentNode.getSyncInfoSet().members(resource);
+ SyncInfoDiffNode[] nodes = new SyncInfoDiffNode[children.length];
+ for (int i = 0; i < children.length; i++) {
+ nodes[i] = createChildNode(parentNode, children[i]);
}
+ return nodes;
}
return new IDiffElement[0];
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeSorter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeSorter.java
index c22018391..4179b2675 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeSorter.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoDiffNodeSorter.java
@@ -12,7 +12,7 @@ package org.eclipse.team.ui.synchronize.views;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.team.internal.ui.synchronize.views.TreeViewerUtils;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.ui.views.navigator.ResourceSorter;
/**
@@ -41,6 +41,7 @@ public class SyncInfoDiffNodeSorter extends ResourceSorter {
}
protected IResource getResource(Object obj) {
- return TreeViewerUtils.getResource(obj);
+ IResource[] resources = Utils.getResources(new Object[] {obj});
+ return resources.length == 1 ? resources[0] : null;
}
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoLabelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoLabelProvider.java
index 5069559e8..9ac552565 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoLabelProvider.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/views/SyncInfoLabelProvider.java
@@ -13,19 +13,14 @@ package org.eclipse.team.ui.synchronize.views;
import java.util.*;
import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.*;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.core.subscribers.*;
import org.eclipse.team.internal.ui.*;
-import org.eclipse.team.internal.ui.synchronize.views.TreeViewerUtils;
import org.eclipse.team.ui.ISharedImages;
import org.eclipse.team.ui.synchronize.SyncInfoDiffNode;
import org.eclipse.ui.internal.WorkbenchColors;
@@ -35,13 +30,13 @@ import org.eclipse.ui.model.WorkbenchLabelProvider;
* @since 3.0
*/
public class SyncInfoLabelProvider extends LabelProvider implements IColorProvider {
-
+
private boolean working = false;
// cache for folder images that have been overlayed with conflict icon
- private Map fgImageCache;
+ private Map fgImageCache;
CompareConfiguration compareConfig = new CompareConfiguration();
private WorkbenchLabelProvider workbenchLabelProvider = new WorkbenchLabelProvider();
-
+
/**
* Decorating label provider that also support color providers
*/
@@ -51,35 +46,38 @@ public class SyncInfoLabelProvider extends LabelProvider implements IColorProvid
super(provider, decorator);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
*/
public Color getForeground(Object element) {
ILabelProvider p = getLabelProvider();
- if(p instanceof IColorProvider) {
- return ((IColorProvider)p).getForeground(element);
+ if (p instanceof IColorProvider) {
+ return ((IColorProvider) p).getForeground(element);
}
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
*/
public Color getBackground(Object element) {
ILabelProvider p = getLabelProvider();
- if(p instanceof IColorProvider) {
- return ((IColorProvider)p).getBackground(element);
+ if (p instanceof IColorProvider) {
+ return ((IColorProvider) p).getBackground(element);
}
return null;
}
}
-
public SyncInfoLabelProvider() {
JobStatusHandler.addJobListener(new IJobListener() {
+
public void started(QualifiedName jobType) {
working = true;
Display.getDefault().asyncExec(new Runnable() {
+
public void run() {
// TODO: What this is this supposed to be?
synchronized (this) {
@@ -88,9 +86,11 @@ public class SyncInfoLabelProvider extends LabelProvider implements IColorProvid
}
});
}
+
public void finished(QualifiedName jobType) {
working = false;
Display.getDefault().asyncExec(new Runnable() {
+
public void run() {
synchronized (this) {
fireLabelProviderChanged(new LabelProviderChangedEvent(SyncInfoLabelProvider.this));
@@ -99,141 +99,121 @@ public class SyncInfoLabelProvider extends LabelProvider implements IColorProvid
});
}
}, TeamSubscriber.SUBSCRIBER_JOB_TYPE);
-
- // The label provider may of been created after the subscriber job has been
+ // The label provider may of been created after the subscriber job has
+ // been
// started.
this.working = JobStatusHandler.hasRunningJobs(TeamSubscriber.SUBSCRIBER_JOB_TYPE);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
*/
- public Color getForeground(Object element) {
- if (working) {
+ public Color getForeground(Object element) {
+ if (working) {
return WorkbenchColors.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- } else {
+ } else {
return null;
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
*/
public Color getBackground(Object element) {
return null;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
*/
public Image getImage(Object element) {
Image base = workbenchLabelProvider.getImage(element);
- if(base != null) {
- SyncInfo info = getSyncInfo(element);
- Image decoratedImage;
- IResource local;
- if(info == null) {
- // TODO: How do we decorate parents of conflicts that have no resource
- local = TreeViewerUtils.getResource(element);
- // The reason we still overlay the compare image is to ensure
- // that the image width for all images shown in the viewer
- // are consistent.
- decoratedImage = getCompareImage(base, SyncInfo.IN_SYNC);
- } else {
- local = info.getLocal();
- decoratedImage = getCompareImage(base, info.getKind());
+ if (base != null) {
+ if (element instanceof SyncInfoDiffNode) {
+ SyncInfoDiffNode syncNode = (SyncInfoDiffNode) element;
+ int kind = syncNode.getKind();
+ Image decoratedImage;
+ if (syncNode.hasChildren()) {
+ // The reason we still overlay the compare image is to
+ // ensure
+ // that the image width for all images shown in the viewer
+ // are consistent.
+ decoratedImage = getCompareImage(base, kind);
+ return propagateConflicts(decoratedImage, syncNode);
+ }
}
- return propagateConflicts(decoratedImage, element, local);
}
return base;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
public String getText(Object element) {
String base = workbenchLabelProvider.getText(element);
- if (TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_SYNCINFO_IN_LABEL)) {
- SyncInfo info = getSyncInfo(element);
- if (info != null && info.getKind() != SyncInfo.IN_SYNC) {
- String syncKindString = SyncInfo.kindToString(info.getKind());
- return Policy.bind("TeamSubscriberSyncPage.labelWithSyncKind", base, syncKindString); //$NON-NLS-1$
+ if (element instanceof SyncInfoDiffNode) {
+ if (TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_SYNCINFO_IN_LABEL)) {
+ // if the folder is already conflicting then don't bother
+ // propagating the conflict
+ int kind = ((SyncInfoDiffNode) element).getKind();
+ if (kind != SyncInfo.IN_SYNC) {
+ String syncKindString = SyncInfo.kindToString(kind);
+ return Policy.bind("TeamSubscriberSyncPage.labelWithSyncKind", base, syncKindString); //$NON-NLS-1$
+ }
}
}
return base;
}
-
+
protected Image getCompareImage(Image base, int kind) {
switch (kind & SyncInfo.DIRECTION_MASK) {
- case SyncInfo.OUTGOING:
- kind = (kind &~ SyncInfo.OUTGOING) | SyncInfo.INCOMING;
+ case SyncInfo.OUTGOING :
+ kind = (kind & ~SyncInfo.OUTGOING) | SyncInfo.INCOMING;
break;
- case SyncInfo.INCOMING:
- kind = (kind &~ SyncInfo.INCOMING) | SyncInfo.OUTGOING;
+ case SyncInfo.INCOMING :
+ kind = (kind & ~SyncInfo.INCOMING) | SyncInfo.OUTGOING;
break;
- }
+ }
return compareConfig.getImage(base, kind);
}
-
- private Image propagateConflicts(Image base, Object element, IResource resource) {
- if (resource != null && resource.getType() == IResource.FILE) return base;
- if(element instanceof SyncInfoDiffNode) {
- // if the folder is already conflicting then don't bother propagating the conflict
- int kind = getSyncKind(element);
- if((kind & SyncInfo.DIRECTION_MASK) != SyncInfo.CONFLICTING) {
- if(((SyncInfoDiffNode)element).hasDecendantConflicts()) {
- ImageDescriptor overlay = new OverlayIcon(
- base,
- new ImageDescriptor[] { TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_CONFLICT_OVR)},
- new int[] {OverlayIcon.BOTTOM_LEFT},
- new Point(base.getBounds().width, base.getBounds().height));
-
- if(fgImageCache == null) {
- fgImageCache = new HashMap(10);
- }
- Image conflictDecoratedImage = (Image) fgImageCache.get(overlay);
- if (conflictDecoratedImage == null) {
- conflictDecoratedImage = overlay.createImage();
- fgImageCache.put(overlay, conflictDecoratedImage);
- }
- return conflictDecoratedImage;
+
+ private Image propagateConflicts(Image base, SyncInfoDiffNode element) {
+ // if the folder is already conflicting then don't bother propagating
+ // the conflict
+ int kind = element.getKind();
+ if ((kind & SyncInfo.DIRECTION_MASK) != SyncInfo.CONFLICTING) {
+ if (element.hasDecendantConflicts()) {
+ ImageDescriptor overlay = new OverlayIcon(base, new ImageDescriptor[]{TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_CONFLICT_OVR)}, new int[]{OverlayIcon.BOTTOM_LEFT}, new Point(base.getBounds().width, base.getBounds().height));
+ if (fgImageCache == null) {
+ fgImageCache = new HashMap(10);
+ }
+ Image conflictDecoratedImage = (Image) fgImageCache.get(overlay);
+ if (conflictDecoratedImage == null) {
+ conflictDecoratedImage = overlay.createImage();
+ fgImageCache.put(overlay, conflictDecoratedImage);
}
+ return conflictDecoratedImage;
}
}
return base;
}
-
- private int getSyncKind(Object element) {
- SyncInfo info = getSyncInfo(element);
- if (info != null) {
- return info.getKind();
- }
- return SyncInfo.IN_SYNC;
- }
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
*/
public void dispose() {
compareConfig.dispose();
- if(fgImageCache != null) {
+ if (fgImageCache != null) {
Iterator it = fgImageCache.values().iterator();
while (it.hasNext()) {
Image element = (Image) it.next();
- element.dispose();
+ element.dispose();
}
}
}
-
- /**
- * Returns the implementation of SyncInfo for the given
- * object. Returns <code>null</code> if the adapter is not defined or the
- * object is not adaptable.
- */
- protected final SyncInfo getSyncInfo(Object o) {
- if (!(o instanceof IAdaptable)) {
- return null;
- }
- return (SyncInfo) ((IAdaptable) o).getAdapter(SyncInfo.class);
- }
} \ No newline at end of file

Back to the top