author | dadubrow |
Tue, 02 Jun 2009 09:59:27 -0500 | |
changeset 16 | 06d88bb6aac0 |
parent 12 | 063eb66097dc |
permissions | -rw-r--r-- |
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1 |
/******************************************************************************* |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2004, 2008 IBM Corporation and others. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. This program and the accompanying materials |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
5 |
* which accompanies this distribution, and is available at |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
7 |
* |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
8 |
* Contributors: |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
9 |
* IBM - Initial API and implementation |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
10 |
*******************************************************************************/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
11 |
package org.eclipse.core.internal.refresh; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
12 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
13 |
import java.util.*; |
16 | 14 |
|
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
15 |
import org.eclipse.core.internal.localstore.PrefixPool; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
16 |
import org.eclipse.core.internal.utils.Messages; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
17 |
import org.eclipse.core.internal.utils.Policy; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
18 |
import org.eclipse.core.resources.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
19 |
import org.eclipse.core.runtime.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
20 |
import org.eclipse.osgi.util.NLS; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
21 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
22 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
23 |
* The <code>RefreshJob</code> class maintains a list of resources that |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
24 |
* need to be refreshed, and periodically schedules itself to perform the |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
25 |
* refreshes in the background. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
26 |
* |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
27 |
* @since 3.0 |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
28 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
29 |
public class RefreshJob extends WorkspaceJob { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
30 |
private static final long UPDATE_DELAY = 200; |
16 | 31 |
|
32 |
/** |
|
33 |
* Flag indicating refreshing in progress if > 0 |
|
34 |
*/ |
|
35 |
private static int refreshingLevel = 0; |
|
36 |
||
37 |
||
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
38 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
39 |
* List of refresh requests. Requests are processed in order from |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
40 |
* the end of the list. Requests can be added to either the beginning |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
41 |
* or the end of the list depending on whether they are explicit user |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
42 |
* requests or background refresh requests. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
43 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
44 |
private final List fRequests; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
45 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
46 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
47 |
* The history of path prefixes visited during this refresh job invocation. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
48 |
* This is used to prevent infinite refresh loops caused by symbolic links in the file system. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
49 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
50 |
private PrefixPool pathPrefixHistory, rootPathHistory; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
51 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
52 |
public RefreshJob() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
53 |
super(Messages.refresh_jobName); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
54 |
fRequests = new ArrayList(1); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
55 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
56 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
57 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
58 |
* Adds the given resource to the set of resources that need refreshing. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
59 |
* Synchronized in order to protect the collection during add. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
60 |
* @param resource |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
61 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
62 |
private synchronized void addRequest(IResource resource) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
63 |
IPath toAdd = resource.getFullPath(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
64 |
for (Iterator it = fRequests.iterator(); it.hasNext();) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
65 |
IPath request = ((IResource) it.next()).getFullPath(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
66 |
//discard any existing requests the same or below the resource to be added |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
67 |
if (toAdd.isPrefixOf(request)) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
68 |
it.remove(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
69 |
//nothing to do if the resource to be added is a child of an existing request |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
70 |
else if (request.isPrefixOf(toAdd)) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
71 |
return; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
72 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
73 |
//finally add the new request to the front of the queue |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
74 |
fRequests.add(resource); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
75 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
76 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
77 |
private synchronized void addRequests(List list) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
78 |
//add requests to the end of the queue |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
79 |
fRequests.addAll(0, list); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
80 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
81 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
82 |
/* (non-Javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
83 |
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(Object) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
84 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
85 |
public boolean belongsTo(Object family) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
86 |
return family == ResourcesPlugin.FAMILY_AUTO_REFRESH; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
87 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
88 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
89 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
90 |
* This method adds all members at the specified depth from the resource |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
91 |
* to the provided list. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
92 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
93 |
private List collectChildrenToDepth(IResource resource, ArrayList children, int depth) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
94 |
if (resource.getType() == IResource.FILE) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
95 |
return children; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
96 |
IResource[] members; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
97 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
98 |
members = ((IContainer) resource).members(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
99 |
} catch (CoreException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
100 |
//resource is not accessible - just return what we have |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
101 |
return children; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
102 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
103 |
for (int i = 0; i < members.length; i++) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
104 |
if (members[i].getType() == IResource.FILE) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
105 |
continue; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
106 |
if (depth <= 1) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
107 |
children.add(members[i]); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
108 |
else |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
109 |
collectChildrenToDepth(members[i], children, depth - 1); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
110 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
111 |
return children; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
112 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
113 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
114 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
115 |
* Returns the path prefixes visited by this job so far. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
116 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
117 |
public PrefixPool getPathPrefixHistory() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
118 |
if (pathPrefixHistory == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
119 |
pathPrefixHistory = new PrefixPool(20); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
120 |
return pathPrefixHistory; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
121 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
122 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
123 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
124 |
* Returns the root paths visited by this job so far. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
125 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
126 |
public PrefixPool getRootPathHistory() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
127 |
if (rootPathHistory == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
128 |
rootPathHistory = new PrefixPool(20); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
129 |
return rootPathHistory; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
130 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
131 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
132 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
133 |
* Returns the next item to refresh, or <code>null</code> if there are no requests |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
134 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
135 |
private synchronized IResource nextRequest() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
136 |
// synchronized: in order to atomically obtain and clear requests |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
137 |
int len = fRequests.size(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
138 |
if (len == 0) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
139 |
return null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
140 |
return (IResource) fRequests.remove(len - 1); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
141 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
142 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
143 |
/* (non-Javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
144 |
* @see org.eclipse.core.resources.refresh.IRefreshResult#refresh |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
145 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
146 |
public void refresh(IResource resource) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
147 |
if (resource == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
148 |
return; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
149 |
addRequest(resource); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
150 |
schedule(UPDATE_DELAY); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
151 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
152 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
153 |
/* (non-Javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
154 |
* @see WorkspaceJob#runInWorkspace |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
155 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
156 |
public IStatus runInWorkspace(IProgressMonitor monitor) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
157 |
long start = System.currentTimeMillis(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
158 |
String msg = Messages.refresh_refreshErr; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
159 |
MultiStatus errors = new MultiStatus(ResourcesPlugin.PI_RESOURCES, 1, msg, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
160 |
long longestRefresh = 0; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
161 |
try { |
16 | 162 |
refreshingLevel++; |
163 |
ResourcesPlugin.writeRefreshLog(RefreshManager.DEBUG_PREFIX + " refreshing started..."); //$NON-NLS-1$ |
|
164 |
for (Iterator iterator = fRequests.iterator(); iterator.hasNext();) { |
|
165 |
IResource resource = (IResource) iterator.next(); |
|
166 |
ResourcesPlugin.writeRefreshLog(RefreshManager.DEBUG_PREFIX + " requested resource to refresh: " + resource.getFullPath()); //$NON-NLS-1$ |
|
167 |
} |
|
168 |
||
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
169 |
if (RefreshManager.DEBUG) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
170 |
Policy.debug(RefreshManager.DEBUG_PREFIX + " starting refresh job"); //$NON-NLS-1$ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
171 |
int refreshCount = 0; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
172 |
int depth = 2; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
173 |
monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
174 |
IResource toRefresh; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
175 |
while ((toRefresh = nextRequest()) != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
176 |
if (monitor.isCanceled()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
177 |
throw new OperationCanceledException(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
178 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
179 |
refreshCount++; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
180 |
long refreshTime = -System.currentTimeMillis(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
181 |
toRefresh.refreshLocal(1000 + depth, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
182 |
refreshTime += System.currentTimeMillis(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
183 |
if (refreshTime > longestRefresh) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
184 |
longestRefresh = refreshTime; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
185 |
//show occasional progress |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
186 |
if (refreshCount % 100 == 0) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
187 |
monitor.subTask(NLS.bind(Messages.refresh_task, Integer.toString(fRequests.size()))); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
188 |
if (refreshCount % 1000 == 0) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
189 |
//be polite to other threads (no effect on some platforms) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
190 |
Thread.yield(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
191 |
//throttle depth if it takes too long |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
192 |
if (longestRefresh > 2000 && depth > 1) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
193 |
depth = 1; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
194 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
195 |
if (longestRefresh < 1000) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
196 |
depth *= 2; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
197 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
198 |
longestRefresh = 0; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
199 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
200 |
addRequests(collectChildrenToDepth(toRefresh, new ArrayList(), depth)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
201 |
} catch (CoreException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
202 |
errors.merge(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, 1, errors.getMessage(), e)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
203 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
204 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
205 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
206 |
pathPrefixHistory = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
207 |
rootPathHistory = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
208 |
monitor.done(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
209 |
if (RefreshManager.DEBUG) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
210 |
System.out.println(RefreshManager.DEBUG_PREFIX + " finished refresh job in: " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
16 | 211 |
|
212 |
ResourcesPlugin.writeRefreshLog(RefreshManager.DEBUG_PREFIX + " finished refresh job in: " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
213 |
refreshingLevel--; |
|
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
214 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
215 |
if (!errors.isOK()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
216 |
return errors; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
217 |
return Status.OK_STATUS; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
218 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
219 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
220 |
/* (non-Javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
221 |
* @see org.eclipse.core.runtime.jobs.Job#shouldRun() |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
222 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
223 |
public synchronized boolean shouldRun() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
224 |
return !fRequests.isEmpty(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
225 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
226 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
227 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
228 |
* Starts the refresh job |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
229 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
230 |
public void start() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
231 |
if (RefreshManager.DEBUG) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
232 |
System.out.println(RefreshManager.DEBUG_PREFIX + " enabling auto-refresh"); //$NON-NLS-1$ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
233 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
234 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
235 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
236 |
* Stops the refresh job |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
237 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
238 |
public void stop() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
239 |
if (RefreshManager.DEBUG) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
240 |
System.out.println(RefreshManager.DEBUG_PREFIX + " disabling auto-refresh"); //$NON-NLS-1$ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
241 |
cancel(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
242 |
} |
16 | 243 |
|
244 |
public static boolean isRefreshing() { |
|
245 |
return refreshingLevel > 0; |
|
246 |
} |
|
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
247 |
} |