TreeTable with a check box selection model

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

TreeTable with a check box selection model

Postby transcend » Thu Sep 07, 2006 1:10 pm

Hi,

I had been hoping that the TreeTable would have an option to add a check box selection model, similar to CheckBoxTree, but it seems not. Is perhaps already in development? If not, would you consider adding it?

Maybe I am missing an obvious way to use the current libraries to add check boxes to the TreeTable?

Regards,
Doug
transcend
 
Posts: 12
Joined: Tue Aug 01, 2006 7:50 am

Postby transcend » Sun Sep 10, 2006 12:01 pm

Hi,

I case anyone is looking for a solution to the same requirement, I thought I would pass along my solution.

- The column 0 cell renderer uses a custom component derived from JPanel, containing a JCheckBox and a JLabel. This is sufficient for each entry in the tree to display a check box and label (with icon if desired), but you stull need a way to actually check and uncheck the check box. (A listener on the cell rendered doesn't work because it is used only to paint the cell, and ceases to exist afetrwards.)

- When the cell is rendered, store the location and size of the JCheckBox. The point is in the coordinate space of the containing JPanel. You need to translate it up a couple of parent component levels to the coordinate space of the containing TreeTable.

- Add a mouse listener to the TreeTable to listen for the mouse clicks. When a mouse click is detected, ask the table which cell it occurred in. If the cell is in column 0, then find the corresponding row object, retrieve the coordinates of its check box (stored above), and determine if the click was within the check box. If so, change the check box state and fire the row's change handler to trigger a table repaint.

Regards,
Doug
transcend
 
Posts: 12
Joined: Tue Aug 01, 2006 7:50 am

Postby JIDE Support » Sun Sep 10, 2006 12:46 pm

This is pretty much what we did to CheckBoxList and CheckBoxTree. The only question I had is how you persist the checked state of the each row. If using the design as CheckBoxList/CheckBoxTree, we should add a ListSelectionModel and keep the checked state in it.

On the other hand, as we already did CheckBoxList and CheckBoxTree, probably we should further generalize it so that CheckBoxTreeTable can be done as well.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36207
Joined: Sun Sep 14, 2003 10:49 am

Postby transcend » Sun Sep 10, 2006 2:51 pm

Currently I am managing the checked state, including propagating checked changes to tree child and parent nodes as needed, within my derived Row objects, and not in a SelectionModel. When I need to get the current selection I consult the set of Rows to see which are checked. But it would be better to rework this to use a specialized SelectionModel instead. Thanks for the suggestion.

Regards,
Doug
transcend
 
Posts: 12
Joined: Tue Aug 01, 2006 7:50 am

Postby scottguil » Wed Nov 14, 2007 10:50 am

Can you post your code for figuring out the checkbox size and location? I can't seem to figure it out...

Thanks,
Scott
scottguil
 
Posts: 4
Joined: Mon Oct 01, 2007 4:03 pm

Postby transcend » Wed Nov 14, 2007 12:46 pm

Hi Scott,

Sure, here's the summary:

1. To start, we have a static method that can translate a child component's location into a parent container's coordinate space:

Code: Select all
class MyUtils
{
    public static Point translatePointToParentCoordSpace(final Point point,
        Container parent, final int numGenerations)
    {
        final Point newPoint = new Point(point.x, point.y);
        for (int i = 0; i < numGenerations; ++i)
        {
            final Point offset = parent.getLocation();
            newPoint.x += offset.x;
            newPoint.y += offset.y;
            parent = parent.getParent();
        }
        return newPoint;
    }
}


2. Class TristatePanel implements a simple panel with a checkbox and a label layed out on it:

Code: Select all
public class TristatePanel extends JPanel
{
    protected TristateCheckBox tristateCheckBox_m = new TristateCheckBox();
    protected Component strut_m = Box.createHorizontalStrut(3);
    protected JLabel label_m = new JLabel();

    // ...
}


3. Class TristateTableCellRenderer can render a TristatePanel as a table cell:

Code: Select all
public class TristateTableCellRenderer extends TristatePanel
    implements TableCellRenderer
{
    // ...
}


4. Class MyTableColumn uses the TristateTableCellRenderer to render itself in its parent table. The renderer's paint() method is the only opportunity to capture the location to which each cell's checkbox is painted:

Code: Select all
public class MyTableColumn extends TableColumn
{
    private static final TableCellRenderer cellRenderer_m =
        new TristateTableCellRenderer()
            {
                // ...

                @Override
                public void paint(Graphics g)
                {
                    super.paint(g);

                    /*
                     * Translate the location of the TristateCheckBox
                     * subcomponent into the coordinate space of the TreeTable.
                     * Remember that the check box has the following container
                     * hierarchy: TristateCheckBox -> TristatePanel ->
                     * TreeExpandablePanel -> CellRendererPane -> TreeTable. So
                     * we need to translate the check box's Point coordinate
                     * three levels up to get it to the TreeTable's coordinate
                     * space.
                     */
                    if (tristateCheckBox_m.isVisible())
                    {
                        Point locOnParent = tristateCheckBox_m.getLocation();
                        Dimension size = tristateCheckBox_m.getSize();

                        Point pointOnTable =
                            MyUtils.translatePointToParentCoordSpace(
                                locOnParent, tristateCheckBox_m.getParent(), 3);
                        Rectangle rectOnTable =
                            new Rectangle(pointOnTable, size);

         // NOTE: rectOnTable is the value you are looking for.
                    }
                }
            };

    // ...
}


I hope this helps.
transcend
 
Posts: 12
Joined: Tue Aug 01, 2006 7:50 am

Postby scottguil » Wed Nov 14, 2007 3:33 pm

That did it! translatePointToParentCoordSpace helped immensely!

Thanks

Scott
scottguil
 
Posts: 4
Joined: Mon Oct 01, 2007 4:03 pm

Postby JIDE Support » Wed Nov 14, 2007 5:49 pm

Thanks transcend for your help!
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36207
Joined: Sun Sep 14, 2003 10:49 am

Postby transcend » Wed Nov 14, 2007 6:22 pm

I'm happy I could help.

Cheers,
transcend
transcend
 
Posts: 12
Joined: Tue Aug 01, 2006 7:50 am

Re: TreeTable with a check box selection model

Postby lciavonne » Fri Apr 25, 2014 12:55 pm

Was CheckBoxTreeTable functionality ever built into JIDE, or is this still the best way to achieve a TreeTable with CheckBoxTree functionality?
lciavonne
 
Posts: 32
Joined: Tue Jul 02, 2013 6:56 pm

Re: TreeTable with a check box selection model

Postby JIDE Support » Fri Apr 25, 2014 2:12 pm

We never got a chance in making such as component. You can follow transcend's posts to give it a try.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36207
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 2 guests

cron