1 package no.uio.ifi.refaktor.handlers;
3 import static no.uio.ifi.refaktor.assertion.RefaktorAssert.assertThat;
4 import static org.hamcrest.CoreMatchers.instanceOf;
5 import no.uio.ifi.refaktor.change.changers.ProjectWideSearchBasedExtractAndMoveMethodChanger;
6 import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
7 import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException;
8 import no.uio.ifi.refaktor.utils.RefaktorDebug;
10 import org.eclipse.core.commands.AbstractHandler;
11 import org.eclipse.core.commands.ExecutionEvent;
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.NullProgressMonitor;
15 import org.eclipse.jdt.core.IJavaProject;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.ITreeSelection;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.handlers.HandlerUtil;
22 public class ProjectWideSearchBasedExtractAndMoveMethodChangerHandler extends AbstractHandler {
25 public Object execute(ExecutionEvent event) throws ExecutionException {
26 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
27 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
29 assertThat(selection, instanceOf(ITreeSelection.class));
30 ITreeSelection treeSelection = (ITreeSelection) selection;
31 Object element = treeSelection.getFirstElement();
32 assertThat(element, instanceOf(IJavaProject.class));
34 RefaktorChanger changer = new ProjectWideSearchBasedExtractAndMoveMethodChanger((IJavaProject) element);
36 changer.checkPreconditions();
37 changer.execute(new NullProgressMonitor());
38 MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " has been excuted");
40 } catch (RefaktorChangerException e) {
42 } catch (CoreException e) {
46 MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " did not execute correctly");