java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
cn.mapway.document.ui.client.component.ace.AceEditor
All Implemented Interfaces:
com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.TakesValue<String>, com.google.gwt.user.client.ui.HasText, com.google.gwt.user.client.ui.HasVisibility, com.google.gwt.user.client.ui.IsRenderable, com.google.gwt.user.client.ui.IsWidget, com.google.gwt.user.client.ui.RequiresResize

public class AceEditor extends com.google.gwt.user.client.ui.Composite implements com.google.gwt.user.client.ui.RequiresResize, com.google.gwt.user.client.ui.HasText, com.google.gwt.user.client.TakesValue<String>
A GWT widget for the Ajax.org Code Editor (ACE).
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject

    com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
  • Field Summary

    Fields inherited from class com.google.gwt.user.client.ui.UIObject

    DEBUG_ID_PREFIX
  • Constructor Summary

    Constructors
    Constructor
    Description
    Preferred constructor.
    AceEditor(boolean unused)
    Deprecated.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAnnotation(int row, int column, String text, AceAnnotationType type)
    Add an annotation to a the local annotations JsArray<AceAnnotation>, but does not set it on the editor
    void
    Add user defined command.
    static void
    Add an AceCompletionProvider to provide custom code completions.
    int
    Adds a floating marker into this editor (the marker follows lines changes as insertions, suppressions...).
    int
    addMarker(AceRange range, String clazz, AceMarkerType type, boolean inFront)
    Adds a static marker into this editor.
    void
    Register a handler for change events generated by the editor.
    void
    Register a handler for cursor position change events generated by the editor.
    void
    Clear any annotations from the editor and reset the local annotations JsArray<AceAnnotation>
    void
    Cleans up the entire editor.
    void
    Execute a command with no arguments.
    void
    Execute a command with arguments (in case args is not null).
    void
    Execute a command possibly containing string argument.
    void
    Execute a command with arguments (in case args is not null).
    void
    execCommand(String command, String arg)
    Execute a command with arguments (in case args is not null).
    void
    Causes the editor to gain input focus.
    Construct java wrapper for registered Ace command.
    Get the current cursor position.
    int
    Give font size
    int
    Gets the given document position as a zero-based index.
    getLine(int row)
    Get the line of text at the given row number.
    int
    Retrieves the number of lines in the editor.
    Gets all the displayed markers.
    Gets a document position from a supplied zero-based index.
    Prepare a wrapper around Ace Selection object.
    Get the complete text in the editor as a String.
     
    void
    gotoLine(int line)
    Go to given line.
    void
    Bind command line and editor.
    void
    Insert given text at the cursor.
    List names of all Ace commands.
    void
     
    void
    Call this to force the editor contents to be redisplayed.
    static void
    Removes all existing completers from the langtools

    This can be used to disable all completers including local completers, which can be very useful when completers are used on very large files (as the local completer tokenizes every word to put in the selected list).

    NOTE: This method may be removed, and replaced with another solution.
    void
    Remove all the displayed markers.
    void
    Remove a command from the editor.
    void
    Remove commands, that may not be required, from the editor
    void
    removeMarker(int markerId)
    Removes the marker with the specified ID.
    void
    Set any annotations which have been added via addAnnotation on the editor
    void
    Set whether or not autocomplete is enabled.
    void
    setFontSize(int fontSize)
    Set integer font size.
    void
    setFontSize(String fontSize)
    Set font size.
    void
    setHighlightSelectedWord(boolean highlightSelectedWord)
    Set or unset highlighting of currently selected word.
    void
    setHScrollBarAlwaysVisible(boolean hScrollBarAlwaysVisible)
    Set whether or not the horizontal scrollbar is always visible.
    void
    Set the mode.
    void
    setModeByName(String shortModeName)
    Set the mode by name.
    void
    setReadOnly(boolean readOnly)
    Set or unset read-only mode.
    void
    setShowGutter(boolean showGutter)
    Set whether or not the gutter is shown.
    void
    setShowPrintMargin(boolean showPrintMargin)
    Set or unset the visibility of the print margin.
    void
    setTabSize(int tabSize)
    Set tab size.
    void
    Set the complete text in the editor from a String.
    void
    Set the theme.
    void
    Set the theme by name.
    void
    setUseSoftTabs(boolean useSoftTabs)
    Set whether or not soft tabs should be used.
    void
    setUseWorker(boolean useWorker)
    Enable a worker for the current session.
    void
    setUseWrapMode(boolean useWrapMode)
    Set whether to use wrap mode or not
    void
     
    void
    Call this method to start the editor.

    Methods inherited from class com.google.gwt.user.client.ui.Composite

    claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget

    Methods inherited from class com.google.gwt.user.client.ui.Widget

    addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents

    Methods inherited from class com.google.gwt.user.client.ui.UIObject

    addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AceEditor

      public AceEditor()
      Preferred constructor.
    • AceEditor

      @Deprecated public AceEditor(boolean unused)
      Deprecated.
      Do not use this constructor: just use the default constructor.
      Parameters:
      unused - this parameter is ignored
  • Method Details

    • startEditor

      public void startEditor()
      Call this method to start the editor. Make sure that the widget has been attached to the DOM tree before calling this method.
    • redisplay

      public void redisplay()
      Call this to force the editor contents to be redisplayed. There seems to be a problem when an AceEditor is embedded in a LayoutPanel: the editor contents don't appear, and it refuses to accept focus and mouse events, until the browser window is resized. Calling this method works around the problem by forcing the underlying editor to redisplay itself fully. (?)
    • destroy

      public void destroy()
      Cleans up the entire editor.
    • setTheme

      public void setTheme(AceEditorTheme theme)
      Set the theme.
      Parameters:
      theme - the theme (one of the values in the AceEditorTheme enumeration)
    • setThemeByName

      public void setThemeByName(String themeName)
      Set the theme by name.
      Parameters:
      themeName - the theme name (e.g., "twilight")
    • setMode

      public void setMode(AceEditorMode mode)
      Set the mode.
      Parameters:
      mode - the mode (one of the values in the AceEditorMode enumeration)
    • setModeByName

      public void setModeByName(String shortModeName)
      Set the mode by name.
      Parameters:
      shortModeName - name of mode (e.g., "eclipse")
    • setUseWorker

      public void setUseWorker(boolean useWorker)
      Enable a worker for the current session.
      Parameters:
      useWorker - true to enable a worker otherwise false
    • addOnChangeHandler

      public void addOnChangeHandler(AceEditorCallback callback)
      Register a handler for change events generated by the editor.
      Parameters:
      callback - the change event handler
    • addOnCursorPositionChangeHandler

      public void addOnCursorPositionChangeHandler(AceEditorCallback callback)
      Register a handler for cursor position change events generated by the editor.
      Parameters:
      callback - the cursor position change event handler
    • getFontSize

      public int getFontSize()
      Give font size
      Returns:
      font size
    • setFontSize

      public void setFontSize(String fontSize)
      Set font size.
      Parameters:
      fontSize - the font size to set, e.g., "16px"
    • setFontSize

      public void setFontSize(int fontSize)
      Set integer font size.
      Parameters:
      fontSize - the font size to set, e.g., 16
    • getText

      public String getText()
      Get the complete text in the editor as a String.
      Specified by:
      getText in interface com.google.gwt.user.client.ui.HasText
      Returns:
      the text in the editor
    • focus

      public void focus()
      Causes the editor to gain input focus.
    • getLineCount

      public int getLineCount()
      Retrieves the number of lines in the editor.
      Returns:
      The number of lines in the editor.
    • setText

      public void setText(String text)
      Set the complete text in the editor from a String.
      Specified by:
      setText in interface com.google.gwt.user.client.ui.HasText
      Parameters:
      text - the text to set in the editor
    • getLine

      public String getLine(int row)
      Get the line of text at the given row number.
      Parameters:
      row - the row number
      Returns:
      the line of text at that row number
    • insertAtCursor

      public void insertAtCursor(String text)
      Insert given text at the cursor.
      Parameters:
      text - text to insert at the cursor
    • getCursorPosition

      public AceEditorCursorPosition getCursorPosition()
      Get the current cursor position.
      Returns:
      the current cursor position
    • getIndexFromPosition

      public int getIndexFromPosition(AceEditorCursorPosition position)
      Gets the given document position as a zero-based index.
      Parameters:
      position - the position to obtain the absolute index of (base zero)
      Returns:
      An index to the current location in the document
    • getPositionFromIndex

      public AceEditorCursorPosition getPositionFromIndex(int index)
      Gets a document position from a supplied zero-based index.
      Parameters:
      index - (base zero)
      Returns:
      A position object showing the row and column of the supplied index in the document
    • setUseSoftTabs

      public void setUseSoftTabs(boolean useSoftTabs)
      Set whether or not soft tabs should be used.
      Parameters:
      useSoftTabs - true if soft tabs should be used, false otherwise
    • setTabSize

      public void setTabSize(int tabSize)
      Set tab size. (Default is 4.)
      Parameters:
      tabSize - the tab size to set
    • gotoLine

      public void gotoLine(int line)
      Go to given line.
      Parameters:
      line - the line to go to
    • setHScrollBarAlwaysVisible

      public void setHScrollBarAlwaysVisible(boolean hScrollBarAlwaysVisible)
      Set whether or not the horizontal scrollbar is always visible.
      Parameters:
      hScrollBarAlwaysVisible - true if the horizontal scrollbar is always visible, false if it is hidden when not needed
    • setShowGutter

      public void setShowGutter(boolean showGutter)
      Set whether or not the gutter is shown.
      Parameters:
      showGutter - true if the gutter should be shown, false if it should be hidden
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Set or unset read-only mode.
      Parameters:
      readOnly - true if editor should be set to readonly, false if the editor should be set to read-write
    • setHighlightSelectedWord

      public void setHighlightSelectedWord(boolean highlightSelectedWord)
      Set or unset highlighting of currently selected word.
      Parameters:
      highlightSelectedWord - true to highlight currently selected word, false otherwise
    • setShowPrintMargin

      public void setShowPrintMargin(boolean showPrintMargin)
      Set or unset the visibility of the print margin.
      Parameters:
      showPrintMargin - true if the print margin should be shown, false otherwise
    • addAnnotation

      public void addAnnotation(int row, int column, String text, AceAnnotationType type)
      Add an annotation to a the local annotations JsArray<AceAnnotation>, but does not set it on the editor
      Parameters:
      row - to which the annotation should be added
      column - to which the annotation applies
      text - to display as a tooltip with the annotation
      type - to be displayed (one of the values in the AceAnnotationType enumeration)
    • setAnnotations

      public void setAnnotations()
      Set any annotations which have been added via addAnnotation on the editor
    • clearAnnotations

      public void clearAnnotations()
      Clear any annotations from the editor and reset the local annotations JsArray<AceAnnotation>
    • removeCommand

      public void removeCommand(AceCommand command)
      Remove a command from the editor.
      Parameters:
      command - the command (one of the values in the AceCommand enumeration)
    • execCommand

      public void execCommand(AceCommand command)
      Execute a command with no arguments. See AceCommand values for example.
      Parameters:
      command - the command (one of the values in the AceCommand enumeration)
    • execCommand

      public void execCommand(AceCommand command, AceCommandArgs args)
      Execute a command with arguments (in case args is not null). See AceCommand values for example.
      Parameters:
      command - the command (one of the values in the AceCommand enumeration)
      args - command arguments (string or map)
    • execCommand

      public void execCommand(String command)
      Execute a command possibly containing string argument.
      Parameters:
      command - the command which could be one or two words separated by whitespaces
    • execCommand

      public void execCommand(String command, String arg)
      Execute a command with arguments (in case args is not null).
      Parameters:
      command - one word command
      arg - command argument
    • execCommand

      public void execCommand(String command, AceCommandArgs args)
      Execute a command with arguments (in case args is not null).
      Parameters:
      command - one word command
      args - command arguments of type AceCommandArgs
    • removeCommandByName

      public void removeCommandByName(String command)
      Remove commands, that may not be required, from the editor
      Parameters:
      command - to be removed, one of "gotoline", "findnext", "findprevious", "find", "replace", "replaceall"
    • getCommandDescription

      public AceCommandDescription getCommandDescription(String command)
      Construct java wrapper for registered Ace command.
      Parameters:
      command - name of command
      Returns:
      command description
    • listCommands

      public List<String> listCommands()
      List names of all Ace commands.
      Returns:
      names of all Ace commands
    • addCommand

      public void addCommand(AceCommandDescription description)
      Add user defined command.
      Parameters:
      description - command description
    • setUseWrapMode

      public void setUseWrapMode(boolean useWrapMode)
      Set whether to use wrap mode or not
      Parameters:
      useWrapMode - true if word wrap should be used, false otherwise
    • onResize

      public void onResize()
      Specified by:
      onResize in interface com.google.gwt.user.client.ui.RequiresResize
    • setValue

      public void setValue(String value)
      Specified by:
      setValue in interface com.google.gwt.user.client.TakesValue<String>
    • getValue

      public String getValue()
      Specified by:
      getValue in interface com.google.gwt.user.client.TakesValue<String>
    • setAutocompleteEnabled

      public void setAutocompleteEnabled(boolean b)
      Set whether or not autocomplete is enabled.
      Parameters:
      b - true if autocomplete should be enabled, false if not
    • removeAllExistingCompleters

      public static void removeAllExistingCompleters()
      Removes all existing completers from the langtools

      This can be used to disable all completers including local completers, which can be very useful when completers are used on very large files (as the local completer tokenizes every word to put in the selected list).

      NOTE: This method may be removed, and replaced with another solution. It works at point of check-in, but treat this as unstable for now.
    • addCompletionProvider

      public static void addCompletionProvider(AceCompletionProvider provider)
      Add an AceCompletionProvider to provide custom code completions. Warning: this is an experimental feature of AceGWT. It is possible that the API will change in an incompatible way in future releases.
      Parameters:
      provider - the AceCompletionProvider
    • addMarker

      public int addMarker(AceRange range, String clazz, AceMarkerType type, boolean inFront)
      Adds a static marker into this editor.
      Parameters:
      range - an AceRange.
      clazz - a CSS class that must be applied to the marker.
      type - an AceMarkerType.
      inFront - set to 'true' if the marker must be in front of the text, 'false' otherwise.
      Returns:
      The marker ID. This id can be then use to remove a marker from the editor.
    • addFloatingMarker

      public int addFloatingMarker(AceRange range, String clazz, AceMarkerType type)
      Adds a floating marker into this editor (the marker follows lines changes as insertions, suppressions...).
      Parameters:
      range - an AceRange.
      clazz - a CSS class that must be applied to the marker.
      type - an AceMarkerType.
      Returns:
      The marker ID. This id can be then use to remove a marker from the editor.
    • removeMarker

      public void removeMarker(int markerId)
      Removes the marker with the specified ID.
      Parameters:
      markerId - the marker ID.
    • getMarkers

      public Map<Integer,AceRange> getMarkers()
      Gets all the displayed markers.
      Returns:
      An unmodifiable Mapping between markerID and the displayed range.
    • removeAllMarkers

      public void removeAllMarkers()
      Remove all the displayed markers.
    • getSelection

      public AceSelection getSelection()
      Prepare a wrapper around Ace Selection object.
      Returns:
      a wrapper around Ace Selection object
    • initializeCommandLine

      public void initializeCommandLine(AceCommandLine cmdLine)
      Bind command line and editor. For default implementation of command line you can use AceCommandLine cmdLine = new AceDefaultCommandLine(textBox) where textBox could be for instance standard GWT TextBox or TextArea.
      Parameters:
      cmdLine - implementation of command line