JAVA GWT cell table action on control click

368 views Asked by At

I have a celltable which consists of 7 columns and 23 rows of checkboxes. I need to add a handler in a way so that when a cell is control+clicked, all cells in the column will toggle if their box is checked or not. I have seen a few similar posts but nothing describing how to handle control+click. (such as: Adding clickHandler to row in CellTable in GWT?). the problem with this method is that it uses a BrowserEvents class which does not have something to match CTRL. Some relevant code for my celltable listed below:

cellTable = new CellTable<TaskSchedule>();
TextColumn<TaskSchedule> taskNameColumn = new TextColumn<TaskSchedule>() {
        @Override
        public void render(Cell.Context context,
                           TaskSchedule object,
                           SafeHtmlBuilder sb) {
            String taskName = getValue(object);


        @Override
        public String getValue(TaskSchedule object) {
            return object.getTaskKey();
        }
    };
cellTable.addColumn(taskNameColumn, "Task Name");
    cellTable.addColumn(createCheckBoxColumn(0), "Monday");
    cellTable.addColumn(createCheckBoxColumn(1), "Tuesday");
    cellTable.addColumn(createCheckBoxColumn(2), "Wednesday");
    cellTable.addColumn(createCheckBoxColumn(3), "Thursday");
    cellTable.addColumn(createCheckBoxColumn(4), "Friday");
    cellTable.addColumn(createCheckBoxColumn(5), "Saturday");
    cellTable.addColumn(createCheckBoxColumn(6), "Sunday");

    cellTable.setColumnWidth(cellTable.getColumn(0), 36, Style.Unit.PCT);
    cellTable.setColumnWidth(cellTable.getColumn(1), 9, Style.Unit.PCT);
    cellTable.setColumnWidth(cellTable.getColumn(2), 9, Style.Unit.PCT);
    cellTable.setColumnWidth(cellTable.getColumn(3), 9, Style.Unit.PCT);
    cellTable.setColumnWidth(cellTable.getColumn(4), 9, Style.Unit.PCT);
    cellTable.setColumnWidth(cellTable.getColumn(5), 9, Style.Unit.PCT);
    cellTable.setColumnWidth(cellTable.getColumn(6), 9, Style.Unit.PCT);
    cellTable.setColumnWidth(cellTable.getColumn(7), 9, Style.Unit.PCT);


    cellTable.setRowData(taskSchedules);
1

There are 1 answers

1
Andrei Volgin On BEST ANSWER

You can use this:

table.addCellPreviewHandler(new Handler<MyObject>() {
    @Override
    public void onCellPreview(CellPreviewEvent<MyObject> event) {
        if ("click".equals(event.getNativeEvent().getType())) {
            if (event.getNativeEvent().getCtrlKey()) {
                // CTRL button was pressed during the click
            }
        }
    }
});