]>
Commit | Line | Data |
---|---|---|
81f6ea7e EK |
1 | package no.uio.ifi.refaktor.handlers; |
2 | ||
81f6ea7e EK |
3 | import no.uio.ifi.refaktor.change.changers.RefaktorChanger; |
4 | import no.uio.ifi.refaktor.change.changers.SearchBasedExtractAndMoveMethodChanger; | |
5 | import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException; | |
b76bc807 | 6 | import no.uio.ifi.refaktor.debugging.RefaktorDebug; |
81f6ea7e EK |
7 | |
8 | import org.eclipse.core.commands.AbstractHandler; | |
9 | import org.eclipse.core.commands.ExecutionEvent; | |
10 | import org.eclipse.core.commands.ExecutionException; | |
11 | import org.eclipse.core.runtime.CoreException; | |
12 | import org.eclipse.core.runtime.NullProgressMonitor; | |
13 | import org.eclipse.jdt.core.IMethod; | |
14 | import org.eclipse.jface.dialogs.MessageDialog; | |
15 | import org.eclipse.jface.viewers.ISelection; | |
16 | import org.eclipse.jface.viewers.ITreeSelection; | |
17 | import org.eclipse.ui.IWorkbenchWindow; | |
18 | import org.eclipse.ui.handlers.HandlerUtil; | |
19 | ||
20 | public class SearchBasedExtractAndMoveMethodChangerHandler extends AbstractHandler { | |
21 | ||
22 | @Override | |
23 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
24 | ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); | |
25 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | |
26 | ||
3cb3a16b | 27 | assert selection instanceof ITreeSelection; |
81f6ea7e EK |
28 | ITreeSelection treeSelection = (ITreeSelection) selection; |
29 | Object o = treeSelection.getFirstElement(); | |
3cb3a16b | 30 | assert o instanceof IMethod; |
81f6ea7e EK |
31 | IMethod method = (IMethod) o; |
32 | ||
33 | RefaktorChanger changer = new SearchBasedExtractAndMoveMethodChanger(method); | |
34 | try { | |
35 | changer.checkPreconditions(); | |
36 | changer.execute(new NullProgressMonitor()); | |
37 | MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " has been excuted"); | |
38 | return null; | |
39 | } catch (RefaktorChangerException e) { | |
40 | RefaktorDebug.log(e); | |
41 | } catch (CoreException e) { | |
42 | RefaktorDebug.log(e); | |
43 | } | |
44 | ||
45 | MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " did not execute correctly"); | |
46 | return null; | |
47 | } | |
48 | ||
49 | } |