Update of /cvsroot/cpptool/rfta/src/eclipseplugin/PluginCode/src/org/eclipse/cpprefactoring/actions
In directory sc8-pr-cvs1:/tmp/cvs-serv31495/org/eclipse/cpprefactoring/actions
Added Files:
RenameLocaleVariableAction.java
Log Message:
Eclipse Plugin JAVA code
--- NEW FILE: RenameLocaleVariableAction.java ---
package org.eclipse.cpprefactoring.actions;
import org.eclipse.cpprefactoring.internal.EclipseBridge;
import org.eclipse.cpprefactoring.ui.RenameLocalVariableDialog;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.texteditor.AbstractTextEditor;
/**
* @author Andre Baresel
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class RenameLocaleVariableAction implements IEditorActionDelegate, IWorkbenchWindowActionDelegate {
private static final String ACTION_RENAMELOCALEVARIABLE_MENU = "org.eclipse.cpprefactoring.actions.RenameLocaleVariableAction.Menu";
private static final String ACTION_RENAMELOCALEVARIABLE_POPUP = "org.eclipse.cpprefactoring.actions.RenameLocaleVariableAction.Popup";
private IEditorPart targetEditor;
private IWorkbenchWindow window;
/**
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
*/
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
this.targetEditor = targetEditor;
}
/**
* @see org.eclipse.ui.IActionDelegate#run(IAction)
*/
public void run(IAction action) {
// initialize active editor for Menu-Actions:
if (action.getId().equals(ACTION_RENAMELOCALEVARIABLE_MENU))
{
IWorkbenchPage page = window.getActivePage();
targetEditor = page.getActiveEditor();
}
//
if ( action.getId().equals(ACTION_RENAMELOCALEVARIABLE_POPUP)
|| action.getId().equals(ACTION_RENAMELOCALEVARIABLE_MENU)
)
{
handleRenameLocalVariable();
} else
{
MessageDialog.openError(
targetEditor.getSite().getShell(),
"Cpp-Refactoring Plugin Error",
"This refactoring-action-item has not yet been implemented: ID="+action.getId());
}
}
/**
* Method is responsible to handle 'RenameLocalVariable' action
*/
public void handleRenameLocalVariable() {
if (! (targetEditor instanceof AbstractTextEditor) )
{
MessageDialog.openError(
targetEditor.getSite().getShell(),
"Cpp-Refactoring Plugin Error",
"The refactoring methods can only be activated in a text editor.");
}
AbstractTextEditor textEditor = (AbstractTextEditor)targetEditor;
IRewriteTarget targetDoc = (IRewriteTarget)targetEditor.getAdapter(IRewriteTarget.class);
ISelectionProvider selectionHlp = (ISelectionProvider)textEditor.getSelectionProvider();
ITextSelection selection = (ITextSelection)selectionHlp.getSelection();
try {
EclipseBridge bridge = new EclipseBridge(selectionHlp,targetDoc);
targetDoc.beginCompoundChange();
bridge.applyRftaRenameLocaleVariable(RenameLocalVariableDialog.class);
targetDoc.endCompoundChange();
} catch (Exception e) {
e.printStackTrace();
MessageDialog.openError(
targetEditor.getSite().getShell(),
"Cpp-Refactoring Plugin Error",
e.getMessage());
} catch (UnsatisfiedLinkError e1) {
MessageDialog.openError(
targetEditor.getSite().getShell(),
"Dynamic Linkage Error",
"Some code is missing in Refactoring-DLLs or DLLs are missing. Exception: "+
e1.toString()
);
e1.printStackTrace();
throw e1;
}
/*MessageDialog.openInformation(
targetEditor.getSite().getShell(),
"done?",
"done?");
*/
}
/**
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
}
public void init(IWorkbenchWindow window) {
this.window = window;
}
public void dispose() {
}
}
|