1 11 package org.eclipse.jdt.internal.ui.propertiesfileeditor; 12 13 import org.eclipse.jface.text.IRegion; 14 import org.eclipse.jface.text.ITextSelection; 15 import org.eclipse.jface.text.Region; 16 import org.eclipse.jface.text.hyperlink.IHyperlink; 17 18 import org.eclipse.ui.IFileEditorInput; 19 20 import org.eclipse.jdt.ui.actions.SelectionDispatchAction; 21 22 36 public class OpenAction extends SelectionDispatchAction { 37 38 39 private PropertiesFileEditor fEditor; 40 41 42 47 public OpenAction(PropertiesFileEditor editor) { 48 super(editor.getEditorSite()); 49 fEditor= editor; 50 setText(PropertiesFileEditorMessages.OpenAction_label); 51 setToolTipText(PropertiesFileEditorMessages.OpenAction_tooltip); 52 53 setEnabled(fEditor.getEditorInput() instanceof IFileEditorInput); 55 } 56 57 60 public void selectionChanged(ITextSelection selection) { 61 setEnabled(checkEnabled(selection)); 62 } 63 64 private boolean checkEnabled(ITextSelection selection) { 65 if (selection == null || selection.isEmpty()) 66 return false; 67 68 return fEditor.getEditorInput() instanceof IFileEditorInput; 70 } 71 72 public void run(ITextSelection selection) { 73 74 if (!checkEnabled(selection)) 75 return; 76 77 IRegion region= new Region(selection.getOffset(), selection.getLength()); 78 PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector(); 79 detector.setContext(fEditor); 80 IHyperlink[]hyperlinks= detector.detectHyperlinks(fEditor.internalGetSourceViewer(), region, false); 81 82 if (hyperlinks != null && hyperlinks.length == 1) 83 hyperlinks[0].open(); 84 85 } 86 } 87 | Popular Tags |