public Object execute(ExecutionEvent event) throws ExecutionException {
// IWorkbenchWindow window =
// HandlerUtil.getActiveWorkbenchWindowChecked(event);
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser browser;
try {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
Object data = wb.getDisplay().getActiveShell().getData();
IWorkbenchPage page = win.getActivePage();
IEditorPart editorPart = page.getActiveEditor();
ITextEditor editor = (ITextEditor) editorPart;
ISelectionProvider sp = editor.getSelectionProvider();
ITextSelection selection = (ITextSelection) sp.getSelection();
IDocumentProvider documentProvider = editor.getDocumentProvider();
IDocument document = documentProvider.getDocument(editorPart
.getEditorInput());
ITextSelection textSelection = (ITextSelection) editorPart
.getSite().getSelectionProvider().getSelection();
int cursorLocation = textSelection.getOffset();
int lineNumber = document.getLineOfOffset(cursorLocation);
IRegion lineInformation = document.getLineInformation(lineNumber);
String lineText = document.get().substring(
lineInformation.getOffset(),
lineInformation.getOffset() + lineInformation.getLength());
String offsetWord = getOffsetWord(lineText, cursorLocation
- lineInformation.getOffset());
// System.out.println("offsetWord" + offsetWord);
//
String word = offsetWord.substring(offsetWord.lastIndexOf(":") + 1,
offsetWord.length());
List<Tag> tagInfoAsList = VisualForceTagDefinition.getTagInfoAsList();
String tagInEditor = "apex:" + word;
boolean found=false;
for (Tag tag : tagInfoAsList) {
if(tag.getTagName().equalsIgnoreCase(tagInEditor)){
found = true;
}
}
browser = support.createBrowser("" + System.currentTimeMillis());
if (found) {
browser.openURL(new URL(
"http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_"
+ word + ".htm"));
} else {
browser.openURL(new URL(
"http://www.salesforce.com/us/developer/docs/pages/index.htm?"+word));
}
//