@Override @SuppressWarnings("unchecked") public void selectionChanged(final SelectionChangedEvent event) { TreeSelection selection = (TreeSelection) event.getSelection(); Object o = selection.getFirstElement(); if (o == null || o instanceof NoDatabaseRoot) { doc.setText(""); return; } // Try to find element to show HoogleResult result = null; if (o instanceof HoogleResult) { result = (HoogleResult) o; } else { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o; if (entry.getValue() instanceof HoogleResult) { result = (HoogleResult) entry.getValue(); } } if (result != null) { String text = ""; switch (result.getType()) { case KEYWORD: text = HtmlUtil.generateDocument("keyword " + result.getName(), ""); break; case PACKAGE: HaskellPackage pkg = ((HoogleResultPackage) result).getPackage(); text = HtmlUtil.generateDocument("package " + pkg.getIdentifier().toString(), pkg.getDoc()); break; case MODULE: HoogleResultModule mod = (HoogleResultModule) result; text = HtmlUtil.generateDocument( "module " + mod.getName(), mod.getPackageIdentifiers(), null, false, mod.getModule().getDoc()); break; case DECLARATION: HoogleResultDeclaration decl = (HoogleResultDeclaration) result; text = HtmlUtil.generateDocument( decl.getDeclaration().getCompleteDefinition(), decl.getPackageIdentifiers(), decl.getModule(), false, decl.getDeclaration().getDoc()); break; case CONSTRUCTOR: HoogleResultConstructor con = (HoogleResultConstructor) result; text = HtmlUtil.generateDocument( con.getConstructor().getCompleteDefinition(), con.getPackageIdentifiers(), con.getModule(), false, con.getDeclaration().getDoc()); break; case WARNING: // not in tree break; } doc.setText(text); } else { doc.setText(HtmlUtil.generateText(UITexts.browser_definedInSeveralLocations)); } }
@SuppressWarnings("unchecked") public void doubleClick(final DoubleClickEvent event) { TreeSelection selection = (TreeSelection) event.getSelection(); Object o = selection.getFirstElement(); if (o == null || o instanceof NoDatabaseRoot) { return; } // Try to find element to show HoogleResult result = null; if (o instanceof HoogleResult) { result = (HoogleResult) o; } else { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o; if (entry.getValue() instanceof HoogleResult) { result = (HoogleResult) entry.getValue(); } else { // Show the first one (better than nothing) result = ((ArrayList<HoogleResult>) entry.getValue()).get(0); } } String url = null; switch (result.getType()) { case PACKAGE: HoogleResultPackage pkg = (HoogleResultPackage) result; url = HtmlUtil.generatePackageUrl(pkg.getPackage().getIdentifier()); break; case MODULE: HoogleResultModule mod = (HoogleResultModule) result; url = HtmlUtil.generateModuleUrl(mod.getPackageIdentifiers().get(0), mod.getName()); break; case CONSTRUCTOR: HoogleResultConstructor con = (HoogleResultConstructor) result; url = HtmlUtil.generateElementUrl( con.getPackageIdentifiers().get(0), con.getModule(), true, con.getName()); break; case DECLARATION: HoogleResultDeclaration decl = (HoogleResultDeclaration) result; url = HtmlUtil.generateElementUrl( decl.getPackageIdentifiers().get(0), decl.getModule(), decl.getDeclaration().getType() == DeclarationType.FUNCTION, decl.getName()); break; } // Open browser if (url != null) { try { IWorkbenchBrowserSupport browserSupport = this.getSite().getWorkbenchWindow().getWorkbench().getBrowserSupport(); URL webUrl = new URL(url); IWebBrowser browser = browserSupport.createBrowser( IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR, null, "Haskell Browser", "Haskell Browser"); browser.openURL(webUrl); } catch (Throwable ex) { // Do nothing } } }