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.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jdt.core.IJavaProject; 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(IJavaProject.class)); RefaktorChanger changer = new ProjectWideSearchBasedExtractAndMoveMethodChanger((IJavaProject) 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; } }