]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
Adding command handler for ProjectWideSearchBasedExtractAndMoveMethodChanger.
authorErlend Kristiansen <erlenkr@ifi.uio.no>
Wed, 29 Jan 2014 15:06:29 +0000 (16:06 +0100)
committerErlend Kristiansen <erlenkr@ifi.uio.no>
Wed, 29 Jan 2014 15:06:29 +0000 (16:06 +0100)
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ProjectWideSearchBasedExtractAndMoveMethodChangerHandler.java [new file with mode: 0644]

diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ProjectWideSearchBasedExtractAndMoveMethodChangerHandler.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ProjectWideSearchBasedExtractAndMoveMethodChangerHandler.java
new file mode 100644 (file)
index 0000000..f947171
--- /dev/null
@@ -0,0 +1,49 @@
+package no.uio.ifi.refaktor.handlers;
+
+import static no.uio.ifi.refaktor.RefaktorAssert.assertThat;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import no.uio.ifi.refaktor.changers.ProjectWideSearchBasedExtractAndMoveMethodChanger;
+import no.uio.ifi.refaktor.changers.RefaktorChanger;
+import no.uio.ifi.refaktor.changers.RefaktorChangerException;
+import no.uio.ifi.refaktor.utils.RefaktorDebug;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class ProjectWideSearchBasedExtractAndMoveMethodChangerHandler extends AbstractHandler {
+
+       @Override
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
+               IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+
+               assertThat(selection, instanceOf(ITreeSelection.class));
+               ITreeSelection treeSelection = (ITreeSelection) selection;
+               Object element = treeSelection.getFirstElement();
+               assertThat(element, instanceOf(IProject.class));
+
+               RefaktorChanger changer = new ProjectWideSearchBasedExtractAndMoveMethodChanger((IProject) element);
+               try {
+                       changer.checkPreconditions();
+                       changer.executeChange(new NullProgressMonitor());
+                       MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " has been excuted");
+                       return null;
+               } catch (RefaktorChangerException e) {
+                       RefaktorDebug.log(e);
+               } catch (CoreException e) {
+                       RefaktorDebug.log(e);
+               }
+
+               MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " did not execute correctly");
+               return null;
+       }
+}
\ No newline at end of file