|
Lines 1-9
Link Here
|
| 1 |
package org.eclipse.equinox.internal.p2.ui.dialogs; |
1 |
package org.eclipse.equinox.internal.p2.ui.dialogs; |
| 2 |
|
2 |
|
| 3 |
import org.eclipse.core.runtime.jobs.IJobChangeEvent; |
3 |
import org.eclipse.core.runtime.*; |
| 4 |
import org.eclipse.core.runtime.jobs.JobChangeAdapter; |
4 |
import org.eclipse.core.runtime.jobs.*; |
| 5 |
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; |
5 |
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; |
|
|
6 |
import org.eclipse.equinox.internal.provisional.p2.ui.ProvisioningOperationRunner; |
| 6 |
import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.IViewMenuProvider; |
7 |
import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.IViewMenuProvider; |
|
|
8 |
import org.eclipse.equinox.internal.provisional.p2.ui.query.QueriedElement; |
| 9 |
import org.eclipse.equinox.internal.provisional.p2.ui.query.QueryableMetadataRepositoryManager; |
| 7 |
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentListener; |
10 |
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentListener; |
| 8 |
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentProvider; |
11 |
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentProvider; |
| 9 |
import org.eclipse.jface.action.MenuManager; |
12 |
import org.eclipse.jface.action.MenuManager; |
|
Lines 31-36
Link Here
|
| 31 |
* |
34 |
* |
| 32 |
*/ |
35 |
*/ |
| 33 |
public class DeferredFetchFilteredTree extends FilteredTree { |
36 |
public class DeferredFetchFilteredTree extends FilteredTree { |
|
|
37 |
private static final long FILTER_DELAY_TIME = 200; |
| 38 |
private static final String WAIT_STRING = ProvUIMessages.DeferredFetchFilteredTree_RetrievingList; |
| 34 |
|
39 |
|
| 35 |
ToolBar toolBar; |
40 |
ToolBar toolBar; |
| 36 |
MenuManager menuManager; |
41 |
MenuManager menuManager; |
|
Lines 40-45
Link Here
|
| 40 |
IViewMenuProvider viewMenuProvider; |
45 |
IViewMenuProvider viewMenuProvider; |
| 41 |
DeferredQueryContentProvider contentProvider; |
46 |
DeferredQueryContentProvider contentProvider; |
| 42 |
boolean useCheckBoxTree = false; |
47 |
boolean useCheckBoxTree = false; |
|
|
48 |
InputSchedulingRule filterRule; |
| 49 |
String savedFilterText; |
| 50 |
Job loadJob; |
| 51 |
WorkbenchJob filterJob; |
| 52 |
|
| 53 |
class InputSchedulingRule implements ISchedulingRule { |
| 54 |
Object input; |
| 55 |
|
| 56 |
InputSchedulingRule(Object input) { |
| 57 |
this.input = input; |
| 58 |
} |
| 59 |
|
| 60 |
/* (non-Javadoc) |
| 61 |
* @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule) |
| 62 |
*/ |
| 63 |
public boolean contains(ISchedulingRule rule) { |
| 64 |
return rule == this; |
| 65 |
} |
| 66 |
|
| 67 |
/* (non-Javadoc) |
| 68 |
* @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule) |
| 69 |
*/ |
| 70 |
public boolean isConflicting(ISchedulingRule rule) { |
| 71 |
if (rule instanceof InputSchedulingRule) { |
| 72 |
InputSchedulingRule other = (InputSchedulingRule) rule; |
| 73 |
if (input == null) |
| 74 |
return other.getInput() == null; |
| 75 |
return input.equals(other.getInput()); |
| 76 |
} |
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
Object getInput() { |
| 81 |
return input; |
| 82 |
} |
| 83 |
} |
| 43 |
|
84 |
|
| 44 |
public DeferredFetchFilteredTree(Composite parent, int treeStyle, PatternFilter filter, final IViewMenuProvider viewMenuProvider, Display display, boolean useCheckBoxViewer) { |
85 |
public DeferredFetchFilteredTree(Composite parent, int treeStyle, PatternFilter filter, final IViewMenuProvider viewMenuProvider, Display display, boolean useCheckBoxViewer) { |
| 45 |
super(parent); |
86 |
super(parent); |
|
Lines 78-83
Link Here
|
| 78 |
} |
119 |
} |
| 79 |
if (viewMenuProvider != null) |
120 |
if (viewMenuProvider != null) |
| 80 |
createViewMenu(filterParent); |
121 |
createViewMenu(filterParent); |
|
|
122 |
filterParent.addDisposeListener(new DisposeListener() { |
| 123 |
public void widgetDisposed(DisposeEvent e) { |
| 124 |
cancelLoadJob(); |
| 125 |
} |
| 126 |
}); |
| 81 |
return filterParent; |
127 |
return filterParent; |
| 82 |
} |
128 |
} |
| 83 |
|
129 |
|
|
Lines 121-126
Link Here
|
| 121 |
public void inputChanged(Viewer v, Object oldInput, Object newInput) { |
167 |
public void inputChanged(Viewer v, Object oldInput, Object newInput) { |
| 122 |
if (newInput == null) |
168 |
if (newInput == null) |
| 123 |
return; |
169 |
return; |
|
|
170 |
// Cancel the load and filter jobs and null out the scheduling rule |
| 171 |
// so that a new one will be created on the new input when needed. |
| 172 |
cancelLoadJob(); |
| 173 |
cancelAndResetFilterJob(); |
| 174 |
filterRule = null; |
| 175 |
contentProvider.setSynchronous(false); |
| 176 |
|
| 124 |
if (showFilterControls && filterText != null && !filterText.isDisposed()) { |
177 |
if (showFilterControls && filterText != null && !filterText.isDisposed()) { |
| 125 |
filterText.setText(getInitialText()); |
178 |
filterText.setText(getInitialText()); |
| 126 |
filterText.selectAll(); |
179 |
filterText.selectAll(); |
|
Lines 136-157
Link Here
|
| 136 |
* @see org.eclipse.ui.dialogs.FilteredTree#doCreateRefreshJob() |
189 |
* @see org.eclipse.ui.dialogs.FilteredTree#doCreateRefreshJob() |
| 137 |
*/ |
190 |
*/ |
| 138 |
protected WorkbenchJob doCreateRefreshJob() { |
191 |
protected WorkbenchJob doCreateRefreshJob() { |
| 139 |
WorkbenchJob job = super.doCreateRefreshJob(); |
192 |
filterJob = super.doCreateRefreshJob(); |
| 140 |
job.addJobChangeListener(new JobChangeAdapter() { |
193 |
filterJob.addJobChangeListener(new JobChangeAdapter() { |
| 141 |
public void aboutToRun(IJobChangeEvent event) { |
194 |
public void aboutToRun(final IJobChangeEvent event) { |
| 142 |
display.syncExec(new Runnable() { |
195 |
display.syncExec(new Runnable() { |
| 143 |
public void run() { |
196 |
public void run() { |
| 144 |
String text = getFilterString(); |
197 |
String text = getFilterString(); |
| 145 |
// If we are about to filter and there is |
198 |
// If we are about to filter and there is |
| 146 |
// actually filtering to do, set the content |
199 |
// actually filtering to do, force a load |
| 147 |
// provider to synchronous mode. |
200 |
// of the input and set the content |
|
|
201 |
// provider to synchronous mode. We want the |
| 202 |
// load job to complete before continuing with filtering. |
| 148 |
if (text == null || (initialText != null && initialText.equals(text))) |
203 |
if (text == null || (initialText != null && initialText.equals(text))) |
| 149 |
return; |
204 |
return; |
| 150 |
contentProvider.setSynchronous(true); |
205 |
if (!contentProvider.getSynchronous()) { |
|
|
206 |
if (filterText != null && !filterText.isDisposed()) { |
| 207 |
filterText.setEnabled(false); |
| 208 |
filterText.setCursor(display.getSystemCursor(SWT.CURSOR_WAIT)); |
| 209 |
savedFilterText = filterText.getText(); |
| 210 |
filterText.setText(WAIT_STRING); |
| 211 |
} |
| 212 |
event.getJob().sleep(); |
| 213 |
scheduleLoadJob(); |
| 214 |
event.getJob().wakeUp(FILTER_DELAY_TIME); |
| 215 |
contentProvider.setSynchronous(true); |
| 216 |
} |
| 217 |
} |
| 218 |
}); |
| 219 |
} |
| 220 |
|
| 221 |
public void done(IJobChangeEvent event) { |
| 222 |
display.asyncExec(new Runnable() { |
| 223 |
public void run() { |
| 224 |
restoreFilterText(); |
| 225 |
} |
| 226 |
}); |
| 227 |
} |
| 228 |
|
| 229 |
public void awake(IJobChangeEvent event) { |
| 230 |
display.asyncExec(new Runnable() { |
| 231 |
public void run() { |
| 232 |
restoreFilterText(); |
| 151 |
} |
233 |
} |
| 152 |
}); |
234 |
}); |
| 153 |
} |
235 |
} |
| 154 |
}); |
236 |
}); |
| 155 |
return job; |
237 |
filterJob.setRule(getFilterJobSchedulingRule()); |
|
|
238 |
return filterJob; |
| 239 |
} |
| 240 |
|
| 241 |
void restoreFilterText() { |
| 242 |
if (filterText != null && !filterText.isDisposed() && !filterText.isEnabled()) { |
| 243 |
filterText.setText(savedFilterText); |
| 244 |
filterText.setEnabled(true); |
| 245 |
filterText.setCursor(null); |
| 246 |
filterText.setFocus(); |
| 247 |
filterText.setSelection(savedFilterText.length(), savedFilterText.length()); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
InputSchedulingRule getFilterJobSchedulingRule() { |
| 252 |
if (filterRule == null) { |
| 253 |
Object input = null; |
| 254 |
if (getViewer() != null) |
| 255 |
input = getViewer().getInput(); |
| 256 |
filterRule = new InputSchedulingRule(input); |
| 257 |
} |
| 258 |
return filterRule; |
| 259 |
} |
| 260 |
|
| 261 |
void scheduleLoadJob() { |
| 262 |
cancelLoadJob(); |
| 263 |
loadJob = new Job(WAIT_STRING) { |
| 264 |
protected IStatus run(IProgressMonitor monitor) { |
| 265 |
if (this.getRule() instanceof InputSchedulingRule) { |
| 266 |
Object input = ((InputSchedulingRule) this.getRule()).getInput(); |
| 267 |
if (input instanceof QueriedElement) |
| 268 |
if (((QueriedElement) input).getQueryable() instanceof QueryableMetadataRepositoryManager) { |
| 269 |
QueryableMetadataRepositoryManager q = (QueryableMetadataRepositoryManager) ((QueriedElement) input).getQueryable(); |
| 270 |
q.loadAll(monitor); |
| 271 |
if (monitor.isCanceled()) |
| 272 |
return Status.CANCEL_STATUS; |
| 273 |
} |
| 274 |
} |
| 275 |
return Status.OK_STATUS; |
| 276 |
} |
| 277 |
}; |
| 278 |
loadJob.setSystem(true); |
| 279 |
loadJob.setUser(false); |
| 280 |
loadJob.setRule(getFilterJobSchedulingRule()); |
| 281 |
// Telling the operation runner about it ensures that listeners know we are running |
| 282 |
// a provisioning-related job. |
| 283 |
ProvisioningOperationRunner.manageJob(loadJob); |
| 284 |
loadJob.schedule(); |
| 285 |
} |
| 286 |
|
| 287 |
void cancelLoadJob() { |
| 288 |
if (loadJob != null) { |
| 289 |
loadJob.cancel(); |
| 290 |
loadJob = null; |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
void cancelAndResetFilterJob() { |
| 295 |
if (filterJob != null) { |
| 296 |
filterJob.cancel(); |
| 297 |
filterJob.setRule(getFilterJobSchedulingRule()); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
protected void textChanged() { |
| 302 |
// Don't refilter if we are merely resetting the filter back |
| 303 |
// to what it was before loading repositories |
| 304 |
if (filterText.getText().trim().equals(WAIT_STRING)) |
| 305 |
return; |
| 306 |
super.textChanged(); |
| 156 |
} |
307 |
} |
| 157 |
} |
308 |
} |