use of org.eclipse.ui.internal.browser.WebBrowserEditor in project tdi-studio-se by Talend.
the class OpenDocumentationAction method openedByBrowser.
//
// private void progress(final Item item, final String extension) {
// if (item == null) {
// return;
// }
//
// ProgressDialog progressDialog = new ProgressDialog(Display.getCurrent().getActiveShell()) {
//
// @Override
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
//
// // use the system program to open the documentation by extension.
// Program program = null;
// if (extension != null) {
// program = Program.findProgram(extension);
// }
// boolean opened = false;
// if (program != null) {
// IFile file = LinkDocumentationHelper.getTempFile(item.getProperty().getId());
// if (file != null) {
// try {
// boolean canExec = false;
// if (item instanceof DocumentationItem) {
// DocumentationItem documentationItem = (DocumentationItem) item;
// documentationItem.getContent().setInnerContentToFile(file.getLocation().toFile());
// canExec = true;
// } else if (item instanceof LinkDocumentationItem) { // link documenation
// LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
// ByteArray byteArray = LinkDocumentationHelper.getLinkItemContent(linkDocItem);
// if (byteArray != null) {
// byteArray.setInnerContentToFile(file.getLocation().toFile());
// canExec = true;
// }
// }
// if (canExec) {
// program.execute(file.getLocation().toOSString());
// opened = true;
// }
// } catch (IOException e) {
// MessageBoxExceptionHandler.process(e);
// }
// }
// }
// // if not opened, extract the content.
// if (!opened) {
// ExtractDocumentationAction extractAction = new ExtractDocumentationAction();
// extractAction.setWorkbenchPart(getWorkbenchPart());
// extractAction.run();
// }
// }
//
// };
// try {
// progressDialog.executeProcess();
// } catch (InvocationTargetException e) {
// ExceptionHandler.process(e);
// } catch (InterruptedException e) {
// // Nothing to do
// }
// }
private void openedByBrowser(Item item, URL url) {
if (url == null || item == null) {
return;
}
WebBrowserEditorInput input = new WebBrowserEditorInput(url);
// add for bug TDI-21189 at 2012-6-8,that a document exist is only opened one time in studio
try {
IWorkbenchPage page = getActivePage();
IEditorReference[] iEditorReference = page.getEditorReferences();
for (IEditorReference editors : iEditorReference) {
if (WebBrowserEditor.WEB_BROWSER_EDITOR_ID.equals(editors.getId())) {
IEditorPart iEditorPart = editors.getEditor(true);
if (iEditorPart != null && iEditorPart instanceof WebBrowserEditor) {
WebBrowserEditorInput webBrowserEditorInput = (WebBrowserEditorInput) iEditorPart.getEditorInput();
if (webBrowserEditorInput != null && url.equals(webBrowserEditorInput.getURL())) {
// page.activate(iEditorPart);
iEditorPart.init(iEditorPart.getEditorSite(), webBrowserEditorInput);
DocumentationUtil.setPartItemId((WebBrowserEditor) iEditorPart, item.getProperty().getId(), ERepositoryObjectType.getItemType(item));
return;
}
}
}
}
input.setName(item.getProperty().getLabel());
//$NON-NLS-1$
input.setToolTipText(item.getProperty().getLabel() + " " + item.getProperty().getVersion());
IEditorPart editorPart = page.openEditor(input, WebBrowserEditor.WEB_BROWSER_EDITOR_ID);
if (editorPart != null && editorPart instanceof WebBrowserEditor) {
DocumentationUtil.setPartItemId((WebBrowserEditor) editorPart, item.getProperty().getId(), ERepositoryObjectType.getItemType(item));
}
} catch (PartInitException e) {
MessageBoxExceptionHandler.process(e);
}
}
use of org.eclipse.ui.internal.browser.WebBrowserEditor in project knime-core by knime.
the class AbstractInjector method findIntroPageBrowser.
/**
* Looks for the open intro page editor (and HTML editor) and returns the Browser instance. This (unfortunately)
* involves some heavy reflection stuff as there is no other way to attach a listener otherwise. If the intro page
* editor cannot be found then <code>null</code> is returned.
*
* @param introPageFile the temporary intro page file
* @return the browser instance showing the intro page or <code>null</code>
*/
@SuppressWarnings("restriction")
static Browser findIntroPageBrowser(final File introPageFile) {
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
for (IWorkbenchPage page : window.getPages()) {
for (IEditorReference ref : page.getEditorReferences()) {
try {
if (isIntroPageEditor(ref, introPageFile)) {
IEditorPart part = ref.getEditor(false);
if (part instanceof WebBrowserEditor) {
WebBrowserEditor editor = (WebBrowserEditor) part;
Field webBrowser = editor.getClass().getDeclaredField("webBrowser");
webBrowser.setAccessible(true);
BrowserViewer viewer = (BrowserViewer) webBrowser.get(editor);
Field browserField = viewer.getClass().getDeclaredField("browser");
browserField.setAccessible(true);
return (Browser) browserField.get(viewer);
}
}
} catch (PartInitException ex) {
NodeLogger.getLogger(AbstractInjector.class).error("Could not open web browser with intro page: " + ex.getMessage(), ex);
} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
NodeLogger.getLogger(AbstractInjector.class).error("Could not attach location listener to web browser: " + ex.getMessage(), ex);
}
}
}
}
return null;
}
Aggregations