]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractAndMoveMethodChangerHandler.java
skeleton done!
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / handlers / SearchBasedExtractAndMoveMethodChangerHandler.java
CommitLineData
81f6ea7e
EK
1package no.uio.ifi.refaktor.handlers;
2
81f6ea7e
EK
3import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
4import no.uio.ifi.refaktor.change.changers.SearchBasedExtractAndMoveMethodChanger;
5import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException;
b76bc807 6import no.uio.ifi.refaktor.debugging.RefaktorDebug;
81f6ea7e
EK
7
8import org.eclipse.core.commands.AbstractHandler;
9import org.eclipse.core.commands.ExecutionEvent;
10import org.eclipse.core.commands.ExecutionException;
11import org.eclipse.core.runtime.CoreException;
12import org.eclipse.core.runtime.NullProgressMonitor;
13import org.eclipse.jdt.core.IMethod;
14import org.eclipse.jface.dialogs.MessageDialog;
15import org.eclipse.jface.viewers.ISelection;
16import org.eclipse.jface.viewers.ITreeSelection;
17import org.eclipse.ui.IWorkbenchWindow;
18import org.eclipse.ui.handlers.HandlerUtil;
19
20public 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}