Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 164483
Collapse All | Expand All

(-)src/org/eclipse/hyades/test/ui/navigator/ProxyNodeTransfer.java (-8 / +10 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-33 Link Here
16
import java.io.DataOutputStream;
16
import java.io.DataOutputStream;
17
import java.io.IOException;
17
import java.io.IOException;
18
18
19
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorProvider;
19
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorContentProvider;
20
import org.eclipse.swt.dnd.ByteArrayTransfer;
20
import org.eclipse.swt.dnd.ByteArrayTransfer;
21
import org.eclipse.swt.dnd.TransferData;
21
import org.eclipse.swt.dnd.TransferData;
22
22
23
/** 
23
/** 
24
 * Transfer class used by Copy/Paste actions of proxy nodes, in resource mode.
24
 * <p>Transfer class used by copy and paste actions of proxy nodes in the Resource view of the Test Navigator.</p>
25
 * 
25
 * 
26
 * @author jgout
26
 * 
27
 * @version February 26, 2008
27
 * @author  Jerome Gout
28
 * @since 3.3
28
 * @author  Paul Slauenwhite
29
 * @version May 18, 2009
30
 * @since   March 7, 2005
29
 */
31
 */
30
public class ProxyNodeTransfer extends ByteArrayTransfer {
32
 public class ProxyNodeTransfer extends ByteArrayTransfer {
31
	private static final ProxyNodeTransfer instance = new ProxyNodeTransfer();
33
	private static final ProxyNodeTransfer instance = new ProxyNodeTransfer();
32
	//- Create a unique ID to make sure that different Eclipse
34
	//- Create a unique ID to make sure that different Eclipse
33
	//- applications use different "types" of <code>ProxyNodeTransfer</code>
35
	//- applications use different "types" of <code>ProxyNodeTransfer</code>
Lines 66-72 Link Here
66
	private IProxyNode readProxy(DataInputStream dataIn) throws IOException {
68
	private IProxyNode readProxy(DataInputStream dataIn) throws IOException {
67
		String fileName = dataIn.readUTF();
69
		String fileName = dataIn.readUTF();
68
		String identifier = dataIn.readUTF();
70
		String identifier = dataIn.readUTF();
69
		return ResourceTestNavigatorProvider.getSharedFileProxyManager().getCorrespondingProxy(fileName, identifier);
71
		return ResourceTestNavigatorContentProvider.getSharedFileProxyManager().getCorrespondingProxy(fileName, identifier);
70
	}
72
	}
71
	
73
	
72
	/**
74
	/**
(-)src/org/eclipse/hyades/test/ui/internal/navigator/TestNavigatorLabelProvider.java (-7 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 26-35 Link Here
26
import org.eclipse.ui.model.IWorkbenchAdapter;
26
import org.eclipse.ui.model.IWorkbenchAdapter;
27
import org.eclipse.ui.model.WorkbenchLabelProvider;
27
import org.eclipse.ui.model.WorkbenchLabelProvider;
28
28
29
/** Label provider used by the views of the test navigator
29
/** 
30
 * <p>Abstract label provider for the Test Navigator.</p>
30
 * 
31
 * 
31
 * @author jgout
32
 * 
32
 * @since 4.0
33
 * @author  Jerome Gout
34
 * @author  Paul Slauenwhite
35
 * @version May 18, 2009
36
 * @since   February 1, 2005
33
 */
37
 */
34
public class TestNavigatorLabelProvider implements ILabelProvider, ILabelProviderListener {
38
public class TestNavigatorLabelProvider implements ILabelProvider, ILabelProviderListener {
35
	
39
	
Lines 48-54 Link Here
48
52
49
		return workbenchAdapter;
53
		return workbenchAdapter;
50
	}
54
	}
51
	
55
		
52
	public Image getImage(Object element) {
56
	public Image getImage(Object element) {
53
		if (element == null)
57
		if (element == null)
54
			return null;
58
			return null;
Lines 98-104 Link Here
98
	}
102
	}
99
103
100
	public void dispose() {
104
	public void dispose() {
101
//		listeners.clear();
102
		workbenchProvider.dispose();
105
		workbenchProvider.dispose();
103
	}
106
	}
104
107
Lines 111-115 Link Here
111
			UiPlugin.logInfo("Unable to remove listener '" + listener.toString()); //$NON-NLS-1$
114
			UiPlugin.logInfo("Unable to remove listener '" + listener.toString()); //$NON-NLS-1$
112
		}
115
		}
113
	}
116
	}
