| Home >> All >> com >> port80 >> eclipse >> jdt >> [ actions Javadoc ] |
Source code: com/port80/eclipse/jdt/actions/RegexReplaceAction.java
1 package com.port80.eclipse.jdt.actions; 2 3 import org.eclipse.jface.action.IAction; 4 import org.eclipse.jface.dialogs.Dialog; 5 import org.eclipse.jface.viewers.AbstractTreeViewer; 6 import org.eclipse.jface.viewers.ISelection; 7 import org.eclipse.jface.viewers.TableViewer; 8 import org.eclipse.jface.viewers.Viewer; 9 import org.eclipse.ui.IEditorActionDelegate; 10 import org.eclipse.ui.IEditorPart; 11 import org.eclipse.ui.IWorkbenchWindow; 12 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 13 import org.eclipse.ui.part.PageBookView; 14 import org.eclipse.ui.texteditor.ITextEditor; 15 16 import com.port80.eclipse.jdt.JdtPlugin; 17 18 /** 19 * @author chrisl 20 * 21 * To change this generated comment edit the template variable "typecomment": 22 * Window>Preferences>Java>Templates. 23 * To enable and disable the creation of type comments go to 24 * Window>Preferences>Java>Code Generation. 25 */ 26 public class RegexReplaceAction implements IWorkbenchWindowActionDelegate, IEditorActionDelegate { 27 28 //////////////////////////////////////////////////////////////////////// 29 30 private static final String NAME = "RegexReplaceAction"; 31 private static final String ID = "com.port80.eclipse.jdt.actions.RegexReplaceAction"; 32 private static final boolean DEBUG = true; 33 34 //////////////////////////////////////////////////////////////////////// 35 36 /** 37 * Constructor for RegexReplace. 38 */ 39 public RegexReplaceAction() { 40 super(); 41 } 42 43 //////////////////////////////////////////////////////////////////////// 44 45 /** 46 * Regex search & replace for TextEditor. 47 * 48 * @see org.eclipse.ui.IActionDelegate#run(IAction) 49 */ 50 public void run(IAction action) { 51 Object part = JdtPlugin.getActiveWorkbenchWindow().getActivePage().getActivePart(); 52 if (DEBUG) 53 System.err.println(NAME + ".run(): " + part); 54 if (part instanceof ITextEditor) { 55 ITextEditor editor = (ITextEditor) part; 56 Dialog dialog = RegexReplaceDialog.getDefault(JdtPlugin.getActiveWorkbenchShell(), editor); 57 dialog.open(); 58 } else { 59 if (part instanceof PageBookView) { 60 part = ((PageBookView) part).getCurrentPage(); 61 } 62 Viewer viewer = Util.getViewer(part); 63 if (viewer == null) { 64 JdtPlugin.getActiveWorkbenchShell().getDisplay().beep(); 65 return; 66 } 67 if (viewer instanceof AbstractTreeViewer) { 68 Dialog dialog = 69 RegexFindDialog.getDefault( 70 JdtPlugin.getActiveWorkbenchShell(), 71 (AbstractTreeViewer) viewer); 72 dialog.open(); 73 } else if (viewer instanceof TableViewer) { 74 Dialog dialog = 75 RegexFindDialog.getDefault( 76 JdtPlugin.getActiveWorkbenchShell(), 77 (TableViewer) viewer); 78 dialog.open(); 79 } 80 } 81 } 82 83 /** 84 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() 85 */ 86 public void dispose() { 87 } 88 89 /** 90 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow) 91 */ 92 public void init(IWorkbenchWindow window) { 93 } 94 95 /** 96 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) 97 */ 98 public void selectionChanged(IAction action, ISelection selection) { 99 } 100 101 //////////////////////////////////////////////////////////////////////// 102 103 /* 104 * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart) 105 */ 106 public void setActiveEditor(IAction action, IEditorPart targetEditor) { 107 } 108 109 //////////////////////////////////////////////////////////////////////// 110 111 }