]> git.uio.no Git - ifi-stolz-refaktor.git/blob - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ProjectWideSearchBasedExtractAndMoveMethodChangerHandler.java
Moving changers into no.uio.ifi.refaktor.change.changer
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / handlers / ProjectWideSearchBasedExtractAndMoveMethodChangerHandler.java
1 package no.uio.ifi.refaktor.handlers;
2
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.changers.exceptions.RefaktorChangerException;
8 import no.uio.ifi.refaktor.utils.RefaktorDebug;
9
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;
21
22 public class ProjectWideSearchBasedExtractAndMoveMethodChangerHandler extends AbstractHandler {
23
24         @Override
25         public Object execute(ExecutionEvent event) throws ExecutionException {
26                 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
27                 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
28
29                 assertThat(selection, instanceOf(ITreeSelection.class));
30                 ITreeSelection treeSelection = (ITreeSelection) selection;
31                 Object element = treeSelection.getFirstElement();
32                 assertThat(element, instanceOf(IJavaProject.class));
33
34                 RefaktorChanger changer = new ProjectWideSearchBasedExtractAndMoveMethodChanger((IJavaProject) element);
35                 try {
36                         changer.checkPreconditions();
37                         changer.executeChange(new NullProgressMonitor());
38                         MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " has been excuted");
39                         return null;
40                 } catch (RefaktorChangerException e) {
41                         RefaktorDebug.log(e);
42                 } catch (CoreException e) {
43                         RefaktorDebug.log(e);
44                 }
45
46                 MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " did not execute correctly");
47                 return null;
48         }
49 }