Search in sources :

Example 1 with IHierarchicalTableViewState

use of de.jaret.util.ui.table.model.IHierarchicalTableViewState in project translationstudio8 by heartsome.

the class JaretTable method setTableModel.

/**
     * Set a hierarchical table model. This will internally create a StdHierrahicalTableModel that is a normal
     * TbaleModel incluuding only the expanded rows.
     * 
     * @param hmodel hierarchical model to display
     */
public void setTableModel(IHierarchicalJaretTableModel hmodel) {
    if (_model != null) {
        _model.removeJaretTableModelListener(this);
    }
    if (_tvs != null) {
        _tvs.removeTableViewStateListener(this);
    }
    _tvs = new DefaultHierarchicalTableViewState();
    _tvs.addTableViewStateListener(this);
    _model = new StdHierarchicalTableModel(hmodel, (IHierarchicalTableViewState) _tvs);
    _model.addJaretTableModelListener(this);
    _hierarchicalModel = hmodel;
    updateColumnList();
    registerRowsForOptimization();
    updateRowList();
    updateColumnList();
    updateYScrollBar();
    updateXScrollBar();
    redraw();
}
Also used : DefaultHierarchicalTableViewState(de.jaret.util.ui.table.model.DefaultHierarchicalTableViewState) StdHierarchicalTableModel(de.jaret.util.ui.table.model.StdHierarchicalTableModel) IHierarchicalTableViewState(de.jaret.util.ui.table.model.IHierarchicalTableViewState)

Example 2 with IHierarchicalTableViewState

use of de.jaret.util.ui.table.model.IHierarchicalTableViewState in project translationstudio8 by heartsome.

the class TableHierarchyRenderer method draw.

/**
     * {@inheritDoc}
     */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    int offx;
    offx = scaleX(_levelWidth);
    ITableNode node = (ITableNode) row;
    int level = node.getLevel();
    boolean leaf = node.getChildren().size() == 0;
    boolean expanded = ((IHierarchicalTableViewState) jaretTable.getTableViewState()).isExpanded(node);
    int x = drawingArea.x + offx * level + SIZE / 2;
    int y = drawingArea.y + (drawingArea.height - SIZE) / 2;
    if (leaf && !_drawIcons) {
        drawLeaf(gc, SIZE, x, y);
    } else if (expanded && !leaf) {
        if (_nodeMarkType == 1) {
            drawMinus(gc, SIZE, x, y);
        } else if (_nodeMarkType == 2) {
            drawTriangleDown(gc, SIZE, x, y);
        }
    } else if (!leaf) {
        if (_nodeMarkType == 1) {
            drawPlus(gc, SIZE, x, y);
        } else if (_nodeMarkType == 2) {
            drawTriangleRight(gc, SIZE, x, y);
        }
    }
    if (_nodeMarkType != 0) {
        x += SIZE + 4;
    }
    // default for drawing selection
    Rectangle labelrect = drawingArea;
    if (_labelProvider != null && (_drawIcons || _drawLabels)) {
        int labelx = x;
        labelrect = new Rectangle(x, y, 0, 0);
        if (_drawIcons) {
            Image img = _labelProvider.getImage(row);
            if (img != null) {
                if (!printing) {
                    gc.drawImage(img, x, y);
                    labelx += img.getBounds().width;
                    labelrect.width += img.getBounds().width;
                    labelrect.height = img.getBounds().height;
                } else {
                    gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width), scaleY(img.getBounds().height));
                    labelx += scaleX(img.getBounds().width);
                    labelrect.width += scaleX(img.getBounds().width);
                    labelrect.height = scaleY(img.getBounds().height);
                }
            }
        }
        if (_drawLabels) {
            String label = _labelProvider.getText(row);
            if (label != null) {
                gc.drawString(label, labelx, y);
                Point extent = gc.stringExtent(label);
                labelrect.width += extent.x;
                labelrect.height = Math.max(labelrect.height, extent.y);
            }
        }
    }
    // draw tree connections
    if (_drawTree) {
        // TimeBarNode node = (TimeBarNode) row;
        if (printing) {
            gc.setLineWidth(3);
        }
        gc.setLineStyle(SWT.LINE_DOT);
        int midy = drawingArea.y + ((drawingArea.height - SIZE) / 2) + SIZE / 2;
        int icoy = drawingArea.y + ((drawingArea.height - SIZE) / 2) + SIZE;
        int icox = drawingArea.x + offx * (level) + SIZE - SIZE / 2;
        int midx = drawingArea.x + +offx * (level) + SIZE;
        int beginx = drawingArea.x + offx * (level - 1) + SIZE;
        int endx = drawingArea.x + offx * (level + 1) + SIZE;
        // connection
        gc.drawLine(beginx, midy, icox, midy);
        // uplink
        gc.drawLine(beginx, drawingArea.y, beginx, midy);
        // downlink
        if ((!leaf && expanded)) {
            gc.drawLine(midx, icoy, midx, drawingArea.y + drawingArea.height);
        }
        boolean hasMoreSiblings = true;
        if (jaretTable.getTableModel() instanceof StdHierarchicalTableModel) {
            StdHierarchicalTableModel model = (StdHierarchicalTableModel) jaretTable.getTableModel();
            hasMoreSiblings = model.moreSiblings(node, node.getLevel());
        }
        // level lines
        if (jaretTable.getTableModel() instanceof StdHierarchicalTableModel) {
            StdHierarchicalTableModel model = (StdHierarchicalTableModel) jaretTable.getTableModel();
            for (int i = 0; i < level; i++) {
                if (model.moreSiblings(node, i)) {
                    x = drawingArea.x + offx * i + SIZE;
                    gc.drawLine(x, drawingArea.y, x, drawingArea.y + drawingArea.height);
                }
            }
        }
        gc.setLineStyle(SWT.LINE_SOLID);
        gc.setLineWidth(1);
    }
    if (drawFocus) {
        drawFocus(gc, labelrect);
    }
    drawSelection(gc, labelrect, cellStyle, selected, printing);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) IHierarchicalTableViewState(de.jaret.util.ui.table.model.IHierarchicalTableViewState) Image(org.eclipse.swt.graphics.Image) StdHierarchicalTableModel(de.jaret.util.ui.table.model.StdHierarchicalTableModel) ITableNode(de.jaret.util.ui.table.model.ITableNode) Point(org.eclipse.swt.graphics.Point)

Example 3 with IHierarchicalTableViewState

use of de.jaret.util.ui.table.model.IHierarchicalTableViewState in project translationstudio8 by heartsome.

the class JaretTable method toggleExpanded.

/**
     * Toggle the expanded state of a row.
     * 
     * @param row row to toggle
     */
private void toggleExpanded(IRow row) {
    IHierarchicalTableViewState hvs = (IHierarchicalTableViewState) _tvs;
    hvs.setExpanded((ITableNode) row, !hvs.isExpanded((ITableNode) row));
}
Also used : IHierarchicalTableViewState(de.jaret.util.ui.table.model.IHierarchicalTableViewState)

Aggregations

IHierarchicalTableViewState (de.jaret.util.ui.table.model.IHierarchicalTableViewState)3 StdHierarchicalTableModel (de.jaret.util.ui.table.model.StdHierarchicalTableModel)2 DefaultHierarchicalTableViewState (de.jaret.util.ui.table.model.DefaultHierarchicalTableViewState)1 ITableNode (de.jaret.util.ui.table.model.ITableNode)1 Image (org.eclipse.swt.graphics.Image)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1