Attach my action to F5 / Update

I am writing a plugin for Eclipse and I would like to attach one of my actions to the Eclipse F5 / Refresh event.

Can anyone help me? Thank!

+3
source share
3 answers

You can connect the IExecutionListener to the ICommandService. You will receive a notification of all completed commands. You can find the required command identifier (in this case org.eclipse.ui.file.refresh) and perform your operation

+4
source

I assume you are writing this for Eclipse Helios (3.6).

In the Eclipse Help in the Platform Plugin Developer's Guide → Programmers Guide → Advanced Resource Concepts → Update Providers, there is an extension point.

org.eclipse.core.resources.refreshProviders

RefreshProvider, .

+1

. ., . Activator , Workbench, . plugin.xml

<extension
     point="org.eclipse.ui.startup">
  <startup
        class="sampleplugin.MyStartUp">
  </startup>
</extension>

MyStartUp ExecutionListener ICommandService. , ExecutionEvent preExecute . ExecutionEvent Command. , MyStartUp.java

public class MyStartUp implements IStartup {

    @Override
    public void earlyStartup() {
        ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService    .class);
        service.addExecutionListener(
                new IExecutionListener() {

                    ...

                    @Override
                    public void postExecuteSuccess(String commandId,
                            Object returnValue) {

                      // do something post

                    }

                    @Override
                    public void preExecute(String commandId,
                            final ExecutionEvent event) {
                            if (org.eclipse.ui.IWorkbenchCommandConstants.FILE_REFRESH.equals(commandId)    ) {

                                IWorkbench wb = PlatformUI.getWorkbench();
                                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                                IWorkbenchPage page = win.getActivePage();

                                ISelection selection = page.getSelection();

                                // do something using selection

                            }
                    }

        });

    }

}

    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win.getActivePage();

    ISelection selection = page.getSelection();

    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);

. Eclipse. ExternalActionManager preExecute, .

    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);

preExecute .

0

Source: https://habr.com/ru/post/1796030/


All Articles