org.eclipse.jface.internal.text.html.BrowserInformationControlInput Java Examples

The following examples show how to use org.eclipse.jface.internal.text.html.BrowserInformationControlInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSTextHover.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Update the action
 */
void update()
{
	properties = null;
	BrowserInformationControlInput input = iControl.getInput();
	if (input instanceof DocumentationBrowserInformationControlInput)
	{
		Object inputElement = input.getInputElement();
		if (inputElement instanceof IParseNode)
		{
			properties = JSModelUtil.getProperties((AbstractThemeableEditor) getEditor(),
					(IParseNode) inputElement);
		}
	}
	setEnabled(!CollectionsUtil.isEmpty(properties));
}
 
Example #2
Source File: JSTextHover.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Update the action
 */
void update()
{
	BrowserInformationControlInput input = iControl.getInput();
	if (input instanceof DocumentationBrowserInformationControlInput)
	{
		JSHyperlinkDetector detector = new JSHyperlinkDetector();
		IRegion hoverRegion = ((DocumentationBrowserInformationControlInput) input).getHoverRegion();
		if (hoverRegion != null)
		{
			hyperlinks = detector.detectHyperlinks((AbstractThemeableEditor) getEditor(), hoverRegion, false);
			setEnabled(!ArrayUtil.isEmpty(hyperlinks) && hyperlinks[0] != null);
			return;
		}

	}
	setEnabled(false);
}
 
Example #3
Source File: JSTextHover.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populateToolbarActions(ToolBarManager tbm, CustomBrowserInformationControl iControl)
{
	final OpenDeclarationAction openDeclarationAction = new OpenDeclarationAction(iControl);
	final OpenHelpAction openHelpAction = new OpenHelpAction(iControl);
	tbm.add(openDeclarationAction);
	tbm.add(openHelpAction);
	IInputChangedListener inputChangeListener = new IInputChangedListener()
	{
		public void inputChanged(Object newInput)
		{
			if (newInput instanceof BrowserInformationControlInput)
			{
				openDeclarationAction.update();
				openHelpAction.update();
			}
		}
	};
	iControl.addInputChangeListener(inputChangeListener);
}
 
Example #4
Source File: CustomBrowserInformationControl.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @deprecated use {@link #setInput(Object)}
 */
public void setInformation(final String content)
{
	setInput(new BrowserInformationControlInput(null)
	{
		public String getHtml()
		{
			return content;
		}

		public String getInputName()
		{
			return ""; //$NON-NLS-1$
		}

		public Object getInputElement()
		{
			return content;
		}
	});
}
 
Example #5
Source File: XtendHoverInEditorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private void hasHoverOver(final CharSequence it, final String textUnderHover, final Class<? extends BrowserInformationControlInput> expectedPopupType, final String expectedHoverContent) {
  try {
    final IFile fileFoo = this.helper.createFile("Foo.xtend", it.toString());
    this._syncUtil.waitForBuild(null);
    final XtextEditor editor = this.helper.openEditor(fileFoo);
    int _indexOf = it.toString().indexOf(textUnderHover);
    int _length = textUnderHover.length();
    final Region region = new Region(_indexOf, _length);
    final Object info = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(editor.getInternalSourceViewer(), region);
    Assert.assertTrue(expectedPopupType.isInstance(info));
    final String html = ((BrowserInformationControlInput) info).getHtml();
    Assert.assertTrue(html.contains(expectedHoverContent));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #6
Source File: AbstractHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void hoverPopupHasContent(BrowserInformationControlInput info, String expectedHoverContent) {
	assertNotNull("No hover found!", info);

	String actualHoverContent = info.getHtml();
	String message = "Could not find the text '%s' in the hover popup:\n%s\n";
	assertTrue(String.format(message, expectedHoverContent, actualHoverContent), actualHoverContent.contains(expectedHoverContent));
}
 
Example #7
Source File: HTMLTextHover.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update the action
 */
void update()
{
	node = null;
	BrowserInformationControlInput input = iControl.getInput();
	if (input instanceof DocumentationBrowserInformationControlInput)
	{
		Object inputElement = input.getInputElement();
		if (inputElement instanceof BaseElement)
		{
			node = (BaseElement) inputElement;
		}
	}
	setEnabled(node != null);
}
 
Example #8
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	BrowserInformationControlInput previous= (BrowserInformationControlInput) fInfoControl.getInput().getPrevious();
	if (previous != null) {
		fInfoControl.setInput(previous);
	}
}
 
Example #9
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void update() {
	BrowserInformationControlInput current= fInfoControl.getInput();

	if (current != null && current.getPrevious() != null) {
		BrowserInput previous= current.getPrevious();
		setToolTipText(Messages.format(JavaHoverMessages.JavadocHover_back_toElement_toolTip, BasicElementLabels.getJavaElementName(previous.getInputName())));
		setEnabled(true);
	} else {
		setToolTipText(JavaHoverMessages.JavadocHover_back);
		setEnabled(false);
	}
}
 
Example #10
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	BrowserInformationControlInput next= (BrowserInformationControlInput) fInfoControl.getInput().getNext();
	if (next != null) {
		fInfoControl.setInput(next);
	}
}
 
Example #11
Source File: DefaultEObjectHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void update() {
	BrowserInformationControlInput current = fInfoControl.getInput();

	if (current != null && current.getNext() != null) {
		setToolTipText(MessageFormat.format(XtextUIMessages.XtextBrowserInformationControlInput_ForwardTo,
				new Object[] { current.getNext().getInputName() }));
		setEnabled(true);
	} else {
		setToolTipText(XtextUIMessages.XtextBrowserInformationControlInput_Forward);
		setEnabled(false);
	}
}
 
Example #12
Source File: DefaultEObjectHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	BrowserInformationControlInput next = (BrowserInformationControlInput) fInfoControl.getInput().getNext();
	if (next != null) {
		fInfoControl.setInput(next);
	}
}
 
