|
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 |
} |