Example usage for org.apache.poi.ss.util CellRangeUtil NO_INTERSECTION

List of usage examples for org.apache.poi.ss.util CellRangeUtil NO_INTERSECTION

Introduction

In this page you can find the example usage for org.apache.poi.ss.util CellRangeUtil NO_INTERSECTION.

Prototype

int NO_INTERSECTION

To view the source code for org.apache.poi.ss.util CellRangeUtil NO_INTERSECTION.

Click Source Link

Usage

From source file:com.vaadin.addon.spreadsheet.action.DeleteTableAction.java

License:Open Source License

@Override
public boolean isApplicableForSelection(Spreadsheet spreadsheet, SelectionChangeEvent event) {
    if (!spreadsheet.getActiveSheet().getProtect() && (event.getIndividualSelectedCells().size() == 0)) {
        if (event.getCellRangeAddresses().size() == 1) {
            List<CellRangeAddress> cras = event.getCellRangeAddresses();
            CellRangeAddress cra = cras.get(0);
            List<SpreadsheetTable> tablesForActiveSheet = spreadsheet.getTablesForActiveSheet();
            for (SpreadsheetTable table : tablesForActiveSheet) {
                if (CellRangeUtil.intersect(cra, table.getFullTableRegion()) != CellRangeUtil.NO_INTERSECTION) {
                    setCaption("Delete Table " + table.getFullTableRegion().formatAsString());
                    tableToDelete = table;
                    return true;
                }/*from   w  w w  .  j ava 2s.c om*/
            }
        } else {
            CellReference selectedCellReference = event.getSelectedCellReference();
            List<SpreadsheetTable> tablesForActiveSheet = spreadsheet.getTablesForActiveSheet();
            for (SpreadsheetTable table : tablesForActiveSheet) {
                if (table.getFullTableRegion().isInRange(selectedCellReference.getRow(),
                        selectedCellReference.getCol())) {
                    setCaption("Delete Table " + table.getFullTableRegion().formatAsString());
                    tableToDelete = table;
                    return true;
                }
            }
        }
    }
    tableToDelete = null;
    return false;
}

From source file:com.vaadin.addon.spreadsheet.action.InsertTableAction.java

License:Open Source License

@Override
public boolean isApplicableForSelection(Spreadsheet spreadsheet, SelectionChangeEvent event) {
    if (!spreadsheet.getActiveSheet().getProtect() && event.getIndividualSelectedCells().size() == 0
            && event.getCellRangeAddresses().size() == 1) {
        List<CellRangeAddress> cras = event.getCellRangeAddresses();
        CellRangeAddress cra = cras.get(0);
        List<SpreadsheetTable> tablesForActiveSheet = spreadsheet.getTablesForActiveSheet();
        // check that the table doesn't contain a table that intersects with
        // the current selection
        for (SpreadsheetTable table : tablesForActiveSheet) {
            if (CellRangeUtil.intersect(cra, table.getFullTableRegion()) != CellRangeUtil.NO_INTERSECTION) {
                return false;
            }/*from  w  w w.ja  v  a 2  s.c om*/
        }
        if (cra.getFirstRow() != cra.getLastRow()) {
            setCaption("Create Table on " + cra.formatAsString());
            return true;
        }
    }
    return false;
}