Example #13
Source File: DefaultEObjectHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void update() {
	BrowserInformationControlInput current = fInfoControl.getInput();

	if (current != null && current.getPrevious() != null) {
		BrowserInput previous = current.getPrevious();
		setToolTipText(MessageFormat.format(XtextUIMessages.XtextBrowserInformationControlInput_BackTo,
				new Object[] { previous.getInputName() }));
		setEnabled(true);
	} else {
		setToolTipText(XtextUIMessages.XtextBrowserInformationControlInput_Back);
		setEnabled(false);
	}
}
 
Example #14
Source File: DefaultEObjectHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	BrowserInformationControlInput previous = (BrowserInformationControlInput) fInfoControl.getInput()
			.getPrevious();
	if (previous != null) {
		fInfoControl.setInput(previous);
	}
}
 
Example #15
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void update() {
	BrowserInformationControlInput current= fInfoControl.getInput();

	if (current != null && current.getNext() != null) {
		setToolTipText(Messages.format(JavaHoverMessages.JavadocHover_forward_toElement_toolTip, BasicElementLabels.getJavaElementName(current.getNext().getInputName())));
		setEnabled(true);
	} else {
		setToolTipText(JavaHoverMessages.JavadocHover_forward_toolTip);
		setEnabled(false);
	}
}
 
Example #16
Source File: CustomBrowserInformationControl.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc} This control can handle {@link String} and {@link BrowserInformationControlInput}.
 */
