use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Nptui method removeBlocksHorizontaly.
/**
* Remove blocks horizontaly, from a column/line position, and horizontaly on a length, from the block factory.
*
* @param blockFactory : the block factory
* @param blockBefore : the block just before the blocks to delete in the block factory, search begins from this block.
* @param column : the column from which delete blocks
* @param line : the line from which delete blocks
* @param length : the length on which delete blocks
*/
private int removeBlocksHorizontaly(BlockFactory blockFactory, Block blockBefore, int column, int line, int length) {
if (blockBefore == null) {
// the block to delete is the first of the block factory (no block before)
// set blockBefore to the block factory's first block
blockBefore = blockFactory.getFirstBlock();
}
Block tmpBlock = blockBefore;
// advance in blockFactory to find the first block to remove
while (tmpBlock != null && (// while tmpBlock is on a line inferior to good line
tmpBlock.line < line || (tmpBlock.line == line && tmpBlock.column < column))) {
// or blockTmp is on the good line but has a column inferior to good column
tmpBlock = blockFactory.getNextBlock(tmpBlock);
}
// or if the block to remove is a panel => exit
if (tmpBlock == null || tmpBlock.line != line || tmpBlock.type.equals("panel")) {
return -1;
}
// save the attribute value to return before removing blocks
int attribute = tmpBlock.attribute;
Block blockToRemove = null;
int maxColumn = column + length - 1;
while (tmpBlock != null && // while blockTmp is on the good line
tmpBlock.line == line && // and tmpBlock column is superior or equal to good column
tmpBlock.column >= column && tmpBlock.column + tmpBlock.length - 1 <= maxColumn) {
// and column of last char of tmpBlock is inferior to maxColumn
blockToRemove = tmpBlock;
tmpBlock = blockFactory.getNextBlock(blockToRemove);
blockFactory.removeBlock(blockToRemove);
}
return attribute;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Nptui method removeBlocksVerticaly.
/**
* Remove blocks verticaly, from a column/line position and verticaly on a height, from the block factory.
*
* @param blockFactory : the block factory
* @param blockBefore : the block just before the blocks to delete in the block factory, search begins from this block.
* @param column : the column from which delete blocks
* @param line : the line from which delete blocks
* @param heigth : the height on which delete blocks
*/
private void removeBlocksVerticaly(BlockFactory blockFactory, Block blockBefore, int column, int line, int height) {
if (blockBefore == null) {
// the block to delete is the first of the block factory (no block before)
// set blockBefore to the block factory's first block
blockBefore = blockFactory.getFirstBlock();
}
Block tmpBlock = blockBefore;
// advance in blockFactory to find the first block to remove
while (// while tmpBlock is on a line inferior to good line
tmpBlock.line < line || (tmpBlock.line == line && tmpBlock.column < column)) {
// or blockTmp is on the good line but has a column inferior to good column
tmpBlock = blockFactory.getNextBlock(tmpBlock);
}
// if first block to remove is not on the good line => exit
if (tmpBlock.line == line) {
Block blockToRemove = null;
int maxLine = line + height - 1;
while (tmpBlock != null && // while blockTmp is on the good column
tmpBlock.column == column && // and tmpBlock line is superior or equal to good line
tmpBlock.line >= line && tmpBlock.line <= maxLine) {
// and tmpBlock line is inferior to maxLine
blockToRemove = tmpBlock;
tmpBlock = blockFactory.getSouthBlock(blockToRemove);
blockFactory.removeBlock(blockToRemove);
}
}
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Nptui method removeBlocksFromWindow.
/**
* Remove blocks corresponding to a window, described by coordinates, from the block factory.
* Copy blocks inside the window to the myPanel block, remove definitively blocks from the window border.
*
* @param blockFactory : the block factory
* @param blockBefore : the block just before the blocks corresponding to the window in the block factory, search begins from this block.
* @param column : the column of the window's top left corner
* @param line : the line of the window's top left corner
* @param width : the window's width
* @param heigth : the window's height
* @param myPanel : the block representing the window
* @param dom : the DOM
*/
private void removeBlocksFromWindow(BlockFactory blockFactory, Block blockBefore, int column, int line, int width, int heigth, Block myPanel, Document dom) {
if (blockBefore == null) {
// the block to delete is the first of the block factory (no block before)
// set blockBefore to the block factory's first block
blockBefore = blockFactory.getFirstBlock();
}
Block curBlock = blockBefore;
Block blockToRemove = null;
XMLRectangle laScreenZone = new XMLRectangle(column, line, width, heigth);
do {
if (!curBlock.type.equals("panel")) {
if (isBlockInScreenZone(curBlock, laScreenZone)) {
// if the block is in the panel
if (!isBlockInBorder(curBlock, laScreenZone)) {
// if the block is not in the border
// clone the block and add the clone to the window
Block clone = null;
try {
clone = (Block) curBlock.clone();
} catch (CloneNotSupportedException e) {
Engine.logBeans.trace("Block from a window not clonable : " + curBlock.toString() + "\n" + "Remove it from block factory.");
}
if (clone != null)
myPanel.addOptionalChildren(clone);
}
// in both cases (block in the border or not) remove the block from the block factory
blockToRemove = curBlock;
curBlock = blockFactory.getPreviousBlock(curBlock);
blockFactory.removeBlock(blockToRemove);
}
}
} while ((curBlock = blockFactory.getNextBlock(curBlock)) != null);
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Subfile method execute.
/**
* Applies the extraction rule to the current iJavelin object.
*
* @param javelin the Javelin object.
* @param block the current block to analyze.
* @param blockFactory the block context of the current block.
*
* @return an ExtractionRuleResult object containing the result of
* the query.
*/
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
// save the screenZone so that we can restore it after the extraction of tableCUA
XMLRectangle oldScreenZone = getSelectionScreenZone();
XMLVector<XMLVector<Object>> oldColumns = getColumns();
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
Block downRightBlock, topLeftBlock, blockTmp, newBlock, topActionBlock;
int columnDataLastCharEast, columnDataLastCharWest, dataLastLine;
int subfileMarkerLine;
// attributes of the field of action in the table
int actionLength = 0;
int actionColumn = 0;
// int actionColumnAttributes = 0;
boolean actionColumnExists = false;
Block lastField = null;
boolean screenZoneSet = false;
StringTokenizer st = new StringTokenizer(endString, ",", false);
ArrayList<String> token = new ArrayList<String>(st.countTokens());
// if screen zone has been set, use it...
if (oldScreenZone.x != -1 || oldScreenZone.y != -1 || oldScreenZone.height != -1 || oldScreenZone.width != -1) {
screenZoneSet = true;
}
// for each string
while (st.hasMoreTokens()) {
token.add((String) st.nextToken());
}
try {
// search of the endString among the blocks of the blockFactory
if (token.contains(block.getText().trim()) && JavelinUtils.isSameAttribute(block.attribute, endStringAttribute) && block.line >= subFileDetectionStartLine) {
WindowedBlockManager windowedBlockManager = new WindowedBlockManager(blockFactory);
Engine.logBeans.trace("Searching the end block in a panel.");
if (!windowedBlockManager.searchPanel(block)) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
// this line of code was not commented. I believe this was to prevent SubFile rule to be run twice. I prefer to set the xrs.newCurrentBlock
// to the correct value. This also corrects the bug that prevented the delete blocks rule to act on the subfile marker as it was marked
// as bFinal to true.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !! block.bFinal = true; !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
subfileMarkerLine = block.line;
// if endString = "+" -> special case (Non-CUA but we can try to define the subfile)
if (block.getText().equals("+")) {
/**
* CASE "+" in the last row, in the last column
*/
downRightBlock = block;
dataLastLine = downRightBlock.line;
// as '+' is on same line as the alst row of data , add one line to subFileMarkerLine
subfileMarkerLine++;
// do not include marker block in data
downRightBlock = windowedBlockManager.getPreviousBlockInPanel(block);
Engine.logBeans.trace("Down Right Block = " + downRightBlock.getText());
block.line = block.line + 1;
} else // if endString != "+" (most common case)
{
// we look for a block directly above the endString
downRightBlock = windowedBlockManager.getPreviousBlockInPanel(block);
Engine.logBeans.trace("Down Right Block = " + downRightBlock.toString());
while (downRightBlock != null && downRightBlock.line == block.line) {
downRightBlock = windowedBlockManager.getPreviousBlockInPanel(downRightBlock);
Engine.logBeans.trace("New Down Right Block = " + downRightBlock.toString());
}
dataLastLine = downRightBlock.line;
}
// if previous block do not contain any text, we give up creation of the table
if (downRightBlock.length == 0) {
Engine.logBeans.info("Give up subfile creation => Down Right Block length is 0 : " + downRightBlock.toString());
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
if ((block.column + block.getText().length()) <= (downRightBlock.column + downRightBlock.getText().length()))
columnDataLastCharEast = downRightBlock.column + downRightBlock.getText().length();
else
columnDataLastCharEast = block.column + block.getText().length();
// we move to west and search for the last block on the line (last row)
blockTmp = downRightBlock;
while (windowedBlockManager.getWestBlock(blockTmp) != null && windowedBlockManager.getWestBlock(blockTmp).line == dataLastLine) {
blockTmp = windowedBlockManager.getWestBlock(blockTmp);
}
Engine.logBeans.trace("last block on the line (west) = " + blockTmp.toString());
columnDataLastCharWest = blockTmp.column;
// we check if action column exists
if (blockTmp.type.equalsIgnoreCase("field")) {
actionColumnExists = true;
actionLength = blockTmp.length;
actionColumn = blockTmp.column;
// actionColumnAttributes = blockTmp.attribute;
} else // maybe action column exists but not on this line
{
List<Block> blockField = windowedBlockManager.getBlocksByType("field");
for (Block blockF : blockField) {
Engine.logBeans.trace("block field found = " + blockF.toString());
if (lastField == null) {
if (blockF.column <= blockTmp.column && blockF.line < blockTmp.line) {
lastField = blockF;
}
} else {
if (blockF.line > lastField.line || blockF.column > lastField.column) {
lastField = blockF;
}
}
}
}
// an action column, it can happen that it doesn't have a title
if (actionColumnExists) {
// if we are in the action column
Engine.logBeans.trace("+++ action column exists +++");
if (columnDataLastCharWest > blockTmp.column) {
columnDataLastCharWest = blockTmp.column;
}
topLeftBlock = null;
} else {
// we are in a data column
Engine.logBeans.trace("Searching title row in data column : " + blockTmp.getText());
while ((windowedBlockManager.getNorthBlock(blockTmp) != null) && (!JavelinUtils.isSameAttribute(windowedBlockManager.getNorthBlock(blockTmp).attribute, titleRowAttribute))) {
blockTmp = windowedBlockManager.getNorthBlock(blockTmp);
Engine.logBeans.trace("Moving to north block : " + blockTmp.getText());
}
// check if the last field is in the data
if (lastField == null || lastField.line < blockTmp.line) {
Engine.logBeans.trace("---actionColumnDoesNotExists");
blockTmp = windowedBlockManager.getNorthBlock(blockTmp);
while (windowedBlockManager.getWestBlock(blockTmp) != null) {
blockTmp = windowedBlockManager.getWestBlock(blockTmp);
Engine.logBeans.trace("Moving to west block : " + blockTmp.getText());
if (columnDataLastCharWest > blockTmp.column) {
columnDataLastCharWest = blockTmp.column;
}
}
topLeftBlock = blockTmp;
Engine.logBeans.trace("Top Left Block = " + (topLeftBlock == null ? "null" : topLeftBlock.getText()));
} else {
Engine.logBeans.trace("+++ action column exists +++");
actionColumnExists = true;
if (columnDataLastCharWest > lastField.column) {
columnDataLastCharWest = lastField.column;
}
blockTmp = lastField;
topLeftBlock = null;
}
}
if (actionColumnExists) {
// we search the bottom of the title rows (but maybe action column doesn't have a title)
while (// while north block of blocktmp not null
(windowedBlockManager.getNorthBlock(blockTmp) != null) && // and north block of blocktmp is not same attribute as titlerow
(!JavelinUtils.isSameAttribute(windowedBlockManager.getNorthBlock(blockTmp).attribute, titleRowAttribute)) && (!JavelinUtils.isSameAttribute(windowedBlockManager.getNorthBlock(blockTmp).attribute, actionLineAttribute))) {
// and north block of blocktmp is not same attribute as actionsline
Engine.logBeans.trace("Wrong title line found (" + blockTmp.line + ") ... keep searching...");
blockTmp = windowedBlockManager.getNorthBlock(blockTmp);
}
// is north block of blocktmp the first title block of first column ?
if (// if north block of blocktmp not null
(windowedBlockManager.getNorthBlock(blockTmp) != null) && // and north block of blocktmp has titlerow attribute
(JavelinUtils.isSameAttribute(windowedBlockManager.getNorthBlock(blockTmp).attribute, titleRowAttribute)) && (goodTitleLine(windowedBlockManager, windowedBlockManager.getNorthBlock(blockTmp)))) {
// and north bolck of blocktmp is on a good title line
// blocktmp is the last top data block of the first column
Engine.logBeans.trace("Top of the action column= " + blockTmp.toString());
topActionBlock = blockTmp;
} else {
// action column is not filled until top, blocktmp is not the last top line of data
// or action column doesn't have a title
Block actiontop = blockTmp;
// Searching a title block
blockTmp = windowedBlockManager.getEastBlock(blockTmp);
blockTmp = windowedBlockManager.getNorthBlock(blockTmp);
// look for a title block of the second column
while (// while north block of blocktmp not null
windowedBlockManager.getNorthBlock(blockTmp) != null && // and north block of blocktmp is the same attribute as titlerow
JavelinUtils.isSameAttribute(windowedBlockManager.getNorthBlock(blockTmp).attribute, titleRowAttribute)) {
Engine.logBeans.trace("Wrong title line found (" + blockTmp.line + ") ... keep searching...");
blockTmp = windowedBlockManager.getNorthBlock(blockTmp);
}
if (blockTmp == null) {
Engine.logBeans.info("Give up subfile creation => Looking for title block : blockTmp is null, no more block to test.");
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
} else {
if (// if blocktmp has same attribute as titlerow
JavelinUtils.isSameAttribute(blockTmp.attribute, titleRowAttribute) && (goodTitleLine(windowedBlockManager, blockTmp))) {
// and blocktmp is on a good title line
Engine.logBeans.trace("Top of the action column= " + actiontop.toString());
topActionBlock = actiontop;
} else {
Engine.logBeans.info("Give up subfile creation => blockTmp is not of title attribute or is not on a good title line : " + blockTmp.toString());
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
}
// go one column to the east of top action line block, and one block to the north
blockTmp = windowedBlockManager.getEastBlock(topActionBlock);
blockTmp = windowedBlockManager.getNorthBlock(blockTmp);
// block tmp is the first down title block of second column
// or another column if there is no data on the east of top action line block
Block firstTitleBlock = blockTmp;
// go to the first row of the title rows (if many)
while (windowedBlockManager.getNorthBlock(blockTmp) != null && JavelinUtils.isSameAttribute(windowedBlockManager.getNorthBlock(blockTmp).attribute, titleRowAttribute) && blockTmp.line - windowedBlockManager.getNorthBlock(blockTmp).line == 1) blockTmp = windowedBlockManager.getNorthBlock(blockTmp);
// we check if action column has a title
while (// while no more block is on the top
topActionBlock != null && // and the title row is not found
!JavelinUtils.isSameAttribute(topActionBlock.attribute, titleRowAttribute) && // and an action line is not found (we suppose that the title row must be under the actions line)
!JavelinUtils.isSameAttribute(topActionBlock.attribute, actionLineAttribute)) topActionBlock = windowedBlockManager.getNorthBlock(topActionBlock);
if (topActionBlock != null && JavelinUtils.isSameAttribute(topActionBlock.attribute, titleRowAttribute)) {
Engine.logBeans.trace("Action column has a title");
topLeftBlock = topActionBlock;
} else {
// we arrived on the top of the screen or on the actions line
Engine.logBeans.trace("Action column does not have a title");
Engine.logBeans.trace("Value of the first block of the title row : " + blockTmp.toString());
newBlock = new Block();
newBlock.column = actionColumn;
newBlock.length = actionLength;
newBlock.line = firstTitleBlock.line;
newBlock.attribute = titleRowAttribute;
newBlock.setText("A");
newBlock.bRender = false;
Engine.logBeans.trace("Creation of the title block of the action column : " + newBlock.toString());
// maybe firstTitleBlock is not the second column title, look to the west to see if there are other titles
while (windowedBlockManager.getWestBlock(firstTitleBlock) != null) firstTitleBlock = windowedBlockManager.getWestBlock(firstTitleBlock);
// now firstTitleBlock is the second column title, can insert the created block after its preceding block
Engine.logBeans.trace("Insert new title block after : " + windowedBlockManager.getPreviousBlock(firstTitleBlock).toString());
windowedBlockManager.insertBlock(newBlock, windowedBlockManager.getPreviousBlock(firstTitleBlock));
Engine.logBeans.trace("Next of the new Block : " + windowedBlockManager.getNextBlock(newBlock).toString());
// if getNextBlock(newBlock) and newBlock are not on the same line, we've inserted the new block in the wrong place
if (windowedBlockManager.getNextBlock(newBlock).line != newBlock.line) {
Engine.logBeans.trace("The new block and its next block are not on the same line. Trying to insert it on the right place.");
Block newBlockTmp = newBlock;
while (windowedBlockManager.getNextBlock(newBlockTmp).line != newBlock.line) {
newBlockTmp = windowedBlockManager.getNextBlock(newBlockTmp);
}
Engine.logBeans.trace("The previous block of the right place is : " + newBlockTmp.toString());
windowedBlockManager.removeBlock(newBlock);
windowedBlockManager.insertBlock(newBlock, newBlockTmp);
}
topLeftBlock = newBlock;
}
}
// Engine.logBeans.trace("---topLeftBlock.attribute="+ topLeftBlock.attribute);
if (topLeftBlock != null && downRightBlock != null && goodTitleLine(windowedBlockManager, topLeftBlock) && topLeftBlock.line != 0 && JavelinUtils.isSameAttribute(topLeftBlock.attribute, titleRowAttribute)) {
// We search the first row of data, to give to super.execute method
Block topLeftDataRow = topLeftBlock;
while (windowedBlockManager.getNextBlock(topLeftDataRow) != null && windowedBlockManager.getNextBlock(topLeftDataRow).line == topLeftBlock.line) {
topLeftDataRow = windowedBlockManager.getNextBlock(topLeftDataRow);
}
topLeftDataRow = windowedBlockManager.getNextBlock(topLeftDataRow);
// Set line of actions and finding columns of the table
if (actionColumnExists) {
setColumnSelection(0);
int checkAction = extractActionsLine(windowedBlockManager, topLeftBlock);
if (checkAction == 0)
setColumnSelection(-1);
else
setLineActions(checkAction);
} else
setColumnSelection(-1);
columnTitleWest = javelin.getScreenWidth();
columnTitleEast = 0;
setColumns(createTitleColumns(windowedBlockManager, topLeftBlock, downRightBlock.line, columnDataLastCharEast));
Engine.logBeans.trace("##### Columns: " + getColumns());
XMLRectangle mySelectionScreenZone = new XMLRectangle(Math.min(columnDataLastCharWest, columnTitleWest), topLeftBlock.line + 1, (Math.max(columnDataLastCharEast, columnTitleEast) - topLeftBlock.column) + 1, subfileMarkerLine - topLeftBlock.line - 1);
if (screenZoneSet)
setSelectionScreenZone(oldScreenZone);
else
setSelectionScreenZone(mySelectionScreenZone);
// set the offset to 1 this will result in the table to be shifted up one line
if (actionColumnExists)
this.setOffset(2);
else
this.setOffset(1);
// removing the subfile blocks from their panel.
Block panel = windowedBlockManager.getPanel();
if (panel != null) {
Engine.logBeans.trace("SelectionScreenZone: " + getSelectionScreenZone().toString());
for (Block panelChildBlock : new ArrayList<Block>(panel.getOptionalBlockChildren())) {
Engine.logBeans.trace("Trying to remove from Panel: " + panelChildBlock.toString());
if (// data line
getSelectionScreenZone().contains(panelChildBlock.column, panelChildBlock.line, panelChildBlock.length, 1) || (JavelinUtils.isSameAttribute(panelChildBlock.attribute, actionLineAttribute) && panelChildBlock.line < getSelectionScreenZone().y && panelChildBlock.line >= getSelectionScreenZone().y + getLineActions())) {
// action line
panel.removeOptionalChildren(panelChildBlock);
Engine.logBeans.trace("Removed.");
}
}
}
Engine.logBeans.trace("columnDataLastCharWest=" + columnDataLastCharWest + "; topLeftBlock-line=" + topLeftBlock.line + "; downright-col= " + columnDataLastCharEast + "; downright-line= " + downRightBlock.line);
xrs = super.execute(javelin, topLeftDataRow, blockFactory, dom);
table.setOptionalAttribute("subfile", "true");
table.setOptionalAttribute("titleheight", Integer.toString(titleHeight + 1));
setSelectionScreenZone(oldScreenZone);
setColumns(oldColumns);
// block still contains the end of sub file marker .. set the newCurrentBlock to this block
xrs.newCurrentBlock = block;
return xrs;
} else {
Engine.logBeans.info("Give up subfile creation => Down Right Block is null : " + downRightBlock.toString());
Engine.logBeans.info(" OR Top Left Block is null or not of title attribute : " + (topLeftBlock == null ? "null" : topLeftBlock.toString()));
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} catch (NullPointerException e) {
Engine.logBeans.error("NullPointerException while executing the Subfile extraction rule", e);
xrs.hasMatched = false;
xrs.newCurrentBlock = blockFactory.getLastBlock();
return xrs;
}
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class JavelinTransaction method isFieldValueDifferent.
/**
* Compares the value to the actual value of the field specified
* by the line and column coordinates.
*
* @param blockName the block name to analize
* @param value the value of the field to be compared to
* @param modifiedFields the Json array of modified fields
*
* @return true if the value is different, false otherwise.
*/
private boolean isFieldValueDifferent(String blockName, String value, String modifiedFields) {
Block block = context.previousFields.get(blockName);
if (block == null) {
Engine.logContext.debug("(JavelinTransaction) Field " + blockName + " not found!");
return true;
} else {
String text = block.getText();
text = DefaultBlockFactory.rightTrim(text);
if (value.compareTo(text) == 0) {
if (modifiedFields.indexOf(blockName) != -1) {
Engine.logContext.debug("(JavelinTransaction) Ignoring unchanged value for block '" + blockName + "'");
return true;
}
return false;
} else {
Engine.logContext.debug("(JavelinTransaction) Value: '" + value + "' differs from : '" + text + "'");
return true;
}
}
}
Aggregations