Methods Summary |
---|
public void | dispose()
// Nothing to do
|
private org.eclipse.core.resources.IFile | getSelectedFile()Returns the active {@link IFile} (hopefully matching our selection) or null.
The file is only returned if it's a file from a project with an Android nature.
At that point we do not try to analyze if the selection nor the file is suitable
for the refactoring. This check is performed when the refactoring is invoked since
it can then produce meaningful error messages as needed.
IWorkbenchWindow wwin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (wwin != null) {
IWorkbenchPage page = wwin.getActivePage();
if (page != null) {
IEditorPart editor = page.getActiveEditor();
if (editor != null) {
IEditorInput input = editor.getEditorInput();
if (input instanceof FileEditorInput) {
FileEditorInput fi = (FileEditorInput) input;
IFile file = fi.getFile();
if (file.exists()) {
IProject proj = file.getProject();
try {
if (proj != null && proj.hasNature(AndroidConstants.NATURE)) {
return file;
}
} catch (CoreException e) {
// ignore
}
}
}
}
}
}
return null;
|
public void | init(org.eclipse.ui.IWorkbenchWindow window)Keep track of the current workbench window.
mWindow = window;
|
public void | run(org.eclipse.jface.action.IAction action)Create a new instance of our refactoring and a wizard to configure it.
if (mSelection != null && mFile != null) {
ExtractStringRefactoring ref = new ExtractStringRefactoring(mFile, mSelection);
RefactoringWizard wizard = new ExtractStringWizard(ref, mFile.getProject());
RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
try {
op.run(mWindow.getShell(), wizard.getDefaultPageTitle());
} catch (InterruptedException e) {
// Interrupted. Pass.
}
}
|
public void | selectionChanged(org.eclipse.jface.action.IAction action, org.eclipse.jface.viewers.ISelection selection)Examine the selection to determine if the action should be enabled or not.
Keep a link to the relevant selection structure (i.e. a part of the Java AST).
// Note, two kinds of selections are returned here:
// ITextSelection on a Java source window
// IStructuredSelection in the outline or navigator
// This simply deals with the refactoring based on a non-empty selection.
// At that point, just enable the action and later decide if it's valid when it actually
// runs since we don't have access to the AST yet.
mSelection = null;
mFile = null;
if (selection instanceof ITextSelection) {
mSelection = (ITextSelection) selection;
if (mSelection.getLength() > 0) {
mFile = getSelectedFile();
}
}
action.setEnabled(mSelection != null && mFile != null);
|