public void setInput(Object input)
{
	Assert.isLegal(input == null || input instanceof String || input instanceof BrowserInformationControlInput);

	if (input instanceof String)
	{
		setInformation((String) input);
		return;
	}

	fInput = (BrowserInformationControlInput) input;

	String content = null;
	if (fInput != null)
		content = fInput.getHtml();

	fBrowserHasContent = content != null && content.length() > 0;

	if (!fBrowserHasContent)
		content = "<html><body ></html>"; //$NON-NLS-1$

	boolean RTL = (getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0;
	boolean resizable = isResizable();

	// The default "overflow:auto" would not result in a predictable width for the client area
	// and the re-wrapping would cause visual noise
	String[] styles = null;
	if (RTL && resizable)
		styles = new String[] { "direction:rtl;", "overflow:scroll;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	else if (RTL && !resizable)
		styles = new String[] { "direction:rtl;", "overflow:hidden;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	else if (!resizable)
		// XXX: In IE, "word-wrap: break-word;" causes bogus wrapping even in non-broken words :-(see e.g. Javadoc
		// of String).
		// Re-check whether we really still need this now that the Javadoc Hover header already sets this style.
		styles = new String[] { "overflow:hidden;"/* , "word-wrap: break-word;" */}; //$NON-NLS-1$
	else
		styles = new String[] { "overflow:scroll;" }; //$NON-NLS-1$

	StringBuffer buffer = new StringBuffer(content);
	HTMLPrinter.insertStyles(buffer, styles);
	content = buffer.toString();

	/*
	 * XXX: Should add some JavaScript here that shows something like "(continued...)" or "..." at the end of the
	 * visible area when the page overflowed with "overflow:hidden;".
	 */

	fCompleted = false;
	fBrowser.setText(content);

	Object[] listeners = fInputChangeListeners.getListeners();
	for (int i = 0; i < listeners.length; i++)
		((IInputChangedListener) listeners[i]).inputChanged(fInput);
}
 
Example #17
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IInformationControl doCreateInformationControl(Shell parent) {
	if (BrowserInformationControl.isAvailable(parent)) {
		ToolBarManager tbm= new ToolBarManager(SWT.FLAT);
		String font= PreferenceConstants.APPEARANCE_JAVADOC_FONT;
		BrowserInformationControl iControl= new BrowserInformationControl(parent, font, tbm);

		final BackAction backAction= new BackAction(iControl);
		backAction.setEnabled(false);
		tbm.add(backAction);
		final ForwardAction forwardAction= new ForwardAction(iControl);
		tbm.add(forwardAction);
		forwardAction.setEnabled(false);

		final ShowInJavadocViewAction showInJavadocViewAction= new ShowInJavadocViewAction(iControl);
		tbm.add(showInJavadocViewAction);
		final OpenDeclarationAction openDeclarationAction= new OpenDeclarationAction(iControl);
		tbm.add(openDeclarationAction);

		final SimpleSelectionProvider selectionProvider= new SimpleSelectionProvider();
		if (fSite != null) {
			OpenAttachedJavadocAction openAttachedJavadocAction= new OpenAttachedJavadocAction(fSite);
			openAttachedJavadocAction.setSpecialSelectionProvider(selectionProvider);
			openAttachedJavadocAction.setImageDescriptor(JavaPluginImages.DESC_ELCL_OPEN_BROWSER);
			openAttachedJavadocAction.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_OPEN_BROWSER);
			selectionProvider.addSelectionChangedListener(openAttachedJavadocAction);
			selectionProvider.setSelection(new StructuredSelection());
			tbm.add(openAttachedJavadocAction);
		}

		IInputChangedListener inputChangeListener= new IInputChangedListener() {
			public void inputChanged(Object newInput) {
				backAction.update();
				forwardAction.update();
				if (newInput == null) {
					selectionProvider.setSelection(new StructuredSelection());
				} else if (newInput instanceof BrowserInformationControlInput) {
					BrowserInformationControlInput input= (BrowserInformationControlInput) newInput;
					Object inputElement= input.getInputElement();
					selectionProvider.setSelection(new StructuredSelection(inputElement));
					boolean isJavaElementInput= inputElement instanceof IJavaElement;
					showInJavadocViewAction.setEnabled(isJavaElementInput);
					openDeclarationAction.setEnabled(isJavaElementInput);
				}
			}
		};
		iControl.addInputChangeListener(inputChangeListener);

		tbm.update(true);

		addLinkListener(iControl);
		return iControl;

	} else {
		return new DefaultInformationControl(parent, true);
	}
}
 
Example #18
Source File: CustomBrowserInformationControl.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return the current browser input or <code>null</code>
 */
public BrowserInformationControlInput getInput()
{
	return fInput;
}
 
Example #19
Source File: DefaultEObjectHoverProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected String getHtml(EObject obj, DefaultEObjectHoverProvider cut) {
	return ((BrowserInformationControlInput)cut.getHoverInfo(obj,null,null).getInfo()).getHtml();
}
 
Example #20
Source File: AbstractHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected BrowserInformationControlInput hoveringOver(IFile dslFile, IRegion hoverRegion) {
	XtextEditor editor = openInEditor(dslFile);
	Object hoverInfo = ((ITextHoverExtension2) eObjectHover).getHoverInfo2(editor.getInternalSourceViewer(), hoverRegion);
	return (BrowserInformationControlInput) hoverInfo;
}
 
Example #21
Source File: XtextBrowserInformationControlAdapter.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @noreference This method is not intended to be referenced by clients.
 */
@Override
public BrowserInformationControlInput getInput() {
	return control.getInput();
}
 
Example #22
Source File: IXtextBrowserInformationControl.java    From xtext-eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @noreference This method is not intended to be referenced by clients.
 */
public BrowserInformationControlInput getInput();