1 11 package org.eclipse.ui.console.actions; 12 13 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.jface.text.ITextOperationTarget; 16 import org.eclipse.jface.text.ITextViewer; 17 import org.eclipse.ui.texteditor.IUpdate; 18 19 26 public class TextViewerAction extends Action implements IUpdate { 27 28 private int fOperationCode= -1; 29 private ITextOperationTarget fOperationTarget; 30 31 38 public TextViewerAction(ITextViewer viewer, int operationCode) { 39 fOperationCode= operationCode; 40 fOperationTarget= viewer.getTextOperationTarget(); 41 update(); 42 } 43 44 52 public void update() { 53 54 boolean wasEnabled= isEnabled(); 55 boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); 56 setEnabled(isEnabled); 57 58 if (wasEnabled != isEnabled) { 59 firePropertyChange(ENABLED, wasEnabled ? Boolean.TRUE : Boolean.FALSE, isEnabled ? Boolean.TRUE : Boolean.FALSE); 60 } 61 } 62 63 66 public void run() { 67 if (fOperationCode != -1 && fOperationTarget != null) { 68 fOperationTarget.doOperation(fOperationCode); 69 } 70 } 71 72 79 public void configureAction(String text, String toolTipText, String description) { 80 setText(text); 81 setToolTipText(toolTipText); 82 setDescription(description); 83 } 84 } 85 | Popular Tags |