Java 类org.eclipse.ui.actions.RefreshAction 实例源码
项目:LibertyEiffel-Eclipse-Plugin
文件:RefreshActionProvider.java
protected void makeActions() {
IShellProvider shellProvider = new IShellProvider() {
@Override
public Shell getShell() {
return shell;
}
};
refreshAction = new RefreshAction(shellProvider) {
@Override
public void run() {
final IStatus[] errorStatus = new IStatus[1];
errorStatus[0] = Status.OK_STATUS;
final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
WorkspaceJob job = new WorkspaceJob("refesh") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
op.run(monitor);
if (shell != null && !shell.isDisposed()) {
shell.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
StructuredViewer viewer = getActionSite().getStructuredViewer();
if (viewer != null && viewer.getControl() != null && !viewer.getControl()
.isDisposed()) {
viewer.refresh();
}
}
});
}
} catch (InvocationTargetException e) {
String msg = NLS.bind("Exception in {0}. run: {1}", getClass().getName(),
e.getTargetException());
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
IStatus.ERROR, msg, e.getTargetException()));
} catch (InterruptedException ex) {
return Status.CANCEL_STATUS;
}
return errorStatus[0];
}
};
ISchedulingRule rule = op.getRule();
if (rule != null) {
job.setRule(rule);
}
job.setUser(true);
job.schedule();
}
};
refreshAction.setDisabledImageDescriptor(getImageDescriptor("icons/refresh_nav_disabled.gif"));
refreshAction.setImageDescriptor(getImageDescriptor("icons/refresh_nav_enabled.gif"));
refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
}