Search in sources :

Example 91 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class AbstractColumnHideShowLayer method underlyingToLocalColumnPositions.

@Override
public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges) {
    Collection<Range> localColumnPositionRanges = new ArrayList<Range>(underlyingColumnPositionRanges.size());
    for (Range underlyingColumnPositionRange : underlyingColumnPositionRanges) {
        int startColumnPosition = getAdjustedUnderlyingToLocalStartPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.start, underlyingColumnPositionRange.end);
        int endColumnPosition = getAdjustedUnderlyingToLocalEndPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.end, underlyingColumnPositionRange.start);
        // returned.
        if (startColumnPosition > -1) {
            localColumnPositionRanges.add(new Range(startColumnPosition, endColumnPosition));
        }
    }
    return localColumnPositionRanges;
}
Also used : ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 92 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayer method showColumnIndexes.

@Override
public void showColumnIndexes(Collection<Integer> columnIndexes) {
    // On show we expect that all visible columns share the free
    // space. To avoid that only the adjacent column is decreased, we
    // disable fixColumnPercentageValuesOnResize in any case and restore it
    // afterwards
    boolean fix = this.bodyDataLayer.isFixColumnPercentageValuesOnResize();
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(false);
    List<Integer> processed = new ArrayList<Integer>();
    for (Integer index : columnIndexes) {
        ColumnSizeInfo info = this.hiddenColumns.remove(index);
        if (info != null) {
            processed.add(index);
            // first make the column resizable
            this.bodyDataLayer.setColumnPositionResizable(index, true);
            // set the previous configured width
            if (info.configuredPercentage && info.configuredPercentageValue >= 0) {
                this.bodyDataLayer.setColumnWidthPercentageByPosition(index, info.configuredPercentageValue);
            } else if (!info.configuredPercentage && info.configuredSize >= 0) {
                this.bodyDataLayer.setColumnWidthByPosition(index, info.configuredSize, false);
            } else {
                this.bodyDataLayer.resetColumnWidth(index, false);
            }
            // set the configured resizable value
            this.bodyDataLayer.setColumnPositionResizable(index, info.configuredResizable);
            // set the previous configured min width
            if (info.configuredMinWidth < 0) {
                this.bodyDataLayer.resetMinColumnWidth(index, false);
            } else {
                this.bodyDataLayer.setMinColumnWidth(index, info.configuredMinWidth);
            }
        }
    }
    // reset the fixColumnPercentageValuesOnResize flag
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(fix);
    if (!processed.isEmpty()) {
        List<Range> ranges = PositionUtil.getRanges(processed);
        // fire events
        for (Range range : ranges) {
            this.bodyDataLayer.fireLayerEvent(new ColumnResizeEvent(this.bodyDataLayer, range));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 93 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayer method hideColumnPositions.

@Override
public void hideColumnPositions(Collection<Integer> columnPositions) {
    Map<Integer, ColumnSizeInfo> positionsToHide = new TreeMap<Integer, ColumnSizeInfo>();
    // On hide we expect that all remaining visible columns share the free
    // space. To avoid that only the adjacent column is increased, we
    // disable fixColumnPercentageValuesOnResize in any case and restore it
    // afterwards
    boolean fix = this.bodyDataLayer.isFixColumnPercentageValuesOnResize();
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(false);
    for (Integer columnPosition : columnPositions) {
        // transform the position to index
        int columnIndex = getColumnIndexByPosition(columnPosition);
        // get the currently applied width of the column
        int configuredWidth = this.bodyDataLayer.getConfiguredColumnWidthByPosition(columnIndex);
        // get the currently applied min width of the column
        int configuredMinWidth = this.bodyDataLayer.getConfiguredMinColumnWidthByPosition(columnIndex);
        // get the currently applied resizable info
        boolean configuredResizable = this.bodyDataLayer.isColumnPositionResizable(columnIndex);
        // get the information if the column is configured for percentage
        // sizing
        boolean configuredPercentage = this.bodyDataLayer.isColumnPercentageSizing(columnIndex);
        // get the currently applied percentage width of the column
        double configuredPercentageValue = this.bodyDataLayer.getConfiguredColumnWidthPercentageByPosition(columnIndex);
        positionsToHide.put(columnIndex, new ColumnSizeInfo(configuredWidth, configuredMinWidth, configuredResizable, configuredPercentage, configuredPercentageValue));
    }
    for (Integer columnIndex : positionsToHide.keySet()) {
        // moment to make hiding work
        if (!this.bodyDataLayer.isColumnPositionResizable(columnIndex)) {
            this.bodyDataLayer.setColumnPositionResizable(columnIndex, true);
        }
        // if a min width is configured, set it to 0 to make hiding work
        if (this.bodyDataLayer.isMinColumnWidthConfigured()) {
            this.bodyDataLayer.setMinColumnWidth(columnIndex, 0);
        }
        // set the column width to 0
        if (positionsToHide.get(columnIndex).configuredPercentage) {
            this.bodyDataLayer.setColumnWidthPercentageByPosition(columnIndex, 0d);
        } else {
            this.bodyDataLayer.setColumnWidthByPosition(columnIndex, 0, false);
        }
        // make that column not resizable
        this.bodyDataLayer.setColumnPositionResizable(columnIndex, false);
    }
    this.hiddenColumns.putAll(positionsToHide);
    // reset the fixColumnPercentageValuesOnResize flag
    this.bodyDataLayer.setFixColumnPercentageValuesOnResize(fix);
    // fire events
    List<Range> ranges = PositionUtil.getRanges(positionsToHide.keySet());
    for (Range range : ranges) {
        this.bodyDataLayer.fireLayerEvent(new ColumnResizeEvent(this.bodyDataLayer, range));
    }
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) TreeMap(java.util.TreeMap) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 94 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayer method expandOrCollapse.

/**
 * Expands or collapses the node at the given index coordinates according to
 * its current state. Expands to the given level, e.g. if toLevel 0 is
 * given, only the first level of a row is expanded, given toLevel is 1 and
 * a node in the first level should be expanded, that node will be expanded
 * as well as all collapsed nodes in the second level for this object.
 *
 * @param columnIndex
 *            The column index of the node to handle.
 * @param rowIndex
 *            The row index of the node to handle.
 * @param toLevel
 *            0 based hierarchy level to expand to. Will be ignored on
 *            collapse or if value is -1.
 *            <p>
 *            <b>Note:</b> This is the level to expand to, not the number of
 *            levels to expand from the expanded level.
 *            </p>
 */
public void expandOrCollapse(int columnIndex, int rowIndex, int toLevel) {
    List<Integer> toProcess = getChildIndexes(columnIndex, rowIndex);
    HierarchicalTreeNode coord = new HierarchicalTreeNode(columnIndex, rowIndex, null);
    if (this.collapsedNodes.contains(coord)) {
        this.collapsedNodes.remove(coord);
        // ensure that deeper level collapsed rows are not shown again
        Range children = new Range(rowIndex, toProcess.get(toProcess.size() - 1));
        int toLevelColumnIndex = (toLevel >= 0) ? this.nodeColumnMapping.get(toLevel) : -1;
        for (Iterator<HierarchicalTreeNode> it = this.collapsedNodes.iterator(); it.hasNext(); ) {
            HierarchicalTreeNode p = it.next();
            // and coord column is bigger than the toLevel
            if (children.contains(p.rowIndex)) {
                if (p.columnIndex > toLevelColumnIndex) {
                    toProcess.removeAll(getChildIndexes(p.columnIndex, p.rowIndex));
                } else {
                    // we also remove the coord in case it will be expanded
                    it.remove();
                }
            }
        }
        this.getHiddenRowIndexes().removeAll(toProcess);
        invalidateCache();
        fireLayerEvent(new ShowRowPositionsEvent(this, toProcess));
    } else {
        coord.rowObject = this.underlyingList.get(coord.rowIndex);
        this.collapsedNodes.add(coord);
        this.getHiddenRowIndexes().addAll(toProcess);
        invalidateCache();
        fireLayerEvent(new HideRowPositionsEvent(this, toProcess));
    }
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)

Example 95 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class HideColumnPositionsEvent method getColumnDiffs.

@Override
public Collection<StructuralDiff> getColumnDiffs() {
    Collection<StructuralDiff> columnDiffs = new ArrayList<StructuralDiff>(getColumnPositionRanges().size());
    for (Range range : getColumnPositionRanges()) {
        StructuralDiff diff = new StructuralDiff(DiffTypeEnum.DELETE, range, new Range(range.start, range.start));
        columnDiffs.add(diff);
    }
    return columnDiffs;
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Aggregations

Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)115 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)40 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)23 HashSet (java.util.HashSet)12 Rectangle (org.eclipse.swt.graphics.Rectangle)12 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)9 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)9 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)6 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)6 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)6 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 Point (org.eclipse.swt.graphics.Point)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4