114
115
}
117
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/ResourceTestNavigatorProvider.java (-240 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 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
 * $Id: ResourceTestNavigatorProvider.java,v 1.10 2007/04/06 13:49:24 jgout Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator;
13
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.core.resources.IContainer;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.hyades.test.ui.UiPlugin;
27
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
28
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.FileProxiesRequest;
29
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.IProxiesRequestListener;
30
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.ProxiesRequest;
31
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
32
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
33
import org.eclipse.hyades.ui.util.IDisposable;
34
35
/** This the resource oriented provider for the test navigator view.
36
 * @author jgout
37
 * @since 4.0
38
 */
39
public class ResourceTestNavigatorProvider extends TestNavigatorProvider {
40
41
    /** The file proxy manager to acces to proxies from files */
42
    private static FileProxyManager fileProxyManager = new FileProxyManager();
43
    
44
    /**
45
     * @return Returns the fileProxyManager.
46
     */
47
    public static FileProxyManager getSharedFileProxyManager() {
48
        return fileProxyManager;
49
    }
50
51
    public ResourceTestNavigatorProvider(TestNavigator testNavigator) {
52
    	super(testNavigator);
53
    }
54
    
55
    private FileProxyRequests requests = new FileProxyRequests();
56
    
57
    protected IFileProxyManager getFileProxyManager() {
58
    	return fileProxyManager;
59
    }
60
61
	public Object getParent(Object element) {
62
		if (element instanceof IResource) {
63
			return ((IResource) element).getParent();
64
		}
65
		return super.getParent(element);
66
	}
67
	
68
	public boolean hasChildren(Object parentElement) {
69
		if (parentElement == null)
70
			return false;
71
		if (parentElement instanceof IContainer) {
72
			IContainer container = (IContainer) parentElement;
73
			if (!container.isAccessible())
74
				return false;
75
76
			IResource[] resources = null;
77
			try {
78
				resources = container.members();
79
			} catch (CoreException e) {
80
				UiPlugin.logError(e);
81
				return false;
82
			}
83
			if (resources.length == 0) return false;
84
			if (parentElement instanceof IProject) {
85
				return true;
86
			}
87
			for (int i = 0; i < resources.length; i++) {
88
				if (resources[i].getType() != IResource.FILE) {
89
					if (!TestNavigator.getFiltersManager().filter(resources[i]))
90
						return true;
91
				} else {
92
					String fileExtension = resources[i].getFileExtension();
93
					if (fileExtension != null) {
94
						if (TestNavigator.getFiltersManager().isVisibleResource(resources[i])) return true;
95
					}
96
				}
97
			}
98
			return false;
99
		}
100
		return super.hasChildren(parentElement);
101
	}
102
	
103
	public Object[] getChildren(Object parentElement) {
104
		if (parentElement instanceof IContainer) {
105
			return getContainerChildren(parentElement);
106
		} else {
107
			return super.getChildren(parentElement);
108
		}
109
	}
110
111
	/** returns the children of a container node (project or folder)
112
	 * @param parentElement
113
	 * @return an array of Object which cn be empty but not null
114
	 */
115
	private Object[] getContainerChildren(Object parentElement) {
116
		IResource[] resources = null;
117
		IContainer container = ((IContainer) parentElement);
118
        if (container.isAccessible()) {
119
            try {
120
                resources = container.members();
121
            } catch (CoreException e) {
122
                UiPlugin.logError(e);
123
                return new Object[0];
124
            }
125
            List children = new ArrayList(resources.length);
126
            FileProxiesRequest request = requests.getRequest(container, resources);
127
            for (int i = 0, maxi = resources.length; i < maxi; i++) {
128
                if (!TestNavigator.getFiltersManager().filter(resources[i])) {
129
                	if (resources[i].getType() != IResource.FILE) { 
130
                		children.add(resources[i]);
131
                	} else {
132
                        //- convert the file in something else (proxy)
133
                    	IFile file = (IFile)resources[i];
134
                        IProxyNode node = request.getProxy(file);
135
                        if (!TestNavigator.getFiltersManager().filter(node)) {
136
                            children.add(node);
137
                            fileProxyManager.cacheProxy(file, node);
138
                        }
139
                    }
140
                }
141
            }
142
            return children.toArray();
143
        }
144
        return new Object[0];
145
	}
146
147
    public IGlobalProxyNodeListener getProxyNodeListener() {
148
    	return requests;
149
    }
150
151
	private class FileProxyRequests implements IProxiesRequestListener, IDisposable, IGlobalProxyNodeListener {
152
		
153
	    private Map containerToRequestMap = Collections.synchronizedMap(new HashMap());
154
	    
155
	    public FileProxiesRequest getRequest(IContainer container, IResource[] members) {
156
	    	FileProxiesRequest request = (FileProxiesRequest)containerToRequestMap.get(container);
157
	    	if (request == null) {
158
	    		request = newRequest(container, members);
159
	    	}
160
	    	return request;
161
	    }
162
	    
163
	    public FileProxiesRequest newRequest(IContainer container, IResource[] members) {
164
	    	ArrayList filesToRequest = new ArrayList(members.length);
165
            for (int i = 0, maxi = members.length; i < maxi; i++) {
166
            	if (members[i].getType() == IResource.FILE) {
167
            		if (!TestNavigator.getFiltersManager().filter(members[i])) {
168
                    	filesToRequest.add(members[i]);
169
                    }
170
                }
171
            }
172
            if (filesToRequest.isEmpty()) return null;
173
            FileProxiesRequest req = new FileProxiesRequest(filesToRequest, fileProxyManager, container, testNavigator);
174
            req.setPriority(getJobPriority());
175
            testNavigator.getJobPool().scheduleJob(req);
176
            if (!req.wait(getResponseTime(), this, 2000)) {
177
            	containerToRequestMap.put(container, req);
178
            }
179
            return req;
180
	    }
181
	    
182
		public void proxyComputed(final ProxiesRequest request, Object key) {
183
		}
184
	
185
		public void computationCompleted(ProxiesRequest request) {
186
			IContainer parent = ((FileProxiesRequest)request).getParent();
187
			if (containerToRequestMap.containsKey(parent)) {
188
				testNavigator.refresh(parent);
189
			}
190
		}
191
192
		public void dispose() {
193
			// Cancel all running requests. As the atomic action of FileProxiesRequest is
194
			// the computation of a single file proxy, all requests should honor the cancel
195
			// request quite quickly. However we don't wait them to complete (i.e. they may
196
			// be still running while this instance has been disposed).
197
			for (Iterator it = containerToRequestMap.values().iterator(); it.hasNext();) {
198
				FileProxiesRequest request = (FileProxiesRequest) it.next();
199
				request.dispose();
200
				it.remove();
201
			}
202
		}
203
204
		public void proxiesComputed(ProxiesRequest request) {
205
			testNavigator.refresh(((FileProxiesRequest)request).getParent());
206
		}
207
208
		public void nodeChanged(Object node) {
209
			if (node instanceof IContainer) {
210
				FileProxiesRequest req = (FileProxiesRequest) containerToRequestMap.remove(node);
211
				if (req != null) {
212
					// Then we need to cancel the current request. A new one will be spawned
213
					// when getChildren() is invoked on this project.
214
					if (req.cancel(1000)) {
215
						containerToRequestMap.remove(node);
216
					}
217
				}
218
			}
219
		}
220
		
221
		public void nodesChanged() {
222
			for (Iterator it = containerToRequestMap.keySet().iterator(); it.hasNext();) {
223
				nodeChanged(it.next());
224
			}
225
		}
226
		
227
		public void computationCancelled(ProxiesRequest request) {
228
			IContainer parent = ((FileProxiesRequest)request).getParent();
229
			containerToRequestMap.remove(parent);
230
			testNavigator.refresh(parent);
231
		}
232
    	
233
	}
234
	
235
	public void dispose() {
236
		requests.dispose();
237
		super.dispose();
238
	}
239
240
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/TestNavigatorProvider.java (-273 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 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
 * $Id: TestNavigatorProvider.java,v 1.13 2009/02/12 19:19:00 paules Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator;
13
14
import java.util.LinkedList;
15
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IWorkspaceRoot;
18
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
20
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
21
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
22
import org.eclipse.hyades.test.ui.navigator.IProxyNodeListener;
23
import org.eclipse.jface.viewers.IBaseLabelProvider;
24
import org.eclipse.jface.viewers.IContentProvider;
25
import org.eclipse.jface.viewers.ITreeContentProvider;
26
import org.eclipse.jface.viewers.Viewer;
27
import org.eclipse.swt.graphics.Image;
28
29
/**
30
 * TestNavigatorProvider.java
31
 * <p/>
32
 *
33
 * 
34
 * @author  Jerome Gout
35
 * @author  Julien Canches
36
 * @author  Paul E. Slauenwhite
37
 * @version February 12, 2008
38
 * @since   March 18, 2005 
39
 */
40
public abstract class TestNavigatorProvider extends TestNavigatorLabelProvider implements ITreeContentProvider {
41
42
	private static final int MAX_PROXY_NODE_CHILDREN = 100;
43
	public static final int CONTEXT_LOADING = 0;
44
	public static final int CONTEXT_INTERACTIVE = 1;
45
	
46
	protected TestNavigator testNavigator;
47
	private int context;
48
	
49
	public TestNavigatorProvider(TestNavigator testNavigator) {
50
		this.testNavigator = testNavigator;
51
		this.context = CONTEXT_LOADING;
52
	}
53
54
	protected abstract IGlobalProxyNodeListener getProxyNodeListener();
55
56
	protected abstract IFileProxyManager getFileProxyManager();
57
		
58
	public Object getParent(Object element) {
59
		if (element instanceof IProxyNode) {
60
            Object parent = ((IProxyNode) element).getParent();
61
            if(parent instanceof FileProxyManager.IUnboundedParent) {
62
                return getFileProxyManager().getParent((IProxyNode) element);
63
            } else {
64
                return parent;
65
            }
66
		}
67
		return null;
68
	}
69
70
	public boolean hasChildren(Object parentElement) {
71
		if (parentElement instanceof IProxyNode) {
72
			IProxyNode proxy = (IProxyNode) parentElement;
73
			return proxy.getChildren().length > 0;
74
		}
75
		if (parentElement instanceof IProxyGroup) {
76
			return true;
77
		}
78
		return false;
79
	}
80
81
	public Object[] getChildren(Object parentElement) {
82
		if (parentElement instanceof IProxyNode) {
83
			IProxyNode proxy = (IProxyNode) parentElement;
84
			return foldProxyNodes(proxy);
85
		}
86
		if (parentElement instanceof IProxyGroup) {
87
			return ((IProxyGroup)parentElement).getChildren();
88
		}
89
		return new Object[0];
90
	}
91
	
92
	public String getText(Object element) {
93
		if (element instanceof IProxyGroup) {
94
			return ((IProxyGroup)element).getText();
95
		}
96
		return super.getText(element);
97
	}
98
	
99
	public Image getImage(Object element) {
100
		if (element instanceof IProxyGroup) {
101
			return ((IProxyGroup)element).getImage();
102
		}
103
		return super.getImage(element);
104
	}
105
	
106
	public Object[] getElements(Object inputElement) {
107
		if (inputElement instanceof IWorkspaceRoot) {
108
			IProject [] projects = ((IWorkspaceRoot) inputElement).getProjects();
109
			LinkedList visibleProjects = new LinkedList();
110
			for(int i = 0; i < projects.length; i++) {
111
				if(!TestNavigator.getFiltersManager().filter(projects[i])) {
112
					visibleProjects.add(projects[i]);
113
				}
114
			}
115
			return visibleProjects.toArray();
116
		}
117
		return getChildren(inputElement);
118
	}
119
    
120
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
121
	}
122
	
123
	public static interface IGlobalProxyNodeListener extends IProxyNodeListener {
124
		
125
		void nodesChanged();
126
		
127
	}
128
	
129
	public static interface IProxyGroup {
130
		IProxyNode[] getChildren();
131
		String getText();
132
		Image getImage();
133
		int getOrder();
134
	}
135
	
136
	private static class ProxyGroup implements IProxyGroup {
137
		private IProxyNode parent;
138
		private int sequence;
139
		public ProxyGroup(IProxyNode node, int sequence) {
140
			this.parent = node;
141
			this.sequence = sequence;
142
		}
143
		public IProxyNode[] getChildren() {
144
			int start = sequence * MAX_PROXY_NODE_CHILDREN;
145
			IProxyNode[] completeChildren = parent.getChildren();
146
			IProxyNode[] children = new IProxyNode[MAX_PROXY_NODE_CHILDREN];
147
			System.arraycopy(completeChildren, start, children, 0, MAX_PROXY_NODE_CHILDREN);
148
			return children;
149
		}
150
		public String getText() {
151
			int start = sequence * MAX_PROXY_NODE_CHILDREN + 1;
152
			int end = (sequence + 1) * MAX_PROXY_NODE_CHILDREN;
153
			return ("[".concat(Integer.toString(start)).concat(" - ").concat(Integer.toString(end)).concat("]"));
154
		}
155
		public Image getImage() {
156
			return parent.getImage();
157
		}
158
		public int getOrder() {
159
			return sequence;
160
		}
161
	}
162
	
163
	private static class RemainingProxyGroup implements IProxyGroup {
164
		private IProxyNode parent;
165
		public RemainingProxyGroup(IProxyNode parent) {
166
			this.parent = parent;
167
		}
168
		public IProxyNode[] getChildren() {
169
			IProxyNode[] completeChildren = parent.getChildren();
170
			int completeLength = completeChildren.length;
171
			int length = completeLength % MAX_PROXY_NODE_CHILDREN;
172
			IProxyNode[] children = new IProxyNode[length];
173
			System.arraycopy(completeChildren, completeLength - length, children, 0, length);
174
			return children;
175
		}
176
		public String getText() {
177
			IProxyNode[] completeChildren = parent.getChildren();
178
			int end = completeChildren.length;
179
			int length = end % MAX_PROXY_NODE_CHILDREN;
180
			int start = end - length + 1;
181
			return ("[".concat(Integer.toString(start)).concat(" - ").concat(Integer.toString(end)).concat("]"));
182
		}
183
		public Image getImage() {
184
			return parent.getImage();
185
		}
186
		public int getOrder() {
187
			return Integer.MAX_VALUE;
188
		}
189
	}
190
	
191
	protected Object[] foldProxyNodes(IProxyNode parent) {
192
		IProxyNode[] children = parent.getChildren();
193
		int length = children.length;
194
		if (length <= MAX_PROXY_NODE_CHILDREN) return children;
195
		int size = length / MAX_PROXY_NODE_CHILDREN;
196
		int remaining = length % MAX_PROXY_NODE_CHILDREN;
197
		int totalSize = size + (remaining > 0 ? 1 : 0);
198
		Object[] groups = new IProxyGroup[totalSize];
199
		for (int i = 0; i < size; i++) {
200
			groups[i] = new ProxyGroup(parent, i);
201
		}
202
		if (remaining > 0) {
203
			groups[size] = new RemainingProxyGroup(parent);
204
		}
205
		return groups;
206
	}
207
208
	/**
209
	 * Sets the context in which the provider is used. There are two available values:
210
	 * INTERACTIVE and LOADING. The context has an effect on two parameters:
211
	 * 1) responsiveness: time that getChildren() is allowed to spent before returning
212
	 * control. High responsiveness means that the provider will return incomplete nodes,
213
	 * compute the remaining in a background task, and update the navigator when computation
214
	 * is complete. Low responsiveness means that the UI will be blocked for a longer period of
215
	 * time but the returned node are more likely to be complete.
216
	 * 2) computation job priority: the priority allocated to the computation job, if the provider
217
	 * does not manage to compute nodes in the allocated time (responsiveness parameter). This does
218
	 * not affect the thread priority, but helps eclipse decide which job should be launched first.
219
	 * In LOADING mode, responsiveness is high (100ms) and priority is low (NORMAL).
220
	 * In INTERACTIVE mode, responsiveness is lower (800ms) and priority is high (INTERACTIVE).
221
	 */
222
	public void setContext(int context) {
223
		this.context = context;
224
	}
225
	
226
	protected int getContext() {
227
		return context;
228
	}
229
	
230
	protected int getResponseTime() {
231
		switch (context) {
232
		case CONTEXT_INTERACTIVE:
233
			return 800;
234
		case CONTEXT_LOADING:
235
			return 100;
236
		}
237
		return 100;
238
	}
239
	
240
	protected int getJobPriority() {
241
		switch(context) {
242
		case CONTEXT_INTERACTIVE:
243
			return Job.INTERACTIVE;
244
		case CONTEXT_LOADING:
245
			return Job.LONG;
246
		}
247
		return Job.LONG;
248
	}
249
	
250
	 /**
251
	 * Empty implementation of the ({@link TestNavigatorLabelProvider#dispose()}) 
252
	 * method.
253
	 * <p/>
254
	 * Since the {@link TestNavigatorProvider} is both a content provider 
255
	 * ({@link IContentProvider}) and label provider ({@link IBaseLabelProvider}), 
256
	 * the {@link #dispose()} method may be invoked as the implementation for the
257
	 * {@link IContentProvider#dispose()} method or {@link IBaseLabelProvider#dispose()}
258
	 * method.  Since there is no way to determine if the invocation of this method is 
259
	 * intended to dispose the  content provider ({@link IContentProvider}) or label 
260
	 * provider ({@link IBaseLabelProvider}), this method is an empty implementation.  
261
	 * <p/>
262
	 * To dispose the label provider, call the {@link TestNavigatorLabelProvider#dispose()}
263
	 * method directly.
264
	 * <p/>
265
	 * 
266
	 * @see TestNavigatorLabelProvider#dispose()
267
	 * @see IContentProvider#dispose()
268
	 * @see IBaseLabelProvider#dispose()
269
	 */
270
	public void dispose() {
271
		//No-operation.
272
	}
273
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/TestNavigator.java (-26 / +27 lines)
Lines 36-43 Link Here
36
import org.eclipse.hyades.test.ui.UiPlugin;
36
import org.eclipse.hyades.test.ui.UiPlugin;
37
import org.eclipse.hyades.test.ui.internal.editor.BaseEditorPart;
37
import org.eclipse.hyades.test.ui.internal.editor.BaseEditorPart;
38
import org.eclipse.hyades.test.ui.internal.model.ResourceUtil.ResourceAdaptable;
38
import org.eclipse.hyades.test.ui.internal.model.ResourceUtil.ResourceAdaptable;
39
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorProvider.IGlobalProxyNodeListener;
39
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorContentProvider.IGlobalProxyNodeListener;
40
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorProvider.IProxyGroup;
40
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorContentProvider.IProxyGroup;
41
import org.eclipse.hyades.test.ui.internal.navigator.action.TestNavigatorActionGroup;
41
import org.eclipse.hyades.test.ui.internal.navigator.action.TestNavigatorActionGroup;
42
import org.eclipse.hyades.test.ui.internal.navigator.action.ToggleViewAction;
42
import org.eclipse.hyades.test.ui.internal.navigator.action.ToggleViewAction;
43
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileFactoryManager;
43
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileFactoryManager;
Lines 70-76 Link Here
70
import org.eclipse.jface.action.IToolBarManager;
70
import org.eclipse.jface.action.IToolBarManager;
71
import org.eclipse.jface.action.Separator;
71
import org.eclipse.jface.action.Separator;
72
import org.eclipse.jface.viewers.DoubleClickEvent;
72
import org.eclipse.jface.viewers.DoubleClickEvent;
73
import org.eclipse.jface.viewers.ILabelDecorator;
74
import org.eclipse.jface.viewers.ILabelProvider;
73
import org.eclipse.jface.viewers.ILabelProvider;
75
import org.eclipse.jface.viewers.ISelection;
74
import org.eclipse.jface.viewers.ISelection;
76
import org.eclipse.jface.viewers.IStructuredSelection;
75
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 101-108 Link Here
101
100
102
/**
101
/**
103
 * <p>Concrete implementation of the
102
 * <p>Concrete implementation of the
104
 * {@link org.eclipse.hyades.ui.internal.navigator.Navigator}for the Hyades
103
 * {@link org.eclipse.hyades.ui.internal.navigator.TreeNavigator} 
105
 * Test objects.</p>
104
 * for test assets.</p>
106
 * 
105
 * 
107
 * 
106
 * 
108
 * @author  Marcelo Paternostro
107
 * @author  Marcelo Paternostro
Lines 110-116 Link Here
110
 * @author  Paul E. Slauewnhite
109
 * @author  Paul E. Slauewnhite
111
 * @author  Paul Klicnik
110
 * @author  Paul Klicnik
112
 * @author  Kurtis Martin
111
 * @author  Kurtis Martin
113
 * @version April 23, 2009
112
 * @version May 18, 2009
114
 * @since   February 1, 2005
113
 * @since   February 1, 2005
115
 */
114
 */
116
public class TestNavigator extends TreeNavigator implements ISelectionListener, IGlobalProxyNodeListener, ITestNavigator {
115
public class TestNavigator extends TreeNavigator implements ISelectionListener, IGlobalProxyNodeListener, ITestNavigator {
Lines 167-174 Link Here
167
    /** actions to switch between both logical and resource views. */
166
    /** actions to switch between both logical and resource views. */
168
    private ToggleViewAction[] viewActions;
167
    private ToggleViewAction[] viewActions;
169
168
170
    /** Current content and label provider. */
169
    /**
171
    private TestNavigatorProvider currentProvider;
170
     * Current content provider for the Test Navigator.
171
     */
172
    private TestNavigatorContentProvider currentContentProvider;
172
173
173
    // - constants are used in the IDialogSettings
174
    // - constants are used in the IDialogSettings
174
    protected final static String SET_SHOW_FOLDERS = "SHOW_FOLDERS"; //$NON-NLS-1$
175
    protected final static String SET_SHOW_FOLDERS = "SHOW_FOLDERS"; //$NON-NLS-1$
Lines 276-282 Link Here
276
    }
277
    }
277
    
278
    
278
    public IFileProxyManager getCurrentFileProxyManager() {
279
    public IFileProxyManager getCurrentFileProxyManager() {
279
    	return currentProvider.getFileProxyManager();
280
    	return currentContentProvider.getFileProxyManager();
280
    }
281
    }
281
282
282
    /**
283
    /**
Lines 306-312 Link Here
306
    private static class TypeProviderContext implements ITypeProviderContext {
307
    private static class TypeProviderContext implements ITypeProviderContext {
307
		private IProxyNodeListener refresher;
308
		private IProxyNodeListener refresher;
308
        public IFileProxyManager getFileProxyManager() {
309
        public IFileProxyManager getFileProxyManager() {
309
            return LogicalTestNavigatorProvider.getSharedFileProxyManager();
310
            return LogicalTestNavigatorContentProvider.getSharedFileProxyManager();
310
        }
311
        }
311
		public IProxyNodeListener getProxyNodeListener() {
312
		public IProxyNodeListener getProxyNodeListener() {
312
			if (refresher == null) {
313
			if (refresher == null) {
Lines 397-407 Link Here
397
    }
398
    }
398
399
399
    private void adjustCurrentProviderContext(boolean isLoading) {
400
    private void adjustCurrentProviderContext(boolean isLoading) {
400
		if (currentProvider != null) {
401
		if (currentContentProvider != null) {
401
			if (isLoading) {
402
			if (isLoading) {
402
				currentProvider.setContext(TestNavigatorProvider.CONTEXT_LOADING);
403
				currentContentProvider.setContext(TestNavigatorContentProvider.CONTEXT_LOADING);
403
			} else {
404
			} else {
404
				currentProvider.setContext(TestNavigatorProvider.CONTEXT_INTERACTIVE);
405
				currentContentProvider.setContext(TestNavigatorContentProvider.CONTEXT_INTERACTIVE);
405
			}
406
			}
406
		}
407
		}
407
	}
408
	}
Lines 563-582 Link Here
563
        updateTestNavigatorProvider(treeViewer);
564
        updateTestNavigatorProvider(treeViewer);
564
    }
565
    }
565
566
566
    /**
567
     * @param treeViewer
568
     */
569
    private void updateTestNavigatorProvider(TreeViewer treeViewer) {
567
    private void updateTestNavigatorProvider(TreeViewer treeViewer) {
568
    	
570
    	if (currentViewIndex == VIEW_ID_RESOURCE) {
569
    	if (currentViewIndex == VIEW_ID_RESOURCE) {
571
    		currentProvider = new ResourceTestNavigatorProvider(this);
570
    		currentContentProvider = new ResourceTestNavigatorContentProvider(this);
572
    	} else {
571
    	} 
573
    		currentProvider = new LogicalTestNavigatorProvider(this);
572
    	else {
573
    		currentContentProvider = new LogicalTestNavigatorContentProvider(this);
574
    	}
574
    	}
575
    	
575
    	adjustCurrentProviderContext(true);
576
    	adjustCurrentProviderContext(true);
576
        treeViewer.setContentProvider(currentProvider);
577
        
577
        ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
578
    	treeViewer.setContentProvider(currentContentProvider);
578
        ILabelProvider labelProvider = new TestDecoratingLabelProvider(currentProvider, decorator, this); 
579
        treeViewer.setLabelProvider(new TestDecoratingLabelProvider(new TestNavigatorLabelProvider(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(), this));
579
        treeViewer.setLabelProvider(labelProvider);
580
580
        adjustCurrentProviderContext(false);
581
        adjustCurrentProviderContext(false);
581
    }
582
    }
582
583
Lines 1081-1092 Link Here
1081
     * Invoked by test providers to notify that a node and its children should be refreshed.
1082
     * Invoked by test providers to notify that a node and its children should be refreshed.
1082
     */
1083
     */
1083
    public void nodeChanged(Object node) {
1084
    public void nodeChanged(Object node) {
1084
    	currentProvider.getProxyNodeListener().nodeChanged(node);
1085
    	currentContentProvider.getProxyNodeListener().nodeChanged(node);
1085
    	refresh(node);
1086
    	refresh(node);
1086
    }
1087
    }
1087
    
1088
    
1088
    public void nodesChanged() {
1089
    public void nodesChanged() {
1089
    	currentProvider.getProxyNodeListener().nodesChanged();
1090
    	currentContentProvider.getProxyNodeListener().nodesChanged();
1090
    	refresh(null);
1091
    	refresh(null);
1091
    }
1092
    }
1092
    
1093
    
Lines 1141-1147 Link Here
1141
    	switch (currentViewIndex) {
1142
    	switch (currentViewIndex) {
1142
	    	case VIEW_ID_LOGICAL: {
1143
	    	case VIEW_ID_LOGICAL: {
1143
	    		IProject project = file.getProject();
1144
	    		IProject project = file.getProject();
1144
	    		if (project != null)currentProvider.getChildren(project);
1145
	    		if (project != null)currentContentProvider.getChildren(project);
1145
	    		return proxyManager.getProxy(file, null);
1146
	    		return proxyManager.getProxy(file, null);
1146
	    	}
1147
	    	}
1147
	    	case VIEW_ID_RESOURCE: {
1148
	    	case VIEW_ID_RESOURCE: {
(-)src/org/eclipse/hyades/test/ui/internal/navigator/LogicalTestNavigatorProvider.java (-248 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 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
 * $Id: LogicalTestNavigatorProvider.java,v 1.11 2007/04/06 13:49:24 jgout Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.hyades.test.ui.TestUIExtension;
24
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
25
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.IProxiesRequestListener;
26
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.LogicalProjectProxiesRequest;
27
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.ProxiesRequest;
28
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
29
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
30
import org.eclipse.hyades.ui.extension.IAssociationConstants;
31
import org.eclipse.hyades.ui.extension.IAssociationDescriptor;
32
import org.eclipse.hyades.ui.extension.IAssociationMapping;
33
import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry;
34
import org.eclipse.hyades.ui.util.IDisposable;
35
import org.eclipse.swt.graphics.Image;
36
37
/** This is the provider of the logical test navigator.
38
 * @author jgout
39
 * @since 4.0
40
 */
41
public class LogicalTestNavigatorProvider extends TestNavigatorProvider {
42
43
    /** The file proxy manager to acces to proxies from files */
44
    private static FileProxyManager fileProxyManager = new FileProxyManager();
45
    
46
    private ProxiesRequests requests = new ProxiesRequests();
47
    
48
    /**
49
     * @return Returns the fileProxyManager.
50
     */
51
    public static IFileProxyManager getSharedFileProxyManager() {
52
        return fileProxyManager;
53
    }
54
55
    public LogicalTestNavigatorProvider(TestNavigator testNavigator) {
56
    	super(testNavigator);
57
    }
58
    
59
    protected IFileProxyManager getFileProxyManager() {
60
    	return fileProxyManager;
61
    }
62
63
	public boolean hasChildren(Object parentElement) {
64
		if (parentElement == null)
65
			return false;
66
		if(parentElement instanceof IProject) {
67
			return true;
68
		}
69
		return super.hasChildren(parentElement);
70
	}
71
	
72
	public Object[] getChildren(Object parentElement) {
73
		if(parentElement instanceof IProject) {
74
			IProject project = (IProject)parentElement;
75
			if (project.isAccessible()) {
76
				Collection types = getTypes();
77
				Collection extensions = getExtensions();
78
				ArrayList ret = new ArrayList(types.size() + extensions.size());
79
				LogicalProjectProxiesRequest request = requests.getRequest(project, types, extensions);
80
				for (Iterator it = types.iterator(); it.hasNext();) {
81
					String type = (String) it.next();
82
					IProxyNode proxy = request.getProxy(LogicalProjectProxiesRequest.TYPE_PROVIDER_PREFIX + type);
83
					if (proxy != null) {
84
						ret.add(proxy);
85
					}
86
				}
87
				for (Iterator it = extensions.iterator(); it.hasNext();) {
88
					String ext = (String) it.next();
89
					IProxyNode proxy = request.getProxy(LogicalProjectProxiesRequest.TEST_ASSET_EXTENSION_PREFIX + ext);
90
					if (proxy != null) {
91
						ret.add(proxy);
92
					}
93
				}
94
				if (request.isPending()) {
95
					ret.add(0, new PendingProxy(project));
96
				}
97
				return ret.toArray();
98
			}
99
			return new Object[0];
100
		}
101
		return super.getChildren(parentElement);
102
	}
103
104
	private Collection getTypes() {
105
        AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry();
106
        IAssociationMapping associationMapping = registry.getAssociationMapping(IAssociationConstants.EP_TYPE_DESCRIPTIONS);
107
        String[] types = associationMapping.getTypes();
108
        List typeProviders = new ArrayList(types.length);
109
        for (int i = 0; i < types.length; i++) {
110
        	IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(types[i]);
111
        	if (descriptor != null) {
112
                typeProviders.add(types[i]);
113
        	}
114
        }
115
        return typeProviders;
116
    }
117
	
118
	private Collection getExtensions() {
119
		return TestNavigator.getTestAssetGroupProxyManager().getExtensions();
120
	}
121
	
122
    public IGlobalProxyNodeListener getProxyNodeListener() {
123
    	return requests;
124
    }
125
126
	public void dispose() {
127
		requests.dispose();
128
		super.dispose();
129
	}
130
131
    class ProxiesRequests implements IProxiesRequestListener, IGlobalProxyNodeListener, IDisposable {
132
    	
133
    	private Map projectToRequestMap = new HashMap();
134
    	
135
    	public LogicalProjectProxiesRequest getRequest(IProject project, Collection types, Collection extensions) {
136
    		LogicalProjectProxiesRequest req = (LogicalProjectProxiesRequest)projectToRequestMap.get(project);
137
    		if (req == null) {
138
    			ArrayList requests = new ArrayList(types.size() + extensions.size());
139
    			for(Iterator it = types.iterator(); it.hasNext(); ) {
140
    				requests.add(LogicalProjectProxiesRequest.TYPE_PROVIDER_PREFIX + (String)it.next());
141
    			}
142
    			for(Iterator it = extensions.iterator(); it.hasNext(); ) {
143
    				requests.add(LogicalProjectProxiesRequest.TEST_ASSET_EXTENSION_PREFIX + (String)it.next());
144
    			}
145
    			req = new LogicalProjectProxiesRequest(requests, TestNavigator.getTypeProviderManager(), TestNavigator.getTestAssetGroupProxyManager(), project, testNavigator);
146
    			req.setPriority(getJobPriority());
147
    			testNavigator.getJobPool().scheduleJob(req);
148
                if (!req.wait(getResponseTime(), this, 2000)) {
149
                	projectToRequestMap.put(project, req);
150
                }
151
    		}
152
    		return req;
153
    	}
154
    	
155
		public void computationCompleted(ProxiesRequest request) {
156
			IProject project = ((LogicalProjectProxiesRequest)request).getProject();
157
			if (projectToRequestMap.containsKey(project)) {
158
				// A last refresh is necessary to remove the "Pending..." node.
159
				testNavigator.refresh(project);
160
			}
161
		}
162
163
		public void proxiesComputed(ProxiesRequest request) {
164
			IProject project = ((LogicalProjectProxiesRequest)request).getProject();
165
			testNavigator.refresh(project);
166
		}
167
168
		public void proxyComputed(ProxiesRequest request, Object key) {
169
		}
170
171
		public void nodeChanged(Object node) {
172
			if (node instanceof IProject) {
173
				LogicalProjectProxiesRequest req = (LogicalProjectProxiesRequest) projectToRequestMap.get(node);
174
				if (req != null) {
175
					// Then we need to cancel the current request. A new one will be spawned
176
					// when getChildren() is invoked on this project.
177
					if (req.cancel(1000)) {
178
						projectToRequestMap.remove(node);
179
					}
180
				}
181
			}
182
		}
183
184
		public void nodesChanged() {
185
			for (Iterator it = projectToRequestMap.keySet().iterator(); it.hasNext();) {
186
				nodeChanged(it.next());
187
			}
188
		}
189
		
190
		public void computationCancelled(ProxiesRequest request) {
191
			IProject project = ((LogicalProjectProxiesRequest)request).getProject();
192
			projectToRequestMap.remove(project);
193
			testNavigator.refresh(project);
194
		}
195
    	
196
		public void dispose() {
197
			// Cancel all running requests. Note that a LogicalProjectProxiesRequest may take
198
			// considerable time before it can honor the cancel request. So in general the
199
			// request may be still running for a long time after this instance has been
200
			// disposed.
201
			// If the user switches from the logical view to the resource view, and then back
202
			// to the logical view, this provider is disposed, and then another instance gets
203
			// created. As a result, two requests for the same project may be running: the old
204
			// one, which has been cancelled but has not stopped yet, and the new one. This
205
			// will look as if two jobs are doing the same thing at the same time. However what
206
			// really happens is that the new job is blocked on a wait until the old request 
207
			// completes, and then the new job automatically leverages the computation performed
208
			// by the old one, so there is no CPU waste. The only drawback is that the new job
209
			// occupies a slot in the Test navigator job pool.
210
			for (Iterator it = projectToRequestMap.values().iterator(); it.hasNext();) {
211
				ProxiesRequest request = (ProxiesRequest) it.next();
212
				request.dispose();
213
				it.remove();
214
			}
215
		}
216
217
    }
218
    
219
    private static class PendingProxy implements IProxyNode {
220
    	public PendingProxy(Object parent) {
221
    		this.parent = parent;
222
    	}
223
    	private Object parent;
224
    	private static IProxyNode[] NO_CHILDREN = new IProxyNode[0];
225
		public IProxyNode[] getChildren() {
226
			return NO_CHILDREN;
227
		}
228
		public Image getImage() {
229
			return null;
230
		}
231
		public Object getParent() {
232
			return parent;
233
		}
234
		public String getText() {
235
			return TestNavigatorMessages.NODE_PENDING;
236
		}
237
		public Object getAdapter(Class adapter) {
238
			return null;
239
		}
240
		public String getIdentifier() {
241
			return "~"; //$NON-NLS-1$
242
		}
243
		public IResource getUnderlyingResource() {
244
			return null;
245
		}
246
    }
247
248
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/CopyAction.java (-8 / +13 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 26-32 Link Here
26
import org.eclipse.core.resources.IResource;
26
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.hyades.test.ui.UiPlugin;
28
import org.eclipse.hyades.test.ui.UiPlugin;
29
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorProvider;
29
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorContentProvider;
30
import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle;
30
import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle;
31
import org.eclipse.hyades.test.ui.navigator.FileProxyNode;
31
import org.eclipse.hyades.test.ui.navigator.FileProxyNode;
32
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
32
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
Lines 42-51 Link Here
42
import org.eclipse.swt.dnd.Transfer;
42
import org.eclipse.swt.dnd.Transfer;
43
import org.eclipse.ui.part.ResourceTransfer;
43
import org.eclipse.ui.part.ResourceTransfer;
44
44
45
/**
45
/** 
46
 * Copy Action for the Resource mode.
46
 * <p>Copy action for the Resource view of the Test Navigator.</p>
47
 * @author jgout,Jerome Bozier
47
 * 
48
 * @version February 26, 2008
48
 * 
49
 * @author  Jerome Gout
50
 * @author  Jerome Bozier
51
 * @author  Paul Slauenwhite
52
 * @version May 18, 2009
53
 * @since   March 7, 2005
49
 */
54
 */
50
public class CopyAction extends Action implements IDisposable {
55
public class CopyAction extends Action implements IDisposable {
51
	private Clipboard clipboard;
56
	private Clipboard clipboard;
Lines 178-184 Link Here
178
	 * @return true if this proxy replaces a file
183
	 * @return true if this proxy replaces a file
179
	 */
184
	 */
180
	private boolean isAFileProxy(IProxyNode proxy) {
185
	private boolean isAFileProxy(IProxyNode proxy) {
181
        Object parent = ResourceTestNavigatorProvider.getSharedFileProxyManager().getParent(proxy);
186
        Object parent = ResourceTestNavigatorContentProvider.getSharedFileProxyManager().getParent(proxy);
182
		return proxy instanceof FileProxyNode || parent instanceof IContainer;
187
		return proxy instanceof FileProxyNode || parent instanceof IContainer;
183
	}
188
	}
184
189
Lines 258-264 Link Here
258
			return res.getParent();
263
			return res.getParent();
259
		} else if (sel instanceof IProxyNode) {
264
		} else if (sel instanceof IProxyNode) {
260
			IProxyNode proxy = (IProxyNode) sel;
265
			IProxyNode proxy = (IProxyNode) sel;
261
            return ResourceTestNavigatorProvider.getSharedFileProxyManager().getParent(proxy);
266
            return ResourceTestNavigatorContentProvider.getSharedFileProxyManager().getParent(proxy);
262
		} else {
267
		} else {
263
			return null;
268
			return null;
264
		}
269
		}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/FileProxyInContainerPaste.java (-9 / +13 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-19 Link Here
13
13
14
import org.eclipse.core.resources.IContainer;
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorProvider;
16
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorContentProvider;
17
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
17
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
18
import org.eclipse.hyades.test.ui.navigator.FileProxyNode;
18
import org.eclipse.hyades.test.ui.navigator.FileProxyNode;
19
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
19
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
Lines 25-38 Link Here
25
import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
25
import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
26
import org.eclipse.ui.part.ResourceTransfer;
26
import org.eclipse.ui.part.ResourceTransfer;
27
27
28
/**
28
/** 
29
 * Paste action for the resource mode.
29
 * <p>Paste action for the Resource view of the Test Navigator.</p>
30
 * @author jgout,Jerome Bozier
30
 * 
31
 * @since 3.3
31
 * 
32
 * @version February 26, 2008
32
 * @author  Jerome Gout
33
 * @author  Jerome Bozier
34
 * @author  Paul Slauenwhite
35
 * @version May 18, 2009
36
 * @since   March 16, 2007
33
 * @deprecated
37
 * @deprecated
34
 */
38
 */
35
public class FileProxyInContainerPaste implements IPaster {
39
 public class FileProxyInContainerPaste implements IPaster {
36
	
40
	
37
	private IResource [] getResourceFromClipboard(final Clipboard clipboard) {
41
	private IResource [] getResourceFromClipboard(final Clipboard clipboard) {
38
		final IResource[][] clipboardData = new IResource[1][];
42
		final IResource[][] clipboardData = new IResource[1][];
Lines 57-63 Link Here
57
				IProxyNode proxy = clipContent[i];
61
				IProxyNode proxy = clipContent[i];
58
                Object parent = proxy.getParent();
62
                Object parent = proxy.getParent();
59
                if(parent instanceof FileProxyManager.IUnboundedParent) {
63
                if(parent instanceof FileProxyManager.IUnboundedParent) {
60
                    parent = ResourceTestNavigatorProvider.getSharedFileProxyManager().getParent(proxy); 
64
                    parent = ResourceTestNavigatorContentProvider.getSharedFileProxyManager().getParent(proxy); 
61
                }
65
                }
62
				if(!(proxy instanceof FileProxyNode) && !(parent instanceof IContainer)) {
66
				if(!(proxy instanceof FileProxyNode) && !(parent instanceof IContainer)) {
63
					return false;
67
					return false;
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/FileFolderInContainerPaste.java (-8 / +12 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 21-27 Link Here
21
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.core.runtime.OperationCanceledException;
23
import org.eclipse.hyades.test.ui.UiPlugin;
23
import org.eclipse.hyades.test.ui.UiPlugin;
24
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorProvider;
24
import org.eclipse.hyades.test.ui.internal.navigator.ResourceTestNavigatorContentProvider;
25
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
25
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
26
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
26
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
27
import org.eclipse.hyades.test.ui.navigator.actions.IPaster;
27
import org.eclipse.hyades.test.ui.navigator.actions.IPaster;
Lines 38-48 Link Here
38
import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
38
import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
39
import org.eclipse.ui.part.ResourceTransfer;
39
import org.eclipse.ui.part.ResourceTransfer;
40
40
41
/**
41
/** 
42
 * Paste action for the resource mode.
42
 * <p>Paste action for the Resource view of the Test Navigator.</p>
43
 * @author jgout,Jerome Bozier
43
 * 
44
 * @since 3.3
44
 * 
45
 * @version February 26, 2008
45
 * @author  Jerome Gout
46
 * @author  Jerome Bozier
47
 * @author  Paul Slauenwhite
48
 * @version May 18, 2009
49
 * @since   March 7, 2005
46
 * @deprecated
50
 * @deprecated
47
 */
51
 */
48
public class FileFolderInContainerPaste implements IPaster {
52
public class FileFolderInContainerPaste implements IPaster {
Lines 191-197 Link Here
191
                                oneCopied = true;
195
                                oneCopied = true;
192
                                if (source instanceof IFile && conflict) {
196
                                if (source instanceof IFile && conflict) {
193
                                    IFile file = source.getWorkspace().getRoot().getFile(destinationPath);
197
                                    IFile file = source.getWorkspace().getRoot().getFile(destinationPath);
194
                                    IProxyNode proxy = ResourceTestNavigatorProvider.getSharedFileProxyManager().getProxy(file, null);
198
                                    IProxyNode proxy = ResourceTestNavigatorContentProvider.getSharedFileProxyManager().getProxy(file, null);
195
                                    IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class);
199
                                    IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class);
196
                                    if (renamer != null) {
200
                                    if (renamer != null) {
197
                                        //- use the renamer of this proxy node to rename properly
201
                                        //- use the renamer of this proxy node to rename properly
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/TestAssetGroupProxyNode.java (-8 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-32 Link Here
14
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.hyades.test.ui.UiPlugin;
16
import org.eclipse.hyades.test.ui.UiPlugin;
17
import org.eclipse.hyades.test.ui.internal.navigator.LogicalTestNavigatorProvider;
17
import org.eclipse.hyades.test.ui.internal.navigator.LogicalTestNavigatorContentProvider;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
19
import org.eclipse.hyades.test.ui.navigator.ITestFolderContentValidator;
19
import org.eclipse.hyades.test.ui.navigator.ITestFolderContentValidator;
20
import org.eclipse.hyades.test.ui.navigator.TestFolderProxyNode;
20
import org.eclipse.hyades.test.ui.navigator.TestFolderProxyNode;
21
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.graphics.Image;
22
22
23
/** 
23
/** 
24
 * Generic test asset group proxy node.
24
 * <p>Generic test asset group proxy node.</p>
25
 * This class is used by the test asset group manager
25
 * 
26
 * @author jgout
26
 * 
27
 * @since 4.0
27
 * @author  Jerome Gout
28
 * @author  Paul Slauenwhite
29
 * @version May 18, 2009
30
 * @since   March 18, 2005
28
 */
31
 */
29
public class TestAssetGroupProxyNode extends TestFolderProxyNode implements ITestAssetGroupProxyNode {
32
 public class TestAssetGroupProxyNode extends TestFolderProxyNode implements ITestAssetGroupProxyNode {
30
	
33
	
31
	private String extension;
34
	private String extension;
32
    private String name;
35
    private String name;
Lines 53-59 Link Here
53
	}
56
	}
54
	
57
	
55
	public TestAssetGroupProxyNode(IProject project, String extension, String name, String imageKey, boolean flat, Object parent) {
58
	public TestAssetGroupProxyNode(IProject project, String extension, String name, String imageKey, boolean flat, Object parent) {
56
		super(project, new TestAssetGroupValidator(extension), LogicalTestNavigatorProvider.getSharedFileProxyManager(), flat, parent);
59
		super(project, new TestAssetGroupValidator(extension), LogicalTestNavigatorContentProvider.getSharedFileProxyManager(), flat, parent);
57
		this.extension = extension;
60
		this.extension = extension;
58
        this.name = name;
61
        this.name = name;
59
        this.imageKey = imageKey;
62
        this.imageKey = imageKey;
(-)src/org/eclipse/hyades/test/ui/internal/navigator/LogicalTestNavigatorContentProvider.java (+252 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 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
 * $Id: LogicalTestNavigatorProvider.java,v 1.11 2007/04/06 13:49:24 jgout Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.hyades.test.ui.TestUIExtension;
24
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
25
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.IProxiesRequestListener;
26
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.LogicalProjectProxiesRequest;
27
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.ProxiesRequest;
28
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
29
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
30
import org.eclipse.hyades.ui.extension.IAssociationConstants;
31
import org.eclipse.hyades.ui.extension.IAssociationDescriptor;
32
import org.eclipse.hyades.ui.extension.IAssociationMapping;
33
import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry;
34
import org.eclipse.hyades.ui.util.IDisposable;
35
import org.eclipse.swt.graphics.Image;
36
37
/** 
38
 * <p>Content provider for the Logical view of the Test Navigator.</p>
39
 * 
40
 * 
41
 * @author  Jerome Gout
42
 * @author  Paul Slauenwhite
43
 * @version May 18, 2009
44
 * @since   February 1, 2005
45
 */
46
public class LogicalTestNavigatorContentProvider extends TestNavigatorContentProvider {
47
48
    /** The file proxy manager to acces to proxies from files */
49
    private static FileProxyManager fileProxyManager = new FileProxyManager();
50
    
51
    private ProxiesRequests requests = new ProxiesRequests();
52
    
53
    /**
54
     * @return Returns the fileProxyManager.
55
     */
56
    public static IFileProxyManager getSharedFileProxyManager() {
57
        return fileProxyManager;
58
    }
59
60
    public LogicalTestNavigatorContentProvider(TestNavigator testNavigator) {
61
    	super(testNavigator);
62
    }
63
    
64
    protected IFileProxyManager getFileProxyManager() {
65
    	return fileProxyManager;
66
    }
67
68
	public boolean hasChildren(Object parentElement) {
69
		if (parentElement == null)
70
			return false;
71
		if(parentElement instanceof IProject) {
72
			return true;
73
		}
74
		return super.hasChildren(parentElement);
75
	}
76
	
77
	public Object[] getChildren(Object parentElement) {
78
		if(parentElement instanceof IProject) {
79
			IProject project = (IProject)parentElement;
80
			if (project.isAccessible()) {
81
				Collection types = getTypes();
82
				Collection extensions = getExtensions();
83
				ArrayList ret = new ArrayList(types.size() + extensions.size());
84
				LogicalProjectProxiesRequest request = requests.getRequest(project, types, extensions);
85
				for (Iterator it = types.iterator(); it.hasNext();) {
86
					String type = (String) it.next();
87
					IProxyNode proxy = request.getProxy(LogicalProjectProxiesRequest.TYPE_PROVIDER_PREFIX + type);
88
					if (proxy != null) {
89
						ret.add(proxy);
90
					}
91
				}
92
				for (Iterator it = extensions.iterator(); it.hasNext();) {
93
					String ext = (String) it.next();
94
					IProxyNode proxy = request.getProxy(LogicalProjectProxiesRequest.TEST_ASSET_EXTENSION_PREFIX + ext);
95
					if (proxy != null) {
96
						ret.add(proxy);
97
					}
98
				}
99
				if (request.isPending()) {
100
					ret.add(0, new PendingProxy(project));
101
				}
102
				return ret.toArray();
103
			}
104
			return new Object[0];
105
		}
106
		return super.getChildren(parentElement);
107
	}
108
109
	private Collection getTypes() {
110
        AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry();
111
        IAssociationMapping associationMapping = registry.getAssociationMapping(IAssociationConstants.EP_TYPE_DESCRIPTIONS);
112
        String[] types = associationMapping.getTypes();
113
        List typeProviders = new ArrayList(types.length);
114
        for (int i = 0; i < types.length; i++) {
115
        	IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(types[i]);
116
        	if (descriptor != null) {
117
                typeProviders.add(types[i]);
118
        	}
119
        }
120
        return typeProviders;
121
    }
122
	
123
	private Collection getExtensions() {
124
		return TestNavigator.getTestAssetGroupProxyManager().getExtensions();
125
	}
126
	
127
    public IGlobalProxyNodeListener getProxyNodeListener() {
128
    	return requests;
129
    }
130
131
	public void dispose() {
132
		requests.dispose();
133
	}
134
135
    class ProxiesRequests implements IProxiesRequestListener, IGlobalProxyNodeListener, IDisposable {
136
    	
137
    	private Map projectToRequestMap = new HashMap();
138
    	
139
    	public LogicalProjectProxiesRequest getRequest(IProject project, Collection types, Collection extensions) {
140
    		LogicalProjectProxiesRequest req = (LogicalProjectProxiesRequest)projectToRequestMap.get(project);
141
    		if (req == null) {
142
    			ArrayList requests = new ArrayList(types.size() + extensions.size());
143
    			for(Iterator it = types.iterator(); it.hasNext(); ) {
144
    				requests.add(LogicalProjectProxiesRequest.TYPE_PROVIDER_PREFIX + (String)it.next());
145
    			}
146
    			for(Iterator it = extensions.iterator(); it.hasNext(); ) {
147
    				requests.add(LogicalProjectProxiesRequest.TEST_ASSET_EXTENSION_PREFIX + (String)it.next());
148
    			}
149
    			req = new LogicalProjectProxiesRequest(requests, TestNavigator.getTypeProviderManager(), TestNavigator.getTestAssetGroupProxyManager(), project, testNavigator);
150
    			req.setPriority(getJobPriority());
151
    			testNavigator.getJobPool().scheduleJob(req);
152
                if (!req.wait(getResponseTime(), this, 2000)) {
153
                	projectToRequestMap.put(project, req);
154
                }
155
    		}
156
    		return req;
157
    	}
158
    	
159
		public void computationCompleted(ProxiesRequest request) {
160
			IProject project = ((LogicalProjectProxiesRequest)request).getProject();
161
			if (projectToRequestMap.containsKey(project)) {
162
				// A last refresh is necessary to remove the "Pending..." node.
163
				testNavigator.refresh(project);
164
			}
165
		}
166
167
		public void proxiesComputed(ProxiesRequest request) {
168
			IProject project = ((LogicalProjectProxiesRequest)request).getProject();
169
			testNavigator.refresh(project);
170
		}
171
172
		public void proxyComputed(ProxiesRequest request, Object key) {
173
		}
174
175
		public void nodeChanged(Object node) {
176
			if (node instanceof IProject) {
177
				LogicalProjectProxiesRequest req = (LogicalProjectProxiesRequest) projectToRequestMap.get(node);
178
				if (req != null) {
179
					// Then we need to cancel the current request. A new one will be spawned
180
					// when getChildren() is invoked on this project.
181
					if (req.cancel(1000)) {
182
						projectToRequestMap.remove(node);
183
					}
184
				}
185
			}
186
		}
187
188
		public void nodesChanged() {
189
			for (Iterator it = projectToRequestMap.keySet().iterator(); it.hasNext();) {
190
				nodeChanged(it.next());
191
			}
192
		}
193
		
194
		public void computationCancelled(ProxiesRequest request) {
195
			IProject project = ((LogicalProjectProxiesRequest)request).getProject();
196
			projectToRequestMap.remove(project);
197
			testNavigator.refresh(project);
198
		}
199
    	
200
		public void dispose() {
201
			// Cancel all running requests. Note that a LogicalProjectProxiesRequest may take
202
			// considerable time before it can honor the cancel request. So in general the
203
			// request may be still running for a long time after this instance has been
204
			// disposed.
205
			// If the user switches from the logical view to the resource view, and then back
206
			// to the logical view, this provider is disposed, and then another instance gets
207
			// created. As a result, two requests for the same project may be running: the old
208
			// one, which has been cancelled but has not stopped yet, and the new one. This
209
			// will look as if two jobs are doing the same thing at the same time. However what
210
			// really happens is that the new job is blocked on a wait until the old request 
211
			// completes, and then the new job automatically leverages the computation performed
212
			// by the old one, so there is no CPU waste. The only drawback is that the new job
213
			// occupies a slot in the Test navigator job pool.
214
			for (Iterator it = projectToRequestMap.values().iterator(); it.hasNext();) {
215
				ProxiesRequest request = (ProxiesRequest) it.next();
216
				request.dispose();
217
				it.remove();
218
			}
219
		}
220
221
    }
222
    
223
    private static class PendingProxy implements IProxyNode {
224
    	public PendingProxy(Object parent) {
225
    		this.parent = parent;
226
    	}
227
    	private Object parent;
228
    	private static IProxyNode[] NO_CHILDREN = new IProxyNode[0];
229
		public IProxyNode[] getChildren() {
230
			return NO_CHILDREN;
231
		}
232
		public Image getImage() {
233
			return null;
234
		}
235
		public Object getParent() {
236
			return parent;
237
		}
238
		public String getText() {
239
			return TestNavigatorMessages.NODE_PENDING;
240
		}
241
		public Object getAdapter(Class adapter) {
242
			return null;
243
		}
244
		public String getIdentifier() {
245
			return "~"; //$NON-NLS-1$
246
		}
247
		public IResource getUnderlyingResource() {
248
			return null;
249
		}
250
    }
251
252
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/ResourceTestNavigatorContentProvider.java (+243 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 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
 * $Id: ResourceTestNavigatorProvider.java,v 1.10 2007/04/06 13:49:24 jgout Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator;
13
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.core.resources.IContainer;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.hyades.test.ui.UiPlugin;
27
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
28
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.FileProxiesRequest;
29
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.IProxiesRequestListener;
30
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.ProxiesRequest;
31
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
32
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
33
import org.eclipse.hyades.ui.util.IDisposable;
34
35
/** 
36
 * <p>Content provider for the Resource view of the Test Navigator.</p>
37
 * 
38
 * 
39
 * @author  Jerome Gout
40
 * @author  Paul Slauenwhite
41
 * @version May 18, 2009
42
 * @since   February 1, 2005
43
 */
44
public class ResourceTestNavigatorContentProvider extends TestNavigatorContentProvider {
45
46
    /** The file proxy manager to acces to proxies from files */
47
    private static FileProxyManager fileProxyManager = new FileProxyManager();
48
    
49
    /**
50
     * @return Returns the fileProxyManager.
51
     */
52
    public static FileProxyManager getSharedFileProxyManager() {
53
        return fileProxyManager;
54
    }
55
56
    public ResourceTestNavigatorContentProvider(TestNavigator testNavigator) {
57
    	super(testNavigator);
58
    }
59
    
60
    private FileProxyRequests requests = new FileProxyRequests();
61
    
62
    protected IFileProxyManager getFileProxyManager() {
63
    	return fileProxyManager;
64
    }
65
66
	public Object getParent(Object element) {
67
		if (element instanceof IResource) {
68
			return ((IResource) element).getParent();
69
		}
70
		return super.getParent(element);
71
	}
72
	
73
	public boolean hasChildren(Object parentElement) {
74
		if (parentElement == null)
75
			return false;
76
		if (parentElement instanceof IContainer) {
77
			IContainer container = (IContainer) parentElement;
78
			if (!container.isAccessible())
79
				return false;
80
81
			IResource[] resources = null;
82
			try {
83
				resources = container.members();
84
			} catch (CoreException e) {
85
				UiPlugin.logError(e);
86
				return false;
87
			}
88
			if (resources.length == 0) return false;
89
			if (parentElement instanceof IProject) {
90
				return true;
91
			}
92
			for (int i = 0; i < resources.length; i++) {
93
				if (resources[i].getType() != IResource.FILE) {
94
					if (!TestNavigator.getFiltersManager().filter(resources[i]))
95
						return true;
96
				} else {
97
					String fileExtension = resources[i].getFileExtension();
98
					if (fileExtension != null) {
99
						if (TestNavigator.getFiltersManager().isVisibleResource(resources[i])) return true;
100
					}
101
				}
102
			}
103
			return false;
104
		}
105
		return super.hasChildren(parentElement);
106
	}
107
	
108
	public Object[] getChildren(Object parentElement) {
109
		if (parentElement instanceof IContainer) {
110
			return getContainerChildren(parentElement);
111
		} else {
112
			return super.getChildren(parentElement);
113
		}
114
	}
115
116
	/** returns the children of a container node (project or folder)
117
	 * @param parentElement
118
	 * @return an array of Object which cn be empty but not null
119
	 */
120
	private Object[] getContainerChildren(Object parentElement) {
121
		IResource[] resources = null;
122
		IContainer container = ((IContainer) parentElement);
123
        if (container.isAccessible()) {
124
            try {
125
                resources = container.members();
126
            } catch (CoreException e) {
127
                UiPlugin.logError(e);
128
                return new Object[0];
129
            }
130
            List children = new ArrayList(resources.length);
131
            FileProxiesRequest request = requests.getRequest(container, resources);
132
            for (int i = 0, maxi = resources.length; i < maxi; i++) {
133
                if (!TestNavigator.getFiltersManager().filter(resources[i])) {
134
                	if (resources[i].getType() != IResource.FILE) { 
135
                		children.add(resources[i]);
136
                	} else {
137
                        //- convert the file in something else (proxy)
138
                    	IFile file = (IFile)resources[i];
139
                        IProxyNode node = request.getProxy(file);
140
                        if (!TestNavigator.getFiltersManager().filter(node)) {
141
                            children.add(node);
142
                            fileProxyManager.cacheProxy(file, node);
143
                        }
144
                    }
145
                }
146
            }
147
            return children.toArray();
148
        }
149
        return new Object[0];
150
	}
151
152
    public IGlobalProxyNodeListener getProxyNodeListener() {
153
    	return requests;
154
    }
155
156
	private class FileProxyRequests implements IProxiesRequestListener, IDisposable, IGlobalProxyNodeListener {
157
		
158
	    private Map containerToRequestMap = Collections.synchronizedMap(new HashMap());
159
	    
160
	    public FileProxiesRequest getRequest(IContainer container, IResource[] members) {
161
	    	FileProxiesRequest request = (FileProxiesRequest)containerToRequestMap.get(container);
162
	    	if (request == null) {
163
	    		request = newRequest(container, members);
164
	    	}
165
	    	return request;
166
	    }
167
	    
168
	    public FileProxiesRequest newRequest(IContainer container, IResource[] members) {
169
	    	ArrayList filesToRequest = new ArrayList(members.length);
170
            for (int i = 0, maxi = members.length; i < maxi; i++) {
171
            	if (members[i].getType() == IResource.FILE) {
172
            		if (!TestNavigator.getFiltersManager().filter(members[i])) {
173
                    	filesToRequest.add(members[i]);
174
                    }
175
                }
176
            }
177
            if (filesToRequest.isEmpty()) return null;
178
            FileProxiesRequest req = new FileProxiesRequest(filesToRequest, fileProxyManager, container, testNavigator);
179
            req.setPriority(getJobPriority());
180
            testNavigator.getJobPool().scheduleJob(req);
181
            if (!req.wait(getResponseTime(), this, 2000)) {
182
            	containerToRequestMap.put(container, req);
183
            }
184
            return req;
185
	    }
186
	    
187
		public void proxyComputed(final ProxiesRequest request, Object key) {
188
		}
189
	
190
		public void computationCompleted(ProxiesRequest request) {
191
			IContainer parent = ((FileProxiesRequest)request).getParent();
192
			if (containerToRequestMap.containsKey(parent)) {
193
				testNavigator.refresh(parent);
194
			}
195
		}
196
197
		public void dispose() {
198
			// Cancel all running requests. As the atomic action of FileProxiesRequest is
199
			// the computation of a single file proxy, all requests should honor the cancel
200
			// request quite quickly. However we don't wait them to complete (i.e. they may
201
			// be still running while this instance has been disposed).
202
			for (Iterator it = containerToRequestMap.values().iterator(); it.hasNext();) {
203
				FileProxiesRequest request = (FileProxiesRequest) it.next();
204
				request.dispose();
205
				it.remove();
206
			}
207
		}
208
209
		public void proxiesComputed(ProxiesRequest request) {
210
			testNavigator.refresh(((FileProxiesRequest)request).getParent());
211
		}
212
213
		public void nodeChanged(Object node) {
214
			if (node instanceof IContainer) {
215
				FileProxiesRequest req = (FileProxiesRequest) containerToRequestMap.remove(node);
216
				if (req != null) {
217
					// Then we need to cancel the current request. A new one will be spawned
218
					// when getChildren() is invoked on this project.
219
					if (req.cancel(1000)) {
220
						containerToRequestMap.remove(node);
221
					}
222
				}
223
			}
224
		}
225
		
226
		public void nodesChanged() {
227
			for (Iterator it = containerToRequestMap.keySet().iterator(); it.hasNext();) {
228
				nodeChanged(it.next());
229
			}
230
		}
231
		
232
		public void computationCancelled(ProxiesRequest request) {
233
			IContainer parent = ((FileProxiesRequest)request).getParent();
234
			containerToRequestMap.remove(parent);
235
			testNavigator.refresh(parent);
236
		}
237
    	
238
	}
239
	
240
	public void dispose() {
241
		requests.dispose();
242
	}
243
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/TestNavigatorContentProvider.java (+254 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 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
 * $Id: TestNavigatorProvider.java,v 1.13 2009/02/12 19:19:00 paules Exp $
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator;
13
14
import java.util.LinkedList;
15
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IWorkspaceRoot;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager;
21
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
22
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
23
import org.eclipse.hyades.test.ui.navigator.IProxyNodeListener;
24
import org.eclipse.jface.viewers.ITreeContentProvider;
25
import org.eclipse.jface.viewers.Viewer;
26
import org.eclipse.swt.graphics.Image;
27
28
/**
29
 * <p>Content provider for the Test Navigator.</p>
30
 *
31
 * 
32
 * @author  Jerome Gout
33
 * @author  Julien Canches
34
 * @author  Paul E. Slauenwhite
35
 * @version May 18, 2009
36
 * @since   March 18, 2005 
37
 */
38
public abstract class TestNavigatorContentProvider implements ITreeContentProvider {
39
40
	private static final int MAX_PROXY_NODE_CHILDREN = 100;
41
	public static final int CONTEXT_LOADING = 0;
42
	public static final int CONTEXT_INTERACTIVE = 1;
43
	
44
	protected TestNavigator testNavigator;
45
	private int context;
46
	
47
	public TestNavigatorContentProvider(TestNavigator testNavigator) {
48
		this.testNavigator = testNavigator;
49
		this.context = CONTEXT_LOADING;
50
	}
51
52
	protected abstract IGlobalProxyNodeListener getProxyNodeListener();
53
54
	protected abstract IFileProxyManager getFileProxyManager();
55
		
56
	public Object getParent(Object element) {
57
		if (element instanceof IProxyNode) {
58
            Object parent = ((IProxyNode) element).getParent();
59
            if(parent instanceof FileProxyManager.IUnboundedParent) {
60
                return getFileProxyManager().getParent((IProxyNode) element);
61
            } else {
62
                return parent;
63
            }
64
		}
65
		return null;
66
	}
67
68
	public boolean hasChildren(Object parentElement) {
69
		if (parentElement instanceof IProxyNode) {
70
			IProxyNode proxy = (IProxyNode) parentElement;
71
			return proxy.getChildren().length > 0;
72
		}
73
		if (parentElement instanceof IProxyGroup) {
74
			return true;
75
		}
76
		return false;
77
	}
78
79
	public Object[] getChildren(Object parentElement) {
80
		if (parentElement instanceof IProxyNode) {
81
			IProxyNode proxy = (IProxyNode) parentElement;
82
			return foldProxyNodes(proxy);
83
		}
84
		if (parentElement instanceof IProxyGroup) {
85
			return ((IProxyGroup)parentElement).getChildren();
86
		}
87
		return new Object[0];
88
	}
89
	
90
	public Object[] getElements(Object inputElement) {
91
		if (inputElement instanceof IWorkspaceRoot) {
92
			IProject [] projects = ((IWorkspaceRoot) inputElement).getProjects();
93
			LinkedList visibleProjects = new LinkedList();
94
			for(int i = 0; i < projects.length; i++) {
95
				if(!TestNavigator.getFiltersManager().filter(projects[i])) {
96
					visibleProjects.add(projects[i]);
97
				}
98
			}
99
			return visibleProjects.toArray();
100
		}
101
		return getChildren(inputElement);
102
	}
103
    
104
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
105
	}
106
	
107
	public static interface IGlobalProxyNodeListener extends IProxyNodeListener {
108
		
109
		void nodesChanged();
110
		
111
	}
112
	
113
	public static interface IProxyGroup extends IProxyNode{
114
		int getOrder();
115
	}
116
	
117
	private static class ProxyGroup implements IProxyGroup {
118
		private IProxyNode parent;
119
		private int sequence;
120
		public ProxyGroup(IProxyNode node, int sequence) {
121
			this.parent = node;
122
			this.sequence = sequence;
123
		}
124
		public IProxyNode[] getChildren() {
125
			int start = sequence * MAX_PROXY_NODE_CHILDREN;
126
			IProxyNode[] completeChildren = parent.getChildren();
127
			IProxyNode[] children = new IProxyNode[MAX_PROXY_NODE_CHILDREN];
128
			System.arraycopy(completeChildren, start, children, 0, MAX_PROXY_NODE_CHILDREN);
129
			return children;
130
		}
131
		public String getText() {
132
			int start = sequence * MAX_PROXY_NODE_CHILDREN + 1;
133
			int end = (sequence + 1) * MAX_PROXY_NODE_CHILDREN;
134
			return ("[".concat(Integer.toString(start)).concat(" - ").concat(Integer.toString(end)).concat("]"));
135
		}
136
		public Image getImage() {
137
			return parent.getImage();
138
		}
139
		public int getOrder() {
140
			return sequence;
141
		}
142
		public Object getParent() {	
143
			return parent;
144
		}
145
		public Object getAdapter(Class adapter) {
146
			return null;
147
		}
148
		public String getIdentifier() {
149
			return null;
150
		}
151
		public IResource getUnderlyingResource() {
152
			return null;
153
		}
154
	}
155
	
156
	private static class RemainingProxyGroup implements IProxyGroup {
157
		private IProxyNode parent;
158
		public RemainingProxyGroup(IProxyNode parent) {
159
			this.parent = parent;
160
		}
161
		public IProxyNode[] getChildren() {
162
			IProxyNode[] completeChildren = parent.getChildren();
163
			int completeLength = completeChildren.length;
164
			int length = completeLength % MAX_PROXY_NODE_CHILDREN;
165
			IProxyNode[] children = new IProxyNode[length];
166
			System.arraycopy(completeChildren, completeLength - length, children, 0, length);
167
			return children;
168
		}
169
		public String getText() {
170
			IProxyNode[] completeChildren = parent.getChildren();
171
			int end = completeChildren.length;
172
			int length = end % MAX_PROXY_NODE_CHILDREN;
173
			int start = end - length + 1;
174
			return ("[".concat(Integer.toString(start)).concat(" - ").concat(Integer.toString(end)).concat("]"));
175
		}
176
		public Image getImage() {
177
			return parent.getImage();
178
		}
179
		public int getOrder() {
180
			return Integer.MAX_VALUE;
181
		}
182
		public Object getParent() {
183
			return parent;
184
		}
185
		public Object getAdapter(Class adapter) {
186
			return null;
187
		}
188
		public String getIdentifier() {
189
			return null;
190
		}
191
		public IResource getUnderlyingResource() {
192
			return null;
193
		}
194
	}
195
	
196
	protected Object[] foldProxyNodes(IProxyNode parent) {
197
		IProxyNode[] children = parent.getChildren();
198
		int length = children.length;
199
		if (length <= MAX_PROXY_NODE_CHILDREN) return children;
200
		int size = length / MAX_PROXY_NODE_CHILDREN;
201
		int remaining = length % MAX_PROXY_NODE_CHILDREN;
202
		int totalSize = size + (remaining > 0 ? 1 : 0);
203
		Object[] groups = new IProxyGroup[totalSize];
204
		for (int i = 0; i < size; i++) {
205
			groups[i] = new ProxyGroup(parent, i);
206
		}
207
		if (remaining > 0) {
208
			groups[size] = new RemainingProxyGroup(parent);
209
		}
210
		return groups;
211
	}
212
213
	/**
214
	 * Sets the context in which the provider is used. There are two available values:
215
	 * INTERACTIVE and LOADING. The context has an effect on two parameters:
216
	 * 1) responsiveness: time that getChildren() is allowed to spent before returning
217
	 * control. High responsiveness means that the provider will return incomplete nodes,
218
	 * compute the remaining in a background task, and update the navigator when computation
219
	 * is complete. Low responsiveness means that the UI will be blocked for a longer period of
220
	 * time but the returned node are more likely to be complete.
221
	 * 2) computation job priority: the priority allocated to the computation job, if the provider
222
	 * does not manage to compute nodes in the allocated time (responsiveness parameter). This does
223
	 * not affect the thread priority, but helps eclipse decide which job should be launched first.
224
	 * In LOADING mode, responsiveness is high (100ms) and priority is low (NORMAL).
225
	 * In INTERACTIVE mode, responsiveness is lower (800ms) and priority is high (INTERACTIVE).
226
	 */
227
	public void setContext(int context) {
228
		this.context = context;
229
	}
230
	
231
	protected int getContext() {
232
		return context;
233
	}
234
	
235
	protected int getResponseTime() {
236
		switch (context) {
237
		case CONTEXT_INTERACTIVE:
238
			return 800;
239
		case CONTEXT_LOADING:
240
			return 100;
241
		}
242
		return 100;
243
	}
244
	
245
	protected int getJobPriority() {
246
		switch(context) {
247
		case CONTEXT_INTERACTIVE:
248
			return Job.INTERACTIVE;
249
		case CONTEXT_LOADING:
250
			return Job.LONG;
251
		}
252
		return Job.LONG;
253
	}	
254
}

Return to bug 164483