Class FormattedTextViewFx
- java.lang.Object
-
- com._1c.g5.v8.dt.md.ui.editor.formattedtext.FormattedTextViewFx
-
- All Implemented Interfaces:
org.eclipse.ui.services.IDisposable
- Direct Known Subclasses:
FormattedTextEditableView
public class FormattedTextViewFx extends Object implements org.eclipse.ui.services.IDisposable
View to display formatted text content. Based onWebView
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
FormattedTextViewFx.HtmlConverterHelper
Part of "FormattedText-to-HTML" converter called from JavaScript code.
-
Constructor Summary
Constructors Constructor Description FormattedTextViewFx(javafx.embed.swt.FXCanvas canvas, String content, Runnable onContentLoaded, IV8Project v8Project, IMdObjectByTypeProvider objectByTypeProvider, IColorProvider colorProvider, IFontProvider fontProvider, int scale, double preferredWidth, double preferredHeight, FormattedStringSettings formattedStringSettings)
Creates new view of formatted text.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
protected Object
executeCommand(String commandName, Object... args)
Executes command with arguments of arbitrary types.protected Object
executeCommand(String commandName, String... args)
Executes command via JavaScript engine with arguments propagated to JavaScript as they are.protected Object
executeCommandStrArg(String commandName, String arg)
Executes command via JavaScript engine with argument propagated to JavaScript as string.protected Object
executeCommandStrArg(String commandName, String arg1, String arg2)
Executes command via JavaScript engine with two arguments propagated to JavaScript as strings.protected Object
executeScript(String script)
Executes arbitrary script via JavaScript engine.protected Object
executeScriptFromResource(String resource)
Executes specified script from resource via JavaScript engine.IColorProvider
getColorProvider()
Gets actual serviceIColorProvider
protected String
getContentAsHtml(String content)
Converts the given formatted text string into html string.org.eclipse.swt.graphics.Point
getContentSize()
Returns size of the loaded content.protected FormattedTextEncoder
getEncoder()
ReturnsFormattedTextEncoder
instance used for converting HTML to formatted text and back.IFontProvider
getFontProvider()
Gets actual serviceIFontProvider
IMdObjectByTypeProvider
getObjectByTypeProvider()
Gets actual serviceIMdObjectByTypeProvider
protected static String
getResourceAsString(String resourcePath)
Reads resource by the given resource path and returns it as string.IV8Project
getV8Project()
GetsIV8Project
Version
getVersion()
Gets actualVersion
protected javafx.scene.web.WebEngine
getWebEngine()
ReturnsWebEngine
instance.void
hideScrollBars(boolean hide)
Hides scroll bars of the view.protected void
initializeJavaScript()
Runs JavaScript initialization scripts before loading HTML content.void
resizeView(double width, double height, Runnable onContentLoaded)
Resizes view containment.protected void
setInitialContent(String html, Runnable onContentLoaded)
Sets HTML content to the view.void
updateFormattedStringSettings(FormattedStringSettings settings, Runnable onContentLoaded)
Updates theFormattedStringSettings
.
-
-
-
Constructor Detail
-
FormattedTextViewFx
public FormattedTextViewFx(javafx.embed.swt.FXCanvas canvas, String content, Runnable onContentLoaded, IV8Project v8Project, IMdObjectByTypeProvider objectByTypeProvider, IColorProvider colorProvider, IFontProvider fontProvider, int scale, double preferredWidth, double preferredHeight, FormattedStringSettings formattedStringSettings)
Creates new view of formatted text.- Parameters:
canvas
- theFXCanvas
instance to which to attach this view, cannot benull
content
- formatted text contentonContentLoaded
- callback to be called when content has been loadedv8Project
- V8 project, cannot benull
objectByTypeProvider
- object by type provider, cannot benull
colorProvider
- the color provider, cannot benull
fontProvider
- the font provider, cannot benull
scale
- the form scale in percentpreferredWidth
- the preferred width of the formatted text, useSWT.DEFAULT
to ignore limitpreferredHeight
- the preferred height of the formatted text, useSWT.DEFAULT
to ignore limitformatStringSettings
- the formatted text default settings, can benull
-
-
Method Detail
-
getContentSize
public org.eclipse.swt.graphics.Point getContentSize()
Returns size of the loaded content.- Returns:
- content size calculated or (-1,-1) in case of problems
-
hideScrollBars
public void hideScrollBars(boolean hide)
Hides scroll bars of the view. Usually scroll bars appear when size of the parent canvas is less then size of the content.- Parameters:
hide
- iftrue
, then scroll bars will never appear
-
updateFormattedStringSettings
public void updateFormattedStringSettings(FormattedStringSettings settings, Runnable onContentLoaded)
Updates theFormattedStringSettings
. If default font style is changed you should use this method to set correct settings.- Parameters:
settings
- new formatted text settings, can't benull
onContentLoaded
- callback to be called when content has been loaded
-
resizeView
public void resizeView(double width, double height, Runnable onContentLoaded)
Resizes view containment.- Parameters:
width
- new width for viewheight
- new height for viewonContentLoaded
- callback to be called when content has been loaded
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceorg.eclipse.ui.services.IDisposable
-
getV8Project
public IV8Project getV8Project()
GetsIV8Project
- Returns:
IV8Project
, cannot benull
-
getObjectByTypeProvider
public IMdObjectByTypeProvider getObjectByTypeProvider()
Gets actual serviceIMdObjectByTypeProvider
- Returns:
- actual service
IMdObjectByTypeProvider
, cannot benull
-
getColorProvider
public IColorProvider getColorProvider()
Gets actual serviceIColorProvider
- Returns:
- actual service
IColorProvider
, cannot benull
-
getFontProvider
public IFontProvider getFontProvider()
Gets actual serviceIFontProvider
- Returns:
- actual service
IFontProvider
, cannot benull
-
initializeJavaScript
protected void initializeJavaScript()
Runs JavaScript initialization scripts before loading HTML content.
-
setInitialContent
protected void setInitialContent(String html, Runnable onContentLoaded)
Sets HTML content to the view.- Parameters:
html
- the content to setonContentLoaded
- the callback to be called when initial content has been loaded
-
executeCommandStrArg
protected Object executeCommandStrArg(String commandName, String arg)
Executes command via JavaScript engine with argument propagated to JavaScript as string. In fact, it wraps the argument with quotes and callsexecuteCommand(String, String...)
.- Parameters:
commandName
- the command to executearg
- the argument- Returns:
- execution result
-
executeCommandStrArg
protected Object executeCommandStrArg(String commandName, String arg1, String arg2)
Executes command via JavaScript engine with two arguments propagated to JavaScript as strings. In fact, it wraps the arguments with quotes and callsexecuteCommand(String, String...)
.- Parameters:
commandName
- the command to executearg1
- the first argumentarg2
- the second argument- Returns:
- execution result
-
executeCommand
protected Object executeCommand(String commandName, String... args)
Executes command via JavaScript engine with arguments propagated to JavaScript as they are.- Parameters:
commandName
- the command to executeargs
- the arguments- Returns:
- execution result
-
executeCommand
protected Object executeCommand(String commandName, Object... args)
Executes command with arguments of arbitrary types. It obtains name of JavaScript object from the command and runsJSObject.call(String, Object...)
method on it.- Parameters:
commandName
- the command to execute, must contain object name separated by dotargs
- the command arguments- Returns:
- execution result or
null
if error occurred
-
executeScriptFromResource
protected Object executeScriptFromResource(String resource)
Executes specified script from resource via JavaScript engine.- Parameters:
resource
- the resource with script- Returns:
- execution result
-
executeScript
protected Object executeScript(String script)
Executes arbitrary script via JavaScript engine.- Parameters:
script
- the script to execute- Returns:
- execution result or
null
if error occurred
-
getWebEngine
protected javafx.scene.web.WebEngine getWebEngine()
ReturnsWebEngine
instance.- Returns:
- the
WebEngine
instance ornull
if not initialized yet
-
getEncoder
protected FormattedTextEncoder getEncoder()
ReturnsFormattedTextEncoder
instance used for converting HTML to formatted text and back.- Returns:
- the
FormattedTextEncoder
instance
-
getResourceAsString
protected static String getResourceAsString(String resourcePath)
Reads resource by the given resource path and returns it as string.- Parameters:
resourcePath
- the resource path to read- Returns:
- the resource as string
-
-