28
28
*/
29
29
package cc .arduino .contributions .ui ;
30
30
31
+ import cc .arduino .contributions .ui .listeners .AbstractKeyListener ;
31
32
import com .google .common .base .Predicate ;
32
33
import processing .app .Base ;
33
34
import processing .app .Theme ;
39
40
import java .awt .*;
40
41
import java .awt .event .ActionEvent ;
41
42
import java .awt .event .ActionListener ;
43
+ import java .awt .event .KeyEvent ;
42
44
import java .awt .event .WindowEvent ;
43
45
44
46
import static cc .arduino .contributions .packages .ui .ContributionIndexTableModel .DESCRIPTION_COL ;
@@ -78,8 +80,6 @@ public abstract class InstallerJDialog<T> extends JDialog {
78
80
protected Box errorMessageBox ;
79
81
private final JLabel errorMessage ;
80
82
81
- protected InstallerTableCell cellEditor ;
82
-
83
83
public InstallerJDialog (Frame parent , String title , ModalityType applicationModal , String noConnectionErrorMessage ) {
84
84
super (parent , title , applicationModal );
85
85
this .noConnectionErrorMessage = noConnectionErrorMessage ;
@@ -104,7 +104,9 @@ public InstallerJDialog(Frame parent, String title, ModalityType applicationModa
104
104
@ Override
105
105
protected void onFilter (String [] _filters ) {
106
106
filters = _filters ;
107
- cellEditor .stopCellEditing ();
107
+ if (contribTable .getCellEditor () != null ) {
108
+ contribTable .getCellEditor ().stopCellEditing ();
109
+ }
108
110
contribModel .updateIndexFilter (categoryFilter , filters );
109
111
}
110
112
};
@@ -130,13 +132,23 @@ protected void onFilter(String[] _filters) {
130
132
contribTable .setIntercellSpacing (new Dimension (0 , 1 ));
131
133
contribTable .setShowVerticalLines (false );
132
134
contribTable .setSelectionBackground (Theme .getColor ("status.notice.bgcolor" ));
135
+ contribTable .addKeyListener (new AbstractKeyListener () {
136
+
137
+ @ Override
138
+ public void keyReleased (KeyEvent keyEvent ) {
139
+ if (keyEvent .getKeyCode () != keyEvent .VK_DOWN && keyEvent .getKeyCode () != KeyEvent .VK_UP ) {
140
+ return ;
141
+ }
142
+
143
+ contribTable .editCellAt (contribTable .getSelectedRow (), contribTable .getSelectedColumn ());
144
+ }
145
+ });
133
146
134
147
{
135
148
TableColumnModel tcm = contribTable .getColumnModel ();
136
149
TableColumn col = tcm .getColumn (DESCRIPTION_COL );
137
150
col .setCellRenderer (createCellRenderer ());
138
- cellEditor = createCellEditor ();
139
- col .setCellEditor (cellEditor );
151
+ col .setCellEditor (createCellEditor ());
140
152
col .setResizable (true );
141
153
}
142
154
@@ -241,8 +253,10 @@ public void setProgressVisible(boolean visible, String status) {
241
253
categoryChooser .setEnabled (!visible );
242
254
contribTable .setEnabled (!visible );
243
255
errorMessageBox .setVisible (false );
244
- cellEditor .setEnabled (!visible );
245
- cellEditor .setStatus (status );
256
+ if (contribTable .getCellEditor () != null ) {
257
+ ((InstallerTableCell ) contribTable .getCellEditor ()).setEnabled (!visible );
258
+ ((InstallerTableCell ) contribTable .getCellEditor ()).setStatus (status );
259
+ }
246
260
}
247
261
248
262
protected ActionListener categoryChooserActionListener = new ActionListener () {
@@ -252,7 +266,9 @@ public void actionPerformed(ActionEvent event) {
252
266
DropdownItem <T > selected = (DropdownItem <T >) categoryChooser .getSelectedItem ();
253
267
if (categoryFilter == null || !categoryFilter .equals (selected )) {
254
268
categoryFilter = selected .getFilterPredicate ();
255
- cellEditor .stopCellEditing ();
269
+ if (contribTable .getCellEditor () != null ) {
270
+ contribTable .getCellEditor ().stopCellEditing ();
271
+ }
256
272
contribModel .updateIndexFilter (categoryFilter , filters );
257
273
}
258
274
}
0 commit comments