Class TableOperationsUtil
java.lang.Object
ro.sync.ecss.extensions.commons.table.operations.TableOperationsUtil
Utility class for table operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareOtherTablesThanChoicetableAllowed(AuthorAccess authorAccess) Check if a table other than choicetable is allowed here.static voidcomputeElementsList(List<AuthorElement> elementsList, AuthorElement node, int startOffset, int endOffset, int type, boolean fullySelected, TableHelper tableHelper) Computes all the nodes of the given type starting from the given node, which are in the given selection.static StringcreateCellXMLFragment(AuthorAccess authorAccess, AuthorDocumentFragment[] fragments, boolean cellsFragment, String cellElementName, int currentFragmentIndex, String namespace, AuthorTableHelper authorTableHelper, String... imposedAttributesFragments) Create a cell fragment for a specific offset, having the name of the cell and a source fragment from which the attributes and content must be copied.static TableHelpercreateTableHelper(AuthorTableHelper authorTableHelper) Create aTableHelperstarting from anAuthorTableHelper.static Map<AuthorElement,Set<Integer>> getCellIndexes(List<AuthorElement> cells, AuthorAccess authorAccess, TableHelper tableHelper, boolean isCals) Obtain the indexes for selected cells.static voidgetChildElements(AuthorElement node, int type, List<AuthorElement> children, TableHelper tableHelper) * Obtain a list of children with the given type.static StringgetContentFromFragment(AuthorAccess authorAccess, boolean cellsFragment, AuthorDocumentFragment fragment) Get the given fragment content.static AuthorElementgetElementAncestor(AuthorNode node, int type, TableHelper tableHelper) Search for an ancestorAuthorNodewith the specified type.static AuthorElementgetTableElementContainingOffset(int offset, String namespace, AuthorAccess access, String... tableElementNames) Returns the element representing the table that contains the given offset and has the given properties (name, namespace).static AuthorElementgetTableElementContainingOffset(int offset, AuthorAccess access, String... tableClassValues) Returns the element representing the table that contains the given offset and has the given properties (name, class attribute).static List<AuthorElement>getTableElementsOfType(AuthorAccess authorAccess, List<Integer[]> selections, int type, TableHelper tableHelper) Collects all the table elements having the given type, determined by the selection intervals.static List<AuthorElement>getTableElementsOfTypeFromSelection(AuthorAccess authorAccess, int type, TableHelper tableHelper, AuthorElement tableElement) Collects all the table elements having the given type, determined by the selection intervals.static booleanhandleColumnSpecAttributeChange(AuthorAccess authorAccess, AuthorTableHelper helper, AuthorElement currentElement, String attributeName, AttrValue newValue) Propagate the change of a column name in the entire table.static booleanisChoiceTableAllowed(AuthorAccess authorAccess) Check if a choice table can be inserted in the current context.static booleanisIgnoredAttribute(String attrName, AuthorTableHelper tableHelper) Check if the attribute should be ignored.static booleanisPropertiesTableGlobalElement(AuthorAccess authorAccess) Check if a properties table is allowed as a global element.static booleannodeHasProperties(AuthorNode node, String name, String namespace) Check if the node has the given namespace and namestatic voidplaceCaretInFirstCell(AuthorAccess authorAccess, TableInfo tableInfo, AuthorDocumentController controller, SchemaAwareHandlerResult result) Place the caret in the first cell of a table that was just inserted (a result of this operation is send as parameter)static voidremoveInvalidColNamesFromCALSTableCells(AuthorAccess authorAccess, AuthorElement tableElement, List<AuthorElement> cells) Remove invalid column names from CALS table cells.
-
Method Details
-
createCellXMLFragment
public static String createCellXMLFragment(AuthorAccess authorAccess, AuthorDocumentFragment[] fragments, boolean cellsFragment, String cellElementName, int currentFragmentIndex, String namespace, AuthorTableHelper authorTableHelper, String... imposedAttributesFragments) throws AuthorOperationException Create a cell fragment for a specific offset, having the name of the cell and a source fragment from which the attributes and content must be copied.- Parameters:
authorAccess- The author access.fragments- The list of all content fragments.cellsFragment-trueif the fragments represents cells.cellElementName- The cell name.currentFragmentIndex- The index of the fragment that must be used for attributes and content.namespace- The cell namespace.authorTableHelper- Author table helper.imposedAttributesFragments- Imposed attributes for the created cell. Each fragment has the following form: "attribute_name=\"attribute_value\""- Returns:
- The cell fragment.
- Throws:
AuthorOperationException
-
isIgnoredAttribute
Check if the attribute should be ignored.- Parameters:
attrName- The attribute name.tableHelper- Author table helper- Returns:
trueif the attribute should be ignored.
-
getContentFromFragment
public static String getContentFromFragment(AuthorAccess authorAccess, boolean cellsFragment, AuthorDocumentFragment fragment) Get the given fragment content. If the cellsFragment parameter istrue, the returned content represent the content of the cell, otherwise the fragment itself.- Parameters:
authorAccess- The author access.cellsFragment-trueif the fragment represent a cell fragmentfragment- The Author fragment.- Returns:
- The fragment content.
-
nodeHasProperties
Check if the node has the given namespace and name- Parameters:
node- The node to check.name- The name to compare the node name with.namespace- The namespace to compare the node namespace with.- Returns:
trueif the node has the given namespace and name.
-
getTableElementContainingOffset
public static AuthorElement getTableElementContainingOffset(int offset, AuthorAccess access, String... tableClassValues) Returns the element representing the table that contains the given offset and has the given properties (name, class attribute). Used for DITA and DITA Maps table operations.- Parameters:
offset- The offset to search the parent table element for.access- Access to Author operations.tableClassValues- Possible table class attributes values.- Returns:
- The table element that contains the given offset.
-
getTableElementContainingOffset
public static AuthorElement getTableElementContainingOffset(int offset, String namespace, AuthorAccess access, String... tableElementNames) Returns the element representing the table that contains the given offset and has the given properties (name, namespace).- Parameters:
offset- The offset to search the parent table element for.namespace- The table node namespace.access- Access to Author operations.tableElementNames- Possible table element names.- Returns:
- The table element that contains the given offset.
-
isChoiceTableAllowed
Check if a choice table can be inserted in the current context.- Parameters:
authorAccess- The author access.- Returns:
trueif a choice table can be inserted in the given context.
-
areOtherTablesThanChoicetableAllowed
Check if a table other than choicetable is allowed here.- Parameters:
authorAccess- The author access.- Returns:
trueif a choice table can be inserted in the given context.
-
isPropertiesTableGlobalElement
Check if a properties table is allowed as a global element.- Parameters:
authorAccess- The author access.- Returns:
trueif the "properties" table element is a global element of the schema.
-
getTableElementsOfTypeFromSelection
public static List<AuthorElement> getTableElementsOfTypeFromSelection(AuthorAccess authorAccess, int type, TableHelper tableHelper, AuthorElement tableElement) Collects all the table elements having the given type, determined by the selection intervals.- Parameters:
authorAccess- The author accesstype- The type of the elements to be collected. Can be one of TYPE_ prefixed constants fromTableHelperConstants.tableHelper- Utility class to determine information about table nodes.tableElement- The table parent elements.- Returns:
- A list with all the elements used to populate the tabs in "Table Properties" dialog.
-
getTableElementsOfType
public static List<AuthorElement> getTableElementsOfType(AuthorAccess authorAccess, List<Integer[]> selections, int type, TableHelper tableHelper) Collects all the table elements having the given type, determined by the selection intervals.- Parameters:
authorAccess- The author accessselections- The currently selected nodes. They can be mixed.type- The type of the elements to be collected. Can be one of TYPE_ prefixed constants fromTableHelperConstants.tableHelper- Utility class to determine information about table nodes.- Returns:
- A list with all the elements used to populate the tabs in "Table Properties" dialog.
-
computeElementsList
public static void computeElementsList(List<AuthorElement> elementsList, AuthorElement node, int startOffset, int endOffset, int type, boolean fullySelected, TableHelper tableHelper) Computes all the nodes of the given type starting from the given node, which are in the given selection.- Parameters:
elementsList- The list which will contain the elements.node- The starting node.startOffset- Selection start.endOffset- Selection end.type- The elements type. Can be one of TYPE_ prefixed constants fromTableHelperConstants.fullySelected-trueif the nodes should be entire contained by the selection.tableHelper- Utility class to determine information about table nodes.
-
getElementAncestor
Search for an ancestorAuthorNodewith the specified type.- Parameters:
node- The starting node.type- The type of the ancestor.tableHelper- Utility class to determine information about table nodes.- Returns:
- The ancestor node of the given
nodeor thenodeitself if the type matches.
-
getChildElements
public static void getChildElements(AuthorElement node, int type, List<AuthorElement> children, TableHelper tableHelper) * Obtain a list of children with the given type.- Parameters:
node- The parent node.type- The child elements type. Can be one of TYPE_ prefixed constants fromTableHelperConstants.children- The list with collected children. Empty when the function is called.tableHelper- Utility class to determine information about table nodes.
-
getCellIndexes
public static Map<AuthorElement,Set<Integer>> getCellIndexes(List<AuthorElement> cells, AuthorAccess authorAccess, TableHelper tableHelper, boolean isCals) Obtain the indexes for selected cells.- Parameters:
cells- The selected cells.authorAccess- The author access.tableHelper- Utility class to determine information about table nodes.isCals-trueif it is a CALS table- Returns:
- A map between the table element and a set of the cell's column indexes.
-
createTableHelper
Create aTableHelperstarting from anAuthorTableHelper.- Parameters:
authorTableHelper- The Author table helper- Returns:
- The
TableHelper
-
placeCaretInFirstCell
public static void placeCaretInFirstCell(AuthorAccess authorAccess, TableInfo tableInfo, AuthorDocumentController controller, SchemaAwareHandlerResult result) Place the caret in the first cell of a table that was just inserted (a result of this operation is send as parameter)- Parameters:
authorAccess- Author access.tableInfo- Table information.controller- Controller.result- Insert operation result.
-
removeInvalidColNamesFromCALSTableCells
public static void removeInvalidColNamesFromCALSTableCells(AuthorAccess authorAccess, AuthorElement tableElement, List<AuthorElement> cells) Remove invalid column names from CALS table cells. Remove references to column names which are not defined in the table.- Parameters:
authorAccess- Author AccesstableElement- The table elementcells- The list of cells.
-
handleColumnSpecAttributeChange
public static boolean handleColumnSpecAttributeChange(AuthorAccess authorAccess, AuthorTableHelper helper, AuthorElement currentElement, String attributeName, AttrValue newValue) Propagate the change of a column name in the entire table.- Parameters:
authorAccess- Author accesshelper- Table helper.currentElement- Current element on which the attribute which should be changed.attributeName- Name of changed attributenewValue- The new attribute value- Returns:
trueif this method handled the change.
-