/
GridSelectionChangedListener.java
66 lines (60 loc) · 2.33 KB
/
GridSelectionChangedListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
* Copyright (c) 2019, 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.app.console.module.data.client;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
/**
* Listener for grid selection changes on Data tab.
*
* @param <M> the model type being selected
*/
public class GridSelectionChangedListener<M extends ModelData> implements Listener<SelectionChangedEvent<M>> {
private GridSelectionModel<M> selectionModel;
protected boolean selectedAgain;
private M selectedItem;
/**
* The constructor
*/
public GridSelectionChangedListener() {
super();
}
/**
* Method for setting the selectionModel
* @param selectionModel
*/
public void setSelectionModel(GridSelectionModel<M> selectionModel) {
this.selectionModel = selectionModel;
}
/**
* Method for handling the SelectionChangedEvent<M> on grid rows.
* This method prevents row deselection using CTRL + Click, by selecting
* the previously chosen value again. In all other cases the row selection
* works as usual.
*
* @param se the selection event
*/
@SuppressWarnings("unchecked")
@Override
public void handleEvent(SelectionChangedEvent<M> se) {
if (selectionModel.getSelectedItem() != null && selectedAgain == false) {
selectedItem = selectionModel.getSelectedItem();
} else if (selectionModel.getSelectedItem() == null) {
selectedAgain = true;
} else if (selectedItem != selectionModel.getSelectedItem()) {
selectedAgain = false;
selectedItem = selectionModel.getSelectedItem();
}
selectionModel.select(false, selectedItem);
}
}