org.xwiki.gwt.wysiwyg.client.plugin.macro
Class MacroDisplayer

java.lang.Object
  extended by org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDisplayer
All Implemented Interfaces:
InnerHTMLListener

public class MacroDisplayer
extends Object
implements InnerHTMLListener

Hides macro meta data and displays macro output in a read only text box.

Version:
$Id: d336f41b7d0ff0d2eab82dfdda34276380a76165 $

Field Summary
static String BLOCK_MACRO_STYLE_NAME
          The CSS class name used on the text box containing the output of a block macro.
static String COLLAPSED_MACRO_STYLE_NAME
          The CSS class name used on the macro container when a place-holder is displayed instead of the macro output.
protected  DOMUtils domUtils
          Collection of DOM utility methods.
static String INLINE_MACRO_STYLE_NAME
          The CSS class name used on the text box containing the output of an in-line macro.
static String MACRO_PLACEHOLDER_STYLE_NAME
          The CSS class name used on the macro content place-holder.
static String MACRO_STYLE_NAME
          The CSS class name used on the text box containing the output of a macro.
static String SELECTED_MACRO_STYLE_NAME
          The CSS class name used on the text box containing the output of a selected macro.
static String START_MACRO_COMMENT_PREFIX
          The prefix of the start macro comment node.
static String STOP_MACRO_COMMENT_VALUE
          The value of the stop macro comment node.
 
Constructor Summary
MacroDisplayer(RichTextArea textArea)
          Creates a new macro displayer for the given rich text area.
 
Method Summary
protected  Element createMacroContainer(com.google.gwt.dom.client.Node start, com.google.gwt.dom.client.Node stop, int siblingCount)
          Puts macro output inside a read only text box that can be collapsed.
protected  Element createReadOnlyBox(boolean inLine)
           
 void destroy()
          Destroys this displayer.
 List<Element> getMacroContainers(Element root)
           
protected  Element getOutput(Element container)
           
protected  Element getPlaceHolder(Element container)
           
 String getSerializedMacroCall(Element container)
           
 RichTextArea getTextArea()
           
 boolean hasOutput(Element container)
          This method is useful to determine if a macro can be expanded or not.
 boolean isCollapsed(Element container)
           
 boolean isMacroContainer(com.google.gwt.dom.client.Node node)
           
 boolean isSelected(Element container)
           
protected  void limitTextSelectionOnDoubleClick(Element container)
          Make sure that a double click inside the given in-line element selects only text that is inside the element.
 void onInnerHTMLChange(Element element)
          
 void setCollapsed(Element container, boolean collapsed)
          Collapses or expands the specified macro.
 void setSelected(Element container, boolean selected)
          Changes the appearance of the specified macro based on its selected state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MACRO_STYLE_NAME

public static final String MACRO_STYLE_NAME
The CSS class name used on the text box containing the output of a macro.

See Also:
Constant Field Values

SELECTED_MACRO_STYLE_NAME

public static final String SELECTED_MACRO_STYLE_NAME
The CSS class name used on the text box containing the output of a selected macro.

See Also:
Constant Field Values

BLOCK_MACRO_STYLE_NAME

public static final String BLOCK_MACRO_STYLE_NAME
The CSS class name used on the text box containing the output of a block macro.

See Also:
Constant Field Values

INLINE_MACRO_STYLE_NAME

public static final String INLINE_MACRO_STYLE_NAME
The CSS class name used on the text box containing the output of an in-line macro.

See Also:
Constant Field Values

COLLAPSED_MACRO_STYLE_NAME

public static final String COLLAPSED_MACRO_STYLE_NAME
The CSS class name used on the macro container when a place-holder is displayed instead of the macro output.

See Also:
Constant Field Values

MACRO_PLACEHOLDER_STYLE_NAME

public static final String MACRO_PLACEHOLDER_STYLE_NAME
The CSS class name used on the macro content place-holder.

See Also:
Constant Field Values

START_MACRO_COMMENT_PREFIX

public static final String START_MACRO_COMMENT_PREFIX
The prefix of the start macro comment node.

See Also:
Constant Field Values

STOP_MACRO_COMMENT_VALUE

public static final String STOP_MACRO_COMMENT_VALUE
The value of the stop macro comment node.

See Also:
Constant Field Values

domUtils

protected final DOMUtils domUtils
Collection of DOM utility methods.

Constructor Detail

MacroDisplayer

public MacroDisplayer(RichTextArea textArea)
Creates a new macro displayer for the given rich text area.

Parameters:
textArea - the rich text area whose macros will be displayed using this object
Method Detail

destroy

public void destroy()
Destroys this displayer.


getTextArea

public RichTextArea getTextArea()
Returns:
textArea

createMacroContainer

protected Element createMacroContainer(com.google.gwt.dom.client.Node start,
                                       com.google.gwt.dom.client.Node stop,
                                       int siblingCount)
Puts macro output inside a read only text box that can be collapsed.

Parameters:
start - start macro comment node
stop - stop macro comment node
siblingCount - the number of siblings between start and stop nodes
Returns:
the created container that holds the macro output

createReadOnlyBox

protected Element createReadOnlyBox(boolean inLine)
Parameters:
inLine - true if the read-only box is going to displayed in-line, false otherwise
Returns:
an element whose contents cannot be edited inside the rich text area

limitTextSelectionOnDoubleClick

protected void limitTextSelectionOnDoubleClick(Element container)
Make sure that a double click inside the given in-line element selects only text that is inside the element.

Parameters:
container - the element for which to limit the text selection on double click

setSelected

public void setSelected(Element container,
                        boolean selected)
Changes the appearance of the specified macro based on its selected state.

Parameters:
container - a macro container
selected - true to select the specified macro, false otherwise

isSelected

public boolean isSelected(Element container)
Parameters:
container - a macro container
Returns:
true if the specified macro is selected, false otherwise

isMacroContainer

public boolean isMacroContainer(com.google.gwt.dom.client.Node node)
Parameters:
node - a DOM node
Returns:
true if the given node is a macro container, false otherwise

getMacroContainers

public List<Element> getMacroContainers(Element root)
Parameters:
root - a DOM element
Returns:
the list of macro containers in the specified subtree

setCollapsed

public void setCollapsed(Element container,
                         boolean collapsed)
Collapses or expands the specified macro.

Parameters:
container - a macro container
collapsed - true to collapse the specified macro, false to expand it

isCollapsed

public boolean isCollapsed(Element container)
Parameters:
container - a macro container
Returns:
true if the specified macro is collapsed, false otherwise

getOutput

protected Element getOutput(Element container)
Parameters:
container - a macro container
Returns:
the macro output wrapper from the given macro container

hasOutput

public boolean hasOutput(Element container)
This method is useful to determine if a macro can be expanded or not. Macros that don't generate any output are always displayed as collapsed because otherwise they would be invisible to the user.

Parameters:
container - a macro container
Returns:
true if the specified macro has any output, false otherwise

getPlaceHolder

protected Element getPlaceHolder(Element container)
Parameters:
container - a macro container
Returns:
the macro place holder from the given macro container

onInnerHTMLChange

public void onInnerHTMLChange(Element element)

Specified by:
onInnerHTMLChange in interface InnerHTMLListener
See Also:
InnerHTMLListener.onInnerHTMLChange(Element)

getSerializedMacroCall

public String getSerializedMacroCall(Element container)
Parameters:
container - a macro container
Returns:
the serialized macro call (e.g. the value of the start macro comment node) associated with the given macro container


Copyright © 2004–2015 XWiki. All rights reserved.