1 11 package org.eclipse.ui.texteditor; 12 13 14 import java.util.ResourceBundle ; 15 16 30 public abstract class TextEditorAction extends ResourceAction implements IUpdate { 31 32 33 private ITextEditor fTextEditor; 34 35 46 protected TextEditorAction(ResourceBundle bundle, String prefix, ITextEditor editor) { 47 super(bundle, prefix); 48 setEditor(editor); 49 update(); 50 } 51 52 65 protected TextEditorAction(ResourceBundle bundle, String prefix, ITextEditor editor, int style) { 66 super(bundle, prefix, style); 67 setEditor(editor); 68 update(); 69 } 70 71 76 protected ITextEditor getTextEditor() { 77 return fTextEditor; 78 } 79 80 85 public void setEditor(ITextEditor editor) { 86 fTextEditor= editor; 87 } 88 89 94 public void update() { 95 setEnabled(getTextEditor() != null); 96 } 97 98 113 protected boolean canModifyEditor() { 114 ITextEditor editor= getTextEditor(); 115 if (editor instanceof ITextEditorExtension2) 116 return ((ITextEditorExtension2) editor).isEditorInputModifiable(); 117 else if (editor instanceof ITextEditorExtension) 118 return !((ITextEditorExtension) editor).isEditorInputReadOnly(); 119 else if (editor != null) 120 return editor.isEditable(); 121 else 122 return false; 123 } 124 125 140 protected boolean validateEditorInputState() { 141 ITextEditor editor= getTextEditor(); 142 if (editor instanceof ITextEditorExtension2) 143 return ((ITextEditorExtension2) editor).validateEditorInputState(); 144 else if (editor instanceof ITextEditorExtension) 145 return !((ITextEditorExtension) editor).isEditorInputReadOnly(); 146 else if (editor != null) 147 return editor.isEditable(); 148 else 149 return false; 150 } 151 } 152 | Popular Tags |