RunAndTrack update accessed variables [message #1770373] |
Thu, 10 August 2017 12:58 |
Felix Dorner Messages: 392 Registered: December 2015 |
Senior Member |
|
|
I understand that a RunAndTrack is initially executed and something records which context variables are accessed during that execution, say I access a, b, c.
Now, when one of these variables changes, the RunAndTrack is executed again. In that second execution, imagine I access variable only variable d, which hasn't been accessed during the first run.
Which variable changes do now cause re-execution of that run and track? a,b,c, or a,b,c,d, or only d?
The concrete example here is some code in ToolBarManagerRenderer:
public void init() {
context.set(ToolBarManagerRenderer.class, this);
String[] vars = {
"org.eclipse.ui.internal.services.EvaluationService.evaluate", //$NON-NLS-1$
IServiceConstants.ACTIVE_CONTEXTS,
IServiceConstants.ACTIVE_PART,
IServiceConstants.ACTIVE_SELECTION,
IServiceConstants.ACTIVE_SHELL };
updateVariables.addAll(Arrays.asList(vars));
context.set(UPDATE_VARS, updateVariables);
RunAndTrack enablementUpdater = new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
for (String var : updateVariables) {
context.get(var);
}
getUpdater().updateContributionItems(ALL_SELECTOR);
return true;
}
};
context.runAndTrack(enablementUpdater);
}
At some point in time, my custom variable is added to 'updateVariables', but the RunAndTrack is not re-executed if I change that variables value afterwards :/
|
|
|
Re: RunAndTrack update accessed variables [message #1770383 is a reply to message #1770373] |
Thu, 10 August 2017 15:37 |
Eclipse User |
|
|
|
Your context needs to request the `UPDATE_VARS` value (with your code above, an easy way would be to add `UPDATE_VARS` to your `updateVariables`), and you need to re-set the value of `UPDATE_VARS` whenever its contents change. That is:
updateVariables.add(UPDATE_VARS); // so the RAT monitors this varname collection too
updateVariables.addAll(Arrays.asList(vars));
context.set(UPDATE_VARS, updateVariables);
...
// later: we add a new variable
updateVariables.add("my new variable");
context.set(UPDATE_VARS, updateVariables); // triggers the RAT
|
|
|
Powered by
FUDForum. Page generated in 0.02876 